0
$\begingroup$

Rosanswers logo

Let's say we want to record a rosbag, and run a python script from a bash script.

rosbag record -o /file/name /topic
PID=$!
sleep 2
python ./run_ROS_script.py
kill -INT $PID

so if you leave out -INT it kills the rosbag, but not nicely: it leaves the rosbag in .active status. If you add -INT (same thing as running ctrl+c on the rosbag process) then the rosbag never finishes, and doesn't leave .active status.

So ... what gives? Why can't we nicely kill this rosbag record?


Originally posted by buckley.toby on ROS Answers with karma: 116 on 2017-11-09

Post score: 5

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You could run your rosbag with a Not anonymous node name

rosbag record -o /file/name /topic __name:=my_bag

and then kill it via rosnode kill :

rosnode kill /my_bag

This assures that rosbag stops gracefully.


Originally posted by Wolf with karma: 7555 on 2017-11-09

This answer was ACCEPTED on the original site

Post score: 7


Original comments

Comment by Girmi on 2018-02-16:
The correct command that worked for me (ROS Kinetic) is:

rosbag record -o /file/name /topic __name:=my_bag
rosnode kill /my_bag

Note the double underscore before the name param (see the "Special keys" section at [Remapping Arguments](http://wiki.ros.org/Remapping Arguments))

Comment by gvdhoorn on 2018-02-16:
You're correct. I've just edited the answer by @Wolf.

Comment by stegelid on 2019-08-21:
You can set a trap in your bash script, catching SIGINT and call rosnode kill from there, eg:

#!/bin/bash
trap "rosnode kill /bagger" SIGINT
rosbag record /my_topic __name:=bagger &
roslaunch mypackage launch.launch

Comment by mch on 2021-10-28:\

rosnode kill /my_bag This assures that rosbag stops gracefully.

That does not seem to stop gracefully though. Rosbag name is *.bag.active not just *.bag

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.