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

How to create a node that listens to particular topic and publishes tf

asked 2013-08-08 00:27:43 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

How can I create a node that listens to that particular topic and publishes the required required tf. I have succesfully published data on a topic. Now I want to exhibit it in TF. Do I need a TF broadcaster, something like this

tf::TransformBroadcaster br;
tf::Transform transform;
transform.setOrigin( tf::Vector3(0,0,0)); 
transform.setRotation( tf::Quaternion(x,y,z,w) ); 
br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "optical", "base_link"));

Even If I have something like this. How do I listen and display it. Forexample do I need a tf listener to listen to some topic which is publishing data. If thats the case. What would the code look like if my topic is /mytopic

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2013-08-08 07:34:48 -0600

Here is a piece of code that publishes an odometry transform over tf.

void pub_odom::odom_callback(const nav_msgs::Odometry& odom) {

btVector3 Position;
btQuaternion Orientation;
tf::TransformBroadcaster odom_broadcaster_;
tf::StampedTransform odom_transform;

Position.setValue(odom.pose.pose.position.x,odom.pose.pose.position.y,odom.pose.pose.position.z);
Orientation.setW(odom.pose.pose.orientation.w);
Orientation.setX(odom.pose.pose.orientation.x);
Orientation.setY(odom.pose.pose.orientation.y);
Orientation.setZ(odom.pose.pose.orientation.z);

odom_transform.setOrigin(map_center);
odom_transform.setRotation(tf::Quaternion(tf::Vector3(0,0,1),-yaw_init));
odom_transform.stamp_ = odom.header.stamp;
odom_transform.child_frame_id_= "/odom";
odom_transform.frame_id_= "/center_map";
odom_broadcaster_.sendTransform(odom_transform);}

Hope it helps you

edit flag offensive delete link more

Comments

You also could replace btVector3 and btQuaternion by tf::Vector3 and tf::Quaternion.

BennyRe gravatar image BennyRe  ( 2013-08-08 21:32:10 -0600 )edit

@Mario Garzon Can you please send me a link to your whole package so that I can visualise your package with tf. danke Schoen. Right now i cannot run your program so that I can understand better.

micheal gravatar image micheal  ( 2013-08-10 06:37:40 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-08-08 00:27:43 -0600

Seen: 527 times

Last updated: Aug 08 '13