Main MRPT website > C++ reference
MRPT logo
CRobotSimulator.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 #ifndef CRobotSimulator_H
00029 #define CRobotSimulator_H
00030 
00031 #include <mrpt/utils/CSerializable.h>
00032 #include <mrpt/poses/CPose2D.h>
00033 
00034 #include <mrpt/base/link_pragmas.h>
00035 
00036 namespace mrpt
00037 {
00038 namespace utils
00039 {
00040         using namespace mrpt::poses;
00041         using namespace mrpt::math;
00042 
00043         /** This class can be used to simulate the kinematics and dynamics of a differential driven planar mobile robot, including odometry errors and dynamics limitations.
00044          *  The main methods are:
00045                         - movementCommand: Call this for send a command to the robot. This comamnd will be
00046                                                                 delayed and passed throught a first order low-pass filter to simulate
00047                                                                 robot dynamics.
00048                         - simulateInterval: Call this for run the simulator for the desired time period.
00049          *
00050                 Versions:
00051                         - 23/MAR/2009: (JLBC) Changed to reuse MRPT poses and methods renamed to conform to MRPT style.
00052                         - 29/AUG/2008: (JLBC) Added parameters for odometry noise.
00053                         - 27/JAN/2008: (JLBC) Translated to English!!! :-)
00054                         - 17/OCT/2005: (JLBC) Integration into the MRML library.
00055                         - 1/DIC/2004: (JLBC) Odometry, cumulative errors added.
00056                         - 18/JUN/2004: (JLBC) First creation.
00057          *
00058          * \ingroup mrpt_base_grp
00059          */
00060         class BASE_IMPEXP CRobotSimulator
00061         {
00062                 private:
00063                         //      Internal state variables:
00064                         // ---------------------------------------
00065                         mrpt::poses::CPose2D  m_pose;   //!< Global, absolute and error-free robot coordinates
00066                         mrpt::poses::CPose2D m_odometry;        //!< Used to simulate odometry (with optional error)
00067 
00068                         /** Instantaneous velocity of the robot (linear, m/s)
00069                           */
00070                         double          v;
00071 
00072                         /** Instantaneous velocity of the robot (angular, rad/s)
00073                           */
00074                         double          w;
00075 
00076                         /** Simulation time variable
00077                           */
00078                         double          t;
00079 
00080                         /** Whether to corrupt odometry with noise  */
00081                         bool            usar_error_odometrico;
00082 
00083                         /** Dynamic limitations of the robot.
00084                           * Approximation to non-infinity motor forces: A first order low-pass filter, using:
00085                           *   Command_Time: Time "t" when the last order was received.
00086                           *   Command_v, Command_w: The user-desired velocities.
00087                           *   Command_v0, Command_w0: Actual robot velocities at the moment of user request.
00088                           */
00089                         double Command_Time,
00090                                Command_v, Command_w,
00091                                    Command_v0, Command_w0;
00092 
00093                         /** The time-constants for the first order low-pass filter for the velocities changes. */
00094                         float                   cTAU;                   // 1.8 sec
00095 
00096                         /** The delay constant for the velocities changes.  */
00097                         float                   cDELAY;
00098 
00099                         double m_Ax_err_bias, m_Ax_err_std;
00100                         double m_Ay_err_bias, m_Ay_err_std;
00101                         double m_Aphi_err_bias, m_Aphi_err_std;
00102 
00103                 public:
00104                         /** Constructor with default dynamic model-parameters
00105                           */
00106                         CRobotSimulator( float TAU = 0, float DELAY = 0);
00107 
00108                         /** Destructor
00109                           */
00110                         virtual ~CRobotSimulator();
00111 
00112                         /** Change the model of delays used for the orders sent to the robot \sa movementCommand */
00113                         void setDelayModelParams(float TAU_delay_sec=1.8f, float CMD_delay_sec=0.3f) {
00114                                 cTAU = TAU_delay_sec;
00115                                 cDELAY = CMD_delay_sec;
00116                         }
00117 
00118                         /** Enable/Disable odometry errors
00119                           *  Errors in odometry are introduced per millisecond.
00120                           */
00121                         void setOdometryErrors(
00122                                 bool enabled,
00123                                 double Ax_err_bias  =  1e-6,
00124                                 double Ax_err_std   = 10e-6,
00125                                 double Ay_err_bias =  1e-6,
00126                                 double Ay_err_std  = 10e-6,
00127                                 double Aphi_err_bias =  DEG2RAD(1e-6),
00128                                 double Aphi_err_std  = DEG2RAD(10e-6)
00129                                 )
00130                         {
00131                                 usar_error_odometrico=enabled;
00132                                 m_Ax_err_bias=Ax_err_bias;
00133                                 m_Ax_err_std=Ax_err_std;
00134                                 m_Ay_err_bias=Ay_err_bias;
00135                                 m_Ay_err_std=Ay_err_std;
00136                                 m_Aphi_err_bias=Aphi_err_bias;
00137                                 m_Aphi_err_std=Aphi_err_std;
00138                         }
00139 
00140                         /** Reset actual robot pose (inmediately, without simulating the movement along time)
00141                           */
00142                         void  setRealPose(mrpt::poses::CPose2D &p ) { this->m_pose = p; }
00143 
00144                         /** Read the instantaneous, error-free status of the simulated robot
00145                           */
00146                         double  getX() const { return m_pose.x(); }
00147 
00148                         /** Read the instantaneous, error-free status of the simulated robot
00149                           */
00150                         double  getY() { return m_pose.y(); }
00151 
00152                         /** Read the instantaneous, error-free status of the simulated robot
00153                           */
00154                         double  getPHI() { return m_pose.phi(); }
00155 
00156                         /** Read the instantaneous, error-free status of the simulated robot
00157                           */
00158                         double  getT()   { return t; }
00159 
00160                         /** Read the instantaneous, error-free status of the simulated robot
00161                           */
00162                         double  getV() { return v; }
00163                         /** Read the instantaneous, error-free status of the simulated robot
00164                           */
00165                         double  getW() { return w; }
00166 
00167                         /** Set actual robot pose (inmediately, without simulating the movement along time) (Not to be called normally!!)
00168                           * \sa MovementCommand
00169                           */
00170                         void    setV(double v) { this->v=v; }
00171                         void    setW(double w) { this->w=w; }
00172 
00173                         /** Used to command the robot a desired movement (velocities)
00174                           */
00175                         void    movementCommand ( double lin_vel, double ang_vel );
00176 
00177                         /** Reset all the simulator variables to 0 (All but current simulator time).
00178                           */
00179                         void    resetStatus();
00180 
00181                         /** Reset time counter
00182                           */
00183                         void    resetTime()  { t = 0.0; }
00184 
00185                         /** This method must be called periodically to simulate discrete time intervals.
00186                           */
00187                         void    simulateInterval( double At);
00188 
00189                         /** Forces odometry to be set to a specified values.
00190                           */
00191                         void    resetOdometry( const mrpt::poses::CPose2D &newOdo = mrpt::poses::CPose2D() ) {
00192                                 m_odometry = newOdo;
00193                         }
00194 
00195                         /** Reads the simulated robot odometry (this is NOT equal to the actual error-free robot coordinates).
00196                           * \sa getRealPose
00197                           */
00198                         void    getOdometry ( CPose2D &pose ) const {
00199                                 pose = m_odometry;
00200                         }
00201 
00202                         /** Reads the simulated robot odometry (this is NOT equal to the actual error-free robot coordinates).
00203                           * \sa getRealPose
00204                           */
00205                         void    getOdometry ( TPose2D &pose ) const {
00206                                 pose = m_odometry;
00207                         }
00208 
00209                         /** Reads the real robot pose. \sa getOdometry  */
00210                         void    getRealPose ( CPose2D &pose ) const {
00211                                 pose = m_pose;
00212                         }
00213 
00214                         /** Reads the real robot pose. \sa getOdometry  */
00215                         void    getRealPose ( TPose2D &pose ) const {
00216                                 pose = m_pose;
00217                         }
00218         };
00219 
00220         } // End of namespace
00221 } // End of namespace
00222 
00223 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011