Ask Your Question
4

start and kill rosbag record from bash shell script

asked 2017-11-08 23:39:58 -0500

buckley.toby gravatar image

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?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
6

answered 2017-11-08 23:56:49 -0500

Wolf gravatar image

updated 2018-02-16 04:59:59 -0500

gvdhoorn gravatar image

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.

edit flag offensive delete link more

Comments

1

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)

Girmi gravatar imageGirmi ( 2018-02-16 04:59:00 -0500 )edit

You're correct. I've just edited the answer by @Wolf.

gvdhoorn gravatar imagegvdhoorn ( 2018-02-16 05:00:30 -0500 )edit

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
stegelid gravatar imagestegelid ( 2019-08-21 10:05:50 -0500 )edit
0

answered 2017-11-08 23:50:10 -0500

buckley.toby gravatar image

Well, I figured out my issue. I was exiting debug mode in my python script (ctrl+d) which bypassed running the rest of the shell script. Need to press 'ctrl+c' for exiting python (even in debug mode, just press ctrl+d afterwards)

edit flag offensive delete link more
0

answered 2017-11-23 12:05:57 -0500

paland3 gravatar image

hey, a work around I came up with is this:

rosbag record as usual, and after: rosnode list | grep record* | xargs rosnode kill

Which kills all the recording nodes you have properly (no active state). BEWARE, it kills ALL of the recordings, and also every node that you have running and is called record* for some reason. Hope it helps.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-11-08 23:39:58 -0500

Seen: 3,399 times

Last updated: Feb 16 '18