class mrpt::hwdrivers::C2DRangeFinderAbstract

This is the base, abstract class for “software drivers” interfaces to 2D scanners (laser range finders).

Physical devices may be interfaced through a serial port, a USB connection,etc. but this class abstract those details throught the “binding” of the specific scanner driver to a given I/O channel, which must be set by calling “hwdrivers::C2DRangeFinderAbstract::bindIO”. See also the derived classes.

There is support for “exclusion polygons”, areas where points, if detected, should be marked as invalid. Those areas are useful in cases where the scanner always detects part of the vehicle itself, and those points want to be ignored (see C2DRangeFinderAbstract::loadExclusionAreas).

See also:

comms::CSerialPort

#include <mrpt/hwdrivers/C2DRangeFinderAbstract.h>

class C2DRangeFinderAbstract:
    public mrpt::system::COutputLogger,
    public mrpt::hwdrivers::CGenericSensor
{
public:
    // enums

    enum TSensorState;

    //
fields

    bool logging_enable_console_output {true};
    bool logging_enable_keep_record {false};

    // construction

    C2DRangeFinderAbstract();

    //
methods

    void logStr(const VerbosityLevel level, std::string_view msg_str) const;
    void logFmt(const VerbosityLevel level, const char* fmt, ...) const;
    void void logCond(const VerbosityLevel level, bool cond, const std::string& msg_str) const;
    void setLoggerName(const std::string& name);
    std::string getLoggerName() const;
    void setVerbosityLevel(const VerbosityLevel level);
    void setVerbosityLevelForCallbacks(const VerbosityLevel level);
    void setMinLoggingLevel(const VerbosityLevel level);
    VerbosityLevel getMinLoggingLevel() const;
    VerbosityLevel getMinLoggingLevelForCallbacks() const;
    void getLogAsString(std::string& log_contents) const;
    std::string getLogAsString() const;
    void writeLogToFile(const std::optional<std::string> fname_in = std::nullopt) const;
    void dumpLogToConsole() const;
    std::string getLoggerLastMsg() const;
    void getLoggerLastMsg(std::string& msg_str) const;
    void loggerReset();
    bool logDeregisterCallback(output_logger_callback_t userFunc);
    void showPreview(bool enable = true);
    void bindIO(const std::shared_ptr<mrpt::io::CStream>& streamIO);
    void getObservation(bool& outThereIsObservation, mrpt::obs::CObservation2DRangeScan& outObservation, bool& hardwareError);
    virtual void doProcess();

    virtual void doProcessSimple(
        bool& outThereIsObservation,
        mrpt::obs::CObservation2DRangeScan& outObservation,
        bool& hardwareError
        ) = 0;

    virtual bool turnOn() = 0;
    virtual bool turnOff() = 0;
    double getEstimatedScanPeriod() const;
    TSensorState getState() const;
    void enableVerbose(bool enabled = true);
    void loadConfig(const mrpt::config::CConfigFileBase& configSource, const std::string& section);
    virtual void initialize();
    void getObservations(TListObservations& lstObjects);
    TListObservations getObservations();
    virtual void setPathForExternalImages(] const std::string& directory);
    void setExternalImageFormat(const std::string& ext);
    void setExternalImageJPEGQuality(const unsigned int quality);
    static std::array<mrpt::system::ConsoleForegroundColor, NUMBER_OF_VERBOSITY_LEVELS>& logging_levels_to_colors();
    static std::array<std::string, NUMBER_OF_VERBOSITY_LEVELS>& logging_levels_to_names();
    static void registerClass(const TSensorClassId* pNewClass);
    static CGenericSensor* createSensor(const std::string& className);
    static Ptr createSensorPtr(const std::string& className);
};

// direct descendants

class CHokuyoURG;
class CLMS100Eth;
class CRoboPeakLidar;
class CSickLaserSerial;
class CSickLaserUSB;
class CSICKTim561Eth;

Inherited Members

public:
    // structs

    struct TMsg;

    //
