class mrpt::hwdrivers::CPhidgetInterfaceKitProximitySensors

Overview

: An interface for the phidget Interface kit board (1018).

Adrien BARRAL - Robopec (aba@robopec.com).

An interface for the Phidgets Interface kit board (part number 1018) on which it could be plugged either an Sharp IR adaptater board (phidget’s part number : 1101),or a MaxBotix EZ-1 sonar (phidget’s part number : 1118). The configuration file describe what is plugged to this board, and the geometry of the sensors on the robots. See the example below.

[PhidgetInterfaceKitProximitySensors]
sensorLabel = FrontProximitySensors
process_rate = 100                      // Integer value in Hz (common to
all
sensors),
default value is 50Hz.
displayRecapitulativeInformations = true    // default value = false.
serialNumber = 12345                        // The interface kit serial number
(Integer
value),
default value is -1.
sensor1 = SHARP-30cm                        // sharp InfraRed sensor 30cm range
(string
value).
capital to convert raw data to range data (in meters).
pose1_x = 0                             // position on the robot (float
value
in
meters)
pose1_y = 0
pose1_z = 0.5
pose1_yaw = -45.0                       // Angles in degrees (float value).
pose1_pitch = 0
pose1_roll = 0
 //...
sensorn = EZ1                           // Maxbotix Ultrasound sonar
posen_x = 0
// ...

The maximum number of sensors on this board is 8. Sensor 1 is the first sensor. If you haven’t plugged any sensor on an entry of the board, you haven’t to specify anyithing about this sensor in the configuration file. The following table enumerate the different sensors supported by this class.

Part Number

Config file identifier

IR or US

MaxBotix EZ-1 Sonar Sensor

EZ1

US

GP2D12

SHARP-30cm

IR

GP2Y0A21

SHARP-80cm

IR

This isn’t an event based implementation of the phidget library. That means that when an instanciation of a CPhidgetInterfaceKitProximitySensors is done, the constructor will block during in the worst case 200ms, if the board isn’t found, an exception will be thrown. mrpt::obs::CObservation returned by this class is a CObservationRange. CObservationrange::minSensorDistance will be the minimum of the minimum of the sensor distances, e.g if you plug to the interface kit a GP2D12 (min range 4 cm) and a GP2Y0A21 (min range 8 cm), then CObservationrange::minSensorDistance = min(0.04,0.08) = 0.04. Respectively for the maximal range. {The Phidget library use udev. By default, udev require to be root to be launched, if you want to be able to run a program which use a phidget board without be root, you must modify files in /etc/udev/rules.d .}

#include <mrpt/hwdrivers/CPhidgetInterfaceKitProximitySensors.h>

class CPhidgetInterfaceKitProximitySensors:
    public mrpt::system::COutputLogger,
    public mrpt::hwdrivers::CGenericSensor
{
public:
    // construction

    CPhidgetInterfaceKitProximitySensors();

    // methods

    void getObservation(mrpt::obs::CObservationRange& outObservation);
    virtual void initialize();
    virtual void doProcess();
};

Inherited Members

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;

    // structs

    struct TMsg;

    // fields

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

    // 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;
    bool isLoggingLevelVisible(VerbosityLevel level) 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();
    void logRegisterCallback(output_logger_callback_t userFunc);
    bool logDeregisterCallback(output_logger_callback_t userFunc);
    COutputLogger& operator = (const COutputLogger&);
    COutputLogger& operator = (COutputLogger&&);
    static std::array<mrpt::system::ConsoleForegroundColor, NUMBER_OF_VERBOSITY_LEVELS>& logging_levels_to_colors();
    static const std::array<const char*, NUMBER_OF_VERBOSITY_LEVELS>& logging_levels_to_names();
    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);

Construction

CPhidgetInterfaceKitProximitySensors()

Constructor.

Parameters:

serialNumber

The board’s serial number. Set -1 to choose the first available board

Methods

void getObservation(mrpt::obs::CObservationRange& outObservation)

This method tries to get a set of range measurements from the IR sensors.

Parameters:

outThereIsObservation

Will be true if an observation was sucessfully received.

virtual void initialize()

Initialize the sensor according to the parameters previously read in the configuration file.

Parameters:

throw

an exception if the board could not be found.

throw

an exception if the process rate can’t be set on one of the board channel.

virtual void doProcess()

This method should be called periodically.

Period depend on the process_rate in the configuration file.