00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 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 namespace mrpt 00035 { 00036 namespace slam 00037 { 00038 using namespace mrpt::poses; 00039 using namespace mrpt::utils; 00040 using namespace mrpt::math; 00041 00042 /** This class can be used to simulate the kinematics and dynamics of a differential driven planar mobile robot, including odometry errors and dynamics limitations. 00043 * The main methods are: 00044 - movementCommand: Call this for send a command to the robot. This comamnd will be 00045 delayed and passed throught a first order low-pass filter to simulate 00046 robot dynamics. 00047 - simulateInterval: Call this for run the simulator for the desired time period. 00048 * 00049 Versions: 00050 - 23/MAR/2009: (JLBC) Changed to reuse MRPT poses and methods renamed to conform to MRPT style. 00051 - 29/AUG/2008: (JLBC) Added parameters for odometry noise. 00052 - 27/JAN/2008: (JLBC) Translated to English!!! :-) 00053 - 17/OCT/2005: (JLBC) Integration into the MRML library. 00054 - 1/DIC/2004: (JLBC) Odometry, cumulative errors added. 00055 - 18/JUN/2004: (JLBC) First creation. 00056 * 00057 */ 00058 class MRPTDLLIMPEXP CRobotSimulator 00059 { 00060 private: 00061 // Internal state variables: 00062 // --------------------------------------- 00063 mrpt::poses::CPose2D m_pose; //!< Global, absolute and error-free robot coordinates 00064 mrpt::poses::CPose2D m_odometry; //!< Used to simulate odometry (with optional error) 00065 00066 /** Instantaneous velocity of the robot (linear, m/s) 00067 */ 00068 double v; 00069 00070 /** Instantaneous velocity of the robot (angular, rad/s) 00071 */ 00072 double w; 00073 00074 /** Simulation time variable 00075 */ 00076 double t; 00077 00078 /** Whether to corrupt odometry with noise */ 00079 bool usar_error_odometrico; 00080 00081 /** Dynamic limitations of the robot. 00082 * Approximation to non-infinity motor forces: A first order low-pass filter, using: 00083 * Command_Time: Time "t" when the last order was received. 00084 * Command_v, Command_w: The user-desired velocities. 00085 * Command_v0, Command_w0: Actual robot velocities at the moment of user request. 00086 */ 00087 double Command_Time, 00088 Command_v, Command_w, 00089 Command_v0, Command_w0; 00090 00091 /** The time-constants for the first order low-pass filter for the velocities changes. */ 00092 float cTAU; // 1.8 sec 00093 00094 /** The delay constant for the velocities changes. */ 00095 float cDELAY; 00096 00097 double m_Ax_err_bias, m_Ax_err_std; 00098 double m_Ay_err_bias, m_Ay_err_std; 00099 double m_Aphi_err_bias, m_Aphi_err_std; 00100 00101 public: 00102 /** Constructor with default dynamic model-parameters 00103 */ 00104 CRobotSimulator( float TAU = 1.9f, float DELAY = 0.3f); 00105 00106 /** Destructor 00107 */ 00108 virtual ~CRobotSimulator(); 00109 00110 /** Change the model of delays used for the orders sent to the robot \sa movementCommand */ 00111 void setDelayModelParams(float TAU_delay_sec=1.8f, float CMD_delay_sec=0.3f) { 00112 cTAU = TAU_delay_sec; 00113 cDELAY = CMD_delay_sec; 00114 } 00115 00116 /** Enable/Disable odometry errors 00117 * Errors in odometry are introduced per millisecond. 00118 */ 00119 void setOdometryErrors( 00120 bool enabled, 00121 double Ax_err_bias = 1e-6, 00122 double Ax_err_std = 10e-6, 00123 double Ay_err_bias = 1e-6, 00124 double Ay_err_std = 10e-6, 00125 double Aphi_err_bias = DEG2RAD(1e-6), 00126 double Aphi_err_std = DEG2RAD(10e-6) 00127 ) 00128 { 00129 usar_error_odometrico=enabled; 00130 m_Ax_err_bias=Ax_err_bias; 00131 m_Ax_err_std=Ax_err_std; 00132 m_Ay_err_bias=Ay_err_bias; 00133 m_Ay_err_std=Ay_err_std; 00134 m_Aphi_err_bias=Aphi_err_bias; 00135 m_Aphi_err_std=Aphi_err_std; 00136 } 00137 00138 /** Reset actual robot pose (inmediately, without simulating the movement along time) 00139 */ 00140 void setRealPose(mrpt::poses::CPose2D &p ) { this->m_pose = p; } 00141 00142 /** Read the instantaneous, error-free status of the simulated robot 00143 */ 00144 double getX() const { return m_pose.x(); } 00145 00146 /** Read the instantaneous, error-free status of the simulated robot 00147 */ 00148 double getY() { return m_pose.y(); } 00149 00150 /** Read the instantaneous, error-free status of the simulated robot 00151 */ 00152 double getPHI() { return m_pose.phi(); } 00153 00154 /** Read the instantaneous, error-free status of the simulated robot 00155 */ 00156 double getT() { return t; } 00157 00158 /** Read the instantaneous, error-free status of the simulated robot 00159 */ 00160 double getV() { return v; } 00161 /** Read the instantaneous, error-free status of the simulated robot 00162 */ 00163 double getW() { return w; } 00164 00165 /** Set actual robot pose (inmediately, without simulating the movement along time) (Not to be called normally!!) 00166 * \sa MovementCommand 00167 */ 00168 void setV(double v) { this->v=v; } 00169 void setW(double w) { this->w=w; } 00170 00171 /** Used to command the robot a desired movement (velocities) 00172 */ 00173 void movementCommand ( double lin_vel, double ang_vel ); 00174 00175 /** Reset all the simulator variables to 0 (All but current simulator time). 00176 */ 00177 void resetStatus(); 00178 00179 /** Reset time counter 00180 */ 00181 void resetTime() { t = 0.0; } 00182 00183 /** This method must be called periodically to simulate discrete time intervals. 00184 */ 00185 void simulateInterval( double At); 00186 00187 /** Forces odometry to be set to a specified values. 00188 */ 00189 void resetOdometry( const mrpt::poses::CPose2D &newOdo = mrpt::poses::CPose2D() ) { 00190 m_odometry = newOdo; 00191 } 00192 00193 /** Reads the simulated robot odometry (this is NOT equal to the actual error-free robot coordinates). 00194 * \sa getRealPose 00195 */ 00196 void getOdometry ( CPose2D &pose ) const { 00197 pose = m_odometry; 00198 } 00199 00200 /** Reads the simulated robot odometry (this is NOT equal to the actual error-free robot coordinates). 00201 * \sa getRealPose 00202 */ 00203 void getOdometry ( TPose2D &pose ) const { 00204 pose = m_odometry; 00205 } 00206 00207 /** Reads the real robot pose. \sa getOdometry */ 00208 void getRealPose ( CPose2D &pose ) const { 00209 pose = m_pose; 00210 } 00211 00212 /** Reads the real robot pose. \sa getOdometry */ 00213 void getRealPose ( TPose2D &pose ) const { 00214 pose = m_pose; 00215 } 00216 }; 00217 00218 } // End of namespace 00219 } // End of namespace 00220 00221 #endif
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:27:43 EDT 2009 |