23 #include <sensor_msgs/JointState.h> 24 #include <control_msgs/JointTrajectoryControllerState.h> 25 #include <std_msgs/Float64.h> 26 #include <geometry_msgs/Twist.h> 29 #include <kdl/chainfksolvervel_recursive.hpp> 30 #include <kdl/chainjnttojacsolver.hpp> 31 #include <kdl/frames.hpp> 32 #include <kdl/jntarray.hpp> 33 #include <kdl/jntarrayvel.hpp> 35 #include <Eigen/Dense> 58 if (!nh_.
getParam(
"chain_base_link", this->chain_base_link_))
60 ROS_ERROR(
"Failed to get parameter \"chain_base_link\".");
64 if (!nh_.
getParam(
"chain_tip_link", this->chain_tip_link_))
66 ROS_ERROR(
"Failed to get parameter \"chain_tip_link\".");
74 ROS_ERROR(
"Failed to construct kdl tree");
78 my_tree.
getChain(this->chain_base_link_, this->chain_tip_link_, chain_);
81 ROS_ERROR(
"Failed to initialize kinematic chain");
86 ROS_WARN(
"~~~~~~~~~~~~~ DEBUG CHAIN ~~~~~~~~~~~~~");
97 ROS_WARN(
"~~~~~~~~~~~~~ DEBUG CHAIN ~~~~~~~~~~~~~");
105 manipulability_pub_ = nh_.
advertise<std_msgs::Float64> (
"debug/manipulability", 1);
106 twist_current_pub_ = nh_.
advertise<geometry_msgs::Twist> (
"debug/twist_current", 1);
107 twist_magnitude_desired_pub_ = nh_.
advertise<sensor_msgs::JointState> (
"debug/twist_magnitude/desired", 1);
108 twist_magnitude_actual_pub_ = nh_.
advertise<sensor_msgs::JointState> (
"debug/twist_magnitude/actual", 1);
122 std::string joint_name = joint.
getName();
130 if (std::find(msg->name.begin(), msg->name.end(), joint_name) != msg->name.end())
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];
145 std::vector< KDL::FrameVel > v_FrameVel;
151 geometry_msgs::Twist twist_msg;
153 twist_current_pub_.
publish(twist_msg);
156 sensor_msgs::JointState magnitude_msg;
157 magnitude_msg.header.stamp = msg->header.stamp;
161 magnitude_msg.velocity.push_back(v_FrameVel[i].GetTwist().vel.Norm());
163 twist_magnitude_actual_pub_.
publish(magnitude_msg);
169 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> prod = jac.data * jac.data.transpose();
170 double d = prod.determinant();
171 double kappa = std::sqrt(std::abs(d));
172 std_msgs::Float64 manipulability_msg;
173 manipulability_msg.data = kappa;
174 manipulability_pub_.
publish(manipulability_msg);
187 std::string joint_name = joint.
getName();
195 if (std::find(msg->joint_names.begin(), msg->joint_names.end(), joint_name) != msg->joint_names.end())
197 unsigned int index = std::distance(msg->joint_names.begin(), std::find(msg->joint_names.begin(), msg->joint_names.end(), joint_name));
198 q_desired(index) = msg->desired.positions[index];
199 q_desired_dot(index) = msg->desired.velocities[index];
200 q_actual(index) = msg->actual.positions[index];
201 q_actual_dot(index) = msg->actual.velocities[index];
205 ROS_ERROR_STREAM(
"Joint '" << joint_name <<
"' not found in JointTrajectoryControllerState");
212 std::vector< KDL::FrameVel > v_FrameVel_desired;
217 sensor_msgs::JointState magnitude_desired_msg;
218 magnitude_desired_msg.header.stamp = msg->header.stamp;
222 magnitude_desired_msg.velocity.push_back(v_FrameVel_desired[i].GetTwist().vel.Norm());
224 twist_magnitude_desired_pub_.
publish(magnitude_desired_msg);
227 std::vector< KDL::FrameVel > v_FrameVel_actual;
232 sensor_msgs::JointState magnitude_actual_msg;
233 magnitude_actual_msg.header.stamp = msg->header.stamp;
237 magnitude_actual_msg.velocity.push_back(v_FrameVel_actual[i].GetTwist().vel.Norm());
239 twist_magnitude_actual_pub_.
publish(magnitude_actual_msg);
246 int main(
int argc,
char** argv)
248 ros::init(argc, argv,
"debug_fk_vel_recursive_node");
251 if (dfvr.
init() != 0)
253 ROS_ERROR(
"Failed to initialize DebugFkVelRecursive.");
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
unsigned int getNrOfSegments() const
ros::Publisher twist_current_pub_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
const Segment & getSegment(unsigned int nr) const
ros::Publisher twist_magnitude_desired_pub_
ros::Publisher twist_magnitude_actual_pub_
ros::Publisher manipulability_pub_
int main(int argc, char **argv)
void controllerstateCallback(const control_msgs::JointTrajectoryControllerState::ConstPtr &msg)
const Joint & getJoint() const
void publish(const boost::shared_ptr< M > &message) const
unsigned int getNrOfJoints() const
ros::Subscriber joint_states_sub_
bool getParam(const std::string &key, std::string &s) const
void twistKDLToMsg(const KDL::Twist &k, geometry_msgs::Twist &m)
bool getChain(const std::string &chain_root, const std::string &chain_tip, Chain &chain) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
const JointType & getType() const
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
void jointstatesCallback(const sensor_msgs::JointState::ConstPtr &msg)
virtual int JntToCart(const JntArrayVel &q_in, FrameVel &out, int segmentNr=-1)
KDL_PARSER_PUBLIC bool treeFromParam(const std::string ¶m, KDL::Tree &tree)
ros::Subscriber controller_state_sub_
KDL::ChainFkSolverVel_recursive * p_fksolver_vel_
KDL::ChainJntToJacSolver * p_jnt2jac_
const std::string & getName() const
std::string chain_base_link_
const std::string & getName() const
#define ROS_ERROR_STREAM(args)
virtual int JntToJac(const JntArray &q_in, Jacobian &jac, int seg_nr=-1)
std::string chain_tip_link_