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