5. TF

TF is ROS’s way of determining the robot’s location and relationships between coordinate frames.  For more comprehensive explanation about TF, click here.

5.1 The robot’s transforms

5.1.1 odom -> base_link

This transform is the relationship between the robot’s current position from its origin. This transform is broadcasted concurrently as /odom topic is published from lino_base_node. Below is the block of commented codes where the TF is broadcasted. /linorobot/src/lino_base_node.cpp

geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw(theta);
geometry_msgs::TransformStamped odom_trans;
odom_trans.header.frame_id = "odom";
odom_trans.child_frame_id = "base_link";

//robot's position in x,y, and z
odom_trans.transform.translation.x = x_pos;
odom_trans.transform.translation.y = y_pos;
odom_trans.transform.translation.z = 0.0;

//robot's heading in quaternion
odom_trans.transform.rotation = odom_quat;
odom_trans.header.stamp = current_time;
//publish robot's tf using odom_trans object

5.1.2 base_link -> laser

This transform is the static relationship between the lidar and the robot’s base. Basically, this tells ROS the lidar’s offset in x, y and z axis from the center of the robot’s base. Imagine a lidar (mounted behind a 10cm long base) detects an obstacle 10 cm in front of the robot. The actual distance of the robot from the obstacle would be 5 cm since there’s a 5 cm offset from the center of the base to the rear. Without this transform, the robot would have hit the obstacle prematurely as it thinks that the obstacle is still 10 cm away when it’s only 5cm away from the obstacle.

5.2 Configuring Laser’s TF

Open laser.launch:

nano ~/catkin_ws/src/linorobot/launch/laser.launch

Determine the lidar’s location from the center of the base and change the first three numbers in “args” to your measured offsets. What these values mean is that the lidar is 6.5 cm forward and 19.6 cm from the ground.

You can Click here to know more about configuring your transforms.

<node pkg="tf" type="static_transform_publisher" name="base_link_to_laser"
args="0.065 0 0.196 0 0 0  /base_link /laser  100"/>

5.3 Checking Laser’s TF

Open two terminals on the robot’s computer.

Run bringup.launch:

roslaunch linorobot bringup.launch

Run laser.launch:

roslaunch linorobot laser.launch

On your development computer, run rviz:

rosrun rviz rviz

Once rviz is open, import laser.rviz by clicking File > Config and choose ~/catkin_ws/src/lino_visualize/rviz/laser.rviz. 

Place the robot 1 m away from a wall. Check on rviz if the wall detected is~1m. Each square in rviz is 1 square meter.

Screenshot from 2016-02-29 00:11:03

5.4 Troubleshooting

If the wall detected on rviz doesn’t match with the actual distance between the wall and the robot, confirm that your x, y, and z offsets defined at laser.launch are correct.

6. Creating a map

The robot is all set. Continue to creating a map for SLAM.