Test program for using the Hokuyo URG-04LX LIDAR with the mbed.

Dependencies:   HOKUYO mbed

Hokuyo Library

This is an example of using the Hokuyo library for the Hokuyo URG-04LX 2 dimensional LIDAR (range finder) with the mbed. /media/uploads/jebradshaw/mbedwse_sbc_hokuyo.jpg

Above is the Hokuyo attached to the mbed WSE Project board (https://developer.mbed.org/users/jebradshaw/code/mbedWSEsbc/). I'm using a xbee form factor RS-232 level converter with a male DB9 (DTE). The on board 5V 1.5A OKI-78SR-5/1.5-W36-C switching regulator is more then sufficient for powering the LIDAR.

/media/uploads/jebradshaw/hokuyo_mbedwsesbc_hookup.jpg

O'scope capture of the serial data. This is using a cluster size of 3, about a degree resolution at 19200 baud gives an update rate of about 3.3Hz.

/media/uploads/jebradshaw/dataterminal_stream.jpg

Above is a screen capture of the data being transmitted to Tera-terminal.

include the mbed library with this snippet

// J Bradshaw  20160304  Hokuyo Lidar interface library example
// cluster - groups together points, each point is .351 degrees
#include "mbed.h"
#include "hokuyo.h"

DigitalOut led1(LED1);
Hokuyo lidar(p13, p14); // tx, rx for Xbee header (RS232 board for Hokuyo)
Serial pc(USBTX, USBRX);

int main() {
    float scan_width = 180.0;   //scan X number of degrees
    int cluster = 3;            //~degree 1 accuracy with every 3 samples at .351/sample
    
    pc.baud(921600);

    if(!lidar.Init())
        pc.printf("Hokuyo Init successful\r\n");
    else{
        pc.printf("Error Initializing Hokuyo!\r\n");
        wait(10);
    }
          
    while(1) {        
        if(!lidar.Read_Scan(scan_width, cluster)){        //scan 30deg wide, cluster of 5 points
            //pc.printf("total points read = %d\r\n\r\n", lidar.numPts);        
            for(int i=0;i<lidar.numPts;i++){
                 pc.printf("%5.2f %05d\r\n", lidar.angle[i], lidar.dist_mm[i]);
                 wait(.0001);
            }
            led1=!led1;
        }
        else
            pc.printf("Error Scanning Hokuyo!\r\n");
    }
}
Committer:
jebradshaw
Date:
Fri Mar 04 16:58:25 2016 +0000
Revision:
0:e7c283192c1c
Example program for using the Hokuyo URG-04LX 2-dimensional laser range finder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jebradshaw 0:e7c283192c1c 1 // J Bradshaw 20160304 Hokuyo Lidar interface library example
jebradshaw 0:e7c283192c1c 2 // cluster - groups together points, each point is .351 degrees
jebradshaw 0:e7c283192c1c 3 #include "mbed.h"
jebradshaw 0:e7c283192c1c 4 #include "hokuyo.h"
jebradshaw 0:e7c283192c1c 5
jebradshaw 0:e7c283192c1c 6 DigitalOut led1(LED1);
jebradshaw 0:e7c283192c1c 7 Hokuyo lidar(p13, p14); // tx, rx for Xbee header (RS232 board for Hokuyo)
jebradshaw 0:e7c283192c1c 8 Serial pc(USBTX, USBRX);
jebradshaw 0:e7c283192c1c 9
jebradshaw 0:e7c283192c1c 10 int main() {
jebradshaw 0:e7c283192c1c 11 float scan_width = 180.0; //scan X number of degrees
jebradshaw 0:e7c283192c1c 12 int cluster = 3; //~degree 1 accuracy with every 3 samples at .351/sample
jebradshaw 0:e7c283192c1c 13
jebradshaw 0:e7c283192c1c 14 pc.baud(921600);
jebradshaw 0:e7c283192c1c 15
jebradshaw 0:e7c283192c1c 16 if(!lidar.Init())
jebradshaw 0:e7c283192c1c 17 pc.printf("Hokuyo Init successful\r\n");
jebradshaw 0:e7c283192c1c 18 else{
jebradshaw 0:e7c283192c1c 19 pc.printf("Error Initializing Hokuyo!\r\n");
jebradshaw 0:e7c283192c1c 20 wait(10);
jebradshaw 0:e7c283192c1c 21 }
jebradshaw 0:e7c283192c1c 22
jebradshaw 0:e7c283192c1c 23 while(1) {
jebradshaw 0:e7c283192c1c 24 if(!lidar.Read_Scan(scan_width, cluster)){ //scan 30deg wide, cluster of 5 points
jebradshaw 0:e7c283192c1c 25 //pc.printf("total points read = %d\r\n\r\n", lidar.numPts);
jebradshaw 0:e7c283192c1c 26 for(int i=0;i<lidar.numPts;i++){
jebradshaw 0:e7c283192c1c 27 pc.printf("%5.2f %05d\r\n", lidar.angle[i], lidar.dist_mm[i]);
jebradshaw 0:e7c283192c1c 28 wait(.0001);
jebradshaw 0:e7c283192c1c 29 }
jebradshaw 0:e7c283192c1c 30 led1=!led1;
jebradshaw 0:e7c283192c1c 31 }
jebradshaw 0:e7c283192c1c 32 else
jebradshaw 0:e7c283192c1c 33 pc.printf("Error Scanning Hokuyo!\r\n");
jebradshaw 0:e7c283192c1c 34 }
jebradshaw 0:e7c283192c1c 35 }