Example of LidarLite library usage. The data from sensor registers is refreshed using refreshRange() / refreshVelocity() / refreshRangeVelocity() functions and measurement data can be read into program using getRange_cm() / getVelocity_cms(). I separated the functions to refresh and report data for ease of upgrade to thread functions.

Dependencies:   LidarLite

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  *  Example of LidarLite library usage. The data from sensor registers is refreshed using refreshRange() / refreshVelocity() / refreshRangeVelocity() functions and 
00003  *  measurement data can be read into program using getRange_cm() / getVelocity_cms(). I separated the functions to refresh and report data for ease of upgrade to thread functions.
00004  *  
00005  *  Akash Vibhute   < akash . roboticist [at] gmail . com >
00006  *  
00007  *  v0.1, 17/Feb/2015 - First version of library, tested using LPC1768 [powered via mbed 3.3v, no additional pullups on I2C necessary]
00008  *
00009  */
00010 
00011 #include "LidarLite.h"
00012 
00013 #define LIDARLite1_SDA p9   //SDA pin on LPC1768
00014 #define LIDARLite1_SCL p10  //SCL pin on LPC1768
00015 
00016 LidarLite sensor1(LIDARLite1_SDA, LIDARLite1_SCL); //Define LIDAR Lite sensor 1
00017 
00018 Timer dt;
00019 
00020 Serial pc(USBTX,USBRX);
00021 
00022 int main()
00023 {    
00024     pc.baud(921600);
00025     dt.start();
00026     
00027     while(1)
00028     {
00029         //sensor1.refreshRange();
00030         //sensor1.refreshVelocity();
00031         sensor1.refreshRangeVelocity();
00032         
00033         pc.printf("range: %d cm, velocity: %d cm/s, rate: %.2f Hz\n", sensor1.getRange_cm(), sensor1.getVelocity_cms(), 1/dt.read());
00034         dt.reset();
00035     }
00036     
00037 }