00001 // ---------------------------------------------------------------------------- 00002 // 00003 // $Id$ 00004 // 00005 // Copyright 2008, 2009, 2010, 2011, 2012 Antonio Franchi and Paolo Stegagno 00006 // 00007 // This file is part of MIP. 00008 // 00009 // MIP is free software: you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 3 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // MIP is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it 00023 // 00024 // ---------------------------------------------------------------------------- 00025 00032 00033 #ifndef __DIFF_DRIVE_ODOMETER_H_ 00034 #define __DIFF_DRIVE_ODOMETER_H_ 00035 00036 #include <baselib.h> 00037 00038 namespace MipAlgorithms{ 00039 00040 // enum OdomIntegrMethods{ 00041 // ODO_INT_METH_EXACT, 00042 // ODO_INT_METH_RUNKUT2, 00043 // ODO_INT_METH_NUM 00044 // }; 00045 00050 class DiffDriveOdometerPar : public MIPObject{ 00051 private: 00052 Decimal _leftWheelDiam; 00053 Decimal _rightWheelDiam; 00054 Decimal _axelTrack; 00055 Decimal _encoderResol; 00056 00057 long int _maxPulseRate; 00058 00059 Decimal _leftRatio; 00060 Decimal _rightRatio; 00061 00062 OdomIntegrMethods _integrMethod; 00063 00064 string getObjectName() const { 00065 return string("DiffDriveOdometer"); 00066 } 00067 00068 public: 00076 DiffDriveOdometerPar(Decimal ld=1.0,Decimal rd=1.0,Decimal wb=1.0,Decimal er=1.0,Decimal maxWheelTurnRate=100000.0, string iM="runge-kutta2"); 00078 DiffDriveOdometerPar(const DiffDriveOdometerPar &p); 00080 DiffDriveOdometerPar& operator=(const DiffDriveOdometerPar& p){ 00081 if (this != &p){ 00082 _leftWheelDiam = p._leftWheelDiam; 00083 _rightWheelDiam = p._rightWheelDiam; 00084 _axelTrack = p._axelTrack; 00085 _encoderResol = p._encoderResol; 00086 _leftRatio = p._leftRatio; 00087 _rightRatio = p._rightRatio; 00088 _maxPulseRate = p._maxPulseRate; 00089 _integrMethod = p._integrMethod; 00090 } 00091 return *this; 00092 } 00093 00095 Decimal getLeftWheelDiam(); 00097 Decimal getRightWheelDiam(); 00099 Decimal getAxelTrack(); 00101 Decimal getEncoderResol(); 00103 Decimal getLeftRatio(); 00105 Decimal getRightRatio(); 00107 long int getMaxPulseRate(); 00109 OdomIntegrMethods getIntegrMethod(); 00111 string print(); 00112 }; 00113 00114 00120 class DiffDriveOdometerVar{ 00121 public: 00122 Pose pose; 00123 DiffDriveEncoderReading encodRead; 00124 long unsigned int step; 00125 00127 // DiffDriveOdometerVar(Pose p, long int lp,long int rp,Time lt,Time rt); 00134 DiffDriveOdometerVar(Pose p=Pose(),DiffDriveEncoderReading r=DiffDriveEncoderReading()); 00135 // DiffDriveOdometerVar(Pose p, long int lp,long int rp,Time lt,Time rt); 00136 00138 DiffDriveOdometerVar(const DiffDriveOdometerVar &p); 00140 DiffDriveOdometerVar& operator=(const DiffDriveOdometerVar& p){ 00141 if (this != &p){ 00142 pose = p.pose; 00143 encodRead = p.encodRead; 00144 step = p.step; 00145 } 00146 return *this; 00147 } 00149 string print(); 00150 }; 00151 00152 00153 00158 class DiffDriveOdometer : public MIPObject{ 00159 private: 00160 DiffDriveOdometerPar _par; 00161 DiffDriveOdometerVar _var; 00162 DiffDriveOdometerVar _prevVar; 00163 fstream _logFile; 00164 00165 string getObjectName() const { 00166 return string("DiffDriveOdometer"); 00167 } 00168 00169 public: 00173 DiffDriveOdometer(const DiffDriveOdometerPar& p,const DiffDriveOdometerVar& v); 00174 00175 ~DiffDriveOdometer(){ 00176 _logFile.close(); 00177 } 00178 00179 // /// \brief Reset the pose to a certain value. 00180 // /// \param p New pose. 00181 // void poseReset(Pose p); 00182 00186 void reset(Pose& pose, DiffDriveEncoderReading& encodRead); 00187 00190 // void varReset(DiffDriveOdometerVar v); 00191 00196 bool step(DiffDriveEncoderReading in,MotionModuleTState &out); 00197 }; 00198 } // End of namespace 00199 00200 #endif