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

asked 2017-11-13 04:52:19 -0600

__VlAd__ gravatar image

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 move_base 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 rqt_reconfigure 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)
        nh_param.setParam("/move_base/global_costmap/inflation_layer/inflation_radius", 0.15);
    ROS_ERROR("Failed to get param ../global_costmap/inflation_layer/inflation_radius");

Do you have any suggestions? Thank you.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by __VlAd__
close date 2017-11-16 06:32:43.723422



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

marcoarruda gravatar image marcoarruda  ( 2017-11-13 06:35:26 -0600 )edit

Thank you for your reply. Still, after some more digging I will resort to something like on this link:

__VlAd__ gravatar image __VlAd__  ( 2017-11-16 05:59:58 -0600 )edit

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

marcoarruda gravatar image marcoarruda  ( 2017-11-16 07:15:25 -0600 )edit