Example: HokuyoURG

1. Description

This example shows how to access a HOKUYO laser scanner and retrieve scans. It makes use of the class hwdrivers::CHokuyoURG, which is in the mrpt-hwdrivers library.

This class works for both versions of the device, URG-04 and UTM-30LX (starting at version MRPT 0.6.0). It will automatically detects the version of the device, then adapts to query the correct amount of scan points.

Basically, the required steps are (refer to the sample code):

  • Specify the serial port to use by its name (e.g. COM4 in Windows or ttyUSB0,ttyACM0 for Linux). This can be set either by loading the configuration from a .ini file, or directly by setting the class member “m_com_port”.
  • Setup communications and turn the laser on, with turnOn() .
  • Invoke in a timely fashion the method doProces() or doProcesSimple(), which processes incoming bytes, builds frames according to the required format, and returns scan data.

There are some options that can be loaded before calling “turnOn()”:


Check also the ready-to-use application rawlog-grabber, which allows gathering data in rawlog format from any number of devices simultaneously.




2. Source code

This example can be found under {MRPT}/samples/HOKUYO_laser_test/ 

Also available online: https://github.com/MRPT/mrpt/tree/master/samples/hwdrivers_hokuyo_example