26 target_frame_id(
"map"),
27 targetAllowedDistance(0.5),
28 targetIsRelative(false),
29 targetDesiredRelSpeed(.05),
30 targetIsIntermediaryWaypoint(false)
38 s +=
mrpt::format(
"target_coords = (%.03f,%.03f,%.03f deg)\n", target_coords.x, target_coords.y, target_coords.phi);
39 s +=
mrpt::format(
"target_frame_id = \"%s\"\n", target_frame_id.c_str());
40 s +=
mrpt::format(
"targetAllowedDistance = %.03f\n", targetAllowedDistance);
41 s +=
mrpt::format(
"targetIsRelative = %s\n", targetIsRelative ?
"YES" :
"NO");
42 s +=
mrpt::format(
"targetIsIntermediaryWaypoint = %s\n", targetIsIntermediaryWaypoint ?
"YES" :
"NO");
43 s +=
mrpt::format(
"targetDesiredRelSpeed = %.02f\n", targetDesiredRelSpeed);
62 s+=
"navparams. Single target:\n";
63 s+= target.getAsText();
70 return (rhs !=
nullptr) && (this->target == rhs->target);
87 mrpt::utils::COutputLogger(
"MRPT_navigator"),
105 this->setVerbosityLevel(mrpt::utils::LVL_DEBUG);
180 "CAbstractNavigator",
"enable_time_profiler",
217 MRPT_LOG_INFO(
"[CAbstractNavigator::navigationStep()] Navigation stopped.");
238 MRPT_LOG_ERROR(
"[CAbstractNavigator::navigationStep()] Stoping Navigation due to a NAV_ERROR state!");
259 if (ev.event_noargs !=
nullptr) {
260 (
m_robot.*(ev.event_noargs))();
262 else if (ev.event_wp_reached) {
265 else if (ev.event_new_wp) {
268 else if (ev.event_cannot_get_closer_target) {
274 MRPT_LOG_WARN(
"sendCannotGetCloserToBlockedTargetEvent() told me to abort navigation.");
320 ASSERT_(
params->target.targetDesiredRelSpeed >= .0 &&
params->target.targetDesiredRelSpeed <= 1.0);
360 const double MIN_TIME_BETWEEN_POSE_UPDATES = 20e-3;
364 if (last_call_age < MIN_TIME_BETWEEN_POSE_UPDATES)
366 MRPT_LOG_THROTTLE_DEBUG_FMT(5.0,
"updateCurrentPoseAndSpeeds: ignoring call, since last call was only %f ms ago.", last_call_age*1e3);
383 MRPT_LOG_ERROR(
"ERROR calling m_robot.getCurrentPoseAndSpeeds, stopping robot and finishing navigation");
384 throw std::runtime_error(
"ERROR calling m_robot.getCurrentPoseAndSpeeds, stopping robot and finishing navigation");
394 if (changed_frame_id)
433 dist_to_target_for_sending_event(0),
434 alarm_seems_not_approaching_target_timeout(30),
435 dist_check_target_is_blocked(0.6),
436 hysteresis_check_target_is_blocked(3)
448 MRPT_SAVE_CONFIG_VAR_COMMENT(dist_to_target_for_sending_event,
"Default value=0, means use the `targetAllowedDistance` passed by the user in the navigation request.");
450 MRPT_SAVE_CONFIG_VAR_COMMENT(dist_check_target_is_blocked,
"When closer than this distance, check if the target is blocked to abort navigation with an error. [Default=0.6 m]");
451 MRPT_SAVE_CONFIG_VAR_COMMENT(hysteresis_check_target_is_blocked,
"How many steps should the condition for dist_check_target_is_blocked be fulfilled to raise an event");
456 return typeid(
a) ==
typeid(
b) &&
a.isEqual(
b);
461 return (targetDist < m_navigationParams->target.targetAllowedDistance);
479 MRPT_LOG_INFO(
"[CAbstractNavigator::navigationStep()] Starting Navigation. Watchdog initiated...\n");
523 MRPT_LOG_DEBUG(
"[CAbstractNavigator::performNavigationStepNavigating] Enqueuing NavigationEndEvent (reason: targetDist<dist_to_target_for_sending_event).");
541 MRPT_LOG_DEBUG(
"[CAbstractNavigator::performNavigationStepNavigating] Enqueuing NavigationEndEvent (reason: checkHasReachedTarget()=true).");
559 MRPT_LOG_WARN(
"Timeout approaching the target. Aborting navigation.");
583 MRPT_LOG_THROTTLE_WARN(5.0,
"Target seems to be blocked by obstacles. Invoking sendCannotGetCloserToBlockedTargetEvent().");
600 if (call_virtual_nav_method) {
604 catch (std::exception &e)
625 MRPT_LOG_ERROR(
"[CAbstractNavigator::navigationStep] Untyped exception!");
638 event_noargs(nullptr),
639 event_wp_reached(false),
641 event_cannot_get_closer_target(false)
double m_badNavAlarm_minDistTarget
For sending an alarm (error event) when it seems that we are not approaching toward the target in a w...
virtual bool stop(bool isEmergencyStop=true)=0
Stop the robot right now.
TRobotPoseVel m_curPoseVel
Current robot pose (updated in CAbstractNavigator::navigationStep() )
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.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
virtual void loadConfigFile(const mrpt::utils::CConfigFileBase &c)
Loads all params from a file.
void rotate(const double ang)
Transform the (vx,vy) components for a counterclockwise rotation of ang radians.
bool event_cannot_get_closer_target
virtual void saveConfigFile(mrpt::utils::CConfigFileBase &c) const
Saves all current options to a config file.
virtual bool stopWatchdog()
Stop the watchdog timer.
mrpt::poses::FrameTransformer< 2 > * m_frame_tf
Optional, user-provided frame transformer.
#define MRPT_LOG_THROTTLE_DEBUG_FMT(_PERIOD_SECONDS, _FMT_STRING,...)
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
TNavigationParams * m_navigationParams
Current navigation parameters.
void setFrameTF(mrpt::poses::FrameTransformer< 2 > *frame_tf)
Sets a user-provided frame transformer object; used only if providing targets in a frame ID different...
double distance(const TPoint2D &point) const
Distance to point.
Base for all high-level navigation commands.
float targetAllowedDistance
(Default=0.5 meters) Allowed distance to target in order to end the navigation.
#define MRPT_LOAD_CONFIG_VAR_CS(variableName, variableType)
Shortcut for MRPT_LOAD_CONFIG_VAR() for config file object named c and section string named s ...
virtual void sendNavigationEndEvent()
Callback: End of navigation command (reach of single goal, or final waypoint of waypoint list) ...
virtual void updateCurrentPoseAndSpeeds()
Call to the robot getCurrentPoseAndSpeeds() and updates members m_curPoseVel accordingly.
functor_event_void_t event_noargs
event w/o arguments
bool targetIsRelative
(Default=false) Whether the target coordinates are in global coordinates (false) or are relative to t...
#define MRPT_LOG_ERROR_FMT(_FMT_STRING,...)
virtual double getNavigationTime()
Returns the number of seconds ellapsed since the constructor of this class was invoked, or since the last call of resetNavigationTimer().
double dist_check_target_is_blocked
(Default value=0.6) When closer than this distance, check if the target is blocked to abort navigatio...
void setInterpolationMethod(TInterpolatorMethod method)
Change the method used to interpolate the robot path. The default method at construction is "imSpline...
virtual void navigationStep()
This method must be called periodically in order to effectively run the navigation.
std::string pose_frame_id
map frame ID for pose
mrpt::utils::CTimeLogger m_timlog_delays
Time logger to collect delay-related stats.
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)
Default: forward call to m_robot.changeSpeed(). Can be overriden.
void enable(bool enabled=true)
virtual bool changeSpeedsNOP()
Default: forward call to m_robot.changeSpeedsNOP(). Can be overriden.
This class allows loading and storing values and vectors of different types from a configuration text...
TState m_navigationState
Current internal state of navigator:
Virtual base for velocity commands of different kinematic models of planar mobile robot...
This class implements a config file-like interface over a memory-stored string list.
virtual void performNavigationStep()=0
To be implemented in derived classes.
void getContent(std::string &str) const
Return the current contents of the virtual "config file".
bool NAV_IMPEXP operator==(const CAbstractNavigator::TNavigationParamsBase &, const CAbstractNavigator::TNavigationParamsBase &)
The struct for configuring navigation requests.
CAbstractNavigator(CRobot2NavInterface &robot_interface_impl)
ctor
virtual void sendCannotGetCloserToBlockedTargetEvent(bool &do_abort_nav)
Callback: Target seems to be blocked by an obstacle.
TState
The different states for the navigation system.
2D segment, consisting of two points.
void insert(mrpt::system::TTimeStamp t, const pose_t &p)
Inserts a new pose in the sequence.
double dist_to_target_for_sending_event
Default value=0, means use the "targetAllowedDistance" passed by the user in the navigation request...
#define MRPT_SAVE_CONFIG_VAR_COMMENT(variableName, __comment)
double targetDesiredRelSpeed
(Default=.05) Desired relative speed (wrt maximum speed), in range [0,1], of the vehicle at target...
virtual void onNavigateCommandReceived()
Called after each call to CAbstractNavigator::navigate()
virtual void sendNavigationStartEvent()
Callback: Start of navigation command.
#define MRPT_LOG_WARN(_STRING)
bool m_rethrow_exceptions
virtual void sendNavigationEndDueToErrorEvent()
Callback: Error asking sensory data from robot or sending motor commands.
std::string target_frame_id
(Default="map") Frame ID in which target is given. Optional, use only for submapping applications...
#define MRPT_LOG_INFO(_STRING)
virtual void resetNavError()
Resets a NAV_ERROR state back to IDLE
#define MRPT_LOG_THROTTLE_WARN(_PERIOD_SECONDS, _STRING)
mrpt::system::TTimeStamp timestamp
void internal_onStartNewNavigation()
Called before starting a new navigation.
Individual target info in CAbstractNavigator::TNavigationParamsBase and derived classes.
reverse_iterator rbegin()
virtual ~CAbstractNavigator()
dtor
#define MRPT_LOG_DEBUG(_STRING)
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
virtual void onStartNewNavigation()=0
Called whenever a new navigation has been started.
GLsizei const GLchar ** string
virtual void sendWaySeemsBlockedEvent()
Callback: No progression made towards target for a predefined period of time.
virtual void resume()
Continues with suspended navigation.
mrpt::math::TPose2D target_coords
Coordinates of desired target location. Heading may be ignored by some reactive implementations.
TState m_lastNavigationState
Last internal state of navigator:
virtual std::string getAsText() const MRPT_OVERRIDE
Gets navigation params as a human-readable format.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
virtual void sendWaypointReachedEvent(int waypoint_index, bool reached_nSkipped)
Callback: Reached an intermediary waypoint in waypoint list navigation.
double alarm_seems_not_approaching_target_timeout
navigator timeout (seconds) [Default=30 sec]
std::list< TPendingEvent > m_pending_events
Events generated during navigationStep(), enqueued to be called at the end of the method execution to...
void dispatchPendingNavEvents()
const double PREVIOUS_POSES_MAX_AGE
virtual bool isEqual(const TNavigationParamsBase &o) const MRPT_OVERRIDE
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
virtual void performNavigationStepNavigating(bool call_virtual_nav_method=true)
Factorization of the part inside navigationStep(), for the case of state being NAVIGATING.
void delete_safe(T *&ptr)
Calls "delete" to free an object only if the pointer is not NULL, then set the pointer to NULL...
virtual bool getCurrentPoseAndSpeeds(mrpt::math::TPose2D &curPose, mrpt::math::TTwist2D &curVelGlobal, mrpt::system::TTimeStamp ×tamp, 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...
std::string getAsText() const
Gets navigation params as a human-readable format.
A safe way to call enter() and leave() of a mrpt::utils::CTimeLogger upon construction and destructio...
void clear()
Clears the current sequence of poses.
virtual void doEmergencyStop(const std::string &msg)
Stops the robot and set navigation state to error.
virtual void loadFromConfigFile(const mrpt::utils::CConfigFileBase &c, const std::string &s) MRPT_OVERRIDE
This method load the options from a ".ini"-like file or memory-stored string list.
virtual void processNavigateCommand(const TNavigationParams *params)
Does the job of navigate(), except the call to onNavigateCommandReceived()
mrpt::utils::CTimeLogger m_navProfiler
Publicly available time profiling object.
TAbstractNavigatorParams params_abstract_navigator
virtual void saveToConfigFile(mrpt::utils::CConfigFileBase &c, const std::string &s) const MRPT_OVERRIDE
This method saves the options to a ".ini"-like file or memory-stored string list. ...
mrpt::math::TTwist2D velLocal
TAbstractNavigatorParams()
int m_counter_check_target_is_blocked
CRobot2NavInterface & m_robot
The navigator-robot interface.
virtual bool checkCollisionWithLatestObstacles(const mrpt::math::TPose2D &relative_robot_pose) const
Checks whether the robot shape, when placed at the given pose (relative to the current pose)...
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)=0
Sends a velocity command to the robot.
In this case, use getErrorReason()
TErrorReason m_navErrorReason
iterator erase(iterator element_to_erase)
virtual void cancel()
Cancel current navegation.
std::string error_msg
Human friendly description of the error.
TargetInfo target
Navigation target.
bool operator==(const TargetInfo &o) const
virtual void suspend()
Suspend current navegation.
double m_last_curPoseVelUpdate_robot_time
virtual TNavigationParams * clone() const
mrpt::math::TTwist2D velGlobal
#define MRPT_LOG_ERROR(_STRING)
double BASE_IMPEXP timeDifference(const mrpt::system::TTimeStamp t_first, const mrpt::system::TTimeStamp t_later)
Returns the time difference from t1 to t2 (positive if t2 is posterior to t1), in seconds...
int hysteresis_check_target_is_blocked
virtual bool checkHasReachedTarget(const double targetDist) const
Default implementation: check if target_dist is below the accepted distance.
std::string m_last_curPoseVelUpdate_pose_frame_id
mrpt::synch::CCriticalSectionRecursive m_nav_cs
mutex for all navigation methods
mrpt::poses::CPose2DInterpolator m_latestOdomPoses
Latest robot poses (updated in CAbstractNavigator::navigationStep() )
bool m_navigationEndEventSent
Will be false until the navigation end is sent, and it is reset with each new command.
The pure virtual interface between a real or simulated robot and any CAbstractNavigator-derived class...
mrpt::system::TTimeStamp m_badNavAlarm_lastMinDistTime
GLubyte GLubyte GLubyte a
GLenum const GLfloat * params
mrpt::poses::CPose2DInterpolator m_latestPoses
double phi
Orientation (rads)
mrpt::math::TPose2D rawOdometry
raw odometry (frame does not match to "pose", but is expected to be smoother in the short term)...
virtual bool stop(bool isEmergencyStop)
Default: forward call to m_robot.stop(). Can be overriden.
bool targetIsIntermediaryWaypoint
virtual void navigate(const TNavigationParams *params)
Navigation request to a single target location.