0
$\begingroup$

Rosanswers logo

Hi all!

is there a way to programmatically update parameters in the dynamic_reconfigure? I can modify the parameters of a node from the dynamic reconfigure but those parameters can possibly get modified also from other nodes at runtime, so I would like that these changes get reflected in the dynamic_reconfigure.

Thanks a lot.


Originally posted by sciarp on ROS Answers with karma: 129 on 2013-03-07

Post score: 5

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I was missing a tutorial too, some questions here helped. So I did this and it works fine:

/// intialize dynamic_reconfigure

ROS_INFO("Starting dynamic_reconfigure...");

// update config to current hardware state
metralabs_ros::ScitosG5Config config;
getFeatures(config);

// mutex needed for dynreconf.updateConfig, see non existent manual, eh I mean source
boost::recursive_mutex::scoped_lock dyn_reconf_lock(dynamic_reconfigure_mutex_);
// ROS_INFO_STREAM("Updating with current config from hardware... " << config.EBC1_Enable24V);
dynamic_reconfigure_server_.updateConfig(config);
dyn_reconf_lock.unlock();

// init reconfigure publisher
boost::thread(&ScitosBase::dynamicReconfigureUpdaterLoop, this, boost::ref(dynamic_reconfigure_server_),
boost::ref(dynamic_reconfigure_mutex_), ros::Rate(2));

// init reconfigure callback
dynamic_reconfigure::Server<metralabs_ros::ScitosG5Config>::CallbackType dyn_reconf_callback_ptr;
dyn_reconf_callback_ptr = boost::bind(&ScitosBase::dynamicReconfigureCallback, this, _1, _2);
dynamic_reconfigure_server_.setCallback(dyn_reconf_callback_ptr);

With the callback being like:

void ScitosBase::dynamicReconfigureCallback(metralabs_ros::ScitosG5Config& config, uint32_t level) {
    // Transfer config to node/hardware
    setFeatures(config);
}

And the updater thread loop being:

void ScitosBase::dynamicReconfigureUpdaterLoop(
        dynamic_reconfigure::Server<metralabs_ros::ScitosG5Config> &dynamic_reconfigure_server,
        boost::recursive_mutex &mutex, ros::Rate loop_rate) {
    metralabs_ros::ScitosG5Config config;
    while (node_handle_.ok()) {
        getFeatures(config);// update config to current hardware state
        boost::recursive_mutex::scoped_lock lock(mutex);
        dynamic_reconfigure_server.updateConfig(config);
        lock.unlock();
        loop_rate.sleep();
    }
}

Including source file


Originally posted by felix k with karma: 1650 on 2013-08-19

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.