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

Revision history [back]

click to hide/show revision 1
initial version

Using args for parameters of ROS nodes is possible, but not necessarily recommended. It might be better to use the Parameter server instead.

args is really only supported for scripts which don't support the Parameter server, or which need to access configuration data before initialising their "ROS side".

Having written that:

And the differences of listener.py and listener2.py are only listener name and chatter name. So I want to pass both name from launch file to python script.

Using parameters to configure names of nodes and topic names is what I would consider an anti-pattern.

Setting the name of the node is done using the name attribute of the node element in the .launch file. You seem to already be doing that, so there should be no need to change rospy.init_node('**listener2**', anonymous=True) again.

Changing topic names at configure / run-time should be done using remapping (#q303611).

In your specific case:

<launch>
  <node pkg="service_communication" name="talker" type="talker.py"/>
  <node pkg="service_communication" name="listener" type="listener.py" output="screen"/>
  <node pkg="service_communication" name="listener2" type="listener2.py" output="screen">
    <remap from="chatter" to="chatter2" />
  </node>
</launch>

Using args for parameters of ROS nodes is possible, but not necessarily recommended. It might be better to use the Parameter server instead.

args is really only supported for scripts which don't support the Parameter server, or which need to access configuration data before initialising their "ROS side".

Having written that:

And the differences of listener.py and listener2.py are only listener name and chatter name. So I want to pass both name from launch file to python script.

Using parameters to configure names of nodes and topic names is what I would consider an anti-pattern.

Setting the name of the node is done using the name attribute of the node element in the .launch file. You seem to already be doing that, so there should be no need to change rospy.init_node('**listener2**', anonymous=True) again.

Changing topic names at configure / run-time should be done using remapping (#q303611).

In your specific case:

<launch>
  <node pkg="service_communication" name="talker" type="talker.py"/>
  <node pkg="service_communication" name="listener" type="listener.py" output="screen"/>
  <node pkg="service_communication" name="listener2" type="listener2.py" type="listener.py" output="screen">
    <remap from="chatter" to="chatter2" />
  </node>
</launch>

Note: there should be no need for two copies of listener.py, if all you want to do is change node and topic names.

So I've changed the type for listener2 back to listener.py.