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

Get rosparam inside launch file

asked 2020-10-20 06:28:19 -0500

definitive gravatar image

How can I get rosparam inside launch file? I'm loading yaml config:

<rosparam file="$(find package_name)/config/main_config.yaml" command="load"/>

Then I want to run node using rosparams:

  <node pkg="/params/param1" type="/params/param2" name="/params/param3">

Maybe should I save param as arg? So how to get rosparam as arg?

<arg name="arg_name1" value="/params/param1" />
<arg name="arg_name2" value="/params/param2" />
<arg name="arg_name3" value="/params/param3" />

And then:

 <node pkg="arg_name1" type="arg_name2" name="arg_name3">
edit retag flag offensive close merge delete

Comments

1

This is a question which comes up quite often and has many existing Q&As already. The following are some related/duplicate questions (in no particular order): #q226980, #q210479, #q213145, #q339208, #q234510 and #q330129.

gvdhoorn gravatar image gvdhoorn  ( 2020-10-21 00:59:29 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2020-10-21 00:54:11 -0500

gvdhoorn gravatar image

No, this is not supported.

as is also described on the wiki/roslaunch page, roslaunch has a very specific way of loading and evaluating .launch files. Parameters are all evaluated and loaded onto the parameter server first, then nodes are started.

Doing what you ask for would also be difficult to implement robustly, as it's very easy to create (invisible, to roslaunch) cycles (fi: param A needs B which tries to get(..) A).

I'm loading yaml config:

<rosparam file="$(find package_name)/config/main_config.yaml" command="load"/>

Then I want to run node using rosparams:

  <node pkg="/params/param1" type="/params/param2" name="/params/param3">

Maybe should I save param as arg? So how to get rosparam as arg?

<arg name="arg_name1" value="/params/param1" />
<arg name="arg_name2" value="/params/param2" />
<arg name="arg_name3" value="/params/param3" />

And then:

 <node pkg="arg_name1" type="arg_name2" name="arg_name3">

I'm not sure I completely understand what you're trying to do, but putting all these details in .yaml files seems like something you may not want to do.

The whole point of .launch files is to provide a way to configure your deployment and bringup. You seem to be looking to create a .launch file completely parameterised by a .yaml file (or multiple files). That's not what this was all created for.

Perhaps if you could help us understand why you want to create such a structure, we could provide (a) better answer(s).

edit flag offensive delete link more
0

answered 2020-10-20 07:01:14 -0500

tuan gravatar image

Here is an example:

In the launch file set

    <param name="variable" type="double" value="0.4" />

If your node source file is python use:

    variable = rospy.get_param("/variable")

If your node source file is cpp use:

double variable;

ros::param::get("/variable", variable);

edit flag offensive delete link more

Comments

Please, read again my question. I'm asking about how to read params INSIDE launch file. Not inside python or cpp node.

definitive gravatar image definitive  ( 2020-10-20 07:03:54 -0500 )edit

for me I was hoping to launch a node based on a parameter.

Geronimo gravatar image Geronimo  ( 2022-01-24 09:58:28 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-10-20 06:28:19 -0500

Seen: 2,138 times

Last updated: Oct 21 '20