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...