Skip to content

Commit d6b0361

Browse files
committed
fix getNrOfJoints vs getNrOfSegments and fixed joint handling
1 parent 02a5a7b commit d6b0361

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

cob_twist_controller/src/debug/debug_evaluate_jointstates_node.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,36 @@ class DebugEvaluateJointStates
116116
// q(i) = msg->position[i];
117117
// q_dot(i) = msg->velocity[i];
118118
// }
119-
for (unsigned int i = 0; i < chain_.getNrOfJoints(); i++)
119+
for (unsigned int i = 0; i < chain_.getNrOfSegments(); i++)
120120
{
121-
std::string joint_name = chain_.getSegment(i).getJoint().getName();
122-
if (std::find(msg->name.begin(), msg->name.end(), joint_name) != msg->name.end())
121+
KDL::Joint joint = chain_.getSegment(i).getJoint();
122+
std::string joint_name = joint.getName();
123+
if (joint.getType() == KDL::Joint::None)
123124
{
124-
unsigned int index = std::distance(msg->name.begin(), std::find(msg->name.begin(), msg->name.end(), joint_name));
125-
q(index) = msg->position[index];
126-
q_dot(index) = msg->velocity[index];
125+
ROS_DEBUG_STREAM("Skip fixed Joint '" << joint_name);
126+
continue;
127127
}
128-
else
128+
else
129129
{
130-
ROS_ERROR_STREAM("Joint '" << joint_name << "' not found in JointStates");
131-
return;
130+
if (std::find(msg->name.begin(), msg->name.end(), joint_name) != msg->name.end())
131+
{
132+
unsigned int index = std::distance(msg->name.begin(), std::find(msg->name.begin(), msg->name.end(), joint_name));
133+
q(index) = msg->position[index];
134+
q_dot(index) = msg->velocity[index];
135+
}
136+
else
137+
{
138+
ROS_ERROR_STREAM("Joint '" << joint_name << "' not found in JointStates");
139+
return;
140+
}
132141
}
133142
}
134143

135144
/// compute current twist
136145
std::vector< KDL::FrameVel > v_FrameVel;
137146
KDL::JntArrayVel jntArrayVel = KDL::JntArrayVel(q, q_dot);
138-
v_FrameVel.resize(chain_.getNrOfJoints());
139-
if (p_fksolver_vel_->JntToCart(jntArrayVel, v_FrameVel, chain_.getNrOfJoints()) >= 0)
147+
v_FrameVel.resize(chain_.getNrOfSegments());
148+
if (p_fksolver_vel_->JntToCart(jntArrayVel, v_FrameVel, chain_.getNrOfSegments()) >= 0)
140149
{
141150
//last entry is twist of tip_link
142151
geometry_msgs::Twist twist_msg;
@@ -146,7 +155,7 @@ class DebugEvaluateJointStates
146155
//recursively calculate FrameVel magnitudes
147156
sensor_msgs::JointState magnitude_msg;
148157
magnitude_msg.header.stamp = msg->header.stamp;
149-
for (unsigned int i = 0; i < chain_.getNrOfJoints(); i++)
158+
for (unsigned int i = 0; i < chain_.getNrOfSegments(); i++)
150159
{
151160
magnitude_msg.name.push_back(chain_.getSegment(i).getName());
152161
magnitude_msg.velocity.push_back(v_FrameVel[i].GetTwist().vel.Norm());

0 commit comments

Comments
 (0)