Go to the documentation of this file.
25 : target_coords(0, 0, 0),
26 target_frame_id(
"map"),
27 targetAllowedDistance(0.5),
28 targetIsRelative(false),
29 targetDesiredRelSpeed(.05),
30 targetIsIntermediaryWaypoint(false)
39 "target_coords = (%.03f,%.03f,%.03f deg)\n", target_coords.x,
40 target_coords.y, target_coords.phi);
41 s +=
mrpt::format(
"target_frame_id = \"%s\"\n", target_frame_id.c_str());
42 s +=
mrpt::format(
"targetAllowedDistance = %.03f\n", targetAllowedDistance);
44 "targetIsRelative = %s\n", targetIsRelative ?
"YES" :
"NO");
46 "targetIsIntermediaryWaypoint = %s\n",
47 targetIsIntermediaryWaypoint ?
"YES" :
"NO");
48 s +=
mrpt::format(
"targetDesiredRelSpeed = %.02f\n", targetDesiredRelSpeed);
67 s +=
"navparams. Single target:\n";
68 s += target.getAsText();
76 return (rhs !=
nullptr) && (this->target == rhs->target);
115 std::lock_guard<std::recursive_mutex> csl(
m_nav_cs);
124 std::lock_guard<std::recursive_mutex> csl(
m_nav_cs);
133 std::lock_guard<std::recursive_mutex> csl(
m_nav_cs);
147 std::lock_guard<std::recursive_mutex> csl(
m_nav_cs);
184 std::lock_guard<std::recursive_mutex> csl(
m_nav_cs);
199 "[CAbstractNavigator::navigationStep()] Navigation "
227 "[CAbstractNavigator::navigationStep()] Stopping "
228 "Navigation due to a NAV_ERROR state!");
275 std::lock_guard<std::recursive_mutex> csl(
m_nav_cs);
284 std::lock_guard<std::recursive_mutex> csl(
m_nav_cs);
288 params->target.targetDesiredRelSpeed >= .0 &&
289 params->target.targetDesiredRelSpeed <= 1.0);
327 const double robot_time_secs =
331 const double MIN_TIME_BETWEEN_POSE_UPDATES = 20e-3;
334 const double last_call_age =
336 if (last_call_age < MIN_TIME_BETWEEN_POSE_UPDATES)
340 "updateCurrentPoseAndSpeeds: ignoring call, since last call "
341 "was only %f ms ago.",
342 last_call_age * 1e3);
366 "ERROR calling m_robot.getCurrentPoseAndSpeeds, stopping robot "
367 "and finishing navigation");
368 throw std::runtime_error(
369 "ERROR calling m_robot.getCurrentPoseAndSpeeds, stopping robot "
370 "and finishing navigation");
377 const bool changed_frame_id =
381 if (changed_frame_id)
426 : dist_to_target_for_sending_event(0),
427 alarm_seems_not_approaching_target_timeout(30),
428 dist_check_target_is_blocked(0.6),
429 hysteresis_check_target_is_blocked(3)
444 dist_to_target_for_sending_event,
445 "Default value=0, means use the `targetAllowedDistance` passed by the "
446 "user in the navigation request.");
448 alarm_seems_not_approaching_target_timeout,
449 "navigator timeout (seconds) [Default=30 sec]");
451 dist_check_target_is_blocked,
452 "When closer than this distance, check if the target is blocked to "
453 "abort navigation with an error. [Default=0.6 m]");
455 dist_to_target_for_sending_event,
456 "Default value=0, means use the `targetAllowedDistance` passed by the"
457 " user in the navigation request.");
459 alarm_seems_not_approaching_target_timeout,
460 "navigator timeout (seconds) [Default=30 sec]");
462 dist_check_target_is_blocked,
463 "When closer than this distance, check if the target is blocked to "
464 "abort navigation with an error. [Default=0.6 m]");
466 hysteresis_check_target_is_blocked,
467 "How many steps should the condition for dist_check_target_is_blocked "
468 "be fulfilled to raise an event");
475 return typeid(
a) ==
typeid(
b) &&
a.isEqual(
b);
481 return (targetDist < m_navigationParams->target.targetAllowedDistance);
495 bool call_virtual_nav_method)
503 "[CAbstractNavigator::navigationStep()] Starting Navigation. "
504 "Watchdog initiated...\n");
507 "[CAbstractNavigator::navigationStep()] Navigation "
540 const double targetDist = seg_robot_mov.
distance(
561 "Navigation target (%.03f,%.03f) was reached\n",
593 .alarm_seems_not_approaching_target_timeout)
596 "Timeout approaching the target. Aborting navigation.");
617 const bool send_event =
626 "Target seems to be blocked by obstacles. Invoking"
627 " sendCannotGetCloserToBlockedTargetEvent().");
631 sendCannotGetCloserToBlockedTargetEvent,
645 if (call_virtual_nav_method)
650 catch (std::exception& e)
653 "[CAbstractNavigator::navigationStep] Exception:\n %s", e.what());
658 "[CAbstractNavigator::navigationStep] Untyped exception!");
TState m_navigationState
Current internal state of navigator:
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)
Default: forward call to m_robot.changeSpeed().
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)=0
Sends a velocity command to the robot.
double 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.
void rotate(const double ang)
Transform the (vx,vy) components for a counterclockwise rotation of ang radians.
virtual void onNavigateCommandReceived()
Called after each call to CAbstractNavigator::navigate()
mrpt::system::TTimeStamp timestamp
virtual void sendNavigationEndEvent()
Callback: End of navigation command (reach of single goal, or final waypoint of waypoint list)
virtual void performNavigationStep()=0
To be implemented in derived classes.
double dist_to_target_for_sending_event
Default value=0, means use the "targetAllowedDistance" passed by the user in the navigation request.
Individual target info in CAbstractNavigator::TNavigationParamsBase and derived classes.
#define MRPT_LOG_INFO(_STRING)
void dispatchPendingNavEvents()
#define MRPT_SAVE_CONFIG_VAR_COMMENT(variableName, __comment)
virtual bool checkHasReachedTarget(const double targetDist) const
Default implementation: check if target_dist is below the accepted distance.
TState
The different states for the navigation system.
void setVerbosityLevel(const VerbosityLevel level)
alias of setMinLoggingLevel()
double m_last_curPoseVelUpdate_robot_time
#define MRPT_LOG_DEBUG(_STRING)
Use: MRPT_LOG_DEBUG("message");
double m_badNavAlarm_minDistTarget
For sending an alarm (error event) when it seems that we are not approaching toward the target in a w...
double phi
Orientation (rads)
std::string pose_frame_id
map frame ID for pose
std::vector< std::function< void(void)> > m_pending_events
Events generated during navigationStep(), enqueued to be called at the end of the method execution to...
mrpt::math::TTwist2D velLocal
void internal_onStartNewNavigation()
Called before starting a new navigation.
virtual void navigationStep()
This method must be called periodically in order to effectively run the navigation.
double distance(const TPoint2D &point) const
Distance to point.
void setFrameTF(const std::weak_ptr< mrpt::poses::FrameTransformer< 2 >> &frame_tf)
Sets a user-provided frame transformer object; used only if providing targets in a frame ID different...
std::unique_ptr< TNavigationParams > m_navigationParams
Current navigation parameters.
virtual bool startWatchdog(float T_ms)
Start the watchdog timer of the robot platform, if any, for maximum expected delay between consecutiv...
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
void updateCurrentPoseAndSpeeds()
Call to the robot getCurrentPoseAndSpeeds() and updates members m_curPoseVel accordingly.
void processNavigateCommand(const TNavigationParams *params)
Does the job of navigate(), except the call to onNavigateCommandReceived()
virtual bool changeSpeedsNOP()
Just like changeSpeeds(), but will be called when the last velocity command is still the preferred so...
virtual double getNavigationTime()
Returns the number of seconds ellapsed since the constructor of this class was invoked,...
virtual void saveToConfigFile(mrpt::config::CConfigFileBase &c, const std::string &s) const override
This method saves the options to a ".ini"-like file or memory-stored string list.
float targetAllowedDistance
(Default=0.5 meters) Allowed distance to target in order to end the navigation.
#define MRPT_LOG_THROTTLE_WARN(_PERIOD_SECONDS, _STRING)
iterator erase(iterator element_to_erase)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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...
bool targetIsRelative
(Default=false) Whether the target coordinates are in global coordinates (false) or are relative to t...
#define ASSERT_(f)
Defines an assertion mechanism.
TAbstractNavigatorParams()
void setInterpolationMethod(TInterpolatorMethod method)
Change the method used to interpolate the robot path.
virtual ~CAbstractNavigator()
dtor
virtual bool isEqual(const TNavigationParamsBase &o) const override
reverse_iterator rbegin()
TAbstractNavigatorParams params_abstract_navigator
void insert(mrpt::system::TTimeStamp t, const pose_t &p)
Inserts a new pose in the sequence.
virtual void onStartNewNavigation()=0
Called whenever a new navigation has been started.
virtual void loadConfigFile(const mrpt::config::CConfigFileBase &c)
Loads all params from a file.
virtual bool stopWatchdog()
Stop the watchdog timer.
The struct for configuring navigation requests.
void logFmt(const VerbosityLevel level, const char *fmt,...) const MRPT_printf_format_check(3
Alternative logging method, which mimics the printf behavior.
bool operator==(const CAbstractNavigator::TNavigationParamsBase &, const CAbstractNavigator::TNavigationParamsBase &)
TState m_lastNavigationState
Last internal state of navigator:
virtual void performNavigationStepNavigating(bool call_virtual_nav_method=true)
Factorization of the part inside navigationStep(), for the case of state being NAVIGATING.
double targetDesiredRelSpeed
(Default=.05) Desired relative speed (wrt maximum speed), in range [0,1], of the vehicle at target.
std::string target_frame_id
(Default="map") Frame ID in which target is given.
#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
mrpt::math::TPose2D rawOdometry
raw odometry (frame does not match to "pose", but is expected to be smoother in the short term).
This class allows loading and storing values and vectors of different types from a configuration text...
void doEmergencyStop(const std::string &msg)
Stops the robot and set navigation state to error.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
virtual void sendWaySeemsBlockedEvent()
Callback: No progression made towards target for a predefined period of time.
#define MRPT_LOG_ERROR_FMT(_FMT_STRING,...)
#define MRPT_LOG_ERROR(_STRING)
mrpt::math::TPose2D target_coords
Coordinates of desired target location.
mrpt::poses::CPose2DInterpolator m_latestOdomPoses
CRobot2NavInterface & m_robot
The navigator-robot interface.
void clear()
Clears the current sequence of poses.
virtual std::string getAsText() const override
Gets navigation params as a human-readable format.
std::string getAsText() const
Gets navigation params as a human-readable format.
virtual bool stop(bool isEmergencyStop)
Default: forward call to m_robot.stop().
void getContent(std::string &str) const
Return the current contents of the virtual "config file".
2D segment, consisting of two points.
TRobotPoseVel m_curPoseVel
Current robot pose (updated in CAbstractNavigator::navigationStep() )
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.
#define MRPT_LOG_WARN(_STRING)
virtual void suspend()
Suspend current navegation.
A safe way to call enter() and leave() of a mrpt::system::CTimeLogger upon construction and destructi...
virtual void resetNavError()
Resets a NAV_ERROR state back to IDLE
virtual bool changeSpeedsNOP()
Default: forward call to m_robot.changeSpeedsNOP().
virtual bool stop(bool isEmergencyStop=true)=0
Stop the robot right now.
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
int hysteresis_check_target_is_blocked
(Default=3) How many steps should the condition for dist_check_target_is_blocked be fulfilled to rais...
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),...
std::weak_ptr< mrpt::poses::FrameTransformer< 2 > > m_frame_tf
Optional, user-provided frame transformer.
#define MRPT_LOG_THROTTLE_DEBUG_FMT(_PERIOD_SECONDS, _FMT_STRING,...)
Usage: MRPT_LOG_THROTTLE_DEBUG_FMT(5.0, "i=%u", i);
std::string m_last_curPoseVelUpdate_pose_frame_id
virtual void cancel()
Cancel current navegation.
virtual void sendNavigationStartEvent()
Callback: Start of navigation command.
CAbstractNavigator(CRobot2NavInterface &robot_interface_impl)
ctor
virtual void navigate(const TNavigationParams *params)
Navigation request to a single target location.
int m_counter_check_target_is_blocked
mrpt::system::CTimeLogger m_timlog_delays
Time logger to collect delay-related stats.
GLsizei const GLchar ** string
bool operator==(const TargetInfo &o) const
This class implements a config file-like interface over a memory-stored string list.
mrpt::math::TTwist2D velGlobal
virtual void sendNavigationEndDueToErrorEvent()
Callback: Error asking sensory data from robot or sending motor commands.
Virtual base for velocity commands of different kinematic models of planar mobile robot.
bool targetIsIntermediaryWaypoint
double dist_check_target_is_blocked
(Default value=0.6) When closer than this distance, check if the target is blocked to abort navigatio...
virtual void saveConfigFile(mrpt::config::CConfigFileBase &c) const
Saves all current options to a config file.
mrpt::poses::CPose2DInterpolator m_latestPoses
Latest robot poses (updated in CAbstractNavigator::navigationStep() )
virtual void loadFromConfigFile(const mrpt::config::CConfigFileBase &c, const std::string &s) override
This method load the options from a ".ini"-like file or memory-stored string list.
COutputLogger()
Default class constructor.
mrpt::system::TTimeStamp m_badNavAlarm_lastMinDistTime
Base for all high-level navigation commands.
GLenum const GLfloat * params
GLubyte GLubyte GLubyte a
std::recursive_mutex m_nav_cs
mutex for all navigation methods
virtual void resume()
Continues with suspended navigation.
const double PREVIOUS_POSES_MAX_AGE
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |