ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Include multiple launch file with same node instances.

asked 2018-10-12 03:20:27 -0600

BhanuKiran.Chaluvadi gravatar image

Hi,

I have a two separate launch files with few common node(same package and name) instances. Now I want to create a main launch file that includes these two launch files but only one instance each should be created for all the common nodes with out giving any

roslaunch file contains multiple nodes named [/joint_states_listener].
Please check all <node> 'name' attributes to make sure they are unique.
Also check that $(anon id) use different ids.
The traceback for the exception was written to the log file

.

edit retag flag offensive close merge delete

Comments

I don't understand. Are you trying to run the same node multiple times for different purposes?

l4ncelot gravatar image l4ncelot  ( 2018-10-12 03:26:38 -0600 )edit

If so, try to use anonymous names for each node with $(anon name). Look here for reference.

l4ncelot gravatar image l4ncelot  ( 2018-10-12 03:41:15 -0600 )edit

$(anon name) will just add an id on the name but it will be the same id if you use the same name.

Delb gravatar image Delb  ( 2018-10-12 04:08:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-10-12 04:01:18 -0600

Delb gravatar image

updated 2018-10-12 06:13:52 -0600

Providing your two launch file could be nice but I see your issue here.

Your launch file is probably looking like that :

<launch>
    <include file="$(find your_pkg)/launch/launchfile_1.launch"/>
    <include file="$(find your_pkg)/launch/launchfile_2.launch"/> 
</launch>

It creates an issue if there are nodes with the same name. To avoid that you have different options :

  • Add a namespace in the include tag :

    <launch>
        <include file="$(find your_pkg)/launch/launchfile_1.launch" ns="namespace1"/>
        <include file="$(find your_pkg)/launch/launchfile_2.launch" ns="namespace2"/> 
    </launch>
    

Like that you will have nodes from the first include named /namespace1/node and from the second include /namespace2/node.

- You can set the name configurable with arguments. Inside yourlaunch files instead of <node pkg="node" type="node" name="your_node_name"/> you can have :

    <arg name="node_name_arg" default="a_name"/>
    <node pkg="node" type="node" name="$(arg node_name_arg)"/>

And your launch file would be :

<launch>
     <include file="$(find your_pkg)/launch/launchfile_1.launch">
           <arg name="node_name_arg" value="node_name_1"/>
     </include>
     <include file="$(find your_pkg)/launch/launchfile_2.launch">
           <arg name="node_name_arg" value="node_name_2"/>
     </include>
</launch>

That is to answer your question BUT you took joint_state_publisher as an exemple but that means you try to launch it twice which is not right. It would be like if you wanted to launch rviz for each of your launch files eventhough it will gather the same data since it subscribes to topics. The right thing to do is to clean up a little bit your launch files to contain only the different nodes, the commons ones should be on the main launch file, like that :

<launch>
     <!-- Launch all the commons nodes for exemple robot_state_publisher and rviz -->
     <node pkg="robot_state_publisher" type="robot_state_publisher" name="spr">
        <param name="publish_frequency" type="double" value="30.0" />
     </node>
     <node name="rviz" pkg="rviz" type="rviz"/>

     <!-- Launch your launch files containing specifics packages -->
     <include file="$(find your_pkg)/launch/launchfile_1.launch"/>
     <include file="$(find your_pkg)/launch/launchfile_2.launch"/>
</launch>

And you might want to create a standalone launch file launching the nodes required for each of your different launch files.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-10-12 03:20:27 -0600

Seen: 2,953 times

Last updated: Oct 12 '18