Main MRPT website > C++ reference
MRPT logo
CAbstractReactiveNavigationSystem.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CAbstractReactiveNavigationSystem_H
29 #define CAbstractReactiveNavigationSystem_H
30 
31 #include <mrpt/maps.h>
32 #include <mrpt/poses.h>
33 
35 
36 
37 #include <cstdarg>
38 
39 namespace mrpt
40 {
41  namespace reactivenav
42  {
43  using namespace mrpt;
44  using namespace mrpt::slam;
45  using namespace mrpt::poses;
46 
47  /** 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.
48  *
49  * The user must define a new class derived from CReactiveInterfaceImplementation and reimplement
50  * all pure virtual and the desired virtual methods according to the documentation in this class.
51  *
52  * \sa CReactiveNavigationSystem, CAbstractReactiveNavigationSystem
53  * \ingroup mrpt_reactivenav_grp
54  */
56  {
57  public:
58  /** Get the current pose and speeds of the robot.
59  * \param curPose Current robot pose.
60  * \param curV Current linear speed, in meters per second.
61  * \param curW Current angular speed, in radians per second.
62  * \return false on any error.
63  */
64  virtual bool getCurrentPoseAndSpeeds( mrpt::poses::CPose2D &curPose, float &curV, float &curW) = 0;
65 
66  /** Change the instantaneous speeds of robot.
67  * \param v Linear speed, in meters per second.
68  * \param w Angular speed, in radians per second.
69  * \return false on any error.
70  */
71  virtual bool changeSpeeds( float v, float w ) = 0;
72 
73  /** Stop the robot right now.
74  * \return false on any error.
75  */
76  virtual bool stop() {
77  return changeSpeeds(0,0);
78  }
79 
80  /** Start the watchdog timer of the robot platform, if any.
81  * \param T_ms Period, in ms.
82  * \return false on any error.
83  */
84  virtual bool startWatchdog(float T_ms) { return true; }
85 
86  /** Stop the watchdog timer.
87  * \return false on any error.
88  */
89  virtual bool stopWatchdog() { return true; }
90 
91  /** Return the current set of obstacle points.
92  * \return false on any error.
93  */
94  virtual bool senseObstacles( mrpt::slam::CSimplePointsMap &obstacles ) = 0;
95 
96  virtual void sendNavigationStartEvent () { std::cout << "[sendNavigationStartEvent] Not implemented by the user." << std::endl; }
97 
98  virtual void sendNavigationEndEvent() { std::cout << "[sendNavigationEndEvent] Not implemented by the user." << std::endl; }
99 
100  virtual void sendNavigationEndDueToErrorEvent() { std::cout << "[sendNavigationEndDueToErrorEvent] Not implemented by the user." << std::endl; }
101 
102  virtual void sendWaySeemsBlockedEvent() { std::cout << "[sendWaySeemsBlockedEvent] Not implemented by the user." << std::endl; }
103 
104  virtual void notifyHeadingDirection(const double heading_dir_angle) { }
105 
106  };
107 
108 
109 
110  /** This is the base class for any reactive navigation system. Here is defined
111  * the interface that users will use with derived classes where algorithms are really implemented.
112  *
113  * Changes history:
114  * - 30/JUN/2004: Creation (JLBC)
115  * - 16/SEP/2004: Totally redesigned.
116  * - 15/SEP/2005: Totally rewritten again, for integration into MRPT Applications Repository.
117  * - 3/NOV/2009: All functors are finally replaced by the new virtual class CReactiveInterfaceImplementation
118  *
119  * How to use:
120  * - A class with callbacks must be defined by the user and provided to the constructor.
121  * - 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.
122  *
123  * \sa CReactiveNavigationSystem, CReactiveInterfaceImplementation
124  */
126  {
127  public:
128  struct TNavigationParams;
129 
130  /** Constructor
131  */
133 
134  /** Destructor
135  */
137  {
138  }
139 
140  /** Cancel current navegacion.
141  */
142  void cancel();
143 
144  /** Continues with suspended navigation.
145  * \sa suspend
146  */
147  void resume();
148 
149  /** Evaluates the practicability of a navigation for given parameters:
150  * \returns An estimation in the range [0,1], for 0 being imposible and 1 being easy.
151  */
152  virtual float evaluate( TNavigationParams *params )=0;
153 
154  /** This method must be called periodically in order to effectively run the navigation.
155  */
156  void navigationStep();
157 
158  /** Navigation request. It starts a new navigation.
159  */
160  virtual void navigate( TNavigationParams *params )=0;
161 
162  /** Changes the parameters for current navigation
163  */
164  virtual void setParams( TNavigationParams *params)=0;
165 
166  /** Suspend current navegation
167  * \sa resume
168  */
169  virtual void suspend();
170 
171  /** The struct for configuring the navigation request.
172  */
174  {
175  /** Coordinates of desired target location.
176  */
177  mrpt::poses::TPoint2D target;
178 
179  /** The allowed distance from target in order to end the navigation.
180  */
182 
183  /** Whether the \a target coordinates are in global coordinates (false) or are relative to the current robot pose (true).
184  */
186  };
187 
188  /** The different states for the navigation system.
189  */
190  enum TState
191  {
192  IDLE=0,
195  NAV_ERROR
196  };
197 
198  /** Returns the current navigator state.
199  */
200  TState getCurrentState() const { return m_navigationState; }
201 
202  private:
203  /** Last internal state of navigator:
204  */
206 
207  protected:
208  /** To be implemented in derived classes
209  */
210  virtual void performNavigationStep( )=0;
211 
212  /** Current internal state of navigator:
213  */
215 
216  /** Current navigation parameters:
217  */
219 
220 
221  CReactiveInterfaceImplementation &m_robot; //!< The navigator-robot interface.
222 
223  public:
224  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
225  };
226  }
227 }
228 
229 
230 #endif
231 



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013