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 CAbstractReactiveNavigationSystem_H 00029 #define CAbstractReactiveNavigationSystem_H 00030 00031 #include <mrpt/maps.h> 00032 #include <mrpt/poses.h> 00033 00034 #include <mrpt/reactivenav/link_pragmas.h> 00035 00036 00037 #include <cstdarg> 00038 00039 namespace mrpt 00040 { 00041 namespace reactivenav 00042 { 00043 using namespace mrpt; 00044 using namespace mrpt::slam; 00045 using namespace mrpt::poses; 00046 00047 /** The pure virtual class that a user of CAbstractReactiveNavigationSystem-derived classes must implement in order to allow the navigator sense the world and send motion commands to the robot. 00048 * 00049 * The user must define a new class derived from CReactiveInterfaceImplementation and reimplement 00050 * all pure virtual and the desired virtual methods according to the documentation in this class. 00051 * 00052 * \sa CReactiveNavigationSystem, CAbstractReactiveNavigationSystem 00053 * \ingroup mrpt_reactivenav_grp 00054 */ 00055 class REACTIVENAV_IMPEXP CReactiveInterfaceImplementation 00056 { 00057 public: 00058 /** Get the current pose and speeds of the robot. 00059 * \param curPose Current robot pose. 00060 * \param curV Current linear speed, in meters per second. 00061 * \param curW Current angular speed, in radians per second. 00062 * \return false on any error. 00063 */ 00064 virtual bool getCurrentPoseAndSpeeds( mrpt::poses::CPose2D &curPose, float &curV, float &curW) = 0; 00065 00066 /** Change the instantaneous speeds of robot. 00067 * \param v Linear speed, in meters per second. 00068 * \param w Angular speed, in radians per second. 00069 * \return false on any error. 00070 */ 00071 virtual bool changeSpeeds( float v, float w ) = 0; 00072 00073 /** Stop the robot right now. 00074 * \return false on any error. 00075 */ 00076 virtual bool stop() { 00077 return changeSpeeds(0,0); 00078 } 00079 00080 /** Start the watchdog timer of the robot platform, if any. 00081 * \param T_ms Period, in ms. 00082 * \return false on any error. 00083 */ 00084 virtual bool startWatchdog(float T_ms) { return true; } 00085 00086 /** Stop the watchdog timer. 00087 * \return false on any error. 00088 */ 00089 virtual bool stopWatchdog() { return true; } 00090 00091 /** Return the current set of obstacle points. 00092 * \return false on any error. 00093 */ 00094 virtual bool senseObstacles( mrpt::slam::CSimplePointsMap &obstacles ) = 0; 00095 00096 virtual void sendNavigationStartEvent () { std::cout << "[sendNavigationStartEvent] Not implemented by the user." << std::endl; } 00097 00098 virtual void sendNavigationEndEvent() { std::cout << "[sendNavigationEndEvent] Not implemented by the user." << std::endl; } 00099 00100 virtual void sendNavigationEndDueToErrorEvent() { std::cout << "[sendNavigationEndDueToErrorEvent] Not implemented by the user." << std::endl; } 00101 00102 virtual void sendWaySeemsBlockedEvent() { std::cout << "[sendWaySeemsBlockedEvent] Not implemented by the user." << std::endl; } 00103 00104 virtual void notifyHeadingDirection(const double heading_dir_angle) { } 00105 00106 }; 00107 00108 00109 00110 /** This is the base class for any reactive navigation system. Here is defined 00111 * the interface that users will use with derived classes where algorithms are really implemented. 00112 * 00113 * Changes history: 00114 * - 30/JUN/2004: Creation (JLBC) 00115 * - 16/SEP/2004: Totally redesigned. 00116 * - 15/SEP/2005: Totally rewritten again, for integration into MRPT Applications Repository. 00117 * - 3/NOV/2009: All functors are finally replaced by the new virtual class CReactiveInterfaceImplementation 00118 * 00119 * How to use: 00120 * - A class with callbacks must be defined by the user and provided to the constructor. 00121 * - navigationStep() must be called periodically in order to effectively run the navigation. This method will internally call the callbacks to gather sensor data and robot positioning data. 00122 * 00123 * \sa CReactiveNavigationSystem, CReactiveInterfaceImplementation 00124 */ 00125 class REACTIVENAV_IMPEXP CAbstractReactiveNavigationSystem : public mrpt::utils::CDebugOutputCapable 00126 { 00127 public: 00128 struct TNavigationParams; 00129 00130 /** Constructor 00131 */ 00132 CAbstractReactiveNavigationSystem( CReactiveInterfaceImplementation &react_iterf_impl ); 00133 00134 /** Destructor 00135 */ 00136 virtual ~CAbstractReactiveNavigationSystem() 00137 { 00138 } 00139 00140 /** Cancel current navegacion. 00141 */ 00142 void cancel(); 00143 00144 /** Continues with suspended navigation. 00145 * \sa suspend 00146 */ 00147 void resume(); 00148 00149 /** Evaluates the practicability of a navigation for given parameters: 00150 * \returns An estimation in the range [0,1], for 0 being imposible and 1 being easy. 00151 */ 00152 virtual float evaluate( TNavigationParams *params )=0; 00153 00154 /** This method must be called periodically in order to effectively run the navigation. 00155 */ 00156 void navigationStep(); 00157 00158 /** Navigation request. It starts a new navigation. 00159 */ 00160 virtual void navigate( TNavigationParams *params )=0; 00161 00162 /** Changes the parameters for current navigation 00163 */ 00164 virtual void setParams( TNavigationParams *params)=0; 00165 00166 /** Suspend current navegation 00167 * \sa resume 00168 */ 00169 virtual void suspend(); 00170 00171 /** The struct for configuring the navigation request. 00172 */ 00173 struct TNavigationParams 00174 { 00175 /** Coordinates of desired target location. 00176 */ 00177 mrpt::poses::TPoint2D target; 00178 00179 /** The allowed distance from target in order to end the navigation. 00180 */ 00181 float targetAllowedDistance; 00182 00183 /** Whether the \a target coordinates are in global coordinates (false) or are relative to the current robot pose (true). 00184 */ 00185 bool targetIsRelative; 00186 }; 00187 00188 /** The different states for the navigation system. 00189 */ 00190 enum TState 00191 { 00192 IDLE=0, 00193 NAVIGATING, 00194 SUSPENDED, 00195 NAV_ERROR 00196 }; 00197 00198 /** Returns the current navigator state. 00199 */ 00200 TState getCurrentState() const { return m_navigationState; } 00201 00202 private: 00203 /** Last internal state of navigator: 00204 */ 00205 TState m_lastNavigationState; 00206 00207 protected: 00208 /** To be implemented in derived classes 00209 */ 00210 virtual void performNavigationStep( )=0; 00211 00212 /** Current internal state of navigator: 00213 */ 00214 TState m_navigationState; 00215 00216 /** Current navigation parameters: 00217 */ 00218 TNavigationParams m_navigationParams; 00219 00220 00221 CReactiveInterfaceImplementation &m_robot; //!< The navigator-robot interface. 00222 00223 public: 00224 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00225 }; 00226 } 00227 } 00228 00229 00230 #endif 00231
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |