Questions for Practical Cases


I think about a real case in reality. That is:

I will launch a file with 5 nodes (for example):

  • Node1 is for a front lidar sensor
  • Node2 is for a rear lidar sensor
  • Node3 is for a package to communicate to PLC
  • Node4 is for a package to communicate to a control system via wifi
  • Node5 is for a motor driver

In the working process, sometimes Node4 has an error. I have to restart this node.

  1. How can I restart this node by program follow the ROS platform?

  2. I see some ros packages is running as default from the beginning but it does not use a terminal to launch it? Could I launch 5 nodes without using terminal and how to do it?


You could create an extra node that manages errors in the other nodes, and use subprocess to relaunch dead nodes, something like this:

import rospy
import subprocess

def is_node_running(node_name):
        # Use rosnode to check if the node is running
        output = subprocess.check_output(['rosnode', 'info', node_name])
        return True
    except subprocess.CalledProcessError:
        return False

def restart_node(node_name):
    # Use rosnode to kill the node['rosnode', 'kill', node_name])
    # Launch the node again
    subprocess.Popen(['roslaunch', 'my_package', 'my_nodes_launch.launch'])

def node_manager():
    while not rospy.is_shutdown():
        if not is_node_running('control_system_node'):
            rospy.logwarn("Control system node is not running. Restarting...")
        rospy.sleep(1)  # Check every 1 second

if __name__ == '__main__':
    except rospy.ROSInterruptException:

I have some questions:

  1. Everytime I kill then start, it will do on a new terminal. So if the machine works for a long time, there are a lot of terminals. Is it good?

  2. Follow your instructions, every node will work on a terminal. So in a big project with many nodes, there are a lot of terminal, right? How you control it in practical?

Do you have any examples of a project to see the concept program (structure and how it works)?


I actually don’t know if that would be launched in a terminal. You can just add nohup if that’s what you are worried about.

Another idea is to implement the ROS 2 lifecycle manager: Managed nodes. You can see how Nav2 implemented it here.

I’m not saying you should follow my instructions. It was just an idea of how you could accomplish what you described.

I have no examples of a project so you can see the concept program.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.