How to pass argument values from launch file to python script?
I am trying to pass argument values from launch file to python script. Why I need this, because a script for each node is same codes. Current code is below.
talk_listen.launch
<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"/>
</launch>
listener.py
import rospy
from std_msgs.msg import String
def callback(data):
rospy.loginfo(rospy.get_caller_id() + 'I heard %s', data.data)
def listener():
rospy.init_node('**listener**', anonymous=True)
rospy.Subscriber('**chatter**', String, callback)
rospy.spin()
listener2.py
import rospy
from std_msgs.msg import String
def callback(data):
rospy.loginfo(rospy.get_caller_id() + 'I heard %s', data.data)
def listener():
rospy.init_node('**listener2**', anonymous=True)
rospy.Subscriber('**chatter2**', String, callback)
rospy.spin()
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.