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
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.
I haven't tried this, but perhaps something like this:
rosbag play foo.bag; rosnode kill -a
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.
Asked: Jan 25
Seen: 161 times
Last updated: Jan 25
ROS Answers is licensed under Creative Commons Attribution 3.0 Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.