Robotics StackExchange | Archived questions

How to setParam of one of the move_base parameters if getParam function is working?

Hello everyone,

I am currently struggling with the next problem: - I wrote a node in C++ that in its constructor I want to test if certain parameters of movebase exist and if they exist and have other values than I need for my application I want to change those values. My problem is that the test for the parameters is working, the getParam is working but when I try to set the parameters, with rqtreconfigure and also in rviz i see that the param remains the same. - the piece of relevant code that I wrote is the following:

float costmap_global_infl_infl_rad;
if (nh_param.getParam("/move_base/global_costmap/inflation_layer/inflation_radius", costmap_global_infl_infl_rad))
{
    ROS_INFO("Got param: ../global_costmap/inflation_layer/inflation_radius");

    if(costmap_global_infl_infl_rad < 0.15)
    {
        std::cout<<costmap_global_infl_infl_rad<<std::endl;
        nh_param.setParam("/move_base/global_costmap/inflation_layer/inflation_radius", 0.15);
    }
}
else
{
    ROS_ERROR("Failed to get param ../global_costmap/inflation_layer/inflation_radius");
}

Do you have any suggestions? Thank you.

Asked by __VlAd__ on 2017-11-13 05:52:19 UTC

Comments

Have you tried to change the parameter value in runtime? Because getParam is usually used once when a program starts. If you set the parameter value later, a node that started before won't have this value updated. If you want to do so, you should use Dynamic Reconfigure

Asked by marcoarruda on 2017-11-13 07:35:26 UTC

Thank you for your reply. Still, after some more digging I will resort to something like on this link: https://answers.ros.org/question/88356/c-node-to-change-dynamic-reconfigure-parameters/

Asked by __VlAd__ on 2017-11-16 06:59:58 UTC

I had answered some time ago this post and shown how to create Dynamic reconfigure parameters and how to use it in C++. It can be helpful too https://answers.ros.org/question/270034/run-rosparam-load-in-runtime/#270668

Asked by marcoarruda on 2017-11-16 08:15:25 UTC

Answers