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

Macro for nodes in launch file

asked 2017-01-18 09:26:49 -0500

Stian gravatar image

I'm trying to use the PID package to control the joints of a snake robot. Since each node will be single controller, I need to start several nodes to control all the joints. The pid nodes have several parameters, so I hope to be able to write some form of macro that can make my launch file more compact and manageable. I found out that launch files are written in XML and not Xacro, so I can't use macros like you can for the URDF files. Does anyone know a clever way to do this?

edit retag flag offensive close merge delete


launch files are written in XML and not Xacro, so I can't use macros like you can for the URDF files

This is incorrect. xacro should be able to generate any xml format, and xacro is also in xml format.

130s gravatar image 130s  ( 2021-01-07 01:36:30 -0500 )edit

Specifically for include-ing a .launch file so this isn't exactly for node, but #q229489 is a good option that doesn't require customization (i.e. needed functionality is in the library).

130s gravatar image 130s  ( 2021-01-07 01:42:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-19 22:28:06 -0500

Thomas D gravatar image

I don't know of a way to have macros or for loops in launch files.

One option is to have a separate yaml file for each controller that contains the parameter values for a single controller. In your launch file you would have to list out each <node> separately but you could have something like this that uses the rosparam tag:

<node pkg="pid" type="controller" name="pid1">
  <rosparam command="load" file="$(arg your_package)/config/pid1.yaml"/>

Repeat that block N times and have N yaml files. The pid1.yaml file would look like (follow the link above for more examples):

Kp: 1.0
Ki: 0.1
Kd: 0.2
upper_limit: 5.0
lower_limit: 0.2
windup_limit: 10.0
edit flag offensive delete link more

Question Tools



Asked: 2017-01-18 09:26:49 -0500

Seen: 470 times

Last updated: Jan 19 '17