30 #ifndef SWRI_ROSCPP_DYNAMIC_PARAMETERS_H_ 31 #define SWRI_ROSCPP_DYNAMIC_PARAMETERS_H_ 36 #include <boost/thread/mutex.hpp> 41 #include <dynamic_reconfigure/Config.h> 42 #include <dynamic_reconfigure/ConfigDescription.h> 43 #include <dynamic_reconfigure/GroupState.h> 44 #include <dynamic_reconfigure/Reconfigure.h> 134 dynamic_reconfigure::Reconfigure::Response &rsp)
136 ROS_DEBUG(
"Got configuration change request");
138 boost::mutex::scoped_lock lock(*mutex_);
141 for (
int i = 0;
i < req.config.doubles.size();
i++)
143 dynamic_reconfigure::DoubleParameter
param = req.config.doubles[
i];
144 std::map<std::string, DynamicValue>::iterator iter = values_.find(param.name);
145 if (iter == values_.end())
147 ROS_ERROR(
"Could not find parameter '%s'", param.name.c_str());
153 ROS_ERROR(
"Value '%s' was not a double type.", param.name.c_str());
159 *iter->second.dbl = param.value;
164 *iter->second.flt = (float)param.value;
168 for (
int i = 0;
i < req.config.ints.size();
i++)
170 dynamic_reconfigure::IntParameter
param = req.config.ints[
i];
171 std::map<std::string, DynamicValue>::iterator iter = values_.find(param.name);
172 if (iter == values_.end())
174 ROS_ERROR(
"Could not find parameter '%s'", param.name.c_str());
180 ROS_ERROR(
"Value '%s' was not a int type.", param.name.c_str());
184 *iter->second.integer = param.value;
187 for (
int i = 0;
i < req.config.bools.size();
i++)
189 dynamic_reconfigure::BoolParameter
param = req.config.bools[
i];
190 std::map<std::string, DynamicValue>::iterator iter = values_.find(param.name);
191 if (iter == values_.end())
193 ROS_ERROR(
"Could not find parameter '%s'", param.name.c_str());
199 ROS_ERROR(
"Value '%s' was not a bool type.", param.name.c_str());
203 *iter->second.boolean = param.value;
206 for (
int i = 0;
i < req.config.strs.size();
i++)
208 dynamic_reconfigure::StrParameter
param = req.config.strs[
i];
209 std::map<std::string, DynamicValue>::iterator iter = values_.find(param.name);
210 if (iter == values_.end())
212 ROS_ERROR(
"Could not find parameter '%s'", param.name.c_str());
218 ROS_ERROR(
"Value '%s' was not a string type.", param.name.c_str());
222 *iter->second.str = param.value;
225 updateCurrent(rsp.config);
238 for (std::map<std::string, DynamicValue>::iterator value = values_.begin(); value != values_.end(); value++)
242 dynamic_reconfigure::DoubleParameter
param;
243 param.name = value->first;
244 param.value = *value->second.dbl;
245 config.doubles.push_back(param);
249 dynamic_reconfigure::DoubleParameter
param;
250 param.name = value->first;
251 param.value = *value->second.flt;
252 config.doubles.push_back(param);
256 dynamic_reconfigure::IntParameter
param;
257 param.name = value->first;
258 param.value = *value->second.integer;
259 config.ints.push_back(param);
263 dynamic_reconfigure::BoolParameter
param;
264 param.name = value->first;
265 param.value = *value->second.boolean;
266 config.bools.push_back(param);
270 dynamic_reconfigure::StrParameter
param;
271 param.name = value->first;
272 param.value = *value->second.str;
273 config.strs.push_back(param);
277 dynamic_reconfigure::GroupState gs;
282 config.groups.push_back(gs);
296 boost::mutex::scoped_lock lock(*mutex_);
299 descr_pub_ = nh_.
advertise<dynamic_reconfigure::ConfigDescription>(
"parameter_descriptions", 1,
true);
300 update_pub_ = nh_.
advertise<dynamic_reconfigure::Config>(
"parameter_updates", 1,
true);
306 boost::mutex::scoped_lock lock(*mutex_);
309 dynamic_reconfigure::ConfigDescription rdesc;
310 dynamic_reconfigure::Group group;
311 group.name =
"Default";
316 dynamic_reconfigure::GroupState gs;
321 for (std::map<std::string, DynamicValue>::iterator
param = values_.begin();
param != values_.end();
param++)
328 dynamic_reconfigure::BoolParameter desc;
329 desc.name =
param->first;
331 rdesc.max.bools.push_back(desc);
333 rdesc.min.bools.push_back(desc);
334 desc.value =
param->second.Default.b;
335 rdesc.dflt.bools.push_back(desc);
341 dynamic_reconfigure::DoubleParameter desc;
342 desc.name =
param->first;
343 desc.value =
param->second.Max.d;
344 rdesc.max.doubles.push_back(desc);
345 desc.value =
param->second.Min.d;
346 rdesc.min.doubles.push_back(desc);
347 desc.value =
param->second.Default.d;
348 rdesc.dflt.doubles.push_back(desc);
354 dynamic_reconfigure::DoubleParameter desc;
355 desc.name =
param->first;
356 desc.value =
param->second.Max.d;
357 rdesc.max.doubles.push_back(desc);
358 desc.value =
param->second.Min.d;
359 rdesc.min.doubles.push_back(desc);
360 desc.value =
param->second.Default.d;
361 rdesc.dflt.doubles.push_back(desc);
367 dynamic_reconfigure::IntParameter desc;
368 desc.name =
param->first;
369 desc.value =
param->second.Max.i;
370 rdesc.max.ints.push_back(desc);
371 desc.value =
param->second.Min.i;
372 rdesc.min.ints.push_back(desc);
373 desc.value =
param->second.Default.i;
374 rdesc.dflt.ints.push_back(desc);
379 dynamic_reconfigure::StrParameter desc;
380 desc.name =
param->first;
382 rdesc.max.strs.push_back(desc);
384 rdesc.min.strs.push_back(desc);
385 desc.value =
param->second.default_string;
386 rdesc.dflt.strs.push_back(desc);
389 dynamic_reconfigure::ParamDescription desc;
390 desc.name =
param->first;
393 desc.description =
param->second.description;
394 desc.edit_method =
"";
395 group.parameters.push_back(desc);
397 rdesc.max.groups.push_back(gs);
398 rdesc.min.groups.push_back(gs);
399 rdesc.dflt.groups.push_back(gs);
400 rdesc.groups.push_back(group);
403 dynamic_reconfigure::Config config;
404 updateCurrent(config);
418 std::map<std::string, DynamicValue>::iterator iter = values_.find(name);
419 if (iter == values_.end())
421 ROS_ERROR(
"Tried to get nonexistant param %s", name.c_str());
426 ROS_ERROR(
"Tried to load parameter %s with the wrong type: double.", name.c_str());
430 return *iter->second.dbl;
436 std::map<std::string, DynamicValue>::iterator iter = values_.find(name);
437 if (iter == values_.end())
439 ROS_ERROR(
"Tried to get nonexistant param %s", name.c_str());
444 ROS_ERROR(
"Tried to load parameter %s with the wrong type: float.", name.c_str());
448 return *iter->second.flt;
453 std::map<std::string, DynamicValue>::iterator iter = values_.find(name);
454 if (iter == values_.end())
456 ROS_ERROR(
"Tried to get nonexistant param %s", name.c_str());
461 ROS_ERROR(
"Tried to load parameter %s with the wrong type: int.", name.c_str());
465 return *iter->second.integer;
471 std::map<std::string, DynamicValue>::iterator iter = values_.find(name);
472 if (iter == values_.end())
474 ROS_ERROR(
"Tried to get nonexistant param %s", name.c_str());
479 ROS_ERROR(
"Tried to load parameter %s with the wrong type: bool.", name.c_str());
483 return *iter->second.boolean;
489 std::map<std::string, DynamicValue>::iterator iter = values_.find(name);
490 if (iter == values_.end())
492 ROS_ERROR(
"Tried to get nonexistant param %s", name.c_str());
497 ROS_ERROR(
"Tried to load parameter %s with the wrong type: string.", name.c_str());
501 return *iter->second.str;
514 return boost::mutex::scoped_lock(*mutex_);
519 void get(
const std::string &
name,
523 const float min = -100,
524 const float max = 100)
533 values_[
name] = value;
537 nh_.
param(name, *value.
flt, default_value);
538 variable = *value.
flt;
539 ROS_INFO(
"Read dynamic parameter %s = %f", name.c_str(), variable);
543 void get(
const std::string &
name,
544 FloatParam &variable,
545 const float default_value,
546 const std::string description =
"None.",
547 const float min = -100,
548 const float max = 100)
557 values_[
name] = value;
559 variable.data = value.
flt;
560 variable.mutex = mutex_;
564 nh_.
param(name, *value.
flt, default_value);
565 ROS_INFO(
"Read dynamic parameter %s = %f", name.c_str(), *variable);
570 void get(
const std::string &
name,
572 const double default_value,
573 const std::string description =
"None.",
574 const double min = -100,
575 const double max = 100)
584 values_[
name] = value;
588 nh_.
param(name, *value.
dbl, default_value);
589 variable = *value.
dbl;
590 ROS_INFO(
"Read dynamic parameter %s = %lf", name.c_str(), variable);
594 void get(
const std::string &
name,
595 DoubleParam &variable,
596 const double default_value,
597 const std::string description =
"None.",
598 const double min = -100,
599 const double max = 100)
608 values_[
name] = value;
610 variable.data = value.
dbl;
611 variable.mutex = mutex_;
615 nh_.
param(name, *value.
dbl, default_value);
616 ROS_INFO(
"Read dynamic parameter %s = %lf", name.c_str(), *variable);
620 void get(
const std::string &
name,
622 const int default_value,
623 const std::string description =
"None.",
624 const int min = -100,
634 values_[
name] = value;
640 ROS_INFO(
"Read dynamic parameter %s = %i", name.c_str(), variable);
644 void get(
const std::string &
name,
646 const int default_value,
647 const std::string description =
"None.",
648 const int min = -100,
658 values_[
name] = value;
661 variable.mutex = mutex_;
666 ROS_INFO(
"Read dynamic parameter %s = %i", name.c_str(), *variable);
671 void get(
const std::string &
name,
673 const bool default_value,
674 const std::string description =
"None.")
681 values_[
name] = value;
687 ROS_INFO(
"Read dynamic parameter %s = %s", name.c_str(), variable ?
"true" :
"false");
691 void get(
const std::string &
name,
693 const bool default_value,
694 const std::string description =
"None.")
701 values_[
name] = value;
704 variable.mutex = mutex_;
709 ROS_INFO(
"Read dynamic parameter %s = %s", name.c_str(), *variable ?
"true" :
"false");
714 void get(
const std::string &
name,
715 std::string &variable,
716 const std::string default_value,
717 const std::string description =
"None.")
724 values_[
name] = value;
728 nh_.
param(name, *value.
str, default_value);
729 variable = *value.
str;
730 ROS_INFO(
"Read dynamic parameter %s = %s", name.c_str(), variable.c_str());
734 void get(
const std::string &
name,
735 StringParam &variable,
736 const std::string default_value,
737 const std::string description =
"None.")
744 values_[
name] = value;
746 variable.data = value.
str;
747 variable.mutex = mutex_;
751 nh_.
param(name, *value.
str, default_value);
752 ROS_INFO(
"Read dynamic parameter %s = %s", name.c_str(), (*variable).c_str());
756 #endif // SWRI_ROSCPP_DYNAMIC_PARAMETERS_H_
boost::shared_ptr< boost::mutex > mutex
void publish(const boost::shared_ptr< M > &message) const
std::string resolveName(const std::string &name, bool remap=true) const
void initialize(ros::NodeHandle &pnh)
void updateCurrent(dynamic_reconfigure::Config &config)
float getFloat(const std::string &name)
boost::shared_ptr< std::string > str
std::string getString(const std::string &name)
bool setConfigCallback(dynamic_reconfigure::Reconfigure::Request &req, dynamic_reconfigure::Reconfigure::Response &rsp)
std::map< std::string, DynamicValue > values_
bool getBool(const std::string &name)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
boost::shared_ptr< double > dbl
TypedParam< bool > BoolParam
union swri::DynamicValue::@1 Min
double getDouble(const std::string &name)
boost::mutex::scoped_lock lock_guard()
void setCallback(boost::function< void(DynamicParameters &)> fun)
static void param(const ros::NodeHandle &nh, const std::string &name, int &variable, const int default_value)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
boost::shared_ptr< bool > boolean
boost::shared_ptr< boost::mutex > mutex_
boost::shared_ptr< float > flt
boost::shared_ptr< int > integer
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TypedParam< double > DoubleParam
TypedParam< int > IntParam
boost::function< void(DynamicParameters &)> on_change_
TypedParam< std::string > StringParam
boost::shared_ptr< T > data
ros::Publisher update_pub_
union swri::DynamicValue::@0 Default
TypedParam< float > FloatParam
std::string default_string
int getInt(const std::string &name)
ros::ServiceServer set_service_
union swri::DynamicValue::@2 Max
ros::Publisher descr_pub_