methods

    CGenericSensor& operator = (const CGenericSensor&);
    virtual void doProcess() = 0;

Fields

bool logging_enable_console_output {true}

[Default=true] Set it to false in case you don’t want the logged messages to be dumped to the output automatically.

bool logging_enable_keep_record {false}

[Default=false] Enables storing all messages into an internal list.

See also:

writeLogToFile, getLogAsString

Construction

C2DRangeFinderAbstract()

Default constructor.

Methods

void logStr(const VerbosityLevel level, std::string_view msg_str) const

Main method to add the specified message string to the logger.

See also:

logCond, logFmt

void logFmt(const VerbosityLevel level, const char* fmt, ...) const

Alternative logging method, which mimics the printf behavior.

Handy for not having to first use mrpt::format to pass a std::string message to logStr

// instead of:
logStr(mrpt::format("Today is the %d of %s, %d", 15, "July", 2016));

// one can use:
logFmt("Today is the %d of %s, %d", 15, "July", 2016);

See also:

logStr, logCond

void void logCond(const VerbosityLevel level, bool cond, const std::string& msg_str) const

Log the given message only if the condition is satisfied.

See also:

log, logFmt

void setLoggerName(const std::string& name)

Set the name of the COutputLogger instance.

See also:

getLoggerName

std::string getLoggerName() const

Return the name of the COutputLogger instance.

See also:

setLoggerName

void setVerbosityLevel(const VerbosityLevel level)

Set the minimum logging level for which the incoming logs are going to be taken into account.

String messages with specified VerbosityLevel smaller than the min, will not be:

  • printed out to the terminal,

  • stored in the internal record,

  • sent out to user-provided callbacks.

Since MRPT 2.5.7, the minimum verbosity level for user callbacks can be independently changed afterwards via setVerbosityLevelForCallbacks()

See also:

setVerbosityLevelForCallbacks(), setVerbosityLevel()

void setVerbosityLevelForCallbacks(const VerbosityLevel level)

Overrides the minimum verbosity level for user callbacks.

(New in MRPT 2.5.7)

See also:

logRegisterCallback()

void setMinLoggingLevel(const VerbosityLevel level)

alias of setVerbosityLevel()

VerbosityLevel getMinLoggingLevel() const

See also:

setMinLoggingLevel

VerbosityLevel getMinLoggingLevelForCallbacks() const

See also:

setVerbosityLevelForCallbacks

void getLogAsString(std::string& log_contents) const

Fill the provided string with the contents of the logger’s history in std::string representation.

std::string getLogAsString() const

Get the history of COutputLogger instance in a string representation.

void writeLogToFile(const std::optional<std::string> fname_in = std::nullopt) const

Write the contents of the COutputLogger instance to an external file.

Upon call to this method, COutputLogger dumps the contents of all the logged commands so far to the specified external file. By default the filename is set to ${LOGGERNAME}.log except if the fname parameter is provided

See also:

dumpToConsole, getAsString

void dumpLogToConsole() const

Dump the current contents of the COutputLogger instance in the terminal window.

See also:

writeToFile

std::string getLoggerLastMsg() const

Return the last Tmsg instance registered in the logger history.

void getLoggerLastMsg(std::string& msg_str) const

Fill inputtted string with the contents of the last message in history.

void loggerReset()

Reset the contents of the logger instance.

Called upon construction.

bool logDeregisterCallback(output_logger_callback_t userFunc)

Returns:

true if an entry was found and deleted.

void showPreview(bool enable = true)

Enables GUI visualization in real-time.

void bindIO(const std::shared_ptr<mrpt::io::CStream>& streamIO)

Binds the object to a given I/O channel.

The stream object must not be deleted before the destruction of this class.

See also:

comms::CSerialPort

void getObservation(
    bool& outThereIsObservation,
    mrpt::obs::CObservation2DRangeScan& outObservation,
    bool& hardwareError
    )

Get the last observation from the sensor, if available, and unmarks it as being “the last one” (thus a new scan must arrive or subsequent calls will find no new observations).

