ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

Initializing ROS 2 parameters

Sorry for asking this seemingly noob question, but I wasn’t able to find the answer anywhere: How can you set a parameter to an initial value when launching a node?

I understand that ROS 2 will use a python based launch system, which isn’t yet available (is that still so?). On the github page for the new launch system there were some few examples, but they didn’t seem to set any parameters.

I would have assumed that parameters can be set through command line arguments, like it was possible in ROS 1. Certainly the ROS 1 syntax doesn’t work anymore. I wasn’t able to locate any code that parses parameters in the RCL github repository. Is this functionality not yet implemented? Is it recommended to just use ordinary command line arguments instead (through getop etc.)?


I don’t believe that there is anything like that in place at the moment.

I have just been manually parsing the command line arguments and then setting the parameters from them. This is how I am doing it:

Thanks, I guess I’ll do something like that too.

How can you set a parameter to an initial value when launching a node?

Indeed, we do not have that yet. But that’s on our short list of things to do, since something like roslaunch isn’t that useful if you cannot remap things and set parameters from the start of a node.

We first want to tie up some loose ends with parameters ( and then we’ll do setting parameters from at least the command line (when you have your own executable).

Even with that we still need to find a way to support initializing the parameters with the “nodelet” style of loading a node, where you run a process and then dynamically load your node into that process with a service call. As well as other patterns, like when you have multiple nodes in a single executable.

That’s correct, we have something that can run and manage processes (called launch), but not the equivalent of “roslaunch” which can actually run nodes and take remappings for topics or set parameters or place whole nodes and other launch files into a namespace.

We will support that, but likely not exactly like the ROS 1 syntax (since we can have more than one node per executable now). We don’t have anything implemented yet, but as I said, it’s on the todo list. For now the best workaround is as you suggested, parsing your own arguments and setting the parameters to that.

1 Like

Although it’s not necessarily the best way, one way we have used successfully to do this is to pass a string containing the parameters formatted like the arguments to a URL (“” etc.). The advantage of this approach is that it’s easy to adapt to different styles of service call. The disadvantage is translating all parameters to text, which must be reparsed, and it being unwieldy for complex data structures.

…not the equivalent of “roslaunch” which can actually run nodes and take remappings for topics or set parameters…

I don’t think that remapping nodes or handling parameters on the command line should fall to the responsibility of a wrapper in ROS2. Let’s just make the underlying libraries handle those command line parameters. E.g. we already pass process args into rclcpp::init – just use those args for remapping.