Test program for using the Hokuyo URG-04LX LIDAR with the 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.
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.
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.
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"); } }
Revision 0:e7c283192c1c, committed 2016-03-04
- Comitter:
- jebradshaw
- Date:
- Fri Mar 04 16:58:25 2016 +0000
- Commit message:
- Example program for using the Hokuyo URG-04LX 2-dimensional laser range finder
Changed in this revision
diff -r 000000000000 -r e7c283192c1c HOKUYO.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HOKUYO.lib Fri Mar 04 16:58:25 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/jebradshaw/code/HOKUYO/#a325ad337940
diff -r 000000000000 -r e7c283192c1c main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 04 16:58:25 2016 +0000 @@ -0,0 +1,35 @@ +// 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"); + } +}
diff -r 000000000000 -r e7c283192c1c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Mar 04 16:58:25 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb \ No newline at end of file