Suitable for Lidar Lite V2

Dependencies:   mbed

Fork of LidarLite by Akash Vibhute

Committer:
thef
Date:
Thu Jun 16 10:26:33 2016 +0000
Revision:
1:b8d3e9e59703
Parent:
0:8e6304ab38d2
Lidar Lite V2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akashvibhute 0:8e6304ab38d2 1 /*
akashvibhute 0:8e6304ab38d2 2 * Library for easy interface of LidarLite with mbed using I2C
akashvibhute 0:8e6304ab38d2 3 *
akashvibhute 0:8e6304ab38d2 4 * Akash Vibhute <akash . roboticist [at] gmail . com>
akashvibhute 0:8e6304ab38d2 5 *
akashvibhute 0:8e6304ab38d2 6 * v0.1, 17/Feb/2015 - First version of library, tested using LPC1768 [powered via mbed 3.3v, no additional pullups on I2C necessary]
akashvibhute 0:8e6304ab38d2 7 *
akashvibhute 0:8e6304ab38d2 8 */
akashvibhute 0:8e6304ab38d2 9
akashvibhute 0:8e6304ab38d2 10 #ifndef LidarLite_H
akashvibhute 0:8e6304ab38d2 11 #define LidarLite_H
akashvibhute 0:8e6304ab38d2 12
akashvibhute 0:8e6304ab38d2 13 #include <mbed.h>
akashvibhute 0:8e6304ab38d2 14
akashvibhute 0:8e6304ab38d2 15 // Default I2C Address of LIDAR-Lite.
akashvibhute 0:8e6304ab38d2 16 #define LIDARLite_WriteAdr 0xc4 //8-bit slave write address
akashvibhute 0:8e6304ab38d2 17 #define LIDARLite_ReadAdr 0xc5 //8-bit slave read address
akashvibhute 0:8e6304ab38d2 18
akashvibhute 0:8e6304ab38d2 19 // Commands
akashvibhute 0:8e6304ab38d2 20 #define SET_CommandReg 0x00 // Register to write to initiate ranging
akashvibhute 0:8e6304ab38d2 21 #define AcqMode 0x04 // Value to set in control register to initiate ranging
akashvibhute 0:8e6304ab38d2 22
akashvibhute 0:8e6304ab38d2 23 // Read Registers
akashvibhute 0:8e6304ab38d2 24 #define GET_DistanceHBReg 0x0f // High byte of distance reading data
akashvibhute 0:8e6304ab38d2 25 #define GET_DistanceLBReg 0x10 // Low byte of distance reading data
akashvibhute 0:8e6304ab38d2 26 #define GET_Distance2BReg 0x8f // Register to get both High and Low bytes of distance reading data in 1 call
akashvibhute 0:8e6304ab38d2 27 #define GET_VelocityReg 0x09 // Velocity measutement data
akashvibhute 0:8e6304ab38d2 28
akashvibhute 0:8e6304ab38d2 29
akashvibhute 0:8e6304ab38d2 30 class LidarLite
akashvibhute 0:8e6304ab38d2 31 {
akashvibhute 0:8e6304ab38d2 32 public:
akashvibhute 0:8e6304ab38d2 33 LidarLite(PinName sda, PinName scl); //Constructor
thef 1:b8d3e9e59703 34 LidarLite(PinName sda, PinName scl, char currentAddress); //Constructor with current address
akashvibhute 0:8e6304ab38d2 35 void refreshRangeVelocity(); //refreshes range and velocity data from registers of sensor
thef 1:b8d3e9e59703 36 void refreshRangeVelocityAdd(char currentAddres); //refreshes range and velocity data from registers of sensor
akashvibhute 0:8e6304ab38d2 37 void refreshVelocity(); //refreshes velocity data from registers of sensor
thef 1:b8d3e9e59703 38 void refreshVelocityAdd(char currentAddres); //refreshes velocity data from registers of sensor
akashvibhute 0:8e6304ab38d2 39 void refreshRange(); //refreshes range data from registers of sensor
thef 1:b8d3e9e59703 40 void refreshRangeAdd(char currentAddres);
thef 1:b8d3e9e59703 41 void changeAddress(char currentAddres,char newAddress);
akashvibhute 0:8e6304ab38d2 42
akashvibhute 0:8e6304ab38d2 43 int16_t getRange_cm(); //Read distance in cm from sensor
akashvibhute 0:8e6304ab38d2 44 int16_t getVelocity_cms(); //Read velocity in cm/s from sensor
akashvibhute 0:8e6304ab38d2 45
akashvibhute 0:8e6304ab38d2 46 private:
akashvibhute 0:8e6304ab38d2 47 I2C* i2c_;
akashvibhute 0:8e6304ab38d2 48 int16_t distance_LL;
akashvibhute 0:8e6304ab38d2 49 int16_t velocity_LL;
akashvibhute 0:8e6304ab38d2 50 };
akashvibhute 0:8e6304ab38d2 51
akashvibhute 0:8e6304ab38d2 52 #endif /* LidarLite_H */