In this section, we explore the TurtleBot's odometry. The general definition of odometry is the use of data from motion sensors to estimate change in position over time. Odometry is used by the TurtleBot to estimate its position and orientation relative to a starting location given in terms of an x and y position and an orientation around the z (upward) axis. The topic is /odom
and the command to view the form of the /odom
message is as follows:
$ rostopic echo /odom
When you execute this echo
command, the output will be updated continuously on the screen. However, we wish to display TurtleBot's motion using rviz. When the odometry option is chosen in rviz, the TurtleBot's position and orientation will be displayed with arrows that are generated as TurtleBot moves.
The simulated TurtleBot will be used to demonstrate the odometry display possible in rviz.
The commands executed on the remote computer to start Gazebo for simulation and rviz for visualization are as follows:
$ roslaunch turtlebot_gazebo turtlebot_world.launch
In another terminal window, run this command:
$ roslaunch turtlebot_rviz_launchers view_robot.launch
Gazebo includes the physics of the robot and rviz allows a variety of visualization options. In particular, it is useful to show the pose of the robot as indicated by arrows that point in the direction of motion of the TurtleBot on the screen.
In rviz, it is necessary to choose several options to show the TurtleBot's odometry arrows on the screen. As shown in the following screenshot, we choose the following:
To track the motion of the simulated TurtleBot on the screen and display the arrows, we issue a movement command. Once the two screens are up for Gazebo and rviz, any commands to move the robot are possible, including the execution of a Python script. For example, in a third terminal window, issue one of the following commands to make the TurtleBot move in a circle on the screen:
$ rostopic pub -r 10 /cmd_vel_mux/input/teleop geometry_msgs/Twist '{linear: {x: 0.1, y: 0, z: 0}, angular: {x: 0, y: 0, z: -0.5}}' $ rostopic pub -r 10 /mobile_base/commands/velocity geometry_msgs/Twist '{linear: {x: 0.1, y: 0, z: 0}, angular: {x: 0, y: 0, z: -0.5}}'
The result is the same in terms of the movement of the robot in our examples, but the /mobile_base/commands/velocity
topic is used to control the mobile base as explained in the Kobuki tutorial at: http://wiki.ros.org/kobuki/Tutorials/Kobuki's%20Control%20System.
The /cmd_vel_mux
variable is used to multiplex velocity commands from different sources, such as the keyboard or a Python script. Either commands make the TurtleBot move in a circle with the result shown in the following screenshot:
The commands used in simulation can be used with the physical TurtleBot. After bringing up the real TurtleBot with the minimal launch, start rviz on the remote computer:
$ roslaunch turtlebot_rviz_launchers view_robot.launch
TurtleBot will appear in rviz, as shown in the following screenshot:
Then, set up rviz with odom for Fixed Frame and navigate to Add | By topic | Odometry, as was done with the simulated TurtleBot.
Run the following command to move TurtleBot in a circle:
$ rostopic pub -r 10 /mobile_base/commands/velocity geometry_msgs/Twist '{linear: {x: 0.1, y: 0, z: 0}, angular: {x: 0, y: 0, z: -0.5}}'
Stop the TurtleBot by pressing Ctrl + C with focus on the window in which you executed the command to move the robot.
In the following screenshot, TurtleBot's turning was stopped by pressing Ctrl + C, and the Python script was executed that drives TurtleBot straight forward until the Ctrl + C keys are pressed again.
The command is as follows:
$ python ControlTurtleBot.py