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