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 CPRRTNavigator_H 00029 #define CPRRTNavigator_H 00030 00031 #include <mrpt/maps.h> 00032 #include <mrpt/poses.h> 00033 #include <mrpt/synch.h> 00034 #include <mrpt/system/threads.h> 00035 #include <mrpt/reactivenav/CParameterizedTrajectoryGenerator.h> 00036 00037 #include <mrpt/reactivenav/link_pragmas.h> 00038 00039 namespace mrpt 00040 { 00041 namespace reactivenav 00042 { 00043 using namespace mrpt; 00044 using namespace mrpt::slam; 00045 using namespace mrpt::math; 00046 using namespace mrpt::synch; 00047 using namespace mrpt::poses; 00048 00049 /** This class is a multi-threaded mobile robot navigator, implementing an (anytime) PTG-based Rapidly-exploring Random Tree (PRRT) search algorithm. 00050 * 00051 * <b>Usage:</b><br> 00052 * - Create an instance of the CPRRTNavigator class (an object on the heap, i.e. no 'new', is preferred, but just for the convenience of the user). 00053 * - Set all the parameters in CPRRTNavigator::params 00054 * - Call CPRRTNavigator::initialize. If all the params are OK, true is returned and you can go on. 00055 * - Start a navigation by calling CPRRTNavigator::navigate. 00056 * - From your application, you must update all the sensory data (from the real robot or a simulator) on a timely-fashion. The navigator will stop the robot if the last sensory data is too old. 00057 * 00058 * Note that all the public methods are thread-safe. 00059 * 00060 * <b>About the algorithm:</b><br> 00061 * 00062 * 00063 * 00064 * 00065 * 00066 * <b>Changes history</b> 00067 * - 05/JUL/2009: Creation (JLBC). This is an evolution from leassons learnt from the pure reactive navigator based on PTGs. 00068 * \ingroup mrpt_reactivenav_grp 00069 */ 00070 class REACTIVENAV_IMPEXP CPRRTNavigator 00071 { 00072 public: 00073 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00074 00075 public: 00076 CPRRTNavigator(); //!< Constructor 00077 virtual ~CPRRTNavigator(); //!< Destructor 00078 00079 /** @name Navigation control methods 00080 @{*/ 00081 /** Initialize the navigator using the parameters in "params"; read the usage instructions in CPRRTNavigator. 00082 * This method should be called only once at the beginning of the robot operation. 00083 * \return true on sucess, false on any error preparing the navigator (and no navigation command will be processed until that's fixed). 00084 */ 00085 bool initialize(); 00086 00087 /** Starts a navigation to a 2D pose (including a desired heading at the target). 00088 * \note CPRRTNavigator::initialize must be called first. 00089 */ 00090 void navigate( const mrpt::math::TPose2D &target_pose); 00091 00092 /** Starts a navigation to a given 2D point (any heading at the target). 00093 * \note CPRRTNavigator::initialize must be called first. 00094 */ 00095 void navigate( const mrpt::math::TPoint2D &target_point); 00096 00097 /** Cancel current navegacion. 00098 * \note CPRRTNavigator::initialize must be called first. 00099 */ 00100 void cancel(); 00101 00102 /** Continues with suspended navigation. 00103 * \sa suspend 00104 * \note CPRRTNavigator::initialize must be called first. 00105 */ 00106 void resume(); 00107 00108 /** Suspend current navegation 00109 * \sa resume 00110 * \note CPRRTNavigator::initialize must be called first. 00111 */ 00112 void suspend(); 00113 00114 /** @} */ 00115 00116 /** @name Navigator data structures 00117 @{*/ 00118 /** Each data point in m_planned_path */ 00119 struct REACTIVENAV_IMPEXP TPathData 00120 { 00121 TPathData() : 00122 p(0,0,0), 00123 max_v(0.1),max_w(0.2), 00124 trg_v(0.1) 00125 {} 00126 00127 TPose2D p; //!< Coordinates are "global" 00128 double max_v, max_w; //!< Maximum velocities along this path segment. 00129 double trg_v; //!< Desired linear velocity at the target point, ie: the robot should program its velocities such as after this arc the speeds are the given ones. 00130 }; 00131 00132 typedef std::list<TPathData> TPlannedPath; //!< An ordered list of path poses. 00133 00134 class REACTIVENAV_IMPEXP TOptions : public mrpt::utils::CLoadableOptions 00135 { 00136 public: 00137 TOptions(); //!< Initial values 00138 00139 /** This method load the options from a ".ini"-like file or memory-stored string list. 00140 */ 00141 void loadFromConfigFile( 00142 const mrpt::utils::CConfigFileBase &source, 00143 const std::string §ion); 00144 00145 /** This method displays clearly all the contents of the structure in textual form, sending it to a CStream. */ 00146 void dumpToTextStream( CStream &out) const; 00147 00148 // Data: 00149 double absolute_max_v; //!< Max linear speed (m/s) 00150 double absolute_max_w; //!< Max angular speed (rad/s) 00151 double max_accel_v; //!< Max desired linear speed acceleration (m/s^2) 00152 double max_accel_w; //!< Max desired angular speed acceleration (rad/s^2) 00153 00154 double max_age_observations; //!< Max age (in seconds) for an observation to be considered invalid for navigation purposes. 00155 00156 /** The robot shape used when computing collisions; it's loaded from the 00157 * config file/text as a single 2xN matrix in MATLAB format, first row are Xs, second are Ys, e.g: 00158 * \code 00159 * robot_shape = [-0.2 0.2 0.2 -0.2; -0.1 -0.1 0.1 0.1] 00160 * \endcode 00161 */ 00162 TPolygon2D robot_shape; 00163 00164 struct REACTIVENAV_IMPEXP TPathTrackingOpts 00165 { 00166 double radius_checkpoints; //!< Radius of each checkpoint in the path, ie: when the robot get closer than this distance, the point is considered as visited and the next one is processed. 00167 }; 00168 TPathTrackingOpts pathtrack; 00169 00170 struct REACTIVENAV_IMPEXP TPlannerOpts 00171 { 00172 double max_time_expend_planning; //!< Maximum time to spend when planning, in seconds. 00173 }; 00174 TPlannerOpts planner; 00175 00176 }; 00177 00178 TOptions params; //!< Change here all the parameters of the navigator. 00179 00180 /** @} */ 00181 00182 /** @name Debug and logging 00183 @{*/ 00184 /** Manually sets the short-time path to be followed by the robot (use 'navigate' instead, this method is for debugging mainly) 00185 */ 00186 void setPathToFollow(const TPlannedPath &path ); 00187 00188 /** Returns the current planned path the robot is following */ 00189 void getCurrentPlannedPath(TPlannedPath &path ) const; 00190 00191 00192 /** @} */ 00193 00194 00195 /** @name Sensory data methods: call them to update the navigator knowledge on the outside world. 00196 @{*/ 00197 /** Updates the navigator with a low or high-rate estimate from a localization (or SLAM) algorithm running somewhere else. 00198 * \param new_robot_pose The (global) coordinates of the mean robot pose as estimated by some external module. 00199 * \param new_robot_cov The 3x3 covariance matrix of that estimate. 00200 * \param timestamp The associated timestamp of the data. 00201 */ 00202 void processNewLocalization(const TPose2D &new_robot_pose, const CMatrixDouble33 &new_robot_cov, TTimeStamp timestamp ); 00203 00204 /** Updates the navigator with high-rate odometry from the mobile base. 00205 * The odometry poses are dealed internally as increments only, so there is no problem is 00206 * arbitrary mismatches between localization (from a particle filter or SLAM) and the odometry. 00207 * \param newOdoPose The global, cummulative odometry as computed by the robot. 00208 * \param timestamp The associated timestamp of the measurement. 00209 * \param hasVelocities If false, the next arguments are ignored. 00210 * \param v Measured linear speed, in m/s. 00211 * \param w Measured angular speed, in rad/s. 00212 */ 00213 void processNewOdometryInfo( const TPose2D &newOdoPose, TTimeStamp timestamp, bool hasVelocities =false, float v =0, float w=0 ); 00214 00215 /** Must be called in a timely fashion to let the navigator know about the obstacles in the environment. 00216 * \param obstacles 00217 * \param timestamp The associated timestamp of the sensed points. 00218 */ 00219 void processNewObstaclesData(const mrpt::slam::CPointsMap* obstacles, TTimeStamp timestamp ); 00220 00221 /** @} */ 00222 00223 /** @name Virtual methods to be implemented by the user. 00224 @{*/ 00225 /** This is the most important method the user must provide: to send an instantaneous velocity command to the robot. 00226 * \param v Desired linear speed, in meters/second. 00227 * \param w Desired angular speed, in rads/second. 00228 * \return false on any error. In that case, the navigator will immediately stop the navigation and announce the error. 00229 */ 00230 virtual bool onMotionCommand(float v, float w ) = 0; 00231 00232 /** Re-implement this method if you want to know when a new navigation has started. 00233 */ 00234 virtual void onNavigationStart( ) { } 00235 00236 /** Re-implement this method if you want to know when and why a navigation has ended. 00237 * \param targetReachedOK Will be false if the navigation failed. 00238 */ 00239 virtual void onNavigationEnd( bool targetReachedOK ) { } 00240 00241 /** Re-implement this method if you want to know when the robot is approaching the target: 00242 * this event is raised before onNavigationEnd, when the robot is closer than a certain distance to the target. 00243 */ 00244 virtual void onApproachingTarget( ) { } 00245 00246 /** @} */ 00247 00248 static const double INVALID_HEADING; //!< Used to refer to undefined or "never mind" headings values. 00249 00250 private: 00251 // ----------- Internal methods & threads ----------- 00252 00253 TThreadHandle m_thr_planner; //!< Thread handle 00254 TThreadHandle m_thr_testcol; //!< Thread handle 00255 TThreadHandle m_thr_pathtrack; //!< Thread handle 00256 00257 void thread_planner(); //!< Thread function 00258 void thread_test_collision(); //!< Thread function 00259 void thread_path_tracking(); //!< Thread function 00260 00261 00262 // ----------- Internal data ----------- 00263 00264 bool m_initialized; //!< The object is ready to navigate. Users must call "initialize" first. 00265 bool m_closingThreads; //!< set to true at destructor. 00266 00267 TPose2D m_target_pose; //!< Heading may be INVALID_HEADING to indicate "don't mind" 00268 TTimeStamp m_target_pose_time; 00269 CCriticalSection m_target_pose_cs; 00270 00271 // Instead of a CSimplePointsMap, just store the X & Y vectors, since 00272 // this is a temporary variable. We'll let the planning thread to build 00273 // a CSimplePointsMap object with these points. 00274 //mrpt::slam::CSimplePointsMap m_last_obstacles; 00275 std::vector<float> m_last_obstacles_x,m_last_obstacles_y; 00276 TTimeStamp m_last_obstacles_time; 00277 CCriticalSection m_last_obstacles_cs; 00278 00279 // The planned path, to be followed: 00280 CCriticalSection m_planned_path_cs; 00281 TTimeStamp m_planned_path_time; //!< The last modification time. INVALID_TIMESTAMP means there is no path. 00282 TPlannedPath m_planned_path; 00283 00284 /** The list of PTGs used by the anytime planner to explore the free-space. */ 00285 TListPTGs m_PTGs; 00286 CCriticalSection m_PTGs_cs; 00287 00288 public: 00289 00290 mrpt::poses::CRobot2DPoseEstimator m_robotStateFilter; //!< Object maintained by the robot-tracking thread (All methods are thread-safe). 00291 00292 00293 00294 }; 00295 } 00296 } 00297 00298 00299 #endif 00300
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |