Main MRPT website > C++ reference
MRPT logo
CAbstractReactiveNavigationSystem.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CAbstractReactiveNavigationSystem_H
10 #define CAbstractReactiveNavigationSystem_H
11 
12 #include <mrpt/poses/CPose2D.h>
14 
16 
17 namespace mrpt
18 {
19  namespace slam { class CSimplePointsMap; }
20 
21  namespace reactivenav
22  {
23  using namespace mrpt;
24  using namespace mrpt::slam;
25  using namespace mrpt::poses;
26 
27  /** 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.
28  *
29  * The user must define a new class derived from CReactiveInterfaceImplementation and reimplement
30  * all pure virtual and the desired virtual methods according to the documentation in this class.
31  *
32  * \sa CReactiveNavigationSystem, CAbstractReactiveNavigationSystem
33  * \ingroup mrpt_reactivenav_grp
34  */
36  {
37  public:
38  /** Get the current pose and speeds of the robot.
39  * \param curPose Current robot pose.
40  * \param curV Current linear speed, in meters per second.
41  * \param curW Current angular speed, in radians per second.
42  * \return false on any error.
43  */
44  virtual bool getCurrentPoseAndSpeeds( mrpt::poses::CPose2D &curPose, float &curV, float &curW) = 0;
45 
46  /** Change the instantaneous speeds of robot.
47  * \param v Linear speed, in meters per second.
48  * \param w Angular speed, in radians per second.
49  * \return false on any error.
50  */
51  virtual bool changeSpeeds( float v, float w ) = 0;
52 
53  /** Stop the robot right now.
54  * \return false on any error.
55  */
56  virtual bool stop() {
57  return changeSpeeds(0,0);
58  }
59 
60  /** Start the watchdog timer of the robot platform, if any.
61  * \param T_ms Period, in ms.
62  * \return false on any error.
63  */
64  virtual bool startWatchdog(float T_ms) {
65  MRPT_UNUSED_PARAM(T_ms);
66  return true;
67  }
68 
69  /** Stop the watchdog timer.
70  * \return false on any error.
71  */
72  virtual bool stopWatchdog() { return true; }
73 
74  /** Return the current set of obstacle points, as seen from the local coordinate frame of the robot.
75  * \return false on any error.
76  */
77  virtual bool senseObstacles( mrpt::slam::CSimplePointsMap &obstacles ) = 0;
78 
79  virtual void sendNavigationStartEvent () { std::cout << "[sendNavigationStartEvent] Not implemented by the user." << std::endl; }
80  virtual void sendNavigationEndEvent() { std::cout << "[sendNavigationEndEvent] Not implemented by the user." << std::endl; }
81  virtual void sendNavigationEndDueToErrorEvent() { std::cout << "[sendNavigationEndDueToErrorEvent] Not implemented by the user." << std::endl; }
82  virtual void sendWaySeemsBlockedEvent() { std::cout << "[sendWaySeemsBlockedEvent] Not implemented by the user." << std::endl; }
83  virtual void notifyHeadingDirection(const double heading_dir_angle) {
84  MRPT_UNUSED_PARAM(heading_dir_angle);
85  }
86  };
87 
88 
89 
90  /** This is the base class for any reactive navigation system. Here is defined
91  * the interface that users will use with derived classes where algorithms are really implemented.
92  *
93  * Changes history:
94  * - 30/JUN/2004: Creation (JLBC)
95  * - 16/SEP/2004: Totally redesigned.
96  * - 15/SEP/2005: Totally rewritten again, for integration into MRPT Applications Repository.
97  * - 3/NOV/2009: All functors are finally replaced by the new virtual class CReactiveInterfaceImplementation
98  * - 16/DEC/2013: Refactoring of code in 2D & 2.5D navigators.
99  *
100  * How to use:
101  * - A class with callbacks must be defined by the user and provided to the constructor.
102  * - 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.
103  *
104  * \sa CReactiveNavigationSystem, CReactiveInterfaceImplementation
105  */
107  {
108  public:
109  /** The struct for configuring navigation requests. See also: CAbstractPTGBasedReactive::TNavigationParamsPTG */
111  {
112  mrpt::math::TPoint2D target; //!< Coordinates of desired target location.
113  double targetHeading; //!< Target location (heading, in radians).
114 
115  float targetAllowedDistance; //!< Allowed distance to target in order to end the navigation.
116  bool targetIsRelative; //!< (Default=false) Whether the \a target coordinates are in global coordinates (false) or are relative to the current robot pose (true).
117 
118  TNavigationParams(); //!< Ctor with default values
119  virtual ~TNavigationParams() {}
120  virtual std::string getAsText() const; //!< Gets navigation params as a human-readable format
121  virtual TNavigationParams* clone() const { return new TNavigationParams(*this); }
122  };
123 
124 
125  /** Constructor */
127 
128  /** Destructor */
130 
131  /** Cancel current navegacion. */
132  void cancel();
133 
134  /** Continues with suspended navigation. \sa suspend */
135  void resume();
136 
137  /** This method must be called periodically in order to effectively run the navigation. */
138  void navigationStep();
139 
140  /** Navigation request. It starts a new navigation.
141  * \param[in] params Pointer to structure with navigation info (its contents will be copied, so the original can be freely destroyed upon return.)
142  */
143  virtual void navigate( const TNavigationParams *params )=0;
144 
145  /** Suspend current navegation. \sa resume */
146  virtual void suspend();
147 
148  /** The different states for the navigation system. */
149  enum TState
150  {
151  IDLE=0,
154  NAV_ERROR
155  };
156 
157  /** Returns the current navigator state. */
158  inline TState getCurrentState() const { return m_navigationState; }
159 
160  private:
161  TState m_lastNavigationState; //!< Last internal state of navigator:
162 
163  protected:
164  /** To be implemented in derived classes */
165  virtual void performNavigationStep( )=0;
166 
167  TState m_navigationState; //!< Current internal state of navigator:
168  TNavigationParams *m_navigationParams; //!< Current navigation parameters
169 
170 
171  CReactiveInterfaceImplementation &m_robot; //!< The navigator-robot interface.
172 
173  public:
175  };
176  }
177 }
178 
179 
180 #endif
181 
The pure virtual class that a user of CAbstractReactiveNavigationSystem-derived classes must implemen...
TState
The different states for the navigation system.
TNavigationParams * m_navigationParams
Current navigation parameters.
virtual bool startWatchdog(float T_ms)
Start the watchdog timer of the robot platform, if any.
#define MRPT_MAKE_ALIGNED_OPERATOR_NEW
Definition: memory.h:112
This namespace contains algorithms for SLAM, localization, map building, representation of robot's ac...
CReactiveInterfaceImplementation & m_robot
The navigator-robot interface.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
mrpt::math::TPoint2D target
Coordinates of desired target location.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
bool targetIsRelative
(Default=false) Whether the target coordinates are in global coordinates (false) or are relative to t...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose.
Definition: CPose2D.h:36
This is the base class for any reactive navigation system.
float targetAllowedDistance
Allowed distance to target in order to end the navigation.
TState getCurrentState() const
Returns the current navigator state.
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
Lightweight 2D point.
virtual void notifyHeadingDirection(const double heading_dir_angle)
This base class provides a common printf-like method to send debug information to std::cout...



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014