00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef __ompl_interface_ros__OMPLDYNAMICRECONFIGURECONFIG_H__
00047 #define __ompl_interface_ros__OMPLDYNAMICRECONFIGURECONFIG_H__
00048
00049 #include <dynamic_reconfigure/config_tools.h>
00050 #include <moveit/macros/class_forward.h>
00051 #include <limits>
00052 #include <ros/node_handle.h>
00053 #include <dynamic_reconfigure/ConfigDescription.h>
00054 #include <dynamic_reconfigure/ParamDescription.h>
00055 #include <dynamic_reconfigure/Group.h>
00056 #include <dynamic_reconfigure/config_init_mutex.h>
00057 #include <boost/any.hpp>
00058
00059 namespace ompl_interface_ros
00060 {
00061 class OMPLDynamicReconfigureConfigStatics;
00062
00063 class OMPLDynamicReconfigureConfig
00064 {
00065 public:
00066 MOVEIT_CLASS_FORWARD(AbstractParamDescription);
00067 class AbstractParamDescription : public dynamic_reconfigure::ParamDescription
00068 {
00069 public:
00070 AbstractParamDescription(std::string n, std::string t, uint32_t l, std::string d, std::string e)
00071 {
00072 name = n;
00073 type = t;
00074 level = l;
00075 description = d;
00076 edit_method = e;
00077 }
00078
00079 virtual void clamp(OMPLDynamicReconfigureConfig& config, const OMPLDynamicReconfigureConfig& max,
00080 const OMPLDynamicReconfigureConfig& min) const = 0;
00081 virtual void calcLevel(uint32_t& level, const OMPLDynamicReconfigureConfig& config1,
00082 const OMPLDynamicReconfigureConfig& config2) const = 0;
00083 virtual void fromServer(const ros::NodeHandle& nh, OMPLDynamicReconfigureConfig& config) const = 0;
00084 virtual void toServer(const ros::NodeHandle& nh, const OMPLDynamicReconfigureConfig& config) const = 0;
00085 virtual bool fromMessage(const dynamic_reconfigure::Config& msg, OMPLDynamicReconfigureConfig& config) const = 0;
00086 virtual void toMessage(dynamic_reconfigure::Config& msg, const OMPLDynamicReconfigureConfig& config) const = 0;
00087 virtual void getValue(const OMPLDynamicReconfigureConfig& config, boost::any& val) const = 0;
00088 };
00089
00090 template <class T>
00091 class ParamDescription : public AbstractParamDescription
00092 {
00093 public:
00094 ParamDescription(std::string name, std::string type, uint32_t level, std::string description,
00095 std::string edit_method, T OMPLDynamicReconfigureConfig::*f)
00096 : AbstractParamDescription(name, type, level, description, edit_method), field(f)
00097 {
00098 }
00099
00100 T(OMPLDynamicReconfigureConfig::*field);
00101
00102 virtual void clamp(OMPLDynamicReconfigureConfig& config, const OMPLDynamicReconfigureConfig& max,
00103 const OMPLDynamicReconfigureConfig& min) const
00104 {
00105 if (config.*field > max.*field)
00106 config.*field = max.*field;
00107
00108 if (config.*field < min.*field)
00109 config.*field = min.*field;
00110 }
00111
00112 virtual void calcLevel(uint32_t& comb_level, const OMPLDynamicReconfigureConfig& config1,
00113 const OMPLDynamicReconfigureConfig& config2) const
00114 {
00115 if (config1.*field != config2.*field)
00116 comb_level |= level;
00117 }
00118
00119 virtual void fromServer(const ros::NodeHandle& nh, OMPLDynamicReconfigureConfig& config) const
00120 {
00121 nh.getParam(name, config.*field);
00122 }
00123
00124 virtual void toServer(const ros::NodeHandle& nh, const OMPLDynamicReconfigureConfig& config) const
00125 {
00126 nh.setParam(name, config.*field);
00127 }
00128
00129 virtual bool fromMessage(const dynamic_reconfigure::Config& msg, OMPLDynamicReconfigureConfig& config) const
00130 {
00131 return dynamic_reconfigure::ConfigTools::getParameter(msg, name, config.*field);
00132 }
00133
00134 virtual void toMessage(dynamic_reconfigure::Config& msg, const OMPLDynamicReconfigureConfig& config) const
00135 {
00136 dynamic_reconfigure::ConfigTools::appendParameter(msg, name, config.*field);
00137 }
00138
00139 virtual void getValue(const OMPLDynamicReconfigureConfig& config, boost::any& val) const
00140 {
00141 val = config.*field;
00142 }
00143 };
00144
00145 MOVEIT_CLASS_FORWARD(AbstractGroupDescription);
00146 class AbstractGroupDescription : public dynamic_reconfigure::Group
00147 {
00148 public:
00149 AbstractGroupDescription(std::string n, std::string t, int p, int i, bool s)
00150 {
00151 name = n;
00152 type = t;
00153 parent = p;
00154 state = s;
00155 id = i;
00156 }
00157
00158 std::vector<AbstractParamDescriptionConstPtr> abstract_parameters;
00159 bool state;
00160
00161 virtual void toMessage(dynamic_reconfigure::Config& msg, const boost::any& config) const = 0;
00162 virtual bool fromMessage(const dynamic_reconfigure::Config& msg, boost::any& config) const = 0;
00163 virtual void updateParams(boost::any& cfg, OMPLDynamicReconfigureConfig& top) const = 0;
00164 virtual void setInitialState(boost::any& cfg) const = 0;
00165
00166 void convertParams()
00167 {
00168 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = abstract_parameters.begin();
00169 i != abstract_parameters.end(); i++)
00170 {
00171 parameters.push_back(dynamic_reconfigure::ParamDescription(**i));
00172 }
00173 }
00174 };
00175
00176 template <class T, class PT>
00177 class GroupDescription : public AbstractGroupDescription
00178 {
00179 public:
00180 GroupDescription(std::string name, std::string type, int parent, int id, bool s, T PT::*f)
00181 : AbstractGroupDescription(name, type, parent, id, s), field(f)
00182 {
00183 }
00184
00185 GroupDescription(const GroupDescription<T, PT>& g)
00186 : AbstractGroupDescription(g.name, g.type, g.parent, g.id, g.state), field(g.field), groups(g.groups)
00187 {
00188 parameters = g.parameters;
00189 abstract_parameters = g.abstract_parameters;
00190 }
00191
00192 virtual bool fromMessage(const dynamic_reconfigure::Config& msg, boost::any& cfg) const
00193 {
00194 PT* config = boost::any_cast<PT*>(cfg);
00195 if (!dynamic_reconfigure::ConfigTools::getGroupState(msg, name, (*config).*field))
00196 return false;
00197
00198 for (std::vector<AbstractGroupDescriptionConstPtr>::const_iterator i = groups.begin(); i != groups.end(); i++)
00199 {
00200 boost::any n = &((*config).*field);
00201 if (!(*i)->fromMessage(msg, n))
00202 return false;
00203 }
00204
00205 return true;
00206 }
00207
00208 virtual void setInitialState(boost::any& cfg) const
00209 {
00210 PT* config = boost::any_cast<PT*>(cfg);
00211 T* group = &((*config).*field);
00212 group->state = state;
00213
00214 for (std::vector<AbstractGroupDescriptionConstPtr>::const_iterator i = groups.begin(); i != groups.end(); i++)
00215 {
00216 boost::any n = boost::any(&((*config).*field));
00217 (*i)->setInitialState(n);
00218 }
00219 }
00220
00221 virtual void updateParams(boost::any& cfg, OMPLDynamicReconfigureConfig& top) const
00222 {
00223 PT* config = boost::any_cast<PT*>(cfg);
00224
00225 T* f = &((*config).*field);
00226 f->setParams(top, abstract_parameters);
00227
00228 for (std::vector<AbstractGroupDescriptionConstPtr>::const_iterator i = groups.begin(); i != groups.end(); i++)
00229 {
00230 boost::any n = &((*config).*field);
00231 (*i)->updateParams(n, top);
00232 }
00233 }
00234
00235 virtual void toMessage(dynamic_reconfigure::Config& msg, const boost::any& cfg) const
00236 {
00237 const PT config = boost::any_cast<PT>(cfg);
00238 dynamic_reconfigure::ConfigTools::appendGroup<T>(msg, name, id, parent, config.*field);
00239
00240 for (std::vector<AbstractGroupDescriptionConstPtr>::const_iterator i = groups.begin(); i != groups.end(); i++)
00241 {
00242 (*i)->toMessage(msg, config.*field);
00243 }
00244 }
00245
00246 T(PT::*field);
00247 std::vector<OMPLDynamicReconfigureConfig::AbstractGroupDescriptionConstPtr> groups;
00248 };
00249
00250 class DEFAULT
00251 {
00252 public:
00253 DEFAULT()
00254 {
00255 state = true;
00256 name = "Default";
00257 }
00258
00259 void setParams(OMPLDynamicReconfigureConfig& config, const std::vector<AbstractParamDescriptionConstPtr> params)
00260 {
00261 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = params.begin(); i != params.end(); i++)
00262 {
00263 boost::any val;
00264 (*i)->getValue(config, val);
00265
00266 if ("link_for_exploration_tree" == (*i)->name)
00267 {
00268 link_for_exploration_tree = boost::any_cast<std::string>(val);
00269 }
00270 }
00271 }
00272
00273 std::string link_for_exploration_tree;
00274
00275 bool state;
00276 std::string name;
00277
00278 } groups;
00279
00280
00281 std::string link_for_exploration_tree;
00282
00283
00284 bool __fromMessage__(dynamic_reconfigure::Config& msg)
00285 {
00286 const std::vector<AbstractParamDescriptionConstPtr>& __param_descriptions__ = __getParamDescriptions__();
00287 const std::vector<AbstractGroupDescriptionConstPtr>& __group_descriptions__ = __getGroupDescriptions__();
00288
00289 int count = 0;
00290 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin();
00291 i != __param_descriptions__.end(); i++)
00292 if ((*i)->fromMessage(msg, *this))
00293 count++;
00294
00295 for (std::vector<AbstractGroupDescriptionConstPtr>::const_iterator i = __group_descriptions__.begin();
00296 i != __group_descriptions__.end(); i++)
00297 {
00298 if ((*i)->id == 0)
00299 {
00300 boost::any n = boost::any(this);
00301 (*i)->updateParams(n, *this);
00302 (*i)->fromMessage(msg, n);
00303 }
00304 }
00305
00306 if (count != dynamic_reconfigure::ConfigTools::size(msg))
00307 {
00308 ROS_ERROR("OMPLDynamicReconfigureConfig::__fromMessage__ called with an unexpected parameter.");
00309 ROS_ERROR("Booleans:");
00310 for (unsigned int i = 0; i < msg.bools.size(); i++)
00311 ROS_ERROR(" %s", msg.bools[i].name.c_str());
00312 ROS_ERROR("Integers:");
00313 for (unsigned int i = 0; i < msg.ints.size(); i++)
00314 ROS_ERROR(" %s", msg.ints[i].name.c_str());
00315 ROS_ERROR("Doubles:");
00316 for (unsigned int i = 0; i < msg.doubles.size(); i++)
00317 ROS_ERROR(" %s", msg.doubles[i].name.c_str());
00318 ROS_ERROR("Strings:");
00319 for (unsigned int i = 0; i < msg.strs.size(); i++)
00320 ROS_ERROR(" %s", msg.strs[i].name.c_str());
00321
00322
00323 return false;
00324 }
00325 return true;
00326 }
00327
00328
00329
00330 void __toMessage__(dynamic_reconfigure::Config& msg,
00331 const std::vector<AbstractParamDescriptionConstPtr>& __param_descriptions__,
00332 const std::vector<AbstractGroupDescriptionConstPtr>& __group_descriptions__) const
00333 {
00334 dynamic_reconfigure::ConfigTools::clear(msg);
00335 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin();
00336 i != __param_descriptions__.end(); i++)
00337 (*i)->toMessage(msg, *this);
00338
00339 for (std::vector<AbstractGroupDescriptionConstPtr>::const_iterator i = __group_descriptions__.begin();
00340 i != __group_descriptions__.end(); i++)
00341 {
00342 if ((*i)->id == 0)
00343 {
00344 (*i)->toMessage(msg, *this);
00345 }
00346 }
00347 }
00348
00349 void __toMessage__(dynamic_reconfigure::Config& msg) const
00350 {
00351 const std::vector<AbstractParamDescriptionConstPtr>& __param_descriptions__ = __getParamDescriptions__();
00352 const std::vector<AbstractGroupDescriptionConstPtr>& __group_descriptions__ = __getGroupDescriptions__();
00353 __toMessage__(msg, __param_descriptions__, __group_descriptions__);
00354 }
00355
00356 void __toServer__(const ros::NodeHandle& nh) const
00357 {
00358 const std::vector<AbstractParamDescriptionConstPtr>& __param_descriptions__ = __getParamDescriptions__();
00359 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin();
00360 i != __param_descriptions__.end(); i++)
00361 (*i)->toServer(nh, *this);
00362 }
00363
00364 void __fromServer__(const ros::NodeHandle& nh)
00365 {
00366 static bool setup = false;
00367
00368 const std::vector<AbstractParamDescriptionConstPtr>& __param_descriptions__ = __getParamDescriptions__();
00369 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin();
00370 i != __param_descriptions__.end(); i++)
00371 (*i)->fromServer(nh, *this);
00372
00373 const std::vector<AbstractGroupDescriptionConstPtr>& __group_descriptions__ = __getGroupDescriptions__();
00374 for (std::vector<AbstractGroupDescriptionConstPtr>::const_iterator i = __group_descriptions__.begin();
00375 i != __group_descriptions__.end(); i++)
00376 {
00377 if (!setup && (*i)->id == 0)
00378 {
00379 setup = true;
00380 boost::any n = boost::any(this);
00381 (*i)->setInitialState(n);
00382 }
00383 }
00384 }
00385
00386 void __clamp__()
00387 {
00388 const std::vector<AbstractParamDescriptionConstPtr>& __param_descriptions__ = __getParamDescriptions__();
00389 const OMPLDynamicReconfigureConfig& __max__ = __getMax__();
00390 const OMPLDynamicReconfigureConfig& __min__ = __getMin__();
00391 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin();
00392 i != __param_descriptions__.end(); i++)
00393 (*i)->clamp(*this, __max__, __min__);
00394 }
00395
00396 uint32_t __level__(const OMPLDynamicReconfigureConfig& config) const
00397 {
00398 const std::vector<AbstractParamDescriptionConstPtr>& __param_descriptions__ = __getParamDescriptions__();
00399 uint32_t level = 0;
00400 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin();
00401 i != __param_descriptions__.end(); i++)
00402 (*i)->calcLevel(level, config, *this);
00403 return level;
00404 }
00405
00406 static const dynamic_reconfigure::ConfigDescription& __getDescriptionMessage__();
00407 static const OMPLDynamicReconfigureConfig& __getDefault__();
00408 static const OMPLDynamicReconfigureConfig& __getMax__();
00409 static const OMPLDynamicReconfigureConfig& __getMin__();
00410 static const std::vector<AbstractParamDescriptionConstPtr>& __getParamDescriptions__();
00411 static const std::vector<AbstractGroupDescriptionConstPtr>& __getGroupDescriptions__();
00412
00413 private:
00414 static const OMPLDynamicReconfigureConfigStatics* __get_statics__();
00415 };
00416
00417 template <>
00418 inline void
00419 OMPLDynamicReconfigureConfig::ParamDescription<std::string>::clamp(OMPLDynamicReconfigureConfig& config,
00420 const OMPLDynamicReconfigureConfig& max,
00421 const OMPLDynamicReconfigureConfig& min) const
00422 {
00423 return;
00424 }
00425
00426 class OMPLDynamicReconfigureConfigStatics
00427 {
00428 friend class OMPLDynamicReconfigureConfig;
00429
00430 OMPLDynamicReconfigureConfigStatics()
00431 {
00432 OMPLDynamicReconfigureConfig::GroupDescription<OMPLDynamicReconfigureConfig::DEFAULT, OMPLDynamicReconfigureConfig>
00433 Default("Default", "", 0, 0, true, &OMPLDynamicReconfigureConfig::groups);
00434
00435 __min__.link_for_exploration_tree = "";
00436
00437 __max__.link_for_exploration_tree = "";
00438
00439 __default__.link_for_exploration_tree = "";
00440
00441 Default.abstract_parameters.push_back(OMPLDynamicReconfigureConfig::AbstractParamDescriptionConstPtr(
00442 new OMPLDynamicReconfigureConfig::ParamDescription<std::string>(
00443 "link_for_exploration_tree", "str", 1, "Show the exploration tree for a particular link", "",
00444 &OMPLDynamicReconfigureConfig::link_for_exploration_tree)));
00445
00446 __param_descriptions__.push_back(OMPLDynamicReconfigureConfig::AbstractParamDescriptionConstPtr(
00447 new OMPLDynamicReconfigureConfig::ParamDescription<std::string>(
00448 "link_for_exploration_tree", "str", 1, "Show the exploration tree for a particular link", "",
00449 &OMPLDynamicReconfigureConfig::link_for_exploration_tree)));
00450
00451 Default.convertParams();
00452
00453 __group_descriptions__.push_back(OMPLDynamicReconfigureConfig::AbstractGroupDescriptionConstPtr(
00454 new OMPLDynamicReconfigureConfig::GroupDescription<OMPLDynamicReconfigureConfig::DEFAULT,
00455 OMPLDynamicReconfigureConfig>(Default)));
00456
00457
00458 for (std::vector<OMPLDynamicReconfigureConfig::AbstractGroupDescriptionConstPtr>::const_iterator i =
00459 __group_descriptions__.begin();
00460 i != __group_descriptions__.end(); i++)
00461 {
00462 __description_message__.groups.push_back(**i);
00463 }
00464 __max__.__toMessage__(__description_message__.max, __param_descriptions__, __group_descriptions__);
00465 __min__.__toMessage__(__description_message__.min, __param_descriptions__, __group_descriptions__);
00466 __default__.__toMessage__(__description_message__.dflt, __param_descriptions__, __group_descriptions__);
00467 }
00468 std::vector<OMPLDynamicReconfigureConfig::AbstractParamDescriptionConstPtr> __param_descriptions__;
00469 std::vector<OMPLDynamicReconfigureConfig::AbstractGroupDescriptionConstPtr> __group_descriptions__;
00470 OMPLDynamicReconfigureConfig __max__;
00471 OMPLDynamicReconfigureConfig __min__;
00472 OMPLDynamicReconfigureConfig __default__;
00473 dynamic_reconfigure::ConfigDescription __description_message__;
00474
00475 static const OMPLDynamicReconfigureConfigStatics* get_instance()
00476 {
00477
00478
00479
00480
00481 static OMPLDynamicReconfigureConfigStatics instance;
00482 return &instance;
00483 }
00484 };
00485
00486 inline const dynamic_reconfigure::ConfigDescription& OMPLDynamicReconfigureConfig::__getDescriptionMessage__()
00487 {
00488 return __get_statics__()->__description_message__;
00489 }
00490
00491 inline const OMPLDynamicReconfigureConfig& OMPLDynamicReconfigureConfig::__getDefault__()
00492 {
00493 return __get_statics__()->__default__;
00494 }
00495
00496 inline const OMPLDynamicReconfigureConfig& OMPLDynamicReconfigureConfig::__getMax__()
00497 {
00498 return __get_statics__()->__max__;
00499 }
00500
00501 inline const OMPLDynamicReconfigureConfig& OMPLDynamicReconfigureConfig::__getMin__()
00502 {
00503 return __get_statics__()->__min__;
00504 }
00505
00506 inline const std::vector<OMPLDynamicReconfigureConfig::AbstractParamDescriptionConstPtr>&
00507 OMPLDynamicReconfigureConfig::__getParamDescriptions__()
00508 {
00509 return __get_statics__()->__param_descriptions__;
00510 }
00511
00512 inline const std::vector<OMPLDynamicReconfigureConfig::AbstractGroupDescriptionConstPtr>&
00513 OMPLDynamicReconfigureConfig::__getGroupDescriptions__()
00514 {
00515 return __get_statics__()->__group_descriptions__;
00516 }
00517
00518 inline const OMPLDynamicReconfigureConfigStatics* OMPLDynamicReconfigureConfig::__get_statics__()
00519 {
00520 const static OMPLDynamicReconfigureConfigStatics* statics;
00521
00522 if (statics)
00523 return statics;
00524
00525 boost::mutex::scoped_lock lock(dynamic_reconfigure::__init_mutex__);
00526
00527 if (statics)
00528 return statics;
00529
00530 statics = OMPLDynamicReconfigureConfigStatics::get_instance();
00531
00532 return statics;
00533 }
00534 }
00535
00536 #endif // __OMPLDYNAMICRECONFIGURERECONFIGURATOR_H__