Search code examples
ros

Launch node if not already running


When doing roslaunch <pkg> <file>.launch I want all nodes that are launched inside that file to only start if they're not running yet. How do I do this? If it's not possible, is it at least possible to do this for each node separately? If someone has an idea it would be great if you added that code to my example .launch snippet below.

<?xml version="1.0" encoding="UTF-8"?>
<launch>
  <node pkg="rviz" type="rviz" name="rviz" />
</launch>

Solution

  • Unfortunately, this is not possible as discussed here. roslaunch and rosrun will always run the node with the desired name which results in the fact, that the roscore will kill living nodes with the same name. You can use the anon tag to run multiple instances with always varying names as explained here. The only exception to this behavior is the roscore.xml and its nodes as explained here. The only current workaround, from my point of view, is writing a script which checks via rosnode list if the desired node is already running and depending on the outcome, run your node or not.