Skip to content

Commit

Permalink
publish digital input data sepalatery
Browse files Browse the repository at this point in the history
  • Loading branch information
seiga-k committed Apr 15, 2024
1 parent c38f7b8 commit 70f7ba7
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/ypspur_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class YpspurRosNode
bool output_;
};
bool digital_input_enable_;
bool digital_input_discrete_;
std::vector<AdParams> ads_;
std::vector<DioParams> dios_;
const int ad_num_ = 8;
Expand Down Expand Up @@ -482,6 +483,9 @@ class YpspurRosNode
pnh_, "ad/" + ads_[i].name_, 1);
}
digital_input_enable_ = false;
pnh_.param("descrete_input", digital_input_discrete_, false);
if (digital_input_discrete_)
ROS_INFO("Digital input publish separatly");
dio_output_default_ = 0;
dio_dir_default_ = 0;
dios_.resize(dio_num_);
Expand All @@ -507,6 +511,12 @@ class YpspurRosNode
pnh_, param.name_, 1,
boost::bind(&YpspurRosNode::cbDigitalOutput, this, _1, i));
}
else if (digital_input_discrete_ && param.input_)
{
pubs_["di/" + param.name_] = compat::advertise<std_msgs::Bool>(
nh_, "di/" + param.name_,
pnh_, "di/" + param.name_, 1);
}

std::string output_default;
pnh_.param(std::string("dio") + std::to_string(i) + std::string("_default"),
Expand Down Expand Up @@ -538,7 +548,7 @@ class YpspurRosNode
}
dio_output_ = dio_output_default_;
dio_dir_ = dio_dir_default_;
if (digital_input_enable_)
if (digital_input_enable_ && !digital_input_discrete_)
{
pubs_["din"] = compat::advertise<ypspur_ros::DigitalInput>(
nh_, "digital_input",
Expand Down Expand Up @@ -1142,13 +1152,23 @@ class YpspurRosNode
{
if (!dios_[i].enable_)
continue;
din.name.push_back(dios_[i].name_);
if (in & (1 << i))
din.state.push_back(true);
else
din.state.push_back(false);
if (!digital_input_discrete_)
{
din.name.push_back(dios_[i].name_);
if (in & (1 << i))
din.state.push_back(true);
else
din.state.push_back(false);
}
else if (dios_[i].input_)
{
std_msgs::Bool di;
di.data = in & (1 << i);
pubs_["di/" + dios_[i].name_].publish(di);
}
}
pubs_["din"].publish(din);
if (!digital_input_discrete_)
pubs_["din"].publish(din);
}

for (int i = 0; i < dio_num_; i++)
Expand Down

0 comments on commit 70f7ba7

Please sign in to comment.