Search code examples
ubuntu-18.04rosrecordsensorsrosbag

Save all recorded bag files acquired from a sensor using `rosbag record`


I am recording data from a range scanner with "sick_scan_xd" on ROS Melodic using the following command:

rosbag record -o nav310_ws/bagFiles/session --split --duration=1 --max-splits 1 /cloud

where nav310_ws/bagFiles is the folder where the latest bag file is temporarily stored.

I was wondering how to save every recorded bag files, or copy each bag file to another folder, e.g., allBags.

I tried the following command just after the first one, but it did not do anything.

cp -a nav310_ws/bagFiles/. nav310_ws/allBags/

My complete recording code is given below:

#!/bin/bash

rm -f nav310_ws/bagFiles/*

while true; do  # Runs on a loop until stopped with CTRL+C
        rosbag record -o nav310_ws/bagFiles/session --split --duration=1 --max-splits 1 /cloud
done

Thank you for any suggestion you could provide.


Solution

  • rosbag record will always save every recorded bag file to disk, until you stop it. You should specify the output dir in the rosbag command. Or, if you're copying multiple files after recording you should use the * operator in your cp command, not .. For example: cp nav310_ws/bagFiles/* nav310_ws/allBags/.

    Edit: The reason you're seeing only one bag file is because you're using the --max-splits arg and setting it to 1. Bags will only split one time and the last bag file will be overwritten. You should up this parameter to fit your needs; or better yet, remove it.