ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

reading xyz form tf/tfMessage

asked 2013-05-21 23:25:35 -0500

Silimon Sorin gravatar image

updated 2016-10-24 09:01:25 -0500

ngrennan gravatar image

hello, I am trying to read xyz from tfMessage which publishes the kinect's translation from the pi_tracker or the openni_launch and i want it sent to tum_simulator..

where is the code

geometry_msgs::Twist command;
ros::Publisher pub_takeoff, pub_land, pub_toggle_state, pub_vel;
geometry_msgs::TransformStamped transforms;
geometry_msgs::Transform transform;
geometry_msgs::Vector3 translation;


using namespace ros;

void chatterCallback(const tf::tfMessage::ConstPtr& mes)

{

    //command.linear=mes;
    command.linear.x = mes->transforms.transform.translation.x;
    //command.linear.y = mes->y;
    //command.linear.z = mes->z;
    //command.angular.z= mes->z;
ROS_INFO("I received %f %f %f %f/n", command.linear.x, command.linear.y, command.linear.z, command.angular.z);
}


int main(int argc, char **argv) {

 //init subscr node
ros::init(argc, argv, "simkin");
// Create a node handle
ros::NodeHandle n;
// Initialize the node
ros::Subscriber sub = n.subscribe("/tf", 1000, chatterCallback);
//ros::spin();


 // A publisher for the movement data
 Publisher pub = n.advertise<geometry_msgs::Twist>("/cmd_vel", 10);

 // Drive forward at a given speed.  The robot points up the x-axis.
 //geometry_msgs::Twist command;


 Rate rate(10);
 while (ok()) {
   pub.publish(command);
   rate.sleep();
   ros::spinOnce();
 }

 return 0;
}

edit retag flag offensive close merge delete

Comments

What is the question? What goes wrong?

davinci gravatar image davinci  ( 2013-05-21 23:32:58 -0500 )edit

it doesn't work,the error is that"transform does not name a type"...I need to read the xyz from the /tf...OR I could you the pi_tracker topic /skeleton which is not so compact but is I put in chatterCallback pi_tracker::skeleton (this is the error:error: ‘pi_tracker’ does not name a type /home/ssr )

Silimon Sorin gravatar image Silimon Sorin  ( 2013-05-22 00:13:56 -0500 )edit

@Silimon Sorin@ngrennan Did you understand how we should do it for kinect? We get transforms of all the skeletal coordinate frames separately. Guess we should receive them separately! Please help

gaussian gravatar image gaussian  ( 2015-01-24 08:54:04 -0500 )edit

2 Answers

Sort by » oldest newest most voted
4

answered 2013-05-22 06:42:08 -0500

ahendrix gravatar image

updated 2013-05-22 07:07:42 -0500

You should use the TF library rather than subscribing to the /tf topic directly. Take a look at the tf documentation and the tf C++ tutorial.

edit flag offensive delete link more

Comments

1

Agreed. The way you access the tf data is not recommended. If you use the tf topic like this, you will receive the data of all transforms in your system. To get the data of a specific transform, use the tf::TransformListener. Have a look at the above linked tutorials to learn how to use it.

bit-pirate gravatar image bit-pirate  ( 2013-05-22 16:19:15 -0500 )edit
0

answered 2018-11-29 01:32:39 -0500

youssef desouky gravatar image

updated 2018-11-29 14:37:04 -0500

ahendrix gravatar image

.

tf::TransformListener frame_listener;

  ros::Rate rate(10.0);

  while (node.ok()){
    tf::StampedTransform right_hand_transform;
    try{
      frame_listener.waitForTransform("/right_hand_1", "/openni_depth_frame", ros::Time(0), ros::Duration(3.0));
      frame_listener.lookupTransform("/right_hand_1", "/openni_depth_frame", ros::Time(0), right_hand_transform);
    }
    catch (tf::TransformException &ex) {
      ROS_ERROR("%s",ex.what());
      ros::Duration(1.0).sleep();
      continue;
    }

  right_hand_x = right_hand_transform.getOrigin().x() * 10;
  right_hand_y = right_hand_transform.getOrigin().y() * 10;
  right_hand_z = right_hand_transform.getOrigin().z() * 10;

  ROS_INFO_STREAM("right_hand_x: " << right_hand_x);
  ROS_INFO_STREAM("right_hand_y: " << right_hand_y);
  ROS_INFO_STREAM("right_hand_z: " << right_hand_z);
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-21 23:25:35 -0500

Seen: 3,455 times

Last updated: Nov 29 '18