Robotics StackExchange | Archived questions

what is equivalent python code for <arg= value=> in launch file?

Hello,

is there any equivalent python code for <arg = value=> that is used in launch files? Is there a way to know how roslaunch works internally? I tried with sys.argv.append() but this doesn´t work when you load a yaml.file that also need this arguments. Thanks in Advance for help.

Asked by burhan on 2020-06-04 04:43:34 UTC

Comments

Answers

If I understand you correctly, you're trying set/get a parameter to/from the parameter server using rospy (if this isn't correct then please update your question with more details about what you're doing, what you expect, and what your results are). Luckily, rospy has this built-in so it's straightforward.

To set a parameter use

rospy.set_param(param_name, param_value)

and to get a parameter use

param_value = rospy.get_param(param_name)

You can get more information from the tutorials on the wiki.

Asked by jayess on 2020-06-04 15:31:51 UTC

Comments

I want to do the same thing that a launch file does in a python script. And in yaml file this arg will also be used like this packagedetails: packageinput: $(arg package)/config How can i implement this in a python script. If i try this with sys.argv.append() the yaml file will not find the arg but if i launch the launch file it will find the arg that is the problem.

Asked by burhan on 2020-06-05 06:21:58 UTC

Hi @burhan,

I think the code you are searching is this a xml loader from ros_comm. The roslaunch implementation source code can be found here. However in my humble opinion it would be much better to use the ROS param server as @jayess mentioned rather than trying to reinvent the wheel.

Asked by Weasfas on 2020-06-09 03:55:41 UTC