ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
5

start and kill rosbag record from bash shell script

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

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
7

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

Wolf gravatar image

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

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 image Girmi  ( 2018-02-16 04:59:00 -0600 )edit

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

gvdhoorn gravatar image gvdhoorn  ( 2018-02-16 05:00:30 -0600 )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 image stegelid  ( 2019-08-21 10:05:50 -0600 )edit

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

mch gravatar image mch  ( 2021-10-28 14:21:10 -0600 )edit
0

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

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
0

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

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

Question Tools

2 followers

Stats

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

Seen: 12,544 times

Last updated: Feb 16 '18