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 #ifndef __turtlebot_follower__FOLLOWERCONFIG_H__
00048 #define __turtlebot_follower__FOLLOWERCONFIG_H__
00049
00050 #include <dynamic_reconfigure/config_tools.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/config_init_mutex.h>
00056
00057 namespace turtlebot_follower
00058 {
00059 class FollowerConfigStatics;
00060
00061 class FollowerConfig
00062 {
00063 public:
00064 class AbstractParamDescription : public dynamic_reconfigure::ParamDescription
00065 {
00066 public:
00067 AbstractParamDescription(std::string n, std::string t, uint32_t l,
00068 std::string d, std::string e)
00069 {
00070 name = n;
00071 type = t;
00072 level = l;
00073 description = d;
00074 edit_method = e;
00075 }
00076
00077 virtual void clamp(FollowerConfig &config, const FollowerConfig &max, const FollowerConfig &min) const = 0;
00078 virtual void calcLevel(uint32_t &level, const FollowerConfig &config1, const FollowerConfig &config2) const = 0;
00079 virtual void fromServer(const ros::NodeHandle &nh, FollowerConfig &config) const = 0;
00080 virtual void toServer(const ros::NodeHandle &nh, const FollowerConfig &config) const = 0;
00081 virtual bool fromMessage(const dynamic_reconfigure::Config &msg, FollowerConfig &config) const = 0;
00082 virtual void toMessage(dynamic_reconfigure::Config &msg, const FollowerConfig &config) const = 0;
00083 };
00084
00085 typedef boost::shared_ptr<AbstractParamDescription> AbstractParamDescriptionPtr;
00086 typedef boost::shared_ptr<const AbstractParamDescription> AbstractParamDescriptionConstPtr;
00087
00088 template <class T>
00089 class ParamDescription : public AbstractParamDescription
00090 {
00091 public:
00092 ParamDescription(std::string name, std::string type, uint32_t level,
00093 std::string description, std::string edit_method, T FollowerConfig::* f) :
00094 AbstractParamDescription(name, type, level, description, edit_method),
00095 field(f)
00096 {}
00097
00098 T (FollowerConfig::* field);
00099
00100 virtual void clamp(FollowerConfig &config, const FollowerConfig &max, const FollowerConfig &min) const
00101 {
00102 if (config.*field > max.*field)
00103 config.*field = max.*field;
00104
00105 if (config.*field < min.*field)
00106 config.*field = min.*field;
00107 }
00108
00109 virtual void calcLevel(uint32_t &comb_level, const FollowerConfig &config1, const FollowerConfig &config2) const
00110 {
00111 if (config1.*field != config2.*field)
00112 comb_level |= level;
00113 }
00114
00115 virtual void fromServer(const ros::NodeHandle &nh, FollowerConfig &config) const
00116 {
00117 nh.getParam(name, config.*field);
00118 }
00119
00120 virtual void toServer(const ros::NodeHandle &nh, const FollowerConfig &config) const
00121 {
00122 nh.setParam(name, config.*field);
00123 }
00124
00125 virtual bool fromMessage(const dynamic_reconfigure::Config &msg, FollowerConfig &config) const
00126 {
00127 return dynamic_reconfigure::ConfigTools::getParameter(msg, name, config.*field);
00128 }
00129
00130 virtual void toMessage(dynamic_reconfigure::Config &msg, const FollowerConfig &config) const
00131 {
00132 dynamic_reconfigure::ConfigTools::appendParameter(msg, name, config.*field);
00133 }
00134 };
00135
00136
00137 double min_x;
00138
00139 double max_x;
00140
00141 double min_y;
00142
00143 double max_y;
00144
00145 double max_z;
00146
00147 double goal_z;
00148
00149 double z_scale;
00150
00151 double x_scale;
00152
00153
00154 bool __fromMessage__(dynamic_reconfigure::Config &msg)
00155 {
00156 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00157 int count = 0;
00158 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00159 if ((*i)->fromMessage(msg, *this))
00160 count++;
00161 if (count != dynamic_reconfigure::ConfigTools::size(msg))
00162 {
00163 ROS_ERROR("FollowerConfig::__fromMessage__ called with an unexpected parameter.");
00164 ROS_ERROR("Booleans:");
00165 for (unsigned int i = 0; i < msg.bools.size(); i++)
00166 ROS_ERROR(" %s", msg.bools[i].name.c_str());
00167 ROS_ERROR("Integers:");
00168 for (unsigned int i = 0; i < msg.ints.size(); i++)
00169 ROS_ERROR(" %s", msg.ints[i].name.c_str());
00170 ROS_ERROR("Doubles:");
00171 for (unsigned int i = 0; i < msg.doubles.size(); i++)
00172 ROS_ERROR(" %s", msg.doubles[i].name.c_str());
00173 ROS_ERROR("Strings:");
00174 for (unsigned int i = 0; i < msg.strs.size(); i++)
00175 ROS_ERROR(" %s", msg.strs[i].name.c_str());
00176
00177
00178 return false;
00179 }
00180 return true;
00181 }
00182
00183
00184
00185 void __toMessage__(dynamic_reconfigure::Config &msg, const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__) const
00186 {
00187 dynamic_reconfigure::ConfigTools::clear(msg);
00188 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00189 (*i)->toMessage(msg, *this);
00190 }
00191
00192 void __toMessage__(dynamic_reconfigure::Config &msg) const
00193 {
00194 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00195 __toMessage__(msg, __param_descriptions__);
00196 }
00197
00198 void __toServer__(const ros::NodeHandle &nh) const
00199 {
00200 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00201 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00202 (*i)->toServer(nh, *this);
00203 }
00204
00205 void __fromServer__(const ros::NodeHandle &nh)
00206 {
00207 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00208 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00209 (*i)->fromServer(nh, *this);
00210 }
00211
00212 void __clamp__()
00213 {
00214 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00215 const FollowerConfig &__max__ = __getMax__();
00216 const FollowerConfig &__min__ = __getMin__();
00217 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00218 (*i)->clamp(*this, __max__, __min__);
00219 }
00220
00221 uint32_t __level__(const FollowerConfig &config) const
00222 {
00223 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00224 uint32_t level = 0;
00225 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00226 (*i)->calcLevel(level, config, *this);
00227 return level;
00228 }
00229
00230 static const dynamic_reconfigure::ConfigDescription &__getDescriptionMessage__();
00231 static const FollowerConfig &__getDefault__();
00232 static const FollowerConfig &__getMax__();
00233 static const FollowerConfig &__getMin__();
00234 static const std::vector<AbstractParamDescriptionConstPtr> &__getParamDescriptions__();
00235
00236 private:
00237 static const FollowerConfigStatics *__get_statics__();
00238 };
00239
00240 template <>
00241 inline void FollowerConfig::ParamDescription<std::string>::clamp(FollowerConfig &config, const FollowerConfig &max, const FollowerConfig &min) const
00242 {
00243 return;
00244 }
00245
00246 class FollowerConfigStatics
00247 {
00248 friend class FollowerConfig;
00249
00250 FollowerConfigStatics()
00251 {
00252
00253 __min__.min_x = -3.0;
00254
00255 __max__.min_x = 3.0;
00256
00257 __default__.min_x = -0.2;
00258
00259 __param_descriptions__.push_back(FollowerConfig::AbstractParamDescriptionConstPtr(new FollowerConfig::ParamDescription<double>("min_x", "double", 0, "The minimum x position of the points in the box.", "", &FollowerConfig::min_x)));
00260
00261 __min__.max_x = -3.0;
00262
00263 __max__.max_x = 3.0;
00264
00265 __default__.max_x = 0.2;
00266
00267 __param_descriptions__.push_back(FollowerConfig::AbstractParamDescriptionConstPtr(new FollowerConfig::ParamDescription<double>("max_x", "double", 0, "The maximum x position of the points in the box.", "", &FollowerConfig::max_x)));
00268
00269 __min__.min_y = -1.0;
00270
00271 __max__.min_y = 3.0;
00272
00273 __default__.min_y = 0.1;
00274
00275 __param_descriptions__.push_back(FollowerConfig::AbstractParamDescriptionConstPtr(new FollowerConfig::ParamDescription<double>("min_y", "double", 0, "The minimum y position of the points in the box.", "", &FollowerConfig::min_y)));
00276
00277 __min__.max_y = -1.0;
00278
00279 __max__.max_y = 3.0;
00280
00281 __default__.max_y = 0.5;
00282
00283 __param_descriptions__.push_back(FollowerConfig::AbstractParamDescriptionConstPtr(new FollowerConfig::ParamDescription<double>("max_y", "double", 0, "The maximum y position of the points in the box.", "", &FollowerConfig::max_y)));
00284
00285 __min__.max_z = 0.0;
00286
00287 __max__.max_z = 3.0;
00288
00289 __default__.max_z = 0.8;
00290
00291 __param_descriptions__.push_back(FollowerConfig::AbstractParamDescriptionConstPtr(new FollowerConfig::ParamDescription<double>("max_z", "double", 0, "The maximum z position of the points in the box.", "", &FollowerConfig::max_z)));
00292
00293 __min__.goal_z = 0.0;
00294
00295 __max__.goal_z = 3.0;
00296
00297 __default__.goal_z = 0.6;
00298
00299 __param_descriptions__.push_back(FollowerConfig::AbstractParamDescriptionConstPtr(new FollowerConfig::ParamDescription<double>("goal_z", "double", 0, "The distance away from the robot to hold the centroid.", "", &FollowerConfig::goal_z)));
00300
00301 __min__.z_scale = 0.0;
00302
00303 __max__.z_scale = 3.0;
00304
00305 __default__.z_scale = 1.0;
00306
00307 __param_descriptions__.push_back(FollowerConfig::AbstractParamDescriptionConstPtr(new FollowerConfig::ParamDescription<double>("z_scale", "double", 0, "The scaling factor for translational robot speed.", "", &FollowerConfig::z_scale)));
00308
00309 __min__.x_scale = 0.0;
00310
00311 __max__.x_scale = 10.0;
00312
00313 __default__.x_scale = 5.0;
00314
00315 __param_descriptions__.push_back(FollowerConfig::AbstractParamDescriptionConstPtr(new FollowerConfig::ParamDescription<double>("x_scale", "double", 0, "The scaling factor for rotational robot speed.", "", &FollowerConfig::x_scale)));
00316
00317
00318 for (std::vector<FollowerConfig::AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00319 __description_message__.parameters.push_back(**i);
00320 __max__.__toMessage__(__description_message__.max, __param_descriptions__);
00321 __min__.__toMessage__(__description_message__.min, __param_descriptions__);
00322 __default__.__toMessage__(__description_message__.dflt, __param_descriptions__);
00323 }
00324 std::vector<FollowerConfig::AbstractParamDescriptionConstPtr> __param_descriptions__;
00325 FollowerConfig __max__;
00326 FollowerConfig __min__;
00327 FollowerConfig __default__;
00328 dynamic_reconfigure::ConfigDescription __description_message__;
00329 static const FollowerConfigStatics *get_instance()
00330 {
00331
00332
00333
00334
00335 static FollowerConfigStatics instance;
00336 return &instance;
00337 }
00338 };
00339
00340 inline const dynamic_reconfigure::ConfigDescription &FollowerConfig::__getDescriptionMessage__()
00341 {
00342 return __get_statics__()->__description_message__;
00343 }
00344
00345 inline const FollowerConfig &FollowerConfig::__getDefault__()
00346 {
00347 return __get_statics__()->__default__;
00348 }
00349
00350 inline const FollowerConfig &FollowerConfig::__getMax__()
00351 {
00352 return __get_statics__()->__max__;
00353 }
00354
00355 inline const FollowerConfig &FollowerConfig::__getMin__()
00356 {
00357 return __get_statics__()->__min__;
00358 }
00359
00360 inline const std::vector<FollowerConfig::AbstractParamDescriptionConstPtr> &FollowerConfig::__getParamDescriptions__()
00361 {
00362 return __get_statics__()->__param_descriptions__;
00363 }
00364
00365 inline const FollowerConfigStatics *FollowerConfig::__get_statics__()
00366 {
00367 const static FollowerConfigStatics *statics;
00368
00369 if (statics)
00370 return statics;
00371
00372 boost::mutex::scoped_lock lock(dynamic_reconfigure::__init_mutex__);
00373
00374 if (statics)
00375 return statics;
00376
00377 statics = FollowerConfigStatics::get_instance();
00378
00379 return statics;
00380 }
00381
00382
00383 }
00384
00385 #endif // __FOLLOWERRECONFIGURATOR_H__