class mrpt::hwdrivers::CGenericSensor

Python API: mrpt.hwdrivers.CGenericSensor

Overview

A generic interface for a wide-variety of sensors designed to be used in the application RawLogGrabber.

Derived classes should be designed with the following execution flow in mind:

  • Object constructor

  • CGenericSensor::loadConfig : The following parameters are common to all sensors in rawlog-grabber (they are automatically loaded by rawlog-grabber) - see each class documentation for additional parameters:

    • “process_rate”: (Mandatory) The rate in Hertz (Hz) at which the sensor thread should invoke “doProcess”.

    • “max_queue_len”: (Optional) The maximum number of objects in the observations queue (default is 200). If overflow occurs, an error message will be issued at run-time.

    • “grab_decimation”: (Optional) Grab only 1 out of N observations captured by the sensor (default is 1, i.e. do not decimate).

  • CGenericSensor::initialize

  • CGenericSensor::doProcess

  • CGenericSensor::getObservations

Notice that there are helper methods for managing the internal list of objects (see CGenericSensor::appendObservation).

Class Factory: This is also a factory of derived classes, through the static method CGenericSensor::createSensor

For more details on RawLogGrabber refer to the wiki page: https://www.mrpt.org/Application:RawLogGrabber

#include <mrpt/hwdrivers/CGenericSensor.h>

class CGenericSensor
{
public:
    // typedefs

    typedef std::shared_ptr<CGenericSensor> Ptr;
    typedef std::multimap<mrpt::system::TTimeStamp, mrpt::serialization::CSerializable::Ptr> TListObservations;
    typedef std::pair<mrpt::system::TTimeStamp, mrpt::serialization::CSerializable::Ptr> TListObsPair;

    // enums

    enum TSensorState;

    // construction

    CGenericSensor();
    CGenericSensor(const CGenericSensor&);

    // methods

    virtual const mrpt::hwdrivers::TSensorClassId* GetRuntimeClass() const = 0;
    TSensorState getState() const;
    double getProcessRate() const;
    std::string getSensorLabel() const;
    void setSensorLabel(const std::string& sensorLabel);
    void enableVerbose(bool enabled = true);
    bool isVerboseEnabled() const;
    CGenericSensor& operator = (const CGenericSensor&);
    virtual void loadConfig(const mrpt::config::CConfigFileBase& configSource, const std::string& section);
    virtual void initialize();
    virtual void doProcess() = 0;
    virtual TListObservations getObservations();
    virtual void setPathForExternalImages(] const std::string& directory);
    virtual void setExternalImageFormat(const std::string& ext);
    virtual void setExternalImageJPEGQuality(const unsigned int quality);
    virtual unsigned int getExternalImageJPEGQuality() const;
    static void registerClass(const TSensorClassId* pNewClass);
    static CGenericSensor* createSensor(const std::string& className);
    static Ptr createSensorPtr(const std::string& className);
};

// direct descendants

class C2DRangeFinderAbstract;
class CCANBusReader;
class CCameraSensor;
class CEnoseModular;
class CGPSInterface;
class CGPS_NTRIP;
class CGillAnemometer;
class CGyroKVHDSP3000;
class CIMUXSens_MT4;
class CIbeoLuxETH;
class CImpinjRFID;
class CKinect;
class CNTRIPEmitter;
class CNationalInstrumentsDAQ;
class COpenNI2Sensor;
class COpenNI2_RGBD360;
class CPhidgetInterfaceKitProximitySensors;
class CRaePID;
class CTaoboticsIMU;
class CVelodyneScanner;
class CWirelessPower;

Construction

CGenericSensor()

Constructor.

Methods

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.

virtual 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.

virtual void doProcess() = 0

This method will be invoked at a minimum rate of “process_rate” (Hz)

Parameters:

This

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

virtual TListObservations getObservations()

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

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.

virtual 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

virtual 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 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.