Appearance
Recording and playing
Recording data using ROS2 (Robot Operating System 2) can be done with the ros2 bag command-line tool, which allows you to record and play back data from ROS2 topics. This is useful for logging sensor data, debugging, and testing your robotic applications. Here's a step-by-step guide to recording data using ROS2:
Install
ros2bagandrosbag2:First, ensure that you have the necessary packages installed. If you haven't already, install
ros2bagand the storage backend (e.g.,rosbag2for SQLite3) using the following command:
sudo apt-get install ros-<distro>-ros2bag ros-<distro>-rosbag2sudo apt-get install ros-<distro>-ros2bag ros-<distro>-rosbag2Replace <distro> with the name of your ROS2 distribution (e.g., foxy, galactic, rolling).
- Source your ROS2 workspace:
Before using ROS2 commands, you need to source your ROS2 workspace. To do this, run the following command in your terminal:
source /opt/ros/<distro>/setup.bashsource /opt/ros/<distro>/setup.bashReplace <distro> with the name of your ROS2 distribution.
- Start your ROS2 system:
Launch your ROS2 nodes or system so that the topics you want to record are being published. This can be done using the ros2 launch command or by starting individual nodes manually.
- Record data with
ros2 bag:
To record data from specific topics, use the following command:
ros2 bag record -o <output_directory> <topic1> <topic2> ...ros2 bag record -o <output_directory> <topic1> <topic2> ...Replace <output_directory> with the desired directory for storing the recorded data and <topic1>, <topic2>, ... with the names of the topics you want to record.
If you want to record data from all available topics, use the following command:
ros2 bag record -a -o <output_directory>ros2 bag record -a -o <output_directory>- Stop the recording:
To stop the recording, press Ctrl+C in the terminal where the ros2 bag record command is running. The recorded data will be saved as a .db3 file in the specified output directory.
- Play back recorded data (optional):
If you want to play back the recorded data, use the following command:
ros2 bag play <output_directory>/<bag_file>ros2 bag play <output_directory>/<bag_file>Replace <output_directory> with the directory where the recorded data is stored and <bag_file> with the name of the .db3 file containing the recorded data.
Keep in mind that the ros2 bag tool can be configured with additional options, such as compression, filtering, or specifying a custom storage backend. You can learn more about these options by referring to the ROS2 documentation or running ros2 bag --help in your terminal.