respawn parameter problem

asked 2018-08-20 02:15:19 -0600

Chickenman gravatar image

updated 2018-09-10 05:02:15 -0600

Hi

I am starting my launchfiles using this tutorial http://wiki.ros.org/roslaunch/API%20U... (Part2). I have problem when I configured node parameter respawn = True in my launch file. Launch is not able to respawn node automatically when node is shutdown. I don't think this is normal behavior.

Thank you for your help.

EDIT: Here is my launchfile

<?xml version="1.0"?>
<launch>

    <!--First specific robot need to be connected -->

    <rosparam command="load" ns="bp" file="$(find test_package)/config/test_config.yaml" />

    <include file="$(find test_package)/launch/test.launch">
        <arg name="load_params" default="false"/>
    </include>

</launch>

And here is the launchfile that is included

<launch>
    <arg name="gui" default="true"/>
    <arg name="robot_ip" default="127.0.0.1" />
    <arg name="scene_source_type" default="XXX" />
    <arg name="gazebo_gripper" default="false" />
    <!--arg name="scanner_ID" default="InstalledExamples" /-->
    <arg name="load_params" default="true"/>


    <node pkg="test_node" type="test_node" name="test_node" respawn= "true" args="$(arg gui)" output="screen">

        <param name="gui" type="bool" value="$(arg gui)" />
        <param name="gazebo_gripper" type="bool" value="$(arg gazebo_gripper)" />
        <param name="robot_ip" type="str" value="$(arg robot_ip)" />
        <param name="scene_source_type" type="str" value="$(arg scene_source_type)" />
        <!--param name="scanner_ID" type="str" value="$(arg scanner_ID)" /-->
    </node>

    <node name="symmetry_parser" pkg="symmetry_parser" type="symmetry_parser" />
</launch>

Point is that when I launch the launchfile through the terminal and node dies it could be restarted normally. When I launch the launchfile through the rospy interface after node dies it is not able to restart itself.

Here is my python code

 def __init__(self, name, launch_path, autorestart=True):
        self.launch_path = launch_path
        self.name = name
        self.running = False
        self.autorestart = autorestart

        #initializing roslaunch UID
        self.uuid = roslaunch.rlutil.get_or_generate_uuid(None, True)
        self.launch = roslaunch.parent.ROSLaunchParent(self.uuid, [self.launch_path])
        self.node_names = []
        xml_data = xmltree.parse(launch_path).getroot()
        for node in xml_data.findall('node'):
            self.node_names.append(str("/") + node.get('name'))


    def start(self):
        if not path.exists(self.launch_path):
            raise Exception("Launchfile " + self.launch_path + " does not exist!")

        if self.running and not self.autorestart:
            print("restart rejected")
            return

        # if this node is running, shut it down
        if self.running:
            self.launch.shutdown()

        # this ensures that UUID will be regenerated upon every restart
        self.uuid = roslaunch.rlutil.get_or_generate_uuid(None, True)
        roslaunch.configure_logging(self.uuid)
        self.launch = roslaunch.parent.ROSLaunchParent(self.uuid, [self.launch_path])

        if self.launch.start() != None:  # if process is launched and has not exitted, it returns None
            raise Exception("Cannot start required launchfile with Launcher!")
        else:
            print("\"{}\" successfully launched").format(self.name)
self.running = True

and I use it like this

launchers['test_launcher'] = Launcher("test_launcher",
**"launcher path"**)
launchers['test_launcher'].start()
edit retag flag offensive close merge delete

Comments

Can you your launchfile here? (or as much of it as is relevant.)

etappan gravatar imageetappan ( 2018-09-04 08:26:07 -0600 )edit

I added my scripts for better understanding the problem

Chickenman gravatar imageChickenman ( 2018-09-10 05:02:33 -0600 )edit