How to pass multiple arguments to rospy node through command line?
I'm looking for a notation like this
rosrun my_package my_node.py arg1 arg2 arg3
That I can cun in the terminal, that will enable me to pass arguments to a ROS node which is implemented in python. So something like:
rosrun my_package read_topics.py arg1:='/topic1' arg2:='/topic2'
And be able to access those inside the python code like for example
subscriber = rospy.Subscriber(arg1, Bool, callback)
publisher = rospy.Publisher(arg2, Bool, queue_size=1)
How can I do that?
EDIT:
Based on the answers, the right approach is to pass arguments in a format
rosrun my_package my_node.py _one_topic:="/topic1" _another_topic:="/topic2" __name:="my_node_name"
and access the arguments inside the script as
publisher = rospy.Publisher(rospy.get_param('~one_topic'), Bool, queue_size=1)
subscriber = rospy.Subscriber(rospy.get_param('~another_topic'), Bool, callback)
The node name can be passed using a special parameter __name
, because we need to know the node name prior to initializing the rospy node.
This works for me. Thank you both.