Tech Arcanist
Get in touch

71Chapter 71 of 74

Odometry Comparison

Introduction

Chapter 69 wrote a noisy controller: a copy of the simple controller that adds a small random number to every wheel angle it reads and publishes its own odometry on bumperbot_controller/odom_noisy. Chapter 70 started it from controller.launch.py, so it now runs next to the simple controller, which publishes the exact odometry on bumperbot_controller/odom.

This chapter puts the two odometries side by side. No code changes. In six terminals the robot is simulated, the two odometries are plotted in PlotJuggler, and the two frames are watched in RViz, first with the robot standing still and then while it is driven with the joystick. The noise is easy to see: the exact numbers stay calm, the noisy numbers vibrate.

Chapters 69 and 70 must already be built and working, and the joystick launch file of chapter 44 must exist. The commands use ROS 2 Jazzy, as in your notes: replace jazzy with the name of your distribution if it is different.

Where the pieces come from

IdeaWhere it was metSection
starting the simulation and the controllerschapters 43 and 70Start the Gazebo simulation
the noisy controller and its odometry topicchapters 69 and 70the noisy node and its launch file
RViz with the fixed frame odom and the TF displaychapter 49Set the fixed frame, Add the TF display and Show the frame names
driving the robot with the joystickchapter 44Connect and launch the joystick and Teleoperate the BumperBot
why odometry is never exactchapter 60When odometry goes wrong

Starting the robot

Terminal 1: build

Open a terminal and build the workspace:

cd bumperbot_ws
colcon build
A terminal after colcon build. Five packages are finished and the last line reads Summary: 5 packages finished [3.15s].
The build: five packages finished.

What you should see

Starting >>> bumperbot_msgs
Starting >>> bumperbot_controller
Starting >>> bumperbot_cpp_examples
Starting >>> bumperbot_description
Finished <<< bumperbot_description [0.26s]
Finished <<< bumperbot_cpp_examples [0.36s]
Finished <<< bumperbot_controller [0.95s]
Finished <<< bumperbot_msgs [0.99s]
Starting >>> bumperbot_py_examples
Finished <<< bumperbot_py_examples [1.97s]

Summary: 5 packages finished [3.15s]

Terminal 2: the simulation

Open a second terminal, source the workspace and start Gazebo with the robot:

. install/setup.bash
ros2 launch bumperbot_description gazebo.launch.py
Two terminals. The top one shows the build summary. In the bottom one, install/setup.bash is sourced and ros2 launch bumperbot_description gazebo.launch.py is typed.
Terminal 2: the Gazebo launch command.

Terminal 3: the controllers

Open a third terminal, source the workspace and launch the controllers. This also starts the simple controller and the noisy controller (chapter 70):

. install/setup.bash
ros2 launch bumperbot_controller controller.launch.py use_simple_controller:=false
Terminal 3: the controllers start, with both the simple controller and the noisy controller.

Plotting the two odometries

Terminal 4: install PlotJuggler

PlotJuggler draws graphs of ROS 2 topics. Open a fourth terminal and install it:

sudo apt-get install ros-jazzy-plotjuggler*
Four terminals. In the bottom one, the command sudo apt-get install ros-jazzy-plotjuggler* is typed and the package manager lists the packages it selects.
Terminal 4: installing PlotJuggler. The name must match the ROS 2 distribution: with a misspelled distribution name apt says it cannot find the package.

When the installation is finished, start it in the same terminal:

ros2 run plotjuggler plotjuggler
Four terminals. In the bottom one, ros2 run plotjuggler plotjuggler is typed with a yellow arrow, and below it PlotJuggler prints that it is loading plugins.
Terminal 4: starting PlotJuggler.

Connect PlotJuggler to ROS 2

PlotJuggler opens with an empty graph:

The PlotJuggler window with an empty graph, a Streaming panel on the left and a Timeseries list that is empty.
PlotJuggler at the start: nothing is plotted yet.
  1. In the Streaming panel, open the list of data sources and choose ROS2 Topic Subscriber.
PlotJuggler with the Streaming list open. A yellow arrow numbered 1 marks the entry ROS2 Topic Subscriber.
Step 1: choose ROS2 Topic Subscriber.
  1. Click Start.
