Hiroaki-K4
Hiroaki-K4

Reputation: 23

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!

Upvotes: 2

Views: 5929

Answers (2)

HARSH MITTAL
HARSH MITTAL

Reputation: 760

You can launch all three nodes using ROS Launch.

In case if you want any node to restart then you can use

respawn="true"

For example; launch file:

<roslaunch>
  <node name="foo" pkg="package" type="node" respawn="true" />
</roslaunch>

You can read more about it in the following links:

http://wiki.ros.org/roslaunch/XML/node

https://answers.ros.org/question/38808/can-nodes-be-made-to-automatically-restart-on-segmentation-faults/

In case if you want the code to start and restart on runtime, then you can also subscribe to a specific topic and accordingly, you can send the data on that topic to start/stop/restart the node and the node can simply perform that action in a separate thread.

Upvotes: 2

davidmesalpz
davidmesalpz

Reputation: 131

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.

Upvotes: 1

Related Questions