Ask Your Question

Save automatically rosbag after a certain interval

asked 2019-10-06 18:58:57 -0600

pcampolucci gravatar image

Hello everyone, I am editing a .launch file such that it records bags of images from a camera. Now, the camera is pretty unstable so it might disconnect and I would not like to miss a whole 5 min record because of an interference.

In the light of this, I was wandering it there was a way to lets say save a rosbag every 30 sec automatically, so that if i record for 5 minutes I have 10 separated rosbags of that record.

Thank you very much.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-07 03:01:27 -0600

pavel92 gravatar image

updated 2019-10-07 03:19:39 -0600

You definitely can but I am not sure if that is the best way to approach this problem. You can take a look at the rosbag API. You can create a timer that opens a bag every 30 sec to record the camera data and closes the previous opened bag.

Another way to tackle this problem is to restart the camera. You will need to check/throw an exception if the camera is disconnected and relaunch the camera node (check the documentation for roslaunch atribute: respawn="true").

edit flag offensive delete link more


Also, there is the rosbag command line API :


-d, --duration

Specify the maximum duration of the recorded bag file.

$ rosbag record --duration=30 /chatter
$ rosbag record --duration=5m /chatter
$ rosbag record --duration=2h /chatter


and :



Split the bag when maximum size or duration is reached

$ rosbag record --split --size=1024 /chatter
$ rosbag record --split --duration=30 /chatter
$ rosbag record --split --duration=5m /chatter
$ rosbag record --split --duration=2h /chatter


something like :

rosbag record /my_topic --split --duration=30

The rosbag will be split every 30sec, thus creating a new bag file every 30sec

lmathieu gravatar image lmathieu  ( 2019-10-07 04:04:27 -0600 )edit

Nice! It worked! Thank you

pcampolucci gravatar image pcampolucci  ( 2019-10-08 14:28:38 -0600 )edit

Im glad it helped! You can mark the answer as correct by clicking the tick mark on the left side above.

pavel92 gravatar image pavel92  ( 2019-10-08 16:26:02 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-10-06 18:58:57 -0600

Seen: 168 times

Last updated: Oct 07 '19