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

Run rosparam load in runtime?

asked 2017-09-01 04:15:16 -0500

angel gravatar image

Hi ROS Community,

I am relatively new to ROS, but so far I have managed to solve everything using examples and tutorials online. Now, I want to be able to reload the parameters from a certain .yaml file while the node is running, i.e., I want to run my node with some parameter, edit the yaml file while the node is still running, and then being able to reload the new parameters. So far I have tried to use "rosparam load" in a different terminal, but didn't update the changes.

The possible solution I see is to read the file by myself using maybe yaml-cpp and use setParam, but it would really be a bit messy to mix the ROS way of handling the yaml file with the manual way. I would be happy to know if this can be done using ROS.


edit retag flag offensive close merge delete


Just making sure we understand what you want to do: if the node doesn't repeatedly reloads its parameters, setting them 'in runtime' vs using rosparam load .. is not going to change anything. rosparam load .. I believe does what you are asking: it updates parameters on the parameters server ..

gvdhoorn gravatar image gvdhoorn  ( 2017-09-01 08:29:00 -0500 )edit

.. potentially while nodes are running. But it doesn't magically change the values of configuration variables inside nodes. For that, the node must reread the parameters itself.

But: for dynamically changing parameters, it's better to use dyn_recfg.

gvdhoorn gravatar image gvdhoorn  ( 2017-09-01 08:30:34 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2017-09-11 07:18:48 -0500

updated 2017-09-18 14:13:14 -0500



If you want to update the parameters in run-time, you should use the "dynamic reconfigure".

Basically, what you need is a parameter file, like below: <your_package>/cfg/MyParams.cfg

#!/usr/bin/env python
PACKAGE = 'my_dyn_rec'

from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

#list of parameters
gen.add('int_param', int_t, 0, "description for the integer parameter", 50, 0, 100)
gen.add('str_param', str_t, 0, "description for the string parameter", "Hello world!")

exit(gen.generate(PACKAGE, "my_dyn_rec", "MyParams"))

The node you want to work with the parameters, here is an example: <your_package>/src/my_node.cpp

#include <ros/ros.h>

#include <dynamic_reconfigure/server.h>
#include <my_dyn_rec/MyParamsConfig.h>

void callback(my_dyn_rec::MyParamsConfig &config, uint32_t level) {
    ROS_INFO("New values: [%d] - [%s]", config.int_param, config.str_param.c_str());

int main(int argc, char **argv) {
    ros::init(argc, argv, "my_node");

    dynamic_reconfigure::Server<my_dyn_rec::MyParamsConfig> server;
    dynamic_reconfigure::Server<my_dyn_rec::MyParamsConfig>::Callback f;

    f = boost::bind(&callback, _1, _2);


    return 0;

Finally, you CMakeLists.txt must be configured. For this example, this should be enough:

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS



add_executable(my_node src/my_node.cpp)

add_dependencies(my_node ${PROJECT_NAME}_gencfg)


You can follow some the tutorials below: ROS wiki oficial tutorial:

And a video I created:

edit flag offensive delete link more



The trick is to use the getParam method inside your loop, if you have, or inside a callback

I've downvoted this. Suggesting people to use getParam(..) inside a loop is really bad advice. The parameter server is not meant for this kind of usage and it incurs quite some overhead ..

gvdhoorn gravatar image gvdhoorn  ( 2017-09-11 09:06:15 -0500 )edit

.. on the whole infrastructure. Dynamically (ie: at runtime) changing parameters is what dynamic_reconfigure was created for.

gvdhoorn gravatar image gvdhoorn  ( 2017-09-11 09:07:06 -0500 )edit

Hello gvdhoorn, I agree with you about not being the right way, that's why I advertised at the beginning:

'I believe if you want to update the parameters in run-time, you should use the "dynamic reconfigure"'

marcoarruda gravatar image marcoarruda  ( 2017-09-11 10:09:20 -0500 )edit

Your post is quite long, and only in one sentence mentions dyn recfg. Then it continues with "there is a work-around". That implies that something is broken, currently not fixed but can still be used / achieved by doing what you then describe in the remainer (~90%) of your answer. This may ..

gvdhoorn gravatar image gvdhoorn  ( 2017-09-11 10:14:49 -0500 )edit

.. be me, but if I were an inexperienced user reading this, it would seem to me that "updating parameters in runtime" can be achieved by implementing (read: copy-pasting) what you show examples of.

If that was not your intention, then I apologise, and I would suggest you update the wording of ..

gvdhoorn gravatar image gvdhoorn  ( 2017-09-11 10:16:24 -0500 )edit

.. your answer. As it is, the downvote is justified imo.

gvdhoorn gravatar image gvdhoorn  ( 2017-09-11 10:16:42 -0500 )edit

But being downvoted for it, I'm sorry but I don't agree. I'm answering the question, with the proper regards. Maybe this question should be closed or something like, in order to avoid people trying to answer it. I don't see a way to solve it using rosparam.

marcoarruda gravatar image marcoarruda  ( 2017-09-11 10:19:26 -0500 )edit

Ok, agreed, the words I used are implying a wrong meaning. I've changed it. Thanks.

marcoarruda gravatar image marcoarruda  ( 2017-09-11 10:21:50 -0500 )edit

answered 2021-11-01 21:31:18 -0500

I guess your core question is: to dynamically change values in the params server, using "rosparam set XX" in another terminal works, but using "load XXX.yaml" doesn't. why would this happen? you may wondering.. since the the documents tell us the "load XXX.yaml" is the same as "rosparam set XX" except for it uses a file the store the values to be set.

I faced the exactly the same issue, and here's the findings: the param name will be different with different setting method: method_1: write "load XXX.yaml" in the launch file and start it using the roslauch. method_2 use "load XXX.yaml" directly. for method_1, the generated param name will have the package name before the param name, the exact name will be like: "pkgname/paramname" . While with method_2, it will be like "paramname".

therefore, your code will likely to use the name "pkgname/paramname", and after launching, your load params in using "load XXX.yaml", the loaded name will be "paramname", see, they are different. that's why your program not reacting to "load XXX.yaml".

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-09-01 04:15:16 -0500

Seen: 4,149 times

Last updated: Sep 18 '17