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 00026 00030 00032 /* @{ */ 00033 00034 00035 #ifndef __ODOMETRY2D_H_ 00036 #define __ODOMETRY2D_H_ 00037 00038 #ifdef MIP_HOST_APPLE 00039 #include <applePatch.h> 00040 #endif 00041 00042 #include <stdio.h> 00043 #include <math.h> 00044 #include <vector> 00045 #include <iostream> 00046 #include <string> 00047 #include <sstream> 00048 #include <sys/time.h> 00049 #include <sys/select.h> 00050 #include <assert.h> 00051 00052 #ifdef FOUND_BOOST_SER 00053 #include <boost/serialization/vector.hpp> 00054 #include <boost/archive/text_iarchive.hpp> 00055 #include <boost/archive/text_oarchive.hpp> 00056 #endif 00057 00058 #include <Types.h> 00059 00060 #include <SE2.h> 00061 00062 using namespace std; 00063 00064 00065 00070 class Odometry2D{ 00071 private: 00072 Decimal _velX; 00073 Decimal _velY; 00074 Decimal _omegaZ; 00075 public: 00076 00077 // /// \brief Default constructor 00078 // inline Odometry2D(){velX = -1.0; velY = -1.0; omegaZ = -1.0;}; 00079 00081 inline Odometry2D(Decimal xVel=0.0, Decimal yVel=0.0, Decimal zOmega=0.0){ _velX = xVel; _velY = yVel; _omegaZ = zOmega;} 00082 00084 inline Odometry2D(Position A, Decimal zOmega=0.0){ _velX = A.x(); _velY = A.y(); _omegaZ = zOmega;} 00085 00087 inline Odometry2D(const Odometry2D &A){_velX = A._velX; _velY = A._velY; _omegaZ = A._omegaZ;} 00088 00090 Odometry2D& operator=(const Odometry2D &A){ _velX = A._velX; _velY = A._velY; _omegaZ = A._omegaZ; return *this;} 00091 00093 Odometry2D& operator+=(const Odometry2D& A) { _velX += A._velX; _velY += A._velY; _omegaZ += A._omegaZ; return *this;} 00094 00096 const Odometry2D operator+(const Odometry2D &other) const{ return Odometry2D(*this) += other;} 00097 00099 Odometry2D& operator*=(const Odometry2D& A) { _velX *= A._velX; _velY *= A._velY; _omegaZ *= A._omegaZ; return *this;} 00100 00102 Odometry2D& operator*=(const Decimal& scalar) { _velX = _velX*scalar; _velY = _velY*scalar; _omegaZ = _omegaZ*scalar; return (*this);} 00103 00105 const Odometry2D operator*(const Odometry2D &other) const{ return Odometry2D(*this) *= other;}; 00106 00108 Odometry2D operator*(const Decimal& scalar) const {return Odometry2D(*this) *= scalar;} 00109 // Odometry2D operator*(const Decimal& scalar) const {Odometry2D ris(_velX*scalar, _velY*scalar, _omegaZ*scalar); return ris;} 00110 00112 Odometry2D& operator-=(const Odometry2D& A) {_velX -= A._velX; _velY -= A._velY; _omegaZ -= A._omegaZ; return *this;} 00113 00115 const Odometry2D operator-(const Odometry2D &other) const {return Odometry2D(*this) -= other;} 00116 00118 Odometry2D& operator/=(const Odometry2D& A) {_velX /= A._velX; _velY /= A._velY; _omegaZ /= A._omegaZ; return *this;} 00119 00121 Odometry2D& operator/=(const Decimal& scalar) { _velX = _velX/scalar; _velY = _velY/scalar; _omegaZ = _omegaZ/scalar; return (*this);} 00122 00124 const Odometry2D operator/(const Odometry2D &other) const {return Odometry2D(*this) /= other;} 00125 00127 Odometry2D operator/(const Decimal& scalar) const {return Odometry2D(*this) /= scalar;} 00128 // Odometry2D operator/(const Decimal& scalar) const {Odometry2D ris(_velX/scalar, _velY/scalar, _omegaZ/scalar); return ris;} 00129 00131 bool operator==(const Odometry2D &other) const { if( (_velX == other._velX) && (_velY == other._velY) && (_omegaZ == other._omegaZ) ) return true; else return false;} 00132 00134 bool operator!=(const Odometry2D &other) const {return !(*this == other);} 00135 00138 inline Decimal getVelX(){ return _velX;} 00139 00142 inline Decimal getVelY(){ return _velY;} 00143 00146 inline Decimal getOmegaZ(){ return _omegaZ;} 00147 00150 inline void setVelX(Decimal xVel){ _velX = xVel;} 00151 00154 inline void setVelY(Decimal yVel){ _velY = yVel;} 00155 00158 inline void setOmegaZ(Decimal zOmega){ _omegaZ = zOmega;} 00159 00161 string print(){ 00162 stringstream ss; 00163 ss << "velX: " << _velX << " velY: " << _velY << " omegaZ: " << _omegaZ; 00164 return ss.str(); 00165 } 00166 }; 00167 00168 00169 00170 00171 00172 00173 #endif 00174 00175 00176 00177 /* @} */