Extension commands for rosbag in ROS 2
Supported ROS distributions:
- humble
If you want to use mcap format bags, you need to install the mcap package in advance.
sudo apt install ros-humble-rosbag2-storage-mcap# create workspace for extension
mkdir -p $HOME/extension_ws/src
# clone extension package
cd $HOME/extension_ws/src
git clone git@github.com:tier4/ros2bag_extensions.git
# build workspace
cd $HOME/extension_ws
source /opt/ros/humble/setup.bash
rosdep install --from-paths . --ignore-src --rosdistro=${ROS_DISTRO}
colcon build --symlink-install --catkin-skip-building-tests --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Releasesource install/local_setup.bash
ros2 bag --helpMake sure that the filter, merge, and slice commands have been added to the list of Commands in the help message.
Merge multiple bag files.
Usage:
# sqlite3 format bag
ros2 bag merge -o rosbag2_merged/ rosbag2_2021_08_20-12_28_24/ rosbag2_2021_08_20-12_30_03/
# mcap format bag
ros2 bag merge -o rosbag2_merged/ rosbag2_2021_08_20-12_28_24/ rosbag2_2021_08_20-12_30_03/ -s mcapFilter by topic names. You can use python3 regular expression operations.
Usage:
If you want to include the specified topic, use -i or --include.
# sqlite3 format bag
ros2 bag filter -o rosbag2_filtered/ rosbag2_merged/ -i "/system/emergency/turn_signal_cmd" "/autoware/driving_capability"
# mcap format bag
ros2 bag filter -o rosbag2_filtered/ rosbag2_merged/ -i "/system/emergency/turn_signal_cmd" "/autoware/driving_capability" -s mcap
# use regular expression
ros2 bag filter -o rosbag2_filtered/ rosbag2_merged/ -i "/sensing/.*" "/vehicle/.*"If you want to exclude the specified topic, use -x or --exclude.
# sqlite3 format bag
ros2 bag filter -o rosbag2_filtered/ rosbag2_merged/ -x "/system/emergency/turn_signal_cmd" "/autoware/driving_capability"
# use regular expression
ros2 bag filter -o rosbag2_filtered/ rosbag2_merged/ -x "/sensing/.*" "/vehicle/.*"This verb has two functions
Save the specified range of data as a bag file by specifying the start time and end time.
Usage:
# sqlite3 format, from 1629430104.911167670 to the bag end time
ros2 bag slice input_bag -o sliced_from -b 1629430104.911167670
# mcap format, from 1629430104.911167670 to the bag end time
ros2 bag slice input_bag -o sliced_from -b 1629430104.911167670 -s mcap
# from the bag begging time to 1629430124
ros2 bag slice input_bag -o sliced_till -e 1629430124
# from 1629430104.911 to 1629430124
ros2 bag slice input_bag -o sliced_between -b 1629430104.911 -e 1629430124Split bag file into multiple files with specified duration second.
Usage:
# split input_bag into sliced bags which has 60secs
ros2 bag slice input_bag -o sliced_bags -d 60