Search code examples
ros

Is it possible to stop or restart a ros node at run time?


Is it possible to start three nodes A, B, and C at the same time, stop only A in the middle, and then restart the stopped A? I'm wondering if the stop and restart triggers can be dynamically changed using dynamic reconfigure, but I don't know how to stop and restart the node. I use the ROS melodic. Thanks!


Solution

  • ROS is intended for all nodes to run continuously until shutdown. Nevertheless there are some ideas that may help you to find a workaround:

    • You could use system() in your code. Use this with wisdom since there are some use cases where use this call is not recommended.
    • The launch files will help you to starting and stopping nodes programmatically. Check roslauch API, more concretely the Node Arguments.
    • At least for killing there is an xmlrpc shutdown call, which is what rosnode kill uses. Sending SIGINT would also be OK as ROS installs a SIGINT handler.