class mrpt::nav::CAbstractNavigator

Overview

Base class for all reactive and planned navigation systems in MRPT.

Implements the core navigation state machine (IDLE, NAVIGATING, SUSPENDED, NAV_ERROR) and provides the standard control API. Derived classes implement the actual motion planning (e.g. CReactiveNavigationSystem for PTG-based reactive nav, CWaypointsNavigator for waypoint sequences).

A CRobot2NavInterface-derived object with user callbacks must be supplied at construction. Then navigationStep() must be called periodically.

This is the base class for any reactive/planned navigation system. See derived classes.

How to use:

  • A class derived from CRobot2NavInterface with callbacks must be defined by the user and provided to the constructor.

  • navigationStep() must be called periodically in order to effectively run the navigation. This method will internally call the callbacks to gather sensor data and robot positioning data.

It implements the following state machine (see CAbstractNavigator::getCurrentState()), taking into account the extensions described in CWaypointsNavigator digraph CAbstractNavigator_States {

IDLE; NAVIGATING; SUSPENDED; NAV_ERROR; IDLE -> NAVIGATING [ label=”CAbstractNavigator::navigate()”]; IDLE -> NAVIGATING [ label=”CWaypointsNavigator::navigateWaypoints()” ]; NAVIGATING -> IDLE [ label=”Final target reached” ]; NAVIGATING -> IDLE [ label=”CAbstractNavigator::cancel()” ]; NAVIGATING -> NAV_ERROR [ label=”Upon sensor errors, timeout,…” ]; NAVIGATING -> SUSPENDED [ label=”CAbstractNavigator::suspend()” ]; SUSPENDED -> NAVIGATING [ label=”CAbstractNavigator::resume()” ]; NAV_ERROR -> IDLE [ label=”CAbstractNavigator::resetNavError()” ];

}

See also:

CWaypointsNavigator, CReactiveNavigationSystem, CRobot2NavInterface, all children classes

#include <mrpt/nav/reactive/CAbstractNavigator.h>

class CAbstractNavigator: public mrpt::system::COutputLogger
{
public:
    // enums

    enum TErrorCode;
    enum TState;

    // structs

    struct TAbstractNavigatorParams;
    struct TErrorReason;
    struct TNavigationParams;
    struct TNavigationParamsBase;
    struct TRobotPoseVel;
    struct TargetInfo;

    // fields

    mrpt::system::CTimeLogger m_navProfiler {false, "mrpt::nav::CAbstractNavigator"};

    // construction

    CAbstractNavigator(CRobot2NavInterface& robot_interface_impl);

    // methods

    virtual void loadConfigFile(const mrpt::config::CConfigFileBase& c);
    virtual void saveConfigFile(mrpt::config::CConfigFileBase& c) const;
    virtual void initialize() = 0;
    virtual void navigationStep();
    virtual void navigate(const TNavigationParams* params);
    virtual void cancel();
    virtual void resume();
    virtual void suspend();
    virtual void resetNavError();
    TState getCurrentState() const;
    const TErrorReason& getErrorReason() const;
    void setFrameTF(const std::weak_ptr<mrpt::poses::FrameTransformer<2>>& frame_tf);
    std::weak_ptr<mrpt::poses::FrameTransformer<2>> getFrameTF() const;
    void enableRethrowNavExceptions(const bool enable);
    const mrpt::system::CTimeLogger& getDelaysTimeLogger() const;
};

// direct descendants

class CNavigatorManualSequence;
class CWaypointsNavigator;

Inherited Members

public:
    // structs

    struct TMsg;

    // methods

    COutputLogger& operator = (const COutputLogger&);
    COutputLogger& operator = (COutputLogger&&);

Fields

mrpt::system::CTimeLogger m_navProfiler {false, "mrpt::nav::CAbstractNavigator"}

Publicly available time profiling object.

Default: disabled

Construction

CAbstractNavigator(CRobot2NavInterface& robot_interface_impl)

ctor

Methods

virtual void loadConfigFile(const mrpt::config::CConfigFileBase& c)

Loads all navigator parameters from a config file.

Must be called before initialize(). Derived classes must call the parent implementation after loading their own parameters.

Parameters:

c

The configuration source to read from.

virtual void saveConfigFile(mrpt::config::CConfigFileBase& c) const

Saves all current navigator parameters to a config file.

Derived classes must call the parent implementation after saving their own parameters.

Parameters:

c

The configuration file to write to.

virtual void initialize() = 0

Initializes the navigator.

Must be called before any navigation command.

virtual void navigationStep()

Runs one navigation cycle.

Must be called periodically (e.g. at 10-20 Hz) to advance navigation logic.

virtual void navigate(const TNavigationParams* params)

Navigation request to a single target location.

It starts a new navigation. A pointer is used so the passed object can be polymorphic with derived types.

Parameters:

params

Pointer to structure with navigation info (its contents will be copied, so the original can be freely destroyed upon return if it was dynamically allocated.)

virtual void cancel()

Cancels the current navigation and returns to IDLE state.

virtual void resume()

Continues a previously suspended navigation.

See also:

suspend

virtual void suspend()

Suspends the current navigation (robot stops; state=SUSPENDED).

See also:

resume

virtual void resetNavError()

Resets a NAV_ERROR state back to IDLE so navigation can restart.

TState getCurrentState() const

Returns the current navigator state.

const TErrorReason& getErrorReason() const

In case of state=NAV_ERROR, this returns the reason for the error.

Error state is reset every time a new navigation starts with a call to navigate(), or when resetNavError() is called.

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 than the one in which robot odometry is given (both IDs default to "map").

std::weak_ptr<mrpt::poses::FrameTransformer<2>> getFrameTF() const

Get the current frame tf object (defaults to nullptr)

See also:

setFrameTF

void enableRethrowNavExceptions(const bool enable)

By default, error exceptions on navigationStep() will dump an error message to the output logger interface.

If rethrow is enabled (default=false), the error message will be reported as well, but exceptions will be re-thrown.

const mrpt::system::CTimeLogger& getDelaysTimeLogger() const

Gives access to a const-ref to the internal time logger used to estimate delays.

See also:

getTimeLogger() in derived classes