16
16
17
17
18
18
#include < string>
19
+ #include < vector>
20
+ #include < algorithm>
19
21
#include < ros/ros.h>
20
22
21
23
#include < sensor_msgs/JointState.h>
@@ -38,6 +40,7 @@ class DebugEvaluateJointStates
38
40
ros::Subscriber jointstate_sub_;
39
41
ros::Publisher manipulability_pub_;
40
42
ros::Publisher twist_current_pub_;
43
+ ros::Publisher twist_magnitude_pub_;
41
44
42
45
std::string chain_base_link_;
43
46
std::string chain_tip_link_;
@@ -83,6 +86,7 @@ class DebugEvaluateJointStates
83
86
jointstate_sub_ = nh_.subscribe (" joint_states" , 1 , &DebugEvaluateJointStates::jointstateCallback, this );
84
87
manipulability_pub_ = nh_.advertise <std_msgs::Float64> (" debug/manipulability" , 1 );
85
88
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 );
86
90
87
91
return 0 ;
88
92
}
@@ -92,20 +96,47 @@ class DebugEvaluateJointStates
92
96
KDL::JntArray q = KDL::JntArray (chain_.getNrOfJoints ());
93
97
KDL::JntArray q_dot = KDL::JntArray (chain_.getNrOfJoints ());
94
98
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++)
96
106
{
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
+ }
99
119
}
100
120
101
121
// / compute current twist
102
- KDL::FrameVel FrameVel ;
122
+ std::vector< KDL::FrameVel > v_FrameVel ;
103
123
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 )
105
126
{
127
+ // last entry is twist of tip_link
106
128
geometry_msgs::Twist twist_msg;
107
- tf::twistKDLToMsg (FrameVel .GetTwist (), twist_msg);
129
+ tf::twistKDLToMsg (v_FrameVel. back () .GetTwist (), twist_msg);
108
130
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);
109
140
}
110
141
111
142
// / compute manipulability
0 commit comments