22 if (!multiple_targets.empty())
24 s +=
"multiple_targets:\n";
26 for (
const auto &e : multiple_targets) {
39 multiple_targets == o->multiple_targets;
44 m_was_aligning(false),
46 m_last_alignment_cmd(
mrpt::system::
now())
74 const size_t N = nav_request.
waypoints.size();
79 for (
size_t i=0;i<N;i++)
153 const double dist2target = robot_move_seg.
distance(wp.target);
156 bool consider_wp_reached =
false;
159 consider_wp_reached =
true;
166 const double ALIGN_WAIT_TIME = 1.5;
168 tim_since_last_align>ALIGN_WAIT_TIME
171 consider_wp_reached =
true;
184 "[CWaypointsNavigator::navigationStep] Trying to align to heading: %.02f deg. " 185 "Relative heading: %.02f deg. " 186 "With motion cmd: %s",
189 align_cmd ? align_cmd->asString().c_str() :
"nullptr (operation not supported by this robot)");
199 consider_wp_reached =
true;
209 if (consider_wp_reached)
213 " segment-to-target dist: " << dist2target <<
", allowed_dist: " << wp.allowed_distance
224 new_events.push_back(ev);
251 const int most_advanced_wp_at_begin = most_advanced_wp;
256 if (wps.
waypoints[idx].reached)
continue;
271 most_advanced_wp = idx;
280 if (most_advanced_wp>=0) {
282 for (
int k=most_advanced_wp_at_begin;k<most_advanced_wp;k++) {
293 new_events.push_back(ev);
337 const bool is_final_wp = ((wp_idx + 1) ==
int(wps.
waypoints.size()));
440 MRPT_SAVE_CONFIG_VAR_COMMENT(min_timesteps_confirm_skip_waypoints,
"Min timesteps a `future` waypoint must be seen as reachable to become the active one.");
441 MRPT_SAVE_CONFIG_VAR_DEGREES_COMMENT(
"waypoint_angle_tolerance", waypoint_angle_tolerance,
"Angular error tolerance for waypoints with an assigned heading [deg] (Default: 5 deg)");
442 MRPT_SAVE_CONFIG_VAR_COMMENT(multitarget_look_ahead,
">=0 number of waypoints to forward to the underlying navigation engine, to ease obstacles avoidance when a waypoint is blocked (Default=0 : none)");
446 max_distance_to_allow_skip_waypoint(-1.0),
447 min_timesteps_confirm_skip_waypoints(1),
448 waypoint_angle_tolerance(
mrpt::utils::
DEG2RAD(5.0) ),
449 multitarget_look_ahead(0)
464 wp = (!wps.waypoints.empty() &&
465 wps.waypoint_index_current_goal >= 0 &&
466 wps.waypoint_index_current_goal < (int)wps.waypoints.size()
469 &wps.waypoints[wps.waypoint_index_current_goal]
472 ret = (wp ==
nullptr && targetDist <= m_navigationParams->target.targetAllowedDistance) ||
480 "with targetDist=" << targetDist <<
" return=" << ret <<
" waypoint: " <<
482 "wps.timestamp_nav_started=" <<
TRobotPoseVel m_curPoseVel
Current robot pose (updated in CAbstractNavigator::navigationStep() )
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.
bool m_was_aligning
Whether the last timestep was "is_aligning" in a waypoint with heading.
TWaypointStatusSequence m_waypoint_nav_status
The latest waypoints navigation command and the up-to-date control status.
virtual bool isEqual(const CAbstractNavigator::TNavigationParamsBase &o) const MRPT_OVERRIDE
std::vector< mrpt::nav::CAbstractNavigator::TargetInfo > multiple_targets
If not empty, this will prevail over the base class single goal target.
virtual void saveConfigFile(mrpt::utils::CConfigFileBase &c) const
Saves all current options to a config file.
std::string getAsText() const
Gets navigation params as a human-readable format.
double waypoint_angle_tolerance
[rad] Angular error tolerance for waypoints with an assigned heading (Default: 5 deg) ...
static const double INVALID_NUM
The default value of fields (used to detect non-set values)
int event_wp_reached_index
TNavigationParams * m_navigationParams
Current navigation parameters.
std::vector< TWaypoint > waypoints
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.
T angDistance(T from, T to)
Computes the shortest angular increment (or distance) between two planar orientations, such that it is constrained to [-pi,pi] and is correct for any combination of angles (e.g.
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
TWaypointsNavigatorParams params_waypoints_navigator
virtual void updateCurrentPoseAndSpeeds()
Call to the robot getCurrentPoseAndSpeeds() and updates members m_curPoseVel accordingly.
virtual bool checkHasReachedTarget(const double targetDist) const MRPT_OVERRIDE
Default implementation: check if target_dist is below the accepted distance.
TWaypointStatusSequence getWaypointNavStatus() const
Get a copy of the control structure which describes the progress status of the waypoint navigation...
bool targetIsRelative
(Default=false) Whether the target coordinates are in global coordinates (false) or are relative to t...
The struct for requesting navigation requests for a sequence of waypoints.
virtual void navigationStep()
This method must be called periodically in order to effectively run the navigation.
mrpt::utils::CTimeLogger m_timlog_delays
Time logger to collect delay-related stats.
bool isRelativePointReachable(const mrpt::math::TPoint2D &wp_local_wrt_robot) const
Returns true if, according to the information gathered at the last navigation step, there is a free path to the given point; false otherwise: if way is blocked or there is missing information, the point is out of range for the existing PTGs, etc.
virtual bool changeSpeeds(const mrpt::kinematics::CVehicleVelCmd &vel_cmd)
Default: forward call to m_robot.changeSpeed(). Can be overriden.
The struct for configuring navigation requests to CWaypointsNavigator and derived classes...
This class allows loading and storing values and vectors of different types from a configuration text...
TState m_navigationState
Current internal state of navigator:
double max_distance_to_allow_skip_waypoint
In meters. <0: unlimited.
bool reached
Whether this waypoint has been reached already (to within the allowed distance as per user specificat...
virtual void navigationStep() MRPT_OVERRIDE
This method must be called periodically in order to effectively run the navigation.
2D segment, consisting of two points.
#define MRPT_LOG_THROTTLE_INFO_FMT(_PERIOD_SECONDS, _FMT_STRING,...)
virtual mrpt::kinematics::CVehicleVelCmdPtr getAlignCmd(const double relative_heading_radians)
Gets a motion command to make the robot to align with a given relative heading, without translating...
double RAD2DEG(const double x)
Radians to degrees.
mrpt::math::TPose2D last_robot_pose
Robot pose at last time step (has INVALID_NUM fields upon initialization)
#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()
std::string target_frame_id
(Default="map") Frame ID in which target is given. Optional, use only for submapping applications...
virtual void cancel() MRPT_OVERRIDE
Cancel current navegation.
virtual void loadConfigFile(const mrpt::utils::CConfigFileBase &c) MRPT_OVERRIDE
Loads all params from a file.
The struct for querying the status of waypoints navigation.
mrpt::system::TTimeStamp m_last_alignment_cmd
Individual target info in CAbstractNavigator::TNavigationParamsBase and derived classes.
A waypoint with an execution status.
bool final_goal_reached
Whether the final waypoint has been reached successfuly.
mrpt::synch::CCriticalSectionRecursive m_nav_waypoints_cs
TPoint2D point2
Destiny point.
virtual void onNavigateCommandReceived() MRPT_OVERRIDE
Called after each call to CAbstractNavigator::navigate()
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
bool event_wp_reached_reached
GLsizei const GLchar ** string
mrpt::math::TPose2D target_coords
Coordinates of desired target location. Heading may be ignored by some reactive implementations.
#define INVALID_TIMESTAMP
Represents an invalid timestamp, where applicable.
virtual std::string getAsText() const MRPT_OVERRIDE
Gets navigation params as a human-readable format.
virtual ~CWaypointsNavigator()
dtor
TPoint2D point1
Origin point.
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.
double norm() const
Point norm.
std::list< TPendingEvent > m_pending_events
Events generated during navigationStep(), enqueued to be called at the end of the method execution to...
void dispatchPendingNavEvents()
#define MRPT_LOAD_CONFIG_VAR(variableName, variableType, configFileObject, sectionNameStr)
An useful macro for loading variables stored in a INI-like file under a key with the same name that t...
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.
TWaypointsNavigatorParams()
A safe way to call enter() and leave() of a mrpt::utils::CTimeLogger upon construction and destructio...
int min_timesteps_confirm_skip_waypoints
How many times shall a future waypoint be seen as reachable to skip to it (Default: 1) ...
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
virtual void navigateWaypoints(const TWaypointSequence &nav_request)
Waypoint navigation request.
virtual void processNavigateCommand(const TNavigationParams *params)
Does the job of navigate(), except the call to onNavigateCommandReceived()
#define MRPT_LOAD_CONFIG_VAR_DEGREES(variableName, configFileObject, sectionNameStr)
Loads a double variable, stored as radians but entered in the INI-file as degrees.
mrpt::utils::CTimeLogger m_navProfiler
Publicly available time profiling object.
virtual bool impl_waypoint_is_reachable(const mrpt::math::TPoint2D &wp_local_wrt_robot) const =0
Implements the way to waypoint is free function in children classes: true must be returned if...
T square(const T x)
Inline function for the square of a number.
mrpt::math::TPoint2D target
[Must be set by the user] Coordinates of desired target location (world/global coordinates).
CRobot2NavInterface & m_robot
The navigator-robot interface.
void inverseComposePoint(const double gx, const double gy, double &lx, double &ly) const
Computes the 2D point L such as .
#define MRPT_LOG_INFO_FMT(_FMT_STRING,...)
double target_heading
[Default=any heading] Optionally, set to the desired orientation [radians] of the robot at this waypo...
double allowed_distance
[Must be set by the user] How close should the robot get to this waypoint for it to be considered rea...
virtual void cancel()
Cancel current navegation.
TargetInfo target
Navigation target.
mrpt::system::TTimeStamp timestamp_nav_started
Timestamp of user navigation command.
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...
std::string BASE_IMPEXP dateTimeLocalToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (in local time): YEAR/MONTH/DAY,HH:MM:SS.MMM.
#define MRPT_SAVE_CONFIG_VAR_DEGREES_COMMENT(__entryName, __variable, __comment)
The pure virtual interface between a real or simulated robot and any CAbstractNavigator-derived class...
CWaypointsNavigator(CRobot2NavInterface &robot_interface_impl)
ctor
std::vector< TWaypointStatus > waypoints
Waypoints parameters and status (reached, skipped, etc.)
virtual void saveConfigFile(mrpt::utils::CConfigFileBase &c) const MRPT_OVERRIDE
Saves all current options to a config file.
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
#define ASSERTMSG_(f, __ERROR_MSG)
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. ...
int waypoint_index_current_goal
Index in waypoints of the waypoint the navigator is currently trying to reach.
This is the base class for any reactive/planned navigation system.
virtual void onStartNewNavigation() MRPT_OVERRIDE
Called whenever a new navigation has been started.
double phi
Orientation (rads)
virtual void waypoints_navigationStep()
The waypoints-specific part of navigationStep()
int multitarget_look_ahead
>=0 number of waypoints to forward to the underlying navigation engine, to ease obstacles avoidance w...
double speed_ratio
(Default=1.0) Desired robot speed at the target, as a ratio of the full robot speed.
virtual bool stop(bool isEmergencyStop)
Default: forward call to m_robot.stop(). Can be overriden.
bool targetIsIntermediaryWaypoint
std::string target_frame_id
(Default="map") Frame ID in which target is given. Optional, use only for submapping applications...