LidarLitev2 Library for distance reading. Capable of both single distance reads and continuous distance read setup.

Dependents:   Lidar_Distance Lidar_DistanceContinuous Lidar_2D_Mapping Motions_Secure_Server_IUPUI ... more

Committer:
sventura3
Date:
Thu Oct 22 23:49:53 2015 +0000
Revision:
1:238f6a0108e7
Parent:
0:7e6c07be1754
Child:
2:b0deebd36eb3
Commenting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sventura3 0:7e6c07be1754 1 #ifndef LidarLitev2_H
sventura3 1:238f6a0108e7 2 #define LidarLitev2_H
sventura3 0:7e6c07be1754 3
sventura3 0:7e6c07be1754 4
sventura3 0:7e6c07be1754 5 #include "mbed.h"
sventura3 0:7e6c07be1754 6
sventura3 1:238f6a0108e7 7 /** My LidarLite class
sventura3 1:238f6a0108e7 8 * Used for controlling and interacting with the LidarLitev2
sventura3 1:238f6a0108e7 9 Example:
sventura3 1:238f6a0108e7 10 * @code
sventura3 1:238f6a0108e7 11 * //Measures distance from the lidarlite and prints it through serial
sventura3 1:238f6a0108e7 12 * #include "LidarLitev2.h"
sventura3 1:238f6a0108e7 13 * LidarLitev2 Lidar(p28, p27);
sventura3 1:238f6a0108e7 14 * Serial pc(USBTX,USBRX);
sventura3 1:238f6a0108e7 15 *
sventura3 1:238f6a0108e7 16 *
sventura3 1:238f6a0108e7 17 * Timer dt;
sventura3 1:238f6a0108e7 18 * int main()
sventura3 1:238f6a0108e7 19 * {
sventura3 1:238f6a0108e7 20 *
sventura3 1:238f6a0108e7 21 * pc.baud(115200);
sventura3 1:238f6a0108e7 22 * Lidar.configure();
sventura3 1:238f6a0108e7 23 * dt.start();
sventura3 1:238f6a0108e7 24 * while(1){
sventura3 1:238f6a0108e7 25 * pc.printf("distance = %d cm frequency = %.2f Hz\n", Lidar.distance(), 1/dt.read());
sventura3 1:238f6a0108e7 26 * dt.reset();
sventura3 1:238f6a0108e7 27 * }
sventura3 1:238f6a0108e7 28 * }
sventura3 1:238f6a0108e7 29 * @endcode
sventura3 1:238f6a0108e7 30 *
sventura3 1:238f6a0108e7 31 *
sventura3 1:238f6a0108e7 32 */
sventura3 0:7e6c07be1754 33
sventura3 0:7e6c07be1754 34 class LidarLitev2
sventura3 0:7e6c07be1754 35 {
sventura3 0:7e6c07be1754 36 public:
sventura3 0:7e6c07be1754 37 LidarLitev2(PinName sda, PinName scl, bool = true); // Constructor iniates I2C setup
sventura3 1:238f6a0108e7 38
sventura3 1:238f6a0108e7 39 /** Configure the different modes of the Lidar */
sventura3 1:238f6a0108e7 40 void configure(int = 0, int = 0xc4); // Configure the mode and slave address
sventura3 1:238f6a0108e7 41
sventura3 1:238f6a0108e7 42 /** Sets the Lidar to read continuously, indicating its ready to be read from by the modepin pulling down, a cerntain amount of times */
sventura3 0:7e6c07be1754 43 void beginContinuous(bool = true, char = 0x04, char = 0xff, int = 0xc4); //Enable if using continous setup with mode from Lidar and pulldown
sventura3 1:238f6a0108e7 44
sventura3 1:238f6a0108e7 45
sventura3 0:7e6c07be1754 46 int distance(bool = true, bool = true, int = 0xc4); //Calclulates distance through I2C protocol of activating sensor with a write, then a write for the register, and a read.
sventura3 0:7e6c07be1754 47 // Returns distance as a integer in cm
sventura3 1:238f6a0108e7 48
sventura3 0:7e6c07be1754 49
sventura3 1:238f6a0108e7 50 int distanceContinuous(int = 0xc4);
sventura3 1:238f6a0108e7 51 // 1.) Set Lidar circuit for continuous mode
sventura3 1:238f6a0108e7 52 // 2.) utilize the beginContinous function and configure as desired
sventura3 1:238f6a0108e7 53 // This function returns distance without any need to activate the lidar senore through a write command,
sventura3 1:238f6a0108e7 54 // instead the mode pin pulls down when the lidar is ready for a read
sventura3 0:7e6c07be1754 55 // Returns distance as a integer in cm
sventura3 1:238f6a0108e7 56
sventura3 0:7e6c07be1754 57 private:
sventura3 0:7e6c07be1754 58 // I2C Functions //
sventura3 0:7e6c07be1754 59 ///////////////////
sventura3 0:7e6c07be1754 60 I2C i2c; // Kept private as to prevent changing the I2C once set in the constructor of LidarLitev2
sventura3 0:7e6c07be1754 61 };
sventura3 0:7e6c07be1754 62
sventura3 0:7e6c07be1754 63 #endif /* LidarLitev2_H */