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

Notify changes to dynamic_reconfigure

asked 2013-03-07 21:17:31 -0600

sciarp gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-08-19 04:07:19 -0600

felix k gravatar image

updated 2013-08-19 04:09:46 -0600

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-03-07 21:17:31 -0600

Seen: 2,917 times

Last updated: Aug 19 '13