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

TF tutorials question

asked 2016-08-08 20:33:54 -0600

patrchri gravatar image

updated 2016-08-10 12:40:04 -0600


I am new to tf and in ros in general - so some follow up questions may rise. My main questions will be marked with bold. I have built a 3 wheel robot on which I have put a lidar (hokuyo_link) and I am trying to setup the tf for my robot. I have managed to manipulate the lidar data for some simple obstacle avoidance movements, but my aim is to use the navigation stack and a main prerequisite for that is the tf. So what I am trying to implement is a odom -> base_link -> hokuyo_link tf, if I have understood correctly the logic.

For a start, I want to create a tf between my lidar and my base_link. For this purpose, I am following this tutorial and I have some questions.

I have wrote a broadcaster -do I need this broadcaster or it is implemented automatically from gazebo during simulation? - copied from the tutorial but changed with my geometric data, and I am trying to write a listener:

#include <ros/ros.h>
#include <geometry_msgs/PointStamped.h>
#include <tf/transform_listener.h>

void transformPoint(const tf::TransformListener& listener){
  //we'll create a point in the base_laser frame that we'd like to transform to the base_link frame
  geometry_msgs::PointStamped laser_point;
  laser_point.header.frame_id = "hokuyo_link";

  //we'll just use the most recent transform available for our simple example
  laser_point.header.stamp = ros::Time();

  //just an arbitrary point in space
  laser_point.point.x = 1.0;
  laser_point.point.y = 0.2;
  laser_point.point.z = 0.0;

    geometry_msgs::PointStamped base_point;
    listener.transformPoint("base_link", laser_point, base_point);

    ROS_INFO("base_laser: (%.2f, %.2f. %.2f) -----> base_link: (%.2f, %.2f, %.2f) at time %.2f",
        laser_point.point.x, laser_point.point.y, laser_point.point.z,
        base_point.point.x, base_point.point.y, base_point.point.z, base_point.header.stamp.toSec());
  catch(tf::TransformException& ex){
    ROS_ERROR("Received an exception trying to transform a point from \"hokuyo_link\" to \"base_link\": %s", ex.what());

int main(int argc, char** argv){
  ros::init(argc, argv, "robot_tf_listener");
  ros::NodeHandle n;

  tf::TransformListener listener(ros::Duration(10));

  //we'll transform a point once every second
  ros::Timer timer = n.createTimer(ros::Duration(1.0), boost::bind(&transformPoint, boost::ref(listener)));



The only thing I changed is the name used for the laser link. The arbitrary point used in the tutorial are in my case my lidar data? And also, if my previous question has a positive answer, this means that the node that listens to the tf channel, needs to subscribe to the /laser/scan topic to get the data ?

Thanks for your answers and for your time in advance, Chris

P.S.: I am sorry if my question seems messed up, I am new to ros.

edit retag flag offensive close merge delete


robot_state_publisher should do all tf broadcasting for you but I still dont understand what are you trying to do. You just want to complete tutorial and you encountered some problem or you want to use lidar for mapping ?

Chickenman gravatar image Chickenman  ( 2016-08-09 18:50:18 -0600 )edit here is how to use robot_state_publisher with your robot urdf

Chickenman gravatar image Chickenman  ( 2016-08-09 18:55:34 -0600 )edit

I want to use lidar for mapping and I am also trying to understand tf through this tutorial, because I read that tf is important to achieve mapping.

patrchri gravatar image patrchri  ( 2016-08-10 09:15:24 -0600 )edit

I want to clear out the definitions of broadcaster and listener. To be more specific, I have created the robot's URDF model and I am using gazebo for simulations and I am trying to adjust the tutorial to my robot. The 3 questions posted are my main barriers for now...

patrchri gravatar image patrchri  ( 2016-08-10 09:18:53 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-10 15:32:11 -0600

Chickenman gravatar image

updated 2016-08-10 15:34:07 -0600

Ok so I try to answer your questions. I dont have very good english so I hope you will understand.

1 When you load your urdf on a parameter server and then you run robot state publisher. It could create transformations for your robot. You dont need to create broadcaster. Robot state publisher will take as a parameter your robot_description and use it for creating transformations

2 This tutorial has nothing to do with mapping. It just shows and explains trasnformations. In the first part you create broadcaster which broadcasts transformation between base_laser and base_link. Then you choose arbitrary point in coordinate system of base_laser and transform it to coordinate system of base_link. And thats all, transformation represents rotation and translation in space. image description For better understanding I recommended you to watch this video . Transformation is global concept used everywhere in robotics graphics and so on not just in ROS.

3 I dont know if you understand the issue but this topic represent and defines a data from laser scan. TF is just used to locate laser_base in space relative to the robot_base.

Last thing. Feel free to ask I am beginner too and I also don't understand everything. Year before when I began with ros I had same questions as you. I know my explanation is also not the best but I hope it helps.

edit flag offensive delete link more


Thank you for your in detail answer and also for your time. I will post my questions in different comments due to character's limitations.

1) So in .launch file that I use to roslaunch my robot in gazebo, i have to add the state publisher's tags and then I will have the necessary broadcasters ?

patrchri gravatar image patrchri  ( 2016-08-10 20:03:04 -0600 )edit

2) So my tf_listener (except from the /tf topic) will also listen to the /laser topic to get the data and then transform them to base_link's local coordinate system in the same logic that the tutorial's code does for the arbitrary point ?

patrchri gravatar image patrchri  ( 2016-08-10 20:05:12 -0600 )edit

3) Yes, I have used the data and I managed to implement a simple obstacle avoidance program, but now I want to use the hector_mapping node and generally slam algorithms, that's why I try to understand tf. I am using ros for 4-5 weeks and I am trying to learn it to its full extend (slowly) :)

patrchri gravatar image patrchri  ( 2016-08-10 20:07:57 -0600 )edit

When someones says that I have the odom->base_link->laser tree, doesn't this mean that he uses tf_listeners ?

patrchri gravatar image patrchri  ( 2016-08-10 20:10:14 -0600 )edit

Question Tools



Asked: 2016-08-08 20:33:54 -0600

Seen: 914 times

Last updated: Aug 10 '16