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



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020