Main MRPT website > C++ reference for MRPT 1.5.9
CRobot2NavInterface.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-2017, 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 #pragma once
10 
12 #include <mrpt/nav/link_pragmas.h>
13 #include <mrpt/obs/obs_frwds.h> // CSimplePointsMap
14 #include <mrpt/utils/CTicTac.h>
16 #include <mrpt/system/datetime.h>
18 
19 namespace mrpt
20 {
21  namespace nav
22  {
23  /** The pure virtual interface between a real or simulated robot and any `CAbstractNavigator`-derived class.
24  *
25  * The user must define a new class derived from `CRobot2NavInterface` and reimplement
26  * all pure virtual and the desired virtual methods according to the documentation in this class.
27  *
28  * [New in MRPT 1.5.0] This class does not make assumptions about the kinematic model of the robot, so it can work with either
29  * Ackermann, differential-driven or holonomic robots. It will depend on the used PTGs, so checkout
30  * each PTG documentation for the lenght and meaning of velocity commands.
31  *
32  * If used for a simulator, users may prefer to inherit from one of these classes, which already provide partial implementations:
33  * - mrpt::nav::CRobot2NavInterfaceForSimulator_DiffDriven
34  * - mrpt::nav::CRobot2NavInterfaceForSimulator_Holo
35  *
36  * \sa CReactiveNavigationSystem, CAbstractNavigator
37  * \ingroup nav_reactive
38  */
39  class NAV_IMPEXP CRobot2NavInterface : public mrpt::utils::COutputLogger
40  {
41  public:
43  virtual ~CRobot2NavInterface();
44 
45  /** Get the current pose and velocity of the robot. The implementation should not take too much time to return,
46  * so if it might take more than ~10ms to ask the robot for the instantaneous data, it may be good enough to
47  * return the latest values from a cache which is updated in a parallel thread.
48  * \return false on any error retrieving these values from the robot.
49  */
50  virtual bool getCurrentPoseAndSpeeds(
51  mrpt::math::TPose2D &curPose, //!< (output) The latest robot pose (typically from a mapping/localization module), in world coordinates. (x,y: meters, phi: radians)
52  mrpt::math::TTwist2D &curVelGlobal, //!< (output) The latest robot velocity vector, in world coordinates. (vx,vy: m/s, omega: rad/s)
53  mrpt::system::TTimeStamp &timestamp, //!< (output) The timestamp for the read pose and velocity values. Use mrpt::system::now() unless you have something more accurate.
54  mrpt::math::TPose2D &curOdometry, //!< (output) The latest robot raw odometry pose; may have long-time drift should be more locally consistent than curPose (x,y: meters, phi: radians)
55  std::string &frame_id //!< (output) ID of the coordinate frame for curPose. Default is not modified is "map". [Only for future support to submapping,etc.]
56  ) = 0;
57 
58  /** Sends a velocity command to the robot.
59  * The number components in each command depends on children classes of mrpt::kinematics::CVehicleVelCmd.
60  * One robot may accept one or more different CVehicleVelCmd classes.
61  * This method resets the watchdog timer (that may be or may be not implemented in a particular robotic platform) started with startWatchdog()
62  * \return false on any error.
63  * \sa startWatchdog
64  */
65  virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd) = 0;
66 
67  /** Just like changeSpeeds(), but will be called when the last velocity command is still the preferred solution,
68  * so there is no need to change that past command. The unique effect of this callback would be resetting the watchdog timer.
69  * \return false on any error.
70  * \sa changeSpeeds(), startWatchdog() */
71  virtual bool changeSpeedsNOP();
72 
73  /** Stop the robot right now.
74  * \param[in] isEmergencyStop true if stop is due to some unexpected error. false if "stop" happens as part of a normal operation (e.g. target reached).
75  * \return false on any error.
76  */
77  virtual bool stop(bool isEmergencyStop=true) = 0;
78 
79  /** Gets the emergency stop command for the current robot
80  * \return the emergency stop command
81  */
82  virtual mrpt::kinematics::CVehicleVelCmdPtr getEmergencyStopCmd() = 0;
83 
84  /** Gets the emergency stop command for the current robot
85  * \return the emergency stop command
86  */
87  virtual mrpt::kinematics::CVehicleVelCmdPtr getStopCmd() = 0;
88 
89  /** Gets a motion command to make the robot to align with a given *relative* heading, without translating.
90  * Only for circular robots that can rotate in place; otherwise, return an empty smart pointer to indicate
91  * that the operation is not possible (this is what the default implementation does). */
92  virtual mrpt::kinematics::CVehicleVelCmdPtr getAlignCmd(const double relative_heading_radians);
93 
94  /** Start the watchdog timer of the robot platform, if any, for maximum expected delay between consecutive calls to changeSpeeds().
95  * \param T_ms Period, in ms.
96  * \return false on any error. */
97  virtual bool startWatchdog(float T_ms);
98 
99  /** Stop the watchdog timer.
100  * \return false on any error. \sa startWatchdog */
101  virtual bool stopWatchdog();
102 
103  /** Return the current set of obstacle points, as seen from the local coordinate frame of the robot.
104  * \return false on any error.
105  * \param[out] obstacles A representation of obstacles in robot-centric coordinates.
106  * \param[out] timestamp The timestamp for the read obstacles. Use mrpt::system::now() unless you have something more accurate.
107  */
108  virtual bool senseObstacles( mrpt::maps::CSimplePointsMap &obstacles, mrpt::system::TTimeStamp &timestamp) = 0;
109 
110  /** @name Navigation event callbacks
111  * @{ */
112  /** Callback: Start of navigation command */
113  virtual void sendNavigationStartEvent();
114 
115  /** Callback: End of navigation command (reach of single goal, or final waypoint of waypoint list) */
116  virtual void sendNavigationEndEvent();
117 
118  /** Callback: Reached an intermediary waypoint in waypoint list navigation.
119  * reached_nSkipped will be `true` if the waypoint was physically reached; `false` if it was actually "skipped".
120  */
121  virtual void sendWaypointReachedEvent(int waypoint_index, bool reached_nSkipped);
122 
123  /** Callback: Heading towards a new intermediary/final waypoint in waypoint list navigation */
124  virtual void sendNewWaypointTargetEvent(int waypoint_index);
125 
126  /** Callback: Error asking sensory data from robot or sending motor commands. */
127  virtual void sendNavigationEndDueToErrorEvent();
128 
129  /** Callback: No progression made towards target for a predefined period of time. */
130  virtual void sendWaySeemsBlockedEvent();
131 
132  /** Callback: Apparent collision event (i.e. there is at least one obstacle point inside the robot shape) */
133  virtual void sendApparentCollisionEvent();
134 
135  /** Callback: Target seems to be blocked by an obstacle. If user
136  * sets `do_abort_nav` to `true` (default is `false`), after this
137  * callback returns, navigation will end with an ERROR state and
138  * another call to sendWaySeemsBlockedEvent() will be done. */
139  virtual void sendCannotGetCloserToBlockedTargetEvent(bool &do_abort_nav);
140 
141  /** @} */
142 
143  /** Returns the number of seconds ellapsed since the constructor of this class was invoked, or since
144  * the last call of resetNavigationTimer(). This will be normally wall-clock time, except in simulators where this method will return simulation time. */
145  virtual double getNavigationTime();
146  /** see getNavigationTime() */
147  virtual void resetNavigationTimer();
148 
149  private:
150  mrpt::utils::CTicTac m_navtime; //!< For getNavigationTime
151  };
152 
153  }
154 }
155 
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
Definition: datetime.h:30
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans. ...
Virtual base for velocity commands of different kinematic models of planar mobile robot...
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
This class implements a high-performance stopwatch.
Definition: CTicTac.h:24
GLsizei const GLchar ** string
Definition: glext.h:3919
mrpt::utils::CTicTac m_navtime
For getNavigationTime.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Lightweight 2D pose.
The pure virtual interface between a real or simulated robot and any CAbstractNavigator-derived class...



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020