ROS 2 Launch Files & Playing Back Data

“The only journey is the one within.” ― Rainer Maria Rilke

Introduction

In the previous post I walked you through Robot Operating System topics. This one expands into launch files and recording playing back data. I will be doing this on Kubuntu 20.04.

ROS 2 Launch Files

This is the tutorial on writing ROS 2 launch files. A launch file or a group of launch files acts as a script for ROS to follow. As it says in the tutorial, the first step is to create a directory to store our launch files in:

mkdir -p ROS2/launch

Then copy and paste the turtlesim_mimic_launch.py file from the turorial. The launch file details are covered in the tutorial. Finally use “ros2 launch” to launch the file:

ros2 launch turtlesim_mimic_launch.py

If you’ve done everything right you should see 2 instances of turtlesim open. If you’d like, you can inspect them with rqt_graph.

Alternatively, you can use XML or YAML (vice Python) to create launch files. Doing so is covered in this tutorial.

Recording Data With Bag Files

You can record data in bag files with the “ros2 bag” command. The tutorial on doing so is here. Be careful when storing large amounts of data; I have run out of disk space more times than I care to admit using bag files.

First, we need a place to store our ROS 2 bag files. Create a directory, e.g.,

mkdir -p bags

Follow the instructions in the tutorial to run a tutlesim instance and a teleop instance. Then choose the topics you want to record in bag files. I have chosen /turtle1/cmd_vel and /turtle1/pose (just like the tutorial):

ros2 bag record -o bag1 /turtle1/cmd_vel /turtle1/pose

Pro Tip: ensure the teleop_key window (NOT the turtlesim window NOR the ros bagging window) has focus.

When your bag file is complete mash Control-C to cease recording. Then use the bag info command to inspect the contents:

ros2 bag info bag1

On my machine this results in the following output:

ros2Bag1Info.png

ROS bag info output for my bag1 file.

This tells us the file name, size, storage type (SQLite), duration, start and end times, total message count, and ROS topics included in the particular bag file.

Playing back data is covered well in the tutorial; we won’t rehash it here.

Previous
Previous

Best Practices for Replacement Software Rollouts

Next
Next

ROS 2 Topics & rqt_graph