class mrpt::hwdrivers::CHokuyoURG

This software driver implements the protocol SCIP-2.0 for interfacing HOKUYO URG/UTM/UXM/UST laser scanners (USB or Ethernet).

Refer to the example code HOKUYO_laser_test and to example rawlog-grabber config files

See also the application “rawlog-grabber” for a ready-to-use application to gather data from the scanner.

 PARAMETERS IN THE ".INI"-LIKE CONFIGURATION STRINGS:
-------------------------------------------------------
  [supplied_section_name]
   HOKUYO_motorSpeed_rpm=600
   #HOKUYO_HS_mode   = false    // Optional (un-comment line if used):
Set/unset the High-sensitivity mode (not on all models/firmwares!)

   # Uncomment serial port or IP address, depending on the Hokuyo model
(serial/USB vs. Ethernet):
   COM_port_WIN = COM3       // Serial port name in Windows
   COM_port_LIN = ttyS0      // Serial port name in GNU/Linux
   #IP_DIR  =   192.168.0.10 // Uncommented this and "PORT_DIR" if the
used HOKUYO is connected by Ethernet instead of USB
   #PORT_DIR = 10940         // Default value: 10940

   pose_x=0.21  // Laser range scaner 3D position in the robot (meters)
   pose_y=0
   pose_z=0.34
   pose_yaw=0   // Angles in degrees
   pose_pitch=0
   pose_roll=0

   #disable_firmware_timestamp = true   // Uncomment to use PC time instead
of laser time

   # Optional: reduced FOV:
   # reduced_fov  = 25 // Deg

   # Sets decimation of scans directly at the Hokuyo scanner.
   # 0=means send all scans, 1=means send 50% of scans, etc.
   # scan_interval = 0

   # Overrides communication timeout [milliseconds]
   # comms_timeout_ms = 100

   #preview = true // Enable GUI visualization of captured data

   # Optional: Exclusion zones to avoid the robot seeing itself:
   #exclusionZone1_x = 0.20 0.30 0.30 0.20
   #exclusionZone1_y = 0.20 0.30 0.30 0.20

   # Optional: Exclusion zones to avoid the robot seeing itself:
   #exclusionAngles1_ini = 20  // Deg
   #exclusionAngles1_end = 25  // Deg
#include <mrpt/hwdrivers/CHokuyoURG.h>

class CHokuyoURG: public mrpt::hwdrivers::C2DRangeFinderAbstract
{
public:
    // structs

    struct TSensorInfo;

    // construction

    CHokuyoURG();

    //
methods

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

    virtual bool turnOn();
    virtual bool turnOff();
    void purgeBuffers();
    void setSerialPort(const std::string& port_name);
    void setIPandPort(const std::string& ip, const unsigned int& port);
    const std::string getSerialPort();
    void setReducedFOV(const double fov);
    bool setHighSensitivityMode(bool enabled);
    bool setIntensityMode(bool enabled);
    void setScanInterval(unsigned int skipScanCount);
    unsigned int getScanInterval() const;
    void sendCmd(const char* str);
};

Inherited Members

public:
    // enums

    enum TSensorState;

    // structs

    struct TMsg;

    //
fields

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

    //
methods

    CGenericSensor& operator = (const CGenericSensor&);
    virtual void doProcess() = 0;
    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 setMinLoggingLevel(const VerbosityLevel level);
    void setVerbosityLevel(const VerbosityLevel level);
    VerbosityLevel getMinLoggingLevel() 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);

Construction

CHokuyoURG()

Constructor.

Methods

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

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 will be typically called in a different thread than other methods, and will be called in a timely fashion.

virtual bool turnOn()

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()

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.

void purgeBuffers()

Empties the RX buffers of the serial port.

void setSerialPort(const std::string& port_name)

If set to non-empty, the serial port will be attempted to be opened automatically when this class is first used to request data from the laser.

void setIPandPort(const std::string& ip, const unsigned int& port)

Set the ip direction and port to connect using Ethernet communication.

const std::string getSerialPort()

Returns the currently set serial port.

See also:

setSerialPort

void setReducedFOV(const double fov)

If called (before calling “turnOn”), the field of view of the laser is reduced to the given range (in radians), discarding the rest of measures.

Call with “0” to disable this reduction again (the default).

bool setHighSensitivityMode(bool enabled)

Changes the high sensitivity mode (HS) (default: false)

Returns:

false on any error

bool setIntensityMode(bool enabled)

If true scans will capture intensity.

(default: false) Should not be called while scanning.

Returns:

false on any error

void setScanInterval(unsigned int skipScanCount)

Set the skip scan count (0 means send all scans).

Must be set before initialize()