0
$\begingroup$

Rosanswers logo

Hello,

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;

  try{
    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)));

  ros::spin();

}

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.


Originally posted by patrchri on ROS Answers with karma: 354 on 2016-08-08

Post score: 0


Original comments

Comment by Chickenman on 2016-08-09:
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 ?

Comment by Chickenman on 2016-08-09:
http://wiki.ros.org/robot_state_publisher/Tutorials/Using%20the%20robot%20state%20publisher%20on%20your%20own%20robot here is how to use robot_state_publisher with your robot urdf

Comment by patrchri on 2016-08-10:
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.

Comment by patrchri on 2016-08-10:
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...

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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 https://www.youtube.com/watch?v=rTN4nawkrZs . 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 http://docs.ros.org/api/sensor_msgs/html/msg/LaserScan.html 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.


Originally posted by Chickenman with karma: 110 on 2016-08-10

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by patrchri on 2016-08-10:
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 ?

Comment by patrchri on 2016-08-10:
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 ?

Comment by patrchri on 2016-08-10:
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) :)

Comment by patrchri on 2016-08-10:
When someones says that I have the odom->base_link->laser tree, doesn't this mean that he uses tf_listeners ?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.