MotionModule.h
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
00019
00020
00021
00022
00023
00024
00025
00026
00033
00037
00038
00039 #ifndef __MOTION_MODULE_H_
00040 #define __MOTION_MODULE_H_
00041
00042 #ifdef MIP_HOST_APPLE
00043 #include <applePatch.h>
00044 #endif
00045
00046 #include <stdlib.h>
00047 #include <string>
00048 #include <sstream>
00049 #include <vector>
00050 #include <assert.h>
00051 #include <list>
00052
00053 #include <baselib.h>
00054 #include <Resource.h>
00055
00056 #include <DiffDriveOdometer/DiffDriveOdometer.h>
00057
00058 namespace MipResources{
00059
00061
00062
00066 class MotionModuleOptions : public Options {
00067 public:
00068 PoseOption *initialPose;
00069 StringOption *odomIntegrMethod;
00070
00071 MotionModuleOptions();
00072 OptionGroupsType getGroup();
00073
00074 string getObjectName() const {
00075 return "MotionModuleOptions";
00076 }
00077 };
00078
00079 using namespace MipBaselib;
00080
00084 class MotionModulePar{
00085 protected:
00087 virtual Decimal _providedMaxDrive(void)=0;
00089 virtual Decimal _providedMaxTurnRate(void)=0;
00091 virtual string _providedName()=0;
00092 public:
00094 MotionModulePar (){};
00095
00097 Decimal maxDrive(void);
00099 Decimal maxTurnRate(void);
00101 string name();
00102
00104 virtual string print();
00105 };
00106
00107
00115 class MotionModule : public Resource{
00116 protected:
00117
00118 MotionModuleTStateLog _varLog;
00119
00120 private:
00121 void _checkAllocation();
00122
00123 void _localizationStep();
00124
00125
00126 protected:
00127 MotionModulePar *_par;
00128 MotionModuleTState *_var;
00129 MotionModuleOptions _options;
00130
00131 virtual MotionModuleTState _providedLocStep()=0;
00132 virtual void _providedLocSet(MotionModuleState state)=0;
00133 virtual void _providedSetCommands(Decimal drive, Decimal turnrate)=0;
00134 public:
00136 MotionModule(int argc, const char* argv[]);
00137
00139 virtual ResourcePlate getPlate() const =0;
00140
00143 MotionModuleTState getState();
00144
00148 virtual MotionModuleTState getState(Time ts);
00149
00160 bool setState(MotionModuleState state, bool setPastTimeStamp=false, Time pastTimeStamp=Time());
00161
00173 bool setState(MotionModuleState correctedState, MotionModuleState &finalState, bool setPastTimeStamp=false, Time pastTimeStamp=Time());
00174
00180 void setCommands(Decimal drive, Decimal turnrate, bool scaled=true);
00181
00188 void setCommands(Decimal drive, Decimal turnrate, MotionModuleTState &finalTState, bool scaled=true);
00189
00200 void setCommandsAndTState(MotionModuleState correctedState, Decimal drive, Decimal turnrate, MotionModuleTState &finalTState, bool scaled=true, bool setPastTimeStamp=false, Time pastTimeStamp=Time());
00201
00204 virtual MotionModulePar* getPar(void){
00205 return _par;
00206 }
00207
00211 void getCurvature(Decimal &c, bool &infinity);
00212
00213 };
00214
00218 class UnicyclePar : public MotionModulePar{};
00219
00223 class UnicycleVar : public MotionModuleTState{};
00224
00228 class Unicycle : public MotionModule{
00229 public:
00230
00231 Unicycle(int argc, const char* argv[]) : MotionModule(argc,argv){};
00232
00233 virtual ResourcePlate getPlate() const =0;
00234 };
00235
00239 class DiffDrivePar : public MotionModulePar{
00240 protected:
00241 Decimal _providedMaxDrive(void);
00242 Decimal _providedMaxTurnRate(void);
00243 virtual string _providedName()=0;
00244 virtual Decimal _providedMaxWheelTurnRate(void)=0;
00245 virtual Decimal _providedLeftDiam(void)=0;
00246 virtual Decimal _providedRightDiam(void)=0;
00247 virtual Decimal _providedAxelTrack(void)=0;
00248 virtual Decimal _providedEncoderResol(void)=0;
00249 public:
00251 DiffDrivePar (){};
00252
00254 Decimal maxWheelTurnRate(void);
00255
00257 Decimal leftDiam(void);
00258
00260 Decimal rightDiam(void);
00261
00263 Decimal averageDiam(void);
00264
00266 Decimal axelTrack(void);
00267
00269 Decimal encoderResol(void);
00270
00272 string print();
00273 };
00274
00278 class DiffDriveVar : public UnicycleVar{};
00279
00280
00285 class DiffDrive : public Unicycle{
00286 protected:
00287 MipAlgorithms::DiffDriveOdometer* _odometer;
00288 DiffDriveEncoderReading _prevEncoder;
00289 DiffDriveEncoderReading _currEncoder;
00290 private:
00291 void _initOdometer();
00292 void _checkAllocation();
00293 protected:
00294
00295
00296
00297 DiffDrivePar *_ddPar;
00298 DiffDriveVar *_ddVar;
00299
00300 MotionModuleTState _providedLocStep();
00302 void _providedLocSet(MotionModuleState state);
00303 void _providedSetCommands(Decimal drive, Decimal turnrate);
00304
00305 public:
00307 DiffDrive(int argc, const char* argv[]);
00308
00310 ~DiffDrive();
00311
00313 virtual ResourcePlate getPlate() const =0;
00314
00318 virtual void setWheelCommands(Decimal leftAngVel, Decimal rightAngVel)=0;
00319
00322 virtual DiffDriveEncoderReading getEncoders()=0;
00323
00326 DiffDrivePar* getPar(){
00327 return _ddPar;
00328 }
00329 };
00330
00331
00332
00333 };
00334
00335
00336 #endif
00337
00338
00339