virtual void doProcess()

Main method for a CGenericSensor.

virtual void doProcessSimple(
    bool& outThereIsObservation,
    mrpt::obs::CObservation2DRangeScan& outObservation,
    bool& hardwareError
    ) = 0

Specific laser scanner “software drivers” must process here new data from the I/O stream, and, if a whole scan has arrived, return it.

This method MUST BE CALLED in a timely fashion by the user to allow the proccessing of incoming data. It can be run in a different thread safely.

virtual bool turnOn() = 0

Enables the scanning mode (which may depend on the specific laser device); this must be called before asking for observations to assure that the protocol has been initializated.

Returns:

If everything works “true”, or “false” if there is any error.

virtual bool turnOff() = 0

Disables the scanning mode (this can be used to turn the device in low energy mode, if available)

Returns:

If everything works “true”, or “false” if there is any error.

double getEstimatedScanPeriod() const

Returns the empirical, filtered estimation for the period at which whole scans are being returned from calls to doProcessSimple()

: Units: seconds

TSensorState getState() const

The current state of the sensor.

void enableVerbose(bool enabled = true)

Enable or disable extra debug info dumped to std::cout during sensor operation.

Default: disabled unless the environment variable “MRPT_HWDRIVERS_VERBOSE” is set to “1” during object creation.

void loadConfig(const mrpt::config::CConfigFileBase& configSource, const std::string& section)

Loads the generic settings common to any sensor (See CGenericSensor), then call to “loadConfig_sensorSpecific”.

Parameters:

This

method throws an exception with a descriptive message if some critical parameter is missing or has an invalid value.

virtual void initialize()

This method can or cannot be implemented in the derived class, depending on the need for it.

Parameters:

This

method must throw an exception with a descriptive message if some critical error is found.

void getObservations(TListObservations& lstObjects)

Returns a list of enqueued objects, emptying it (thread-safe).

TListObservations getObservations()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

virtual void setPathForExternalImages(] const std::string& directory)

Set the path where to save off-rawlog image files (will be ignored in those sensors where this is not applicable).

An empty string (the default value at construction) means to save images embedded in the rawlog, instead of on separate files.

Parameters:

std::exception

If the directory doesn’t exists and cannot be created.

void setExternalImageFormat(const std::string& ext)

Set the extension (“jpg”,”gif”,”png”,…) that determines the format of images saved externally.

Default: “png”.

See also:

setPathForExternalImages, setExternalImageJPEGQuality

void setExternalImageJPEGQuality(const unsigned int quality)

The quality of JPEG compression, when external images is enabled and the format is “jpg”.

See also:

setExternalImageFormat

static std::array<mrpt::system::ConsoleForegroundColor, NUMBER_OF_VERBOSITY_LEVELS>& logging_levels_to_colors()

Map from VerbosityLevels to their corresponding mrpt::system::TConsoleColor.

Handy for coloring the input based on the verbosity of the message

static std::array<std::string, NUMBER_OF_VERBOSITY_LEVELS>& logging_levels_to_names()

Map from VerbosityLevels to their corresponding names.

Handy for printing the current message VerbosityLevel along with the actual content

static void registerClass(const TSensorClassId* pNewClass)

Register a class into the internal list of “CGenericSensor” descendents.

Used internally in the macros DEFINE_GENERIC_SENSOR, etc…

Can be used as “CGenericSensor::registerClass( SENSOR_CLASS_ID(CMySensor) );” if building custom sensors outside mrpt libraries in user code.

static CGenericSensor* createSensor(const std::string& className)

Creates a sensor by a name of the class.

Typically the user may want to create a smart pointer around the returned pointer, whis is made with:

  CGenericSensor::Ptr sensor = CGenericSensor::Ptr(
CGenericSensor::createSensor("XXX") );

Returns:

A pointer to a new class, or nullptr if class name is unknown.

static Ptr createSensorPtr(const std::string& className)

Just like createSensor, but returning a smart pointer to the newly created sensor object.