Ask Your Question
1

Kill roscore and all nodes when rosbag play finishes?

asked Jan 25

Jason LaPenta gravatar image Jason LaPenta
21 3

Hello,

I'm writing some automated test scripts. I'd like to run a launch script with a bag file, which works fine. But when the rosbag play completes I would like roslaunch to exit so my script can load up a new bag file and rerun roslaunch with the test.launch file. Is there an elegant way to cause all ros nodes and roscore to exit when a bag file is finished? I was thinking of making another script to monitor when rosbag finished and then execute a rosnode kill, but I thought there might be a better way.

Thanks, Jason

delete close flag offensive retag edit

Comments

This is tangential, but you may want to look into using rostest to bring your test fixture up and down using roslaunch files kwc (Jan 25)edit

3 Answers

Sort by ยป oldest newest most voted
3

answered Jan 25

Dan Lazewatsky gravatar image Dan Lazewatsky
2269 15 27 45
http://cse.wustl.edu/~dla...

If you're running all your nodes from the same launch file as the bag, just add requred="true" to the node tag for rosbag. This will cause the entire roslaunch to die when rosbag terminates.

link delete flag offensive edit

Comments

this appears to work perfectly, thanks Jason LaPenta (Jan 25)edit
1
When you get a good/the best answer please use the checkbox to the left to mark it as answered. I've done so for you this time. tfoote (Feb 02)edit
0

answered Jan 25

JeffRousseau gravatar image JeffRousseau
1141 15 21 34
http://jeffrousseau.info/

I haven't tried this, but perhaps something like this:

rosbag play foo.bag; rosnode kill -a
link delete flag offensive edit
0

answered Jan 25

DimitriProsser gravatar image DimitriProsser flag of United States
6817 23 59 126

I would personally do this via Bash. I assume that's what you're doing already, but here's how I would do it:

#!/bin/bash

rosbag play my_bag.bag 

while [ ! "$(ps aux | grep bag | grep -v grep)" ] # or $(rosnode list | grep play)
do
    sleep 1;
done

if [ "$(ps aux | grep ros | grep -v grep | awk '{print $2}')" ]; then # or $(rosnode list)
    for i in $(ps aux | grep ros | grep -v grep | awk '{print $2}')
    do
        kill -2 $i;
    done
fi

I use this because according to the rosnode kill documentation, it's not guaranteed to actually kill a node, especially when it's set to respawn. This function guarantees that they all die. You'd then be free to launch again. You could even put this all in a loop.

link delete flag offensive edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Follow

subscribe to rss feed

Stats

Asked: Jan 25

Seen: 161 times

Last updated: Jan 25