In this section, we explore the TurtleBot's odometry. The general definition of odometry is the use of data from motion sensors, such as wheel encoders, to estimate change in Turtlebot's position over time. Odometry is used by the TurtleBot to estimate its position and orientation relative to its starting location given in terms of an x and y position and an orientation around the z (upward) axis as the TurtleBot moves.
The odometry data to determine position and orientation can become very inaccurate as the TurtleBot moves a long distance. The inaccuracy can be due to errors in the robot's parameters such as incorrect wheel diameters used in calculation of distance or due to the uneven driving surfaces causing the wheel encoders to output inaccurate data. A comprehensive discussion of odometry is found in the paper Measurement and Correction of Systematic Odometry Errors in Mobile Robots by Johann Borenstein and Liqiang Feng. The paper can be found at the following site: http://www-personal.umich.edu/~johannb/Papers/paper58.pdf.
For the TurtleBot 2's Kobuki base, the odometry data published combines outputs from wheel encoders and the Kobuki's Inertial Measurement Unit (IMU) to determine TurtleBot's position and orientation relative to the starting pose. The form of the odometry data is found by typing several commands to determine the type and then the message format. First, type the following command:
$ rostopic type /odom
This yields the message type:
nav_msgs/Odometry
Then, determine the format of the message by typing the following command:
$ rosmsg show nav_msgs/Odometry
The message yields the following information:
std_msgs/Header header uint32 seq time stamp string frame_id string child_frame_id geometry_msgs/PoseWithCovariance pose geometry_msgs/Pose pose geometry_msgs/Point position float64 x float64 y float64 z geometry_msgs/Quaternion orientation float64 x float64 y float64 z float64 w float64[36] covariance geometry_msgs/TwistWithCovariance twist geometry_msgs/Twist twist geometry_msgs/Vector3 linear float64 x float64 y float64 z geometry_msgs/Vector3 angular float64 x float64 y float64 z float64[36] covariance
The nav_msgs/Odometry
type contains header and other information as well as geometry_msgs
, which contain the position, orientation, linear velocity, and angular velocity of TurtleBot. The pose
of TurtleBot is defined in terms of position and orientation by the geometry_msgs/Pose
messages. The linear and angular velocities are given by the geometry_msgs/Twist
messages. The structure for the pose
is pose/pose/position
or pose/pose/orientation
. We will demonstrate several variations of the rostopic echo odom
command to explain its use.
Typing the following command:
$ rostopic echo /odom
This yields a typical output similar to the following with TurtleBot stopped at an arbitrary position and orientation:
header: seq: 135240 stamp: secs: 1496265119 nsecs: 103228903 frame_id: odom child_frame_id: base_footprint pose: pose: position: x: 0.190646478751 y: 0.255858923656 z: 0.0 orientation: x: 0.0 y: 0.0 z: -0.634932792625 w: 0.772567374958 covariance: [0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.7976931348623157e+308, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.7976931348623157e+308, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.7976931348623157e+308, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.05] twist: twist: linear: x: 0.0 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: -0.00174532925199 covariance: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] ---
When you execute this rostopic echo
command, the output will be updated continuously on the screen. The output here indicates that TurtleBot is at the point in x, y about (0.19, 0.26) meters from the (0,0) value of TurtleBot's original position.
To reset the odometry values to zero after the TurtleBot has moved, you can find the message type by typing:
$ rostopic type /mobile_base/commands/reset_odometry std_msgs/Empty
Then publish the message to reset the odometry values by typing:
$ rostopic pub /mobile_base/commands/reset_odometry std_msgs/Empty
This yields the following output:
publishing and latching message. Press ctrl-C to terminate
If only the position and orientation of TurtleBot are desired, they can be found by typing:
$ rostopic echo /odom/pose/pose
with the result is as follows for TurtleBot at its origin:
position: x: 0.0 y: 0.0 z: 0.0 orientation: x: 0.0 y: 0.0 z: 0.0 w: 1.0
This indicates that the TurtleBot is at the (0,0) position pointing in its +x direction. This position and orientation occurs as a result of the TurtleBot minimal launch or after the odometry values are reset.
The IMU data can be displayed with the following command:
$ rostopic echo /mobile_base/sensors/imu_data
The IMU data for TurtleBot indicates the orientation as a quaternion, the angular velocity about the z axis, and the linear acceleration. The orientation values are the same as for the /odom
topic since the orientation is determined by the IMU.
Using the numbers that are generated by the /odom
topic can be useful in many cases. However, often 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.
To run Gazebo on your remote computer, you must reassign the ROS Master if it is assigned to the TurtleBot in the .bashrc
file. In each terminal window you open, type the following commands or put the commands in the .bashrc
file:
$ export ROS_MASTER_URI=http://localhost:11311 $ export ROS_HOSTNAME=localhost
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 the 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:
base_link
or base_footprint
to odom
.odom
and the screen will keep 100 arrows that point to the direction of the simulated TurtleBot as it moves: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%27s%20Control%20System.
The /cmd_vel_mux
node is used to multiplex velocity commands from different sources, such as the keyboard or a Python script. Either command makes 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 the 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 straightforward until the Ctrl + C keys are pressed again.
The command is as follows:
$ python ControlTurtleBot.py