Ask Your Question

Revision history [back]

Hello,

I believe if you want to update the parameters in run-time, you should use the "dynamic reconfigure". Although, there's a workaround to get the updated values of a param inside a node.

The trick is to use the getParam method inside your loop, if you have, or inside a callback. It depends where you want to have the parameters updated. See below 2 examples, but in the 2nd case, the value is updated in every iteration:

Here the value is get at the beginning and not updated anymore:

ros::init(argc, argv, "node")
ros::NodeHandle nh;
ros::Rate rate(1);
std::string param1;
nh.getParam("param1", param1);
while(ros::ok()) {
    ROS_INFO("param1: [%s]", param1.c_str());
    ros::spinOnce();
    rate.sleep();
}

And here we have the parameter updated:

ros::init(argc, argv, "node")
ros::NodeHandle nh;
ros::Rate rate(1);
std::string param1;
while(ros::ok()) {
    nh.getParam("param1", param1);
    ROS_INFO("param1: [%s]", param1.c_str());
    ros::spinOnce();
    rate.sleep();
}

It'll work updating the parameter using a terminal (setting it or loading a yaml file) or even updating the value using another node.

There's a video tutorial showing the implementation, the explanation goes further: https://www.youtube.com/watch?v=GENcUT5m0yg

Hello,

I believe if you want to update the parameters in run-time, you should use the "dynamic reconfigure". Although, there's a workaround way to get the updated values of a param inside a node.node, but I'm not sure about the consequences (maybe ROS parameter server can be overloaded by doing it, not sure about it)

The trick is to use the getParam method inside your loop, if you have, or inside a callback. It depends where you want to have the parameters updated. See below 2 examples, but in the 2nd case, an example where the value is updated in every iteration:

Here the value is get at the beginning and not updated anymore:

ros::init(argc, argv, "node")
ros::NodeHandle nh;
ros::Rate rate(1);
std::string param1;
nh.getParam("param1", param1);
while(ros::ok()) {
    ROS_INFO("param1: [%s]", param1.c_str());
    ros::spinOnce();
    rate.sleep();
}

And here we have the parameter updated:

ros::init(argc, argv, "node")
ros::NodeHandle nh;
ros::Rate rate(1);
std::string param1;
while(ros::ok()) {
    nh.getParam("param1", param1);
    ROS_INFO("param1: [%s]", param1.c_str());
    ros::spinOnce();
    rate.sleep();
}

It'll work updating the parameter using a terminal (setting it or loading a yaml file) or even updating the value using another node.

There's a video tutorial showing the implementation, the explanation coding goes further: https://www.youtube.com/watch?v=GENcUT5m0yg

Hello,

I believe if you want to update the parameters in run-time, you should use the "dynamic reconfigure". Although, there's you could re-read the param inside a way loop to get updated the updated values of a param inside a node, but I'm not sure about the consequences (maybe ROS parameter server can be overloaded by doing it, not sure about it)

The trick is to use the getParam method inside your loop, if you have, or inside a callback. It depends where you want to have the parameters updated. See below an example where the value is updated in every iteration:

ros::init(argc, argv, "node")
ros::NodeHandle nh;
ros::Rate rate(1);
std::string param1;
while(ros::ok()) {
    nh.getParam("param1", param1);
    ROS_INFO("param1: [%s]", param1.c_str());
    ros::spinOnce();
    rate.sleep();
}

It'll work updating the parameter using a terminal (setting it or loading a yaml file) or even updating the value using another node.

There's a video tutorial showing the implementation, the coding goes further: https://www.youtube.com/watch?v=GENcUT5m0yg

Hello,

I believe if you want to update the parameters in run-time, you should use the "dynamic reconfigure". Although, you could re-read the param inside a loop to updated update the values inside a node, but I'm not sure about the consequences (maybe ROS parameter server can be overloaded by doing it, not sure about it)

The trick is to use the getParam method inside your loop, if you have, or inside a callback. It depends where you want to have the parameters updated. See below an example where the value is updated in every iteration:

ros::init(argc, argv, "node")
ros::NodeHandle nh;
ros::Rate rate(1);
std::string param1;
while(ros::ok()) {
    nh.getParam("param1", param1);
    ROS_INFO("param1: [%s]", param1.c_str());
    ros::spinOnce();
    rate.sleep();
}

It'll work updating the parameter using a terminal (setting it or loading a yaml file) or even updating the value using another node.

There's a video tutorial showing the implementation, the coding goes further: https://www.youtube.com/watch?v=GENcUT5m0yg

Hello,

I believe if you want to update the parameters in run-time, you should use the "dynamic reconfigure". Although, you could re-read the param inside a loop to update the values inside a node, but I'm not sure about the consequences (maybe ROS parameter server can be overloaded by doing it, not sure about it)

The trick is You can try to use the getParam method inside your a loop, if you have, or inside a callback. It depends where you want to have the parameters updated. See below an example where the value is updated in every iteration:

ros::init(argc, argv, "node")
ros::NodeHandle nh;
ros::Rate rate(1);
std::string param1;
while(ros::ok()) {
    nh.getParam("param1", param1);
    ROS_INFO("param1: [%s]", param1.c_str());
    ros::spinOnce();
    rate.sleep();
}

It'll work updating the parameter using a terminal (setting it or loading a yaml file) or even updating the value using another node.

There's a video tutorial showing the implementation, the coding goes further: https://www.youtube.com/watch?v=GENcUT5m0yg

[UPDATED ANSWER]

Hello,

I believe if If you want to update the parameters in run-time, you should use the "dynamic reconfigure". Although, you could re-read the param inside reconfigure".

Basically, what you need is a loop to update the values inside a node, but I'm not sure about the consequences (maybe ROS parameter server can be overloaded by doing it, not sure about it)

You can try to use the getParam method inside a loop, if you have, or inside a callback. It depends where 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 have the parameters updated. See below work with the parameters, here is an example where the value is updated in every iteration: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, "node")
ros::NodeHandle nh;
ros::Rate rate(1);
std::string param1;
while(ros::ok()) {
    nh.getParam("param1", param1);
    ROS_INFO("param1: [%s]", param1.c_str());
    ros::spinOnce();
    rate.sleep();
"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);
    server.setCallback(f);

    ros::spin();

    return 0;
}

It'll work updating the parameter using a terminal (setting it or loading a yaml file) or even updating the value using another node.

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

cmake_minimum_required(VERSION 2.8.3)
project(my_dyn_rec)

find_package(catkin REQUIRED COMPONENTS
  dynamic_reconfigure
  roscpp
  rospy
)

generate_dynamic_reconfigure_options(
  cfg/MyParams.cfg
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

add_executable(my_node src/my_node.cpp)

add_dependencies(my_node ${PROJECT_NAME}_gencfg)

target_link_libraries(my_node
  ${catkin_LIBRARIES}
)

You can follow some the tutorials below: ROS wiki oficial tutorial: http://wiki.ros.org/dynamic_reconfigure/Tutorials

And a video tutorial showing the implementation, the coding goes further: https://www.youtube.com/watch?v=GENcUT5m0yg

I created: https://youtu.be/YKZkZSVcsnI