Record and Playback Actions under ROS – RACECAR/J

One of the first things people like to do with their RACECAR is gather data. Using ROS we can record and playback actions. It’s easy! Looky here:

Background

The usual note here: You should definitely have the book “Programming Robots with ROS, a practical introduction to the Robot Operating System” by Morgan Quigley, Brian Gerkey and William D. Smart. The book is written by the people who wrote ROS originally, and has a very good overview of ROS and practical application.

rosbag is a command line tool that records messages and allows you to play them back later. You can think of a rosbag as similar to a digital video file that records not only video but also other types of sensor messages. Think of it as a multi-track recording, where you can have not only a video track but also a sound track, an IMU track, and so on. There is a master time code which then allows all of the messages to synchronize when they play back.

Why is this useful? For debugging purposes, this mechanism allows you to present the same data in a controllable manner which allows you to isolate and fix bugs. It also allows you to develop algorithms independent of having a physical robot. You can record sensor data from the robot, and then use the recorded data for development.

Another use is to take the data within the rosbag to train Deep Learning networks. This has become increasingly more important over the last few years. For example, on RACECAR/J you may want to drive the robot while recording the camera image along with the throttle and steering values. You take that information and train a neural network on how to “drive” the robot. Transfer the trained network to the Jetson which can then infer from the network how to drive the robot.

Usage

rosbag is simple to use. It’s basically:

$ rosbag record <topics>

and

$ rosbag play <name of file>

There are all sorts of command line parameters you can pass which allows control of obvious things like the name of the file to record, to other more interesting ideas like controlling the speed of playback and where you start playback in the file. Check out the ros wiki for more.

Example

In the video, we use rqt to visualize which rostopics to record and playback. From the racecar-ws directory in two separate terminals, we launched the RACECAR teleop launch file and the Stereolabs ZED camera wrapper:

$ roslaunch racecar teleop.launch

and

$ roslaunch zed_wrapper zed.launch

Record

Then we recorded the rosbag:

$ rosbag record /ackermann_cmd /zed/rgb/image_rect_color -O racecarj.bag

This recorded two topics:

  • /ackermann_cmd which contains the information that ultimately controls the steering and the throttle
  • /zed/rgb/image_rect_color which contains the rectified color image from the ZED camera

Playback

In the video, after some fumbling around, we played the rosbag. We also point out remapping topics so that the messages can be injected at different places in the node graph topography.

To look at the recorded image, we loaded the image_view package:

$ sudo apt-get install ros-kinetic-image-view -y

Next we ran an image view on the topic /video_stuff:

$ rosrun image_view image_view image:=/video_stuff

Then we are ready to playback the rosbag:

$ rosbag play racecarj.bag /ackermann_cmd:=/ackermann_cmd_mux/input/navigation /zed/rgb/image_rect:=/video_stuff

This command plays back the topics that were previously recorded. However, the topics were remmapped with /ackermann_cmd going to the Ackermann Command Mux (ackermann_cmd_mux/input/navigation) and the ZED image being remapped to /video_stuff. The video in the rosbag displays in the image_view.

Basically, remapping the topics help smooth out the playback.

Conclusion

Conceptually ROS is pretty simple, but can be tricky to think about because it is a concurrent, distributed system. rosbags are a very useful tool for help with debugging, simulation and training. rosbags be good!

1 Comment

Leave a Reply

Your email address will not be published.


*