00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 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 CReactiveNavigationSystem_H 00029 #define CReactiveNavigationSystem_H 00030 00031 #include <mrpt/maps.h> 00032 #include <mrpt/poses.h> 00033 #include <mrpt/math_mrpt.h> 00034 #include <mrpt/synch.h> 00035 #include <mrpt/reactivenav/link_pragmas.h> 00036 00037 #include "CAbstractReactiveNavigationSystem.h" 00038 #include "CParameterizedTrajectoryGenerator.h" 00039 #include "CLogFileRecord.h" 00040 #include "CAbstractHolonomicReactiveMethod.h" 00041 #include "CHolonomicVFF.h" 00042 #include "CHolonomicND.h" 00043 00044 namespace mrpt 00045 { 00046 /** This namespace contains classes for building a TP-Space Reactive Navigation System. 00047 */ 00048 namespace reactivenav 00049 { 00050 /** The implemented reactive navigation methods 00051 */ 00052 enum THolonomicMethod 00053 { 00054 hmVIRTUAL_FORCE_FIELDS = 0, 00055 hmSEARCH_FOR_BEST_GAP = 1 00056 }; 00057 00058 /** Implements a reactive navigation system based on TP-Space, with an arbitrary holonomic 00059 reactive method running on it, and any desired number of PTG for transforming the navigation space. 00060 Both, the holonomic method and the PTGs can be customized by the apropriate user derived classes. 00061 For running it, the method NavigateStep must be invoked periodically. 00062 00063 - 17/JUN/2004: First design. 00064 - 16/SEP/2004: Totally redesigned, according to document "MultiParametric Based Space 00065 Transformation for Reactive Navigation" 00066 - 29/SEP/2005: Totally rewritten again, for integration into MRPT library and according to the ICRA paper. 00067 - 17/OCT/2007: Whole code updated to accomodate to MRPT 0.5 and make it portable to Linux. 00068 00069 \sa CAbstractReactiveNavigationSystem, CParameterizedTrajectoryGenerator, CAbstractHolonomicReactiveMethod 00070 */ 00071 class REACTIVENAV_IMPEXP CReactiveNavigationSystem : public CAbstractReactiveNavigationSystem 00072 { 00073 public: 00074 /** Constructor 00075 * \param configINIFile The file to load the configuration from. See loadConfigFile 00076 * \param robotConfigFile The file to load the robot specific configuration from. 00077 * \param rmc A set of wrappers that must be filled in. 00078 * \param sensors A set of wrappers that must be filled in. 00079 * \param dbg A set of wrappers that must be filled in. 00080 * \param evnts A set of wrappers that must be filled in. 00081 * \param enableConsoleOutput Set to false if console output is not desired. 00082 * \param enableLogFile Set to true to enable logging to file. 00083 */ 00084 CReactiveNavigationSystem( 00085 CReactiveInterfaceImplementation &react_iterf_impl, 00086 bool enableConsoleOutput = true, 00087 bool enableLogFile = false); 00088 00089 /** Destructor 00090 */ 00091 virtual ~CReactiveNavigationSystem(); 00092 00093 /** Reload the configuration from a file 00094 */ 00095 void loadConfigFile(const mrpt::utils::CConfigFileBase &ini, const mrpt::utils::CConfigFileBase &robotIni); 00096 00097 /** Must be called for loading collision grids, or the first navigation 00098 * command may last a long time to be executed. 00099 */ 00100 void initialize(); 00101 00102 /** Evaluate navigation hardness: 00103 */ 00104 float evaluate( TNavigationParams *params ); 00105 00106 /** Start navigation: 00107 */ 00108 void navigate( TNavigationParams *params ); 00109 00110 /** Change current navigation params: 00111 */ 00112 void setParams( TNavigationParams *params ); 00113 00114 /** Selects which one from the set of available holonomic methods will be used 00115 * into transformed TP-Space, and sets its configuration from a configuration file. 00116 */ 00117 void setHolonomicMethod( 00118 THolonomicMethod method, 00119 const char *config_INIfile = "./CONFIG_ReactiveNavigator.ini"); 00120 00121 /** Change the robot shape, which is taken into account for collision 00122 * grid building. 00123 */ 00124 void changeRobotShape( math::CPolygon &shape ); 00125 00126 /** Provides a copy of the last log record with information about execution. On any unexpected error "*o" will be NULL. 00127 * \param o An object where the log will be stored into. 00128 */ 00129 void getLastLogRecord( CLogFileRecord &o ); 00130 00131 00132 /** See 'navigatorBehavior' 00133 */ 00134 enum TNavigatorBehavior 00135 { 00136 /** The robot tries to get to the given target point 00137 */ 00138 beNormalNavigation = 0, 00139 /** The robot rotates to head the direction "m_beHeadDirection_rad", then goes into normal behavior 00140 */ 00141 beHeadDirection, 00142 /** The robot tries to get to a given auxiliar target "m_beAuxTarget", then goes into behavior 'beDoorCrosing2' 00143 */ 00144 beDoorCrosing1, 00145 /** The robot rotates to head the direction "m_beHeadDirection_rad", then goes into behavior 'beDoorCrosing3' 00146 */ 00147 beDoorCrosing2, 00148 /** The robot rotates tries to get to a given auxiliar target "m_beAuxTarget", then goes into normal behavior 00149 */ 00150 beDoorCrosing3 00151 }; 00152 00153 /** Enables / disables the logging into a file. 00154 */ 00155 void enableLogFile(bool enable); 00156 00157 private: 00158 // ------------------------------------------------------ 00159 // PRIVATE DEFINITIONS 00160 // ------------------------------------------------------ 00161 00162 /** This defines the 'behavior' of the navigator (see posible values in TNavigatorBehavior) 00163 */ 00164 TNavigatorBehavior navigatorBehavior; 00165 00166 /** The desired heading direction (in rads), for behaviors 'beHeadDirection' and 'beDoorCrosing2'. 00167 */ 00168 float m_beHeadDirection_rad; 00169 00170 /** Auxiliary target position, for behaviors 'beDoorCrosing1' and 'beDoorCrosing3'. 00171 */ 00172 CPoint2D m_beAuxTarget; 00173 00174 /** This is the desired "path" for passing a door (in GLOBAL coordinates!) 00175 */ 00176 CPoint2D m_bePassPoint1,m_bePassPoint2; 00177 00178 /** The structure used for storing a movement generated by a holonomic-method . 00179 */ 00180 struct THolonomicMovement { 00181 CParameterizedTrajectoryGenerator *PTG; /// The associated PTG 00182 double direction, speed; /// The holonomic movement 00183 double evaluation; /// An evaluation in the range [0,1] for the goodness of the movement. 00184 }; 00185 00186 /** The last log. 00187 */ 00188 CLogFileRecord lastLogRecord; 00189 00190 /** For the histeresis: 00191 */ 00192 float last_cmd_v,last_cmd_w; 00193 00194 /** Will be false until the navigation end is sent, and it is reset with each new command 00195 */ 00196 bool navigationEndEventSent; 00197 00198 /** Critical zones: 00199 */ 00200 synch::CCriticalSection m_critZoneLastLog,m_critZoneNavigating; 00201 00202 // ------------------------------------------------------ 00203 // PRIVATE METHODS 00204 // ------------------------------------------------------ 00205 /** The main method for the navigator 00206 */ 00207 void performNavigationStep( ); 00208 00209 00210 // ------------------------------------------------------ 00211 // PRIVATE VARIABLES 00212 // ------------------------------------------------------ 00213 /** The current log file stream, or NULL if not being used 00214 */ 00215 CAbstractHolonomicReactiveMethod *holonomicMethod; 00216 /** The current log file stream, or NULL if not being used 00217 */ 00218 utils::CStream *logFile; 00219 /** Enables / disables the console debug output. 00220 */ 00221 bool enableConsoleOutput; 00222 00223 CTicTac timerForExecutionPeriod; 00224 00225 // Loaded from INI file: 00226 std::string robotName; // El nombre del robot donde estamos 00227 float refDistance; // "dmax" in papers. 00228 float colGridRes_x,colGridRes_y; // Resolucion de la rejilla de distancias de choque precalculadas 00229 float robotMax_V_mps; // Max. vel del robot en m/s 00230 float robotMax_W_degps; // Max. vel del robot en rad/s 00231 float ROBOTMODEL_TAU,ROBOTMODEL_DELAY; // Params for the motor system modelation 00232 vector_float weights; // length: 6 [0,5] 00233 float minObstaclesHeight, maxObstaclesHeight; // The range of "z" coordinates for obstacles to be considered 00234 float DIST_TO_TARGET_FOR_SENDING_EVENT; 00235 00236 float DOOR_CROSSING_SEARCH_TARGET_DISTANCEx2; 00237 float VORONOI_MINIMUM_CLEARANCE; 00238 float DISABLE_PERIOD_AFTER_FAIL; 00239 float VORONOI_PATH_DIST_FROM_DOORWAY; 00240 float DOORCROSSING_HEADING_ACCURACY_DEG; 00241 float DOORCROSSING_ROTATION_CTE_DEG; 00242 float DOOR_CROSSING_DIST_TO_AUX_TARGETS; 00243 float DOOR_CROOSING_BEH3_TIMEOUT; 00244 float DOOR_CROSSING_MAXIMUM_DOORWAY_SIZE; 00245 00246 /** The iterations count. 00247 */ 00248 unsigned long nIteration; 00249 00250 /** Runtime estimation of execution period of the method. 00251 */ 00252 float meanExecutionPeriod; 00253 00254 00255 /** For sending an alarm (error event) when it seems that we are not approaching toward the target in a while... 00256 */ 00257 float badNavAlarm_minDistTarget; 00258 mrpt::system::TTimeStamp badNavAlarm_lastMinDistTime; 00259 float badNavAlarm_AlarmTimeout; 00260 00261 00262 /** The robot 2D shape model 00263 */ 00264 math::CPolygon robotShape; 00265 bool collisionGridsMustBeUpdated; 00266 00267 /** The set of transformations to be used: 00268 */ 00269 std::vector<CParameterizedTrajectoryGenerator*> PTGs; 00270 00271 00272 // Steps for the reactive navigation sytem. 00273 // ---------------------------------------------------------------------------- 00274 void STEP1_CollisionGridsBuilder(); 00275 00276 bool STEP2_Sense( 00277 mrpt::slam::CSimplePointsMap &out_obstacles); 00278 00279 void STEP3_SpaceTransformer( 00280 poses::CPointsMap &in_obstacles, 00281 CParameterizedTrajectoryGenerator *in_PTG, 00282 vector_double &out_TPObstacles); 00283 00284 void STEP4_HolonomicMethod( 00285 vector_double &in_Obstacles, 00286 poses::CPoint2D &in_Target, 00287 float in_maxRobotSpeed, 00288 THolonomicMovement &out_selectedMovement, 00289 CHolonomicLogFileRecordPtr &in_HLFR ); 00290 00291 void STEP5_Evaluator( 00292 THolonomicMovement &in_holonomicMovement, 00293 vector_double &in_TPObstacles, 00294 poses::CPoint2D &WS_Target, 00295 poses::CPoint2D &TP_Target, 00296 bool wasSelectedInLast, 00297 CLogFileRecord::TInfoPerPTG &log ); 00298 00299 void STEP6_Selector( 00300 std::vector<THolonomicMovement> &in_holonomicMovements, 00301 THolonomicMovement &out_selectedHolonomicMovement, 00302 int &out_nSelectedPTG); 00303 00304 void STEP7_NonHolonomicMovement( 00305 THolonomicMovement &in_movement, 00306 float &out_v, 00307 float &out_w); 00308 00309 // 00310 bool CerrandoHilo; 00311 00312 // Para casos de errores: 00313 void Error_ParadaDeEmergencia( const char *msg ); 00314 00315 /** For taken the dynamics of the robot into account. 00316 */ 00317 class CDynamicWindow 00318 { 00319 public: 00320 float v_max, v_min; // m/sec 00321 float w_max, w_min; // rad/sec 00322 00323 private: 00324 float c1,c2,c3,c4; // Curvature of corners. 00325 00326 public: 00327 00328 /** Finds the max/min curvatures in the DW. 00329 */ 00330 void findMinMaxCurvatures(float &minCurv, float &maxCurv); 00331 00332 /** Returns the corner which is closer (in curvature, and abs. values) to the desired command. 00333 */ 00334 void findBestApproximation(float desV,float desW, float &outV,float &outW); 00335 00336 private: 00337 /** Find the closest cut of a line with the DW 00338 */ 00339 bool findClosestCut( float cmd_v, float cmd_w, // IN 00340 float &out_v,float &out_w); // OUT 00341 00342 }; 00343 00344 }; 00345 } 00346 } 00347 00348 00349 #endif 00350 00351 00352 00353 00354
| Page generated by Doxygen 1.7.1 for MRPT 0.9.1 SVN:exported at Fri Aug 6 10:31:35 UTC 2010 |
