Skip to content

Commit fd60940

Browse files
committed
jointStateCB: compare joint names, reject updates with differing names or number of joints
fixes ros-industrial#326 based on gavanderhoorn@e369ddc
1 parent 0bccd6b commit fd60940

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

motoman_driver/src/industrial_robot_client/joint_trajectory_interface.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ bool JointTrajectoryInterface::calc_velocity(const motoman_msgs::DynamicJointsGr
518518
return true;
519519
}
520520

521-
robot_groups_[pt.group_number].get_joint_names();
522521
for (size_t i = 0; i < robot_groups_[pt.group_number].get_joint_names().size(); ++i)
523522
{
524523
const std::string &jnt_name = robot_groups_[pt.group_number].get_joint_names()[i];
@@ -727,12 +726,32 @@ bool JointTrajectoryInterface::is_valid(const motoman_msgs::DynamicJointTrajecto
727726
void JointTrajectoryInterface::jointStateCB(
728727
const sensor_msgs::JointStateConstPtr &msg)
729728
{
729+
if (msg->name.size() != this->all_joint_names_.size())
730+
return;
731+
732+
// compare all names, reject message if a name is not in both lists
733+
for (size_t i=0; i<msg->name.size(); i++)
734+
if (std::find(msg->name.begin(), msg->name.end(), this->all_joint_names_[i]) == msg->name.end())
735+
return;
736+
730737
this->cur_joint_pos_ = *msg;
731738
}
732739

733740
void JointTrajectoryInterface::jointStateCB(
734741
const sensor_msgs::JointStateConstPtr &msg, int robot_id)
735742
{
743+
if (msg->name.size() != this->robot_groups_[robot_id].get_joint_names().size())
744+
{
745+
return;
746+
}
747+
748+
// compare all names, reject message if a name is not in both lists
749+
for (size_t i=0; i<msg->name.size(); i++)
750+
{
751+
if (std::find(msg->name.begin(), msg->name.end(), this->robot_groups_[robot_id].get_joint_names()[i]) == msg->name.end())
752+
return;
753+
}
754+
736755
this->cur_joint_pos_map_[robot_id] = *msg;
737756
}
738757

0 commit comments

Comments
 (0)