Skip to content

Commit 992bac6

Browse files
committed
extend debug_evaluate_jointstates_node to recursively publish cart vel magnitudes for frames of chain
1 parent c652fcc commit 992bac6

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

cob_twist_controller/src/debug/debug_evaluate_jointstates_node.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717

1818
#include <string>
19+
#include <vector>
20+
#include <algorithm>
1921
#include <ros/ros.h>
2022

2123
#include <sensor_msgs/JointState.h>
@@ -38,6 +40,7 @@ class DebugEvaluateJointStates
3840
ros::Subscriber jointstate_sub_;
3941
ros::Publisher manipulability_pub_;
4042
ros::Publisher twist_current_pub_;
43+
ros::Publisher twist_magnitude_pub_;
4144

4245
std::string chain_base_link_;
4346
std::string chain_tip_link_;
@@ -83,6 +86,7 @@ class DebugEvaluateJointStates
8386
jointstate_sub_ = nh_.subscribe("joint_states", 1, &DebugEvaluateJointStates::jointstateCallback, this);
8487
manipulability_pub_ = nh_.advertise<std_msgs::Float64> ("debug/manipulability", 1);
8588
twist_current_pub_ = nh_.advertise<geometry_msgs::Twist> ("debug/twist_current", 1);
89+
twist_magnitude_pub_ = nh_.advertise<sensor_msgs::JointState> ("debug/twist_magnitude", 1);
8690

8791
return 0;
8892
}
@@ -92,20 +96,47 @@ class DebugEvaluateJointStates
9296
KDL::JntArray q = KDL::JntArray(chain_.getNrOfJoints());
9397
KDL::JntArray q_dot = KDL::JntArray(chain_.getNrOfJoints());
9498

95-
for (unsigned int i = 0; i < msg->name.size(); i++)
99+
// //TODO: sort wrt kinematic order
100+
// for (unsigned int i = 0; i < msg->name.size(); i++)
101+
// {
102+
// q(i) = msg->position[i];
103+
// q_dot(i) = msg->velocity[i];
104+
// }
105+
for (unsigned int i = 0; i < chain_.getNrOfJoints(); i++)
96106
{
97-
q(i) = msg->position[i];
98-
q_dot(i) = msg->velocity[i];
107+
std::string joint_name = chain_.getSegment(i).getJoint().getName();
108+
if (std::find(msg->name.begin(), msg->name.end(), joint_name) != msg->name.end())
109+
{
110+
unsigned int index = std::distance(msg->name.begin(), std::find(msg->name.begin(), msg->name.end(), joint_name));
111+
q(index) = msg->position[index];
112+
q_dot(index) = msg->velocity[index];
113+
}
114+
else
115+
{
116+
ROS_ERROR_STREAM("Joint '" << joint_name << "' not found in JointStates");
117+
return;
118+
}
99119
}
100120

101121
/// compute current twist
102-
KDL::FrameVel FrameVel;
122+
std::vector< KDL::FrameVel > v_FrameVel;
103123
KDL::JntArrayVel jntArrayVel = KDL::JntArrayVel(q, q_dot);
104-
if (p_fksolver_vel_->JntToCart(jntArrayVel, FrameVel, -1) >= 0)
124+
v_FrameVel.resize(chain_.getNrOfJoints());
125+
if (p_fksolver_vel_->JntToCart(jntArrayVel, v_FrameVel, chain_.getNrOfJoints()) >= 0)
105126
{
127+
//last entry is twist of tip_link
106128
geometry_msgs::Twist twist_msg;
107-
tf::twistKDLToMsg(FrameVel.GetTwist(), twist_msg);
129+
tf::twistKDLToMsg(v_FrameVel.back().GetTwist(), twist_msg);
108130
twist_current_pub_.publish(twist_msg);
131+
132+
//recursively calculate FrameVel magnitudes
133+
sensor_msgs::JointState magnitude_msg;
134+
for (unsigned int i = 0; i < chain_.getNrOfJoints(); i++)
135+
{
136+
magnitude_msg.name.push_back(chain_.getSegment(i).getName());
137+
magnitude_msg.velocity.push_back(v_FrameVel[i].GetTwist().vel.Norm());
138+
}
139+
twist_magnitude_pub_.publish(magnitude_msg);
109140
}
110141

111142
/// compute manipulability

0 commit comments

Comments
 (0)