Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef UndercarriageCtrlGeom_INCLUDEDEF_H
00019 #define UndercarriageCtrlGeom_INCLUDEDEF_H
00020
00021 #include <vector>
00022 #include <string>
00023 #include <stdexcept>
00024 #include <boost/make_shared.hpp>
00025
00026 struct PlatformState{
00027 double dVelLongMMS;
00028 double dVelLatMMS;
00029 double dRotRobRadS;
00030
00031 const double getVelX() { return dVelLongMMS / 1000.0; }
00032 const double getVelY() { return dVelLatMMS / 1000.0; }
00033
00034 void setVelX(const double val) { dVelLongMMS = val * 1000.0; }
00035 void setVelY(const double val) { dVelLatMMS = val * 1000.0; }
00036
00037 PlatformState() : dVelLongMMS(0), dVelLatMMS(0),dRotRobRadS(0) {}
00038 };
00039 struct WheelState {
00040 double dVelGearDriveRadS;
00041 double dVelGearSteerRadS;
00042 double dAngGearSteerRad;
00043 WheelState() : dVelGearDriveRadS(0), dVelGearSteerRadS(0), dAngGearSteerRad(0) {}
00044 };
00045 struct WheelCommand : public WheelState {
00046 double dAngGearSteerRadDelta;
00047 WheelCommand() : dAngGearSteerRadDelta(0) {}
00048 };
00049 struct WheelGeom{
00050 std::string steer_name, drive_name;
00051
00056 double dWheelXPosMM;
00057 double dWheelYPosMM;
00058
00059 double dSteerDriveCoupling;
00060
00061 double dRadiusWheelMM;
00062 double dDistSteerAxisToDriveWheelMM;
00063
00064 };
00065 struct WheelData {
00066 WheelGeom geom_;
00067
00072 double dFactorVel;
00073
00074 WheelState state_;
00075
00080 double m_dExWheelXPosMM;
00081 double m_dExWheelYPosMM;
00082 double m_dExWheelDistMM;
00083 double m_dExWheelAngRad;
00084
00085 double m_dVelWheelMMS;
00086
00087 void updateState(const WheelState &state);
00088 double getVelX() const;
00089 double getVelY() const;
00090
00091 static double mergeRotRobRadS(const WheelData &wheel1, const WheelData &wheel2);
00092
00093 WheelData(const WheelGeom &geom)
00094 : geom_(geom),
00095 dFactorVel(-geom_.dSteerDriveCoupling + geom_.dDistSteerAxisToDriveWheelMM / geom_.dRadiusWheelMM) {
00096 updateState(WheelState());
00097 }
00098 };
00099
00100 class UndercarriageGeomBase
00101 {
00102 public:
00103
00104 virtual void calcDirect(PlatformState &state) const = 0;
00105
00106
00107 virtual void updateWheelStates(const std::vector<WheelState> &states) = 0;
00108
00109 virtual ~UndercarriageGeomBase() {}
00110
00111 protected:
00112 template<typename V> static void updateWheelStates(V& wheels, const std::vector<WheelState> &states)
00113 {
00114 if(wheels.size() != states.size()) throw std::length_error("number of states does not match number of wheels");
00115
00116 for(size_t i = 0; i < wheels.size(); ++i){
00117 wheels[i]->updateState(states[i]);
00118 }
00119 }
00120
00121 template<typename V> static void calcDirect(PlatformState &state, const V& wheels)
00122 {
00123 double dtempRotRobRADPS = 0;
00124 double dtempVelXRobMMS = 0;
00125 double dtempVelYRobMMS = 0;
00126
00127
00128 for(int i = 0; i < wheels.size() ; i++)
00129 {
00130 const WheelData &wheel = *wheels[i];
00131 const WheelData &other_wheel = *wheels[(i+1) % wheels.size()];
00132
00133 dtempRotRobRADPS += WheelData::mergeRotRobRadS(wheel, other_wheel);
00134 dtempVelXRobMMS += wheel.getVelX();
00135 dtempVelYRobMMS += wheel.getVelY();
00136 }
00137
00138
00139 state.dRotRobRadS = dtempRotRobRADPS/wheels.size();
00140
00141
00142 state.dVelLongMMS = dtempVelXRobMMS/wheels.size();
00143 state.dVelLatMMS = dtempVelYRobMMS/wheels.size();
00144
00145 }
00146
00147 };
00148
00149 class UndercarriageGeom : public UndercarriageGeomBase {
00150 public:
00151 struct WheelParams {
00152 WheelGeom geom;
00153 };
00154
00155
00156 UndercarriageGeom(const std::vector<WheelParams> ¶ms);
00157
00158
00159 virtual void calcDirect(PlatformState &state) const;
00160
00161
00162 virtual void updateWheelStates(const std::vector<WheelState> &states);
00163
00164 private:
00165 std::vector<boost::shared_ptr<WheelData> > wheels_;
00166 };
00167
00168 double limitValue(double value, double limit);
00169
00170 template<typename T> class UndercarriageCtrlBase : public UndercarriageGeomBase {
00171 public:
00172
00173 template<typename T2> UndercarriageCtrlBase(const std::vector<T2> ¶ms){
00174 for(typename std::vector<T2>::const_iterator it = params.begin(); it != params.end(); ++it){
00175 wheels_.push_back(boost::make_shared<T>(*it));
00176 }
00177 }
00178
00179
00180 virtual void calcDirect(PlatformState &state) const {
00181 UndercarriageGeomBase::calcDirect(state, wheels_);
00182 }
00183
00184
00185 virtual void updateWheelStates(const std::vector<WheelState> &states) {
00186 UndercarriageGeomBase::updateWheelStates(wheels_, states);
00187 }
00188
00189 void setTarget(const PlatformState &state) {
00190 for(size_t i = 0; i < wheels_.size(); ++i){
00191 wheels_[i]->setTarget(state);
00192 }
00193 }
00194
00195
00196 void calcControlStep(std::vector<WheelCommand> &commands, double dCmdRateS, bool reset) {
00197 commands.resize(wheels_.size());
00198
00199 for(size_t i = 0; i < wheels_.size(); ++i){
00200 wheels_[i]->calcControlStep(commands[i], dCmdRateS, reset);
00201 }
00202 }
00203
00204 void reset() {
00205 for(size_t i = 0; i < wheels_.size(); ++i){
00206 wheels_[i]->reset();
00207 }
00208 }
00209
00210 protected:
00211 std::vector<boost::shared_ptr<T> > wheels_;
00212 };
00213
00214 struct CtrlParams{
00215 double dWheelNeutralPos;
00216
00217 double dMaxDriveRateRadpS;
00218 double dMaxSteerRateRadpS;
00219 };
00220
00221 struct WheelCtrlParams {
00222 WheelGeom geom;
00223 CtrlParams ctrl;
00224 };
00225
00226 struct CtrlData : public WheelData {
00227 CtrlParams params_;
00228
00229 double m_dAngGearSteerTargetRad;
00230 double m_dVelGearDriveTargetRadS;
00231
00232
00233 void setTarget(const PlatformState &state);
00234
00235 virtual void calcControlStep(WheelCommand &command, double dCmdRateS, bool reset);
00236
00237 virtual void reset();
00238
00239 template<typename P> CtrlData(const P ¶ms)
00240 : WheelData(params.geom), params_(params.ctrl) {
00241 state_.dAngGearSteerRad = params_.dWheelNeutralPos;
00242 updateState(WheelState());
00243 setTarget(PlatformState());
00244 m_dAngGearSteerTargetRad = params_.dWheelNeutralPos;
00245 }
00246 };
00247
00248 class UndercarriageDirectCtrl : public UndercarriageCtrlBase < CtrlData > {
00249 public:
00250 typedef WheelCtrlParams WheelParams;
00251 UndercarriageDirectCtrl(const std::vector<WheelParams> ¶ms) : UndercarriageCtrlBase(params) {}
00252 };
00253
00254 struct PosCtrlParams {
00265 double dSpring, dDamp, dVirtM, dDPhiMax, dDDPhiMax;
00266 };
00267
00268 struct WheelCtrlPosParams {
00269 WheelGeom geom;
00270 CtrlParams ctrl;
00271 PosCtrlParams pos_ctrl;
00272 };
00273
00274 struct PosCtrlData : public CtrlData {
00275 PosCtrlParams pos_params_;
00276
00277
00278
00279
00280 double m_dCtrlVelCmdInt;
00281
00282 virtual void calcControlStep(WheelCommand &command, double dCmdRateS, bool reset);
00283
00284 virtual void reset();
00285
00286 PosCtrlData(const WheelCtrlPosParams ¶ms)
00287 : CtrlData(params), pos_params_(params.pos_ctrl),m_dCtrlVelCmdInt(0) {
00288 state_.dAngGearSteerRad = params_.dWheelNeutralPos;
00289 updateState(WheelState());
00290 setTarget(PlatformState());
00291 m_dAngGearSteerTargetRad = params_.dWheelNeutralPos;
00292 }
00293 };
00294
00295 class UndercarriageCtrl : public UndercarriageCtrlBase < PosCtrlData > {
00296 public:
00297 typedef WheelCtrlPosParams WheelParams;
00298 void configure(const std::vector<PosCtrlParams> &pos_ctrl);
00299 UndercarriageCtrl(const std::vector<WheelParams> ¶ms) : UndercarriageCtrlBase(params) {}
00300 };
00301
00302 #endif