PlotJuggler with ROS2 Topic Subscriber selected and a yellow arrow at the Start button.
Step 2: Start.
  1. A list of topics opens. Select /bumperbot_controller/odom and /bumperbot_controller/odom_noisy, then click OK.
The Select ROS messages dialog with a list of topics. The two rows /bumperbot_controller/odom and /bumperbot_controller/odom_noisy are highlighted and marked by yellow arrows, and another arrow marks the OK button.
Step 3: select the two odometry topics and press OK.

Put the two speeds in the graph

The topics appear in the Timeseries list on the left. Open the exact odometry and drag its linear speed into the graph. The path is the same every time: odom, then twist, then twist again, then linear, then x.

The Timeseries list of PlotJuggler, cropped. Yellow arrows numbered 1 to 5 follow the tree odom, twist, twist, linear and x.
The tree of the exact odometry: 1 odom, 2 twist, 3 twist, 4 linear, 5 x. Drag x into the graph.

Do the same for the noisy odometry: open odom_noisy, then twist, twist, linear and drag x into the same graph.

PlotJuggler with a graph. A blue line jumps up and down between about minus 0.04 and plus 0.06 around zero, and a red line stays near zero. A legend shows the two series odom twist linear x and odom_noisy twist linear x.
The two linear speeds with the robot standing still: the exact one (red) stays near 0, the noisy one (blue) vibrates around it.

The robot is standing still, so the real speed is 0. The exact odometry says about 0. The noisy odometry jumps up and down around 0 by several centimetres per second. The robot did not move: the noise is only in the numbers of the noisy node. The picture below shows where this size of jumps comes from:

Watching the frames in RViz

Terminal 5: start RViz

Open a fifth terminal, source the workspace and start RViz:

. install/setup.bash
rviz2
Five terminals. In the bottom one install/setup.bash is sourced and rviz2 is typed, with a yellow arrow at the rviz2 command.
Terminal 5: rviz2.

Set up RViz

The numbers match the yellow numbers in the picture below.

  1. Change the Fixed Frame to odom.
  2. Click Add and add the TF display.
  3. Open the options of TF and tick Show Names.
  4. Open Frames.
  5. Tick base_footprint.
  6. Tick base_footprint_noisy.
RViz with six yellow numbers: 1 the Fixed Frame odom, 2 the Add button, 3 Show Names ticked, 4 the Frames list, 5 and 6 the two frames base_footprint and base_footprint_noisy ticked. The 3D view shows the two frame names on top of each other.
RViz with the fixed frame odom and the two frames ticked.

The two frames start in the same place. When the robot moves, base_footprint follows the exact odometry and base_footprint_noisy follows the noisy one. Watch the noisy frame:

The frame base_footprint_noisy vibrates because of the noise.

Driving with the joystick

Terminal 6: the joystick

Open a sixth terminal, source the workspace and launch the joystick teleoperation of chapter 44:

. install/setup.bash
ros2 launch bumperbot_controller joystick_teleop.launch.py
Six terminals. In the bottom one the command ros2 launch bumperbot_controller joystick_teleop.launch.py is typed with a yellow arrow.
Terminal 6: the joystick launch command. If launch says the file was not found, check the spelling of the file name.

Connect the joystick and start driving. Watch the graph in PlotJuggler and the two frames in RViz while the robot moves:

The real robot moves in Gazebo as before. Both odometries follow it, but the noisy one also jitters on top. Later chapters use probability tools and filtering to deal with this kind of noise.

Remember

  • The simple controller publishes the exact odometry on bumperbot_controller/odom and the noisy controller publishes the noisy one on bumperbot_controller/odom_noisy. Both start from controller.launch.py.
  • PlotJuggler (ROS2 Topic Subscriber, then Start) draws the topics. Plot twist, twist, linear, x of both odometries in one graph to compare them.
  • With the robot standing still the exact speed stays near 0 and the noisy speed vibrates around it. The robot is not moving: the noise lives in the numbers of the noisy node.
  • A small noise on the wheel angles becomes a big jump in the speed, because the speed is a change of angle divided by a short time.
  • In RViz, with the fixed frame odom and both frames ticked, base_footprint follows the exact odometry and base_footprint_noisy follows the noisy one and vibrates.
  • The joystick launch file drives the robot while both odometries are watched. Noise like this is the reason the next chapters turn to probability tools and filtering.