MRPT  2.0.4
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
mrpt::nav::CRobot2NavInterface::changeSpeeds
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)=0
Sends a velocity command to the robot.
mrpt::nav::CRobot2NavInterface::sendCannotGetCloserToBlockedTargetEvent
virtual void sendCannotGetCloserToBlockedTargetEvent()
Callback: Target seems to be blocked by an obstacle.
Definition: CRobot2NavInterface.cpp:110
mrpt::nav::CRobot2NavInterface::sendNavigationEndEvent
virtual void sendNavigationEndEvent()
Callback: End of navigation command (reach of single goal, or final waypoint of waypoint list)
Definition: CRobot2NavInterface.cpp:63
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:17
mrpt::nav::CRobot2NavInterface::startWatchdog
virtual bool startWatchdog(float T_ms)
Start the watchdog timer of the robot platform, if any, for maximum expected delay between consecutiv...
Definition: CRobot2NavInterface.cpp:37
mrpt::nav::CRobot2NavInterface::changeSpeedsNOP
virtual bool changeSpeedsNOP()
Just like changeSpeeds(), but will be called when the last velocity command is still the preferred so...
Definition: CRobot2NavInterface.cpp:21
mrpt::nav::CRobot2NavInterface::getNavigationTime
virtual double getNavigationTime()
Returns the number of seconds ellapsed since the constructor of this class was invoked,...
Definition: CRobot2NavInterface.cpp:119
TPose2D.h
mrpt::nav
Definition: CAbstractHolonomicReactiveMethod.h:20
mrpt::nav::CRobot2NavInterface::getEmergencyStopCmd
virtual mrpt::kinematics::CVehicleVelCmd::Ptr getEmergencyStopCmd()=0
Gets the emergency stop command for the current robot.
mrpt::nav::CRobot2NavInterface
The pure virtual interface between a real or simulated robot and any CAbstractNavigator-derived class...
Definition: CRobot2NavInterface.h:43
mrpt::nav::CRobot2NavInterface::sendApparentCollisionEvent
virtual void sendApparentCollisionEvent()
Callback: Apparent collision event (i.e.
Definition: CRobot2NavInterface.cpp:102
mrpt::nav::CRobot2NavInterface::getAlignCmd
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.
Definition: CRobot2NavInterface.cpp:30
mrpt::nav::CRobot2NavInterface::CRobot2NavInterface
CRobot2NavInterface()
Definition: CRobot2NavInterface.cpp:16
mrpt::nav::CRobot2NavInterface::stopWatchdog
virtual bool stopWatchdog()
Stop the watchdog timer.
Definition: CRobot2NavInterface.cpp:47
TTwist2D.h
mrpt::nav::CRobot2NavInterface::~CRobot2NavInterface
~CRobot2NavInterface() override
mrpt::nav::CRobot2NavInterface::getStopCmd
virtual mrpt::kinematics::CVehicleVelCmd::Ptr getStopCmd()=0
Gets the emergency stop command for the current robot.
COutputLogger.h
mrpt::nav::CRobot2NavInterface::sendWaySeemsBlockedEvent
virtual void sendWaySeemsBlockedEvent()
Callback: No progression made towards target for a predefined period of time.
Definition: CRobot2NavInterface.cpp:94
mrpt::math::TPose2D
Lightweight 2D pose.
Definition: TPose2D.h:22
mrpt::maps::CSimplePointsMap
A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.
Definition: CSimplePointsMap.h:30
mrpt::system::TTimeStamp
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
obs_frwds.h
mrpt::nav::CRobot2NavInterface::getCurrentPoseAndSpeeds
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.
mrpt::system::COutputLogger
Versatile class for consistent logging and management of output messages.
Definition: system/COutputLogger.h:117
mrpt::kinematics::CVehicleVelCmd::Ptr
std::shared_ptr< CVehicleVelCmd > Ptr
Definition: CVehicleVelCmd.h:22
mrpt::nav::CRobot2NavInterface::stop
virtual bool stop(bool isEmergencyStop=true)=0
Stop the robot right now.
mrpt::nav::CRobot2NavInterface::sendWaypointReachedEvent
virtual void sendWaypointReachedEvent(int waypoint_index, bool reached_nSkipped)
Callback: Reached an intermediary waypoint in waypoint list navigation.
Definition: CRobot2NavInterface.cpp:70
CTicTac.h
mrpt::nav::CRobot2NavInterface::senseObstacles
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::nav::CRobot2NavInterface::sendNavigationStartEvent
virtual void sendNavigationStartEvent()
Callback: Start of navigation command.
Definition: CRobot2NavInterface.cpp:56
mrpt::nav::CRobot2NavInterface::resetNavigationTimer
virtual void resetNavigationTimer()
see getNavigationTime()
Definition: CRobot2NavInterface.cpp:121
mrpt::nav::CRobot2NavInterface::sendNavigationEndDueToErrorEvent
virtual void sendNavigationEndDueToErrorEvent()
Callback: Error asking sensory data from robot or sending motor commands.
Definition: CRobot2NavInterface.cpp:86
mrpt::nav::CRobot2NavInterface::m_navtime
mrpt::system::CTicTac m_navtime
For getNavigationTime.
Definition: CRobot2NavInterface.h:196
mrpt::nav::CRobot2NavInterface::sendNewWaypointTargetEvent
virtual void sendNewWaypointTargetEvent(int waypoint_index)
Callback: Heading towards a new intermediary/final waypoint in waypoint list navigation.
Definition: CRobot2NavInterface.cpp:79
mrpt::kinematics::CVehicleVelCmd
Virtual base for velocity commands of different kinematic models of planar mobile robot.
Definition: CVehicleVelCmd.h:20
CVehicleVelCmd.h
datetime.h
mrpt::math::TTwist2D
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
Definition: TTwist2D.h:19



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 17:54:30 UTC 2020