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()
ordoProcesSimple()
, 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()”:
1 2 3 4 5 6 7 8 9 10 |
[supplied_section_name] COM_port_WIN = COM3 COM_port_LIN = ttyS0 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 HOKUYO_motorSpeed_rpm=600 ; (Optional) |
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