class mrpt::hwdrivers::CHokuyoURG
Overview
Driver for Hokuyo URG/UTM/UXM/UST 2-D laser range-finders via the SCIP-2.0 protocol over USB serial or Ethernet.
Produces observations of type mrpt::obs::CObservation2DRangeScan. Both USB (serial) and Ethernet connections are supported; set either COM_port_WIN/COM_port_LIN or IP_DIR + PORT_DIR in the config file.
No external library is required; communication is handled directly via a serial port or TCP socket.
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 COutputLogger& operator = (const COutputLogger&); COutputLogger& operator = (COutputLogger&&); 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 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 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); virtual void loadConfig(const mrpt::config::CConfigFileBase& configSource, const std::string& section); virtual void initialize(); virtual TListObservations getObservations(); virtual void setPathForExternalImages(] const std::string& directory); virtual void setExternalImageFormat(const std::string& ext); virtual void setExternalImageJPEGQuality(const unsigned int quality); static const std::array<const char*, 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 )
Reads and decodes incoming SCIP-2.0 data; stores a complete scan when available.
Typically called from a dedicated polling thread.
Parameters:
outThereIsObservation |
Set to true when a full scan is ready. |
outObservation |
Filled with the new scan when outThereIsObservation is true. |
hardwareError |
Set to true on communication failure. |
virtual bool turnOn()
Initializes communication and starts the continuous scan mode.
Must be called before requesting any observations.
Returns:
true on success, false on any error.
virtual bool turnOff()
Stops the continuous scan mode and puts the device in idle state.
Returns:
true on success, false on any error.
void purgeBuffers()
Discards any pending bytes in the receive buffer.
void setSerialPort(const std::string& port_name)
Configures the serial port device name for USB/serial connection.
When set, the port is opened automatically on the first data request.
Parameters:
port_name |
Device name, e.g. “ttyUSB0” or “COM3”. |
void setIPandPort(const std::string& ip, const unsigned int& port)
Configures the IP address and TCP port for Ethernet connection.
Parameters:
ip |
IPv4 address of the Hokuyo (e.g. “192.168.0.10”). |
port |
TCP port (default for Hokuyo: 10940). |
const std::string getSerialPort()
Returns the currently configured serial port name.
Returns:
The device name as set by setSerialPort().
void setReducedFOV(const double fov)
Restricts the angular field of view of the scanner.
Must be called before turnOn(). Pass 0 to disable FOV restriction.
Parameters:
fov |
Desired half-FOV in radians (full FOV = 2*fov). |
bool setHighSensitivityMode(bool enabled)
Enables or disables High-Sensitivity (HS) mode.
Not available on all firmware versions.
Parameters:
enabled |
true to enable HS mode. |
Returns:
false on any communication error.
bool setIntensityMode(bool enabled)
Enables or disables intensity (RSSI) capture alongside range.
Should not be changed while scanning is active.
Parameters:
enabled |
true to request intensity data. |
Returns:
false on any communication error.
void setScanInterval(unsigned int skipScanCount)
Sets the scan decimation factor.
A value of 0 means all scans are transmitted; N>0 means only 1 out of (N+1) scans is sent. Must be set before initialize().
Parameters:
skipScanCount |
Number of scans to skip between deliveries. |
unsigned int getScanInterval() const
Returns the current scan decimation count.
Returns:
The skip count as set by setScanInterval().