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 __gazebo_plugins__HOKUYOCONFIG_H__
00048 #define __gazebo_plugins__HOKUYOCONFIG_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 gazebo_plugins
00058 {
00059 class HokuyoConfigStatics;
00060
00061 class HokuyoConfig
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(HokuyoConfig &config, const HokuyoConfig &max, const HokuyoConfig &min) const = 0;
00078 virtual void calcLevel(uint32_t &level, const HokuyoConfig &config1, const HokuyoConfig &config2) const = 0;
00079 virtual void fromServer(const ros::NodeHandle &nh, HokuyoConfig &config) const = 0;
00080 virtual void toServer(const ros::NodeHandle &nh, const HokuyoConfig &config) const = 0;
00081 virtual bool fromMessage(const dynamic_reconfigure::Config &msg, HokuyoConfig &config) const = 0;
00082 virtual void toMessage(dynamic_reconfigure::Config &msg, const HokuyoConfig &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 HokuyoConfig::* f) :
00094 AbstractParamDescription(name, type, level, description, edit_method),
00095 field(f)
00096 {}
00097
00098 T (HokuyoConfig::* field);
00099
00100 virtual void clamp(HokuyoConfig &config, const HokuyoConfig &max, const HokuyoConfig &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 HokuyoConfig &config1, const HokuyoConfig &config2) const
00110 {
00111 if (config1.*field != config2.*field)
00112 comb_level |= level;
00113 }
00114
00115 virtual void fromServer(const ros::NodeHandle &nh, HokuyoConfig &config) const
00116 {
00117 nh.getParam(name, config.*field);
00118 }
00119
00120 virtual void toServer(const ros::NodeHandle &nh, const HokuyoConfig &config) const
00121 {
00122 nh.setParam(name, config.*field);
00123 }
00124
00125 virtual bool fromMessage(const dynamic_reconfigure::Config &msg, HokuyoConfig &config) const
00126 {
00127 return dynamic_reconfigure::ConfigTools::getParameter(msg, name, config.*field);
00128 }
00129
00130 virtual void toMessage(dynamic_reconfigure::Config &msg, const HokuyoConfig &config) const
00131 {
00132 dynamic_reconfigure::ConfigTools::appendParameter(msg, name, config.*field);
00133 }
00134 };
00135
00136
00137 double min_ang;
00138
00139 double max_ang;
00140
00141 bool intensity;
00142
00143 int cluster;
00144
00145 int skip;
00146
00147 std::string port;
00148
00149 bool calibrate_time;
00150
00151 std::string frame_id;
00152
00153 double time_offset;
00154
00155 bool allow_unsafe_settings;
00156
00157
00158 bool __fromMessage__(dynamic_reconfigure::Config &msg)
00159 {
00160 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00161 int count = 0;
00162 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00163 if ((*i)->fromMessage(msg, *this))
00164 count++;
00165 if (count != dynamic_reconfigure::ConfigTools::size(msg))
00166 {
00167 ROS_ERROR("HokuyoConfig::__fromMessage__ called with an unexpected parameter.");
00168 ROS_ERROR("Booleans:");
00169 for (unsigned int i = 0; i < msg.bools.size(); i++)
00170 ROS_ERROR(" %s", msg.bools[i].name.c_str());
00171 ROS_ERROR("Integers:");
00172 for (unsigned int i = 0; i < msg.ints.size(); i++)
00173 ROS_ERROR(" %s", msg.ints[i].name.c_str());
00174 ROS_ERROR("Doubles:");
00175 for (unsigned int i = 0; i < msg.doubles.size(); i++)
00176 ROS_ERROR(" %s", msg.doubles[i].name.c_str());
00177 ROS_ERROR("Strings:");
00178 for (unsigned int i = 0; i < msg.strs.size(); i++)
00179 ROS_ERROR(" %s", msg.strs[i].name.c_str());
00180
00181
00182 return false;
00183 }
00184 return true;
00185 }
00186
00187
00188
00189 void __toMessage__(dynamic_reconfigure::Config &msg, const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__) const
00190 {
00191 dynamic_reconfigure::ConfigTools::clear(msg);
00192 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00193 (*i)->toMessage(msg, *this);
00194 }
00195
00196 void __toMessage__(dynamic_reconfigure::Config &msg) const
00197 {
00198 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00199 __toMessage__(msg, __param_descriptions__);
00200 }
00201
00202 void __toServer__(const ros::NodeHandle &nh) const
00203 {
00204 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00205 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00206 (*i)->toServer(nh, *this);
00207 }
00208
00209 void __fromServer__(const ros::NodeHandle &nh)
00210 {
00211 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00212 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00213 (*i)->fromServer(nh, *this);
00214 }
00215
00216 void __clamp__()
00217 {
00218 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00219 const HokuyoConfig &__max__ = __getMax__();
00220 const HokuyoConfig &__min__ = __getMin__();
00221 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00222 (*i)->clamp(*this, __max__, __min__);
00223 }
00224
00225 uint32_t __level__(const HokuyoConfig &config) const
00226 {
00227 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00228 uint32_t level = 0;
00229 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00230 (*i)->calcLevel(level, config, *this);
00231 return level;
00232 }
00233
00234 static const dynamic_reconfigure::ConfigDescription &__getDescriptionMessage__();
00235 static const HokuyoConfig &__getDefault__();
00236 static const HokuyoConfig &__getMax__();
00237 static const HokuyoConfig &__getMin__();
00238 static const std::vector<AbstractParamDescriptionConstPtr> &__getParamDescriptions__();
00239
00240 private:
00241 static const HokuyoConfigStatics *__get_statics__();
00242 };
00243
00244 template <>
00245 inline void HokuyoConfig::ParamDescription<std::string>::clamp(HokuyoConfig &config, const HokuyoConfig &max, const HokuyoConfig &min) const
00246 {
00247 return;
00248 }
00249
00250 class HokuyoConfigStatics
00251 {
00252 friend class HokuyoConfig;
00253
00254 HokuyoConfigStatics()
00255 {
00256
00257 __min__.min_ang = -3.14159265359;
00258
00259 __max__.min_ang = 3.14159265359;
00260
00261 __default__.min_ang = -1.57079632679;
00262
00263 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<double>("min_ang", "double", 1, "The angle of the first range measurement. The unit depends on ~ang_radians.", "", &HokuyoConfig::min_ang)));
00264
00265 __min__.max_ang = -3.14159265359;
00266
00267 __max__.max_ang = 3.14159265359;
00268
00269 __default__.max_ang = 1.57079632679;
00270
00271 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<double>("max_ang", "double", 1, "The angle of the first range measurement. The unit depends on ~ang_radians.", "", &HokuyoConfig::max_ang)));
00272
00273 __min__.intensity = 0;
00274
00275 __max__.intensity = 1;
00276
00277 __default__.intensity = 0;
00278
00279 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<bool>("intensity", "bool", 1, "Whether or not the hokuyo returns intensity values.", "", &HokuyoConfig::intensity)));
00280
00281 __min__.cluster = 0;
00282
00283 __max__.cluster = 99;
00284
00285 __default__.cluster = 1;
00286
00287 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<int>("cluster", "int", 1, "The number of adjacent range measurements to cluster into a single reading", "", &HokuyoConfig::cluster)));
00288
00289 __min__.skip = 0;
00290
00291 __max__.skip = 9;
00292
00293 __default__.skip = 0;
00294
00295 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<int>("skip", "int", 1, "The number of scans to skip between each measured scan", "", &HokuyoConfig::skip)));
00296
00297 __min__.port = "";
00298
00299 __max__.port = "";
00300
00301 __default__.port = "/dev/ttyACM0";
00302
00303 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<std::string>("port", "str", 3, "The serial port where the hokuyo device can be found", "", &HokuyoConfig::port)));
00304
00305 __min__.calibrate_time = 0;
00306
00307 __max__.calibrate_time = 1;
00308
00309 __default__.calibrate_time = 1;
00310
00311 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<bool>("calibrate_time", "bool", 3, "Whether the node should calibrate the hokuyo's time offset", "", &HokuyoConfig::calibrate_time)));
00312
00313 __min__.frame_id = "";
00314
00315 __max__.frame_id = "";
00316
00317 __default__.frame_id = "laser";
00318
00319 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<std::string>("frame_id", "str", 0, "The frame in which laser scans will be returned", "", &HokuyoConfig::frame_id)));
00320
00321 __min__.time_offset = -0.25;
00322
00323 __max__.time_offset = 0.25;
00324
00325 __default__.time_offset = 0.0;
00326
00327 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<double>("time_offset", "double", 0, "An offet to add to the timestamp before publication of a scan", "", &HokuyoConfig::time_offset)));
00328
00329 __min__.allow_unsafe_settings = 0;
00330
00331 __max__.allow_unsafe_settings = 1;
00332
00333 __default__.allow_unsafe_settings = 0;
00334
00335 __param_descriptions__.push_back(HokuyoConfig::AbstractParamDescriptionConstPtr(new HokuyoConfig::ParamDescription<bool>("allow_unsafe_settings", "bool", 3, "Turn this on if you wish to use the UTM-30LX with an unsafe angular range. Turning this option on may cause occasional crashes or bad data. This option is a tempory workaround that will hopefully be removed in an upcoming driver version.", "", &HokuyoConfig::allow_unsafe_settings)));
00336
00337
00338 for (std::vector<HokuyoConfig::AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00339 __description_message__.parameters.push_back(**i);
00340 __max__.__toMessage__(__description_message__.max, __param_descriptions__);
00341 __min__.__toMessage__(__description_message__.min, __param_descriptions__);
00342 __default__.__toMessage__(__description_message__.dflt, __param_descriptions__);
00343 }
00344 std::vector<HokuyoConfig::AbstractParamDescriptionConstPtr> __param_descriptions__;
00345 HokuyoConfig __max__;
00346 HokuyoConfig __min__;
00347 HokuyoConfig __default__;
00348 dynamic_reconfigure::ConfigDescription __description_message__;
00349 static const HokuyoConfigStatics *get_instance()
00350 {
00351
00352
00353
00354
00355 static HokuyoConfigStatics instance;
00356 return &instance;
00357 }
00358 };
00359
00360 inline const dynamic_reconfigure::ConfigDescription &HokuyoConfig::__getDescriptionMessage__()
00361 {
00362 return __get_statics__()->__description_message__;
00363 }
00364
00365 inline const HokuyoConfig &HokuyoConfig::__getDefault__()
00366 {
00367 return __get_statics__()->__default__;
00368 }
00369
00370 inline const HokuyoConfig &HokuyoConfig::__getMax__()
00371 {
00372 return __get_statics__()->__max__;
00373 }
00374
00375 inline const HokuyoConfig &HokuyoConfig::__getMin__()
00376 {
00377 return __get_statics__()->__min__;
00378 }
00379
00380 inline const std::vector<HokuyoConfig::AbstractParamDescriptionConstPtr> &HokuyoConfig::__getParamDescriptions__()
00381 {
00382 return __get_statics__()->__param_descriptions__;
00383 }
00384
00385 inline const HokuyoConfigStatics *HokuyoConfig::__get_statics__()
00386 {
00387 const static HokuyoConfigStatics *statics;
00388
00389 if (statics)
00390 return statics;
00391
00392 boost::mutex::scoped_lock lock(dynamic_reconfigure::__init_mutex__);
00393
00394 if (statics)
00395 return statics;
00396
00397 statics = HokuyoConfigStatics::get_instance();
00398
00399 return statics;
00400 }
00401
00402
00403 }
00404
00405 #endif // __HOKUYORECONFIGURATOR_H__