41 JointStatesDeflater::JointStatesDeflater()
46 void JointStatesDeflater::setDeflationJointNames(std::vector<std::string> joint_names)
48 joint_names_ = joint_names;
49 mapping_.resize(joint_names_.size());
52 void JointStatesDeflater::deflate(
const sensor_msgs::JointStateConstPtr& joint_states,
DeflatedJointStates& deflated_elem)
54 if (joint_states->name.size() != joint_states->position.size()){
55 ROS_ERROR(
"JointStatesDeflater got invalid joint state message");
59 if (mapping_.size() != joint_names_.size())
60 updateMapping(*joint_states);
62 const unsigned int N = joint_names_.size();
66 for (
unsigned int i=0; i<
N; i++)
68 if ( mapping_[i] >= joint_states->name.size() )
69 updateMapping(*joint_states);
71 if ( joint_states->name[mapping_[i]] != joint_names_[i])
72 updateMapping(*joint_states);
74 deflated_elem.
header = joint_states->header;
75 deflated_elem.
channels_[i] = joint_states->position[mapping_[i]];
76 deflated_elem.
msg_ = joint_states;
80 void JointStatesDeflater::prune(
const sensor_msgs::JointState& joint_states, sensor_msgs::JointState& pruned_joint_states)
82 if (joint_states.name.size() != joint_states.position.size())
84 ROS_ERROR(
"JointStatesDeflater got invalid joint state message. name's size and position's size don't match.");
88 if (mapping_.size() != joint_names_.size())
89 updateMapping(joint_states);
91 const unsigned int N = joint_names_.size();
94 pruned_joint_states.header.stamp = joint_states.header.stamp;
95 pruned_joint_states.name.resize(N);
96 pruned_joint_states.position.resize(N);
97 pruned_joint_states.velocity.clear();
98 pruned_joint_states.effort.clear();
100 for (
unsigned int i=0; i<
N; i++)
102 if ( mapping_[i] >= joint_states.name.size() )
103 updateMapping(joint_states);
105 if ( joint_states.name[mapping_[i]] != joint_names_[i])
106 updateMapping(joint_states);
108 pruned_joint_states.name[i] = joint_states.name[mapping_[i]];
109 pruned_joint_states.position[i] = joint_states.position[mapping_[i]];
115 void JointStatesDeflater::updateMapping(
const sensor_msgs::JointState& joint_states)
117 ROS_DEBUG(
"Updating the JointStates mapping");
119 const unsigned int N = joint_names_.size();
123 for (
unsigned int i=0; i<
N; i++)
125 bool mapping_found =
false;
126 for (
unsigned int j=0; j<joint_states.name.size(); j++)
128 if ( joint_names_[i] == joint_states.name[j])
131 mapping_found =
true;
134 ROS_ERROR_COND(!mapping_found,
"Couldn't find mapping for [%s]", joint_names_[i].c_str());
sensor_msgs::JointStateConstPtr msg_
#define ROS_ERROR_COND(cond,...)
std::vector< double > channels_
static const unsigned int N