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

Revision history [back]

click to hide/show revision 1
initial version

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.