is it possible that i want the transform of one link only, in order to get their specific coordinate?
To get the coordinates of a joint you need a fixed frame (such as world
or map
) otherwise any joint could have any coordinates depending the frame you are reading the coordinates from.
rosrun tf tf_echo /world /joint
This command can give you the coordinates of a specific joint in the world (can be map
or any other frame that is fixed in your world). You will be able to read those coordinates in the terminal but given what you said I assume you actually want to get those coordinates in your code to process them.
You will achieve that using tf
by checking the transformation between your reference frame and your desired joint. Here's an example using geometry_msgs::PoseStamped
(to get x
, y
, z
) to constantly get the coordinates of a joint :
//Required includes
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#include <tf2_ros/transform_listener.h>
tf2_ros::Buffer tf_;
geometry_msgs::PoseStamped joint_global_frame_pose_stamped;
geometry_msgs::PoseStamped joint_pose_stamped;
//Just an initialization
tf2::toMsg(tf2::Transform::getIdentity(), joint_global_frame_pose_stamped.pose);
tf2::toMsg(tf2::Transform::getIdentity(), joint_pose_stamped.pose);
ros::Rate rate(10.0);
while(ros::ok())
{
//The frame you want to get the pose
joint_pose_stamped.header.frame_id = "joint";
joint_pose_stamped.header.stamp = ros::Time();
//Catch exceptions
try
{
//3rd param = The global frame
tf_.transform(joint_pose_stamped, joint_global_frame_pose_stamped, "map");
}
catch (tf2::LookupException& ex)
{
ROS_ERROR_THROTTLE(1.0, "No Transform available Error looking up joint pose: %s\n", ex.what());
}
catch (tf2::ConnectivityException& ex)
{
ROS_ERROR_THROTTLE(1.0, "Connectivity Error looking up joint pose: %s\n", ex.what());
}
catch (tf2::ExtrapolationException& ex)
{
ROS_ERROR_THROTTLE(1.0, "Extrapolation Error looking up joint pose: %s\n", ex.what());
}
ROS_INFO("The joint position is { %.2f; %.2f; %.2f}",
joint_global_frame_pose_stamped.pose.postion.x,
joint_global_frame_pose_stamped.pose.postion.y,
joint_global_frame_pose_stamped.pose.postion.z);
}
rosrun tf view_frames
- will generate a pdf of the tf tree and save where your terminal is currentlyrosrun rqt_tf_tree rqt_tf_tree
- will show that same tree in a rqt pluginrosrun tf tf_echo /base_link /gripper
- will print out the transforms between the two links if it is being publishedrostopic echo /joint_states -n 1
will print only 1 message from the topic joint_state_publisherIf you need any other info please provide more specific info on what you would like to achieve.
Thanks for your reply. but I would like to know the actual coordinate* of each of the joint instead of angle, because I will substitute the angles for each of the joint in forward kinematic, while want the feedback of each of the x,y,z coordinate of each of the joint. Thanks
I wonder with the rosrun tf tf_echo /base_link /gripper, if gives out the transform between two links, but is it possible that i want the transform of one link only, in order to get their specific coordinate? Thanks in advance.