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

Revision history [back]

click to hide/show revision 1
initial version

So I found the solution for my self, not exactly what I wanted, but it works.

I finally managed the code from Notify changes to dynamic_reconfigure question to work. My problem was that I didn't initialize the dyn_config properly in a class constructor, which entailed the parameters to constantly update with random, out-of-scope numbers. But this solution didn't work for me eventually and here is why. From the example, in the link above, we can see the function void ScitosBase::dynamicReconfigureUpdaterLoop that updates the parameters every ros::Rate loop_rate = 0.5 sec. The problem is how the rqt_reconfigure node reacts on these updates: if you didn't manage to move the slider at the position you want within this 0.5 sec to change the value, it put it to the position you had it taken from; whereas if you try to change the value by typing manually, you should also do it in a half of second, otherwise the pointer drop out from typing bar. So this solution doesn't work for me - I need the parameters to update fast while having the time to type a new value.

So what I do in short - I don't update the values constantly with some specific update rate, but run the analog of void ScitosBase::dynamicReconfigureUpdaterLoop each time I update the dyn_param value from the code:
main

int main(int argc, char * *argv)  
{  
    ros::init(argc, argv, "flight_controller");  
    ros::NodeHandle my_node;  
    static My_class *class = new My_class(my_node);      
}

My_class

class My_class  
{  
private:  
    ros::NodeHandle node;  
    void parametersCallback(Config &config, uint32_t level);  
    dynamic_reconfigure::Server<Config> param_server;  
    dynamic_reconfigure::Server<Config>::CallbackType call_type;  
    boost::recursive_mutex config_mutex; //I am not sure whether I need it 
public:  
    My_class(ros::NodeHandle &node_)  
    {  
        node = node_;  

        boost::recursive_mutex::scoped_lock dyn_reconf_lock(config_mutex);  
        dyn_reconf_lock.unlock();  

        call_type = boost::bind(&My_class::parametersCallback, this, _1, _2);  
        param_server.setCallback(call_type);  
        /* Initialize the parameters at once, otherwise the values will be random */
        Config config;
        param_server.getConfigDefault(config);
        param_server.updateConfig(config);
    }  
void dynamicReconfigureUpdate(); 
double a,b; 
}

void My_class::dynamicReconfigureUpdate()  
{  
    Config config;
    /* You need to assign every single value of you dyn_parameters configuration. Unassigned values will turn into random at rqt_reconfigure */
    config.a = my_a_value_in_code;
    config.b = my_b_value_in_code;
    boost::recursive_mutex::scoped_lock lock(config_mutex); // I am not sure I need it
    param_server.updateConfig(config);
    lock.unlock();
}

void My_class::parametersCallback(Config &config, uint32_t level)  
{
    a = config.a;  
    b = config.b;
}

So each time I am changing a or b within my program I run My_class::dynamicReconfigureUpdate() to update the rqt_reconfigure. It will not work if you call the function less than it takes for you to move rqt slider or input the value manually, which is not my case.

The last question I have is regarding the recursive_mutex. It is said here that you need to implement it if you call void updateConfig(const ConfigType &config) but I am not familiar with the recursive_mutex and I am not sure I am using it right. Can somebody give me a hint?