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

Use macros with rosparam

asked 2020-08-06 08:03:30 -0600

HLaloge-LC gravatar image

I have a software that can controls multiple similar robots. I would like to have a minimal configuration file for each robots, containing for example its size, its maximum speed, etc... And use them to populate the rest of the parameter server.

For instance, a parameter "half_length" that is equal to the half of the length to the robot. So I would want something a-la xacro, but for rosparam :

robot_a.yaml:

length: 0.8
width: 0.4

robot_b.yaml:

length: 1.0
width: 0.2

global_config.yaml:

half_length: {length / 2.0}

How can I achieve this? If I use xacro, I end up with a big XML file in a single param, which is not what I want.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-08-07 22:23:05 -0600

David Lu gravatar image

I would set your parameters with roslaunch instead of strict yaml files.

<arg name="length" default="1.0" /> <param name="half_length" value="$(eval arg('length') / 2)"/>

edit flag offensive delete link more
0

answered 2020-08-09 10:39:51 -0600

Tahir M. gravatar image

rosparam api has the functionality to do so if needed in a script apart from launch file. An example in python could be:

file_path = os.path.join(rospkg.RosPack().get_path('your_package'), 'folder', 'your_file.yml')

params = yaml.load(open(file_path))

rosparam.upload_params(namespace, params)
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-08-06 08:03:30 -0600

Seen: 229 times

Last updated: Aug 09 '20