Library for easy interface of LidarLite with mbed using I2C
Dependents: LidarLite_mbed Lidar_Magnet
Library for easy interface of LidarLite with mbed using I2C
LidarLite.h@0:8e6304ab38d2, 2015-02-17 (annotated)
- Committer:
- akashvibhute
- Date:
- Tue Feb 17 12:01:04 2015 +0000
- Revision:
- 0:8e6304ab38d2
- Child:
- 1:543c0d15d3b3
v0.1, 17/Feb/2015 - First version of library, tested using LPC1768 [powered via mbed 3.3v, no additional pullups on I2C necessary]
Who changed what in which revision?
User | Revision | Line number | New 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 |
akashvibhute | 0:8e6304ab38d2 | 34 | void refreshRangeVelocity(); //refreshes range and velocity data from registers of sensor |
akashvibhute | 0:8e6304ab38d2 | 35 | void refreshVelocity(); //refreshes velocity data from registers of sensor |
akashvibhute | 0:8e6304ab38d2 | 36 | void refreshRange(); //refreshes range data from registers of sensor |
akashvibhute | 0:8e6304ab38d2 | 37 | |
akashvibhute | 0:8e6304ab38d2 | 38 | int16_t getRange_cm(); //Read distance in cm from sensor |
akashvibhute | 0:8e6304ab38d2 | 39 | int16_t getVelocity_cms(); //Read velocity in cm/s from sensor |
akashvibhute | 0:8e6304ab38d2 | 40 | |
akashvibhute | 0:8e6304ab38d2 | 41 | private: |
akashvibhute | 0:8e6304ab38d2 | 42 | I2C* i2c_; |
akashvibhute | 0:8e6304ab38d2 | 43 | int16_t distance_LL; |
akashvibhute | 0:8e6304ab38d2 | 44 | int16_t velocity_LL; |
akashvibhute | 0:8e6304ab38d2 | 45 | }; |
akashvibhute | 0:8e6304ab38d2 | 46 | |
akashvibhute | 0:8e6304ab38d2 | 47 | #endif /* LidarLite_H */ |