Library for the LidarLite, gets distance in cm using the pwm output

Dependents:   LidarLite_test

Fork of MaxbotixDriver by Daniel Casner

Committer:
joe4465
Date:
Wed Apr 01 11:18:45 2015 +0000
Revision:
3:0b1f4404cb21
Parent:
2:be66a4cd86c0
...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joe4465 1:32f0a592b9e5 1 #include "LidarLitePwm.h"
joe4465 1:32f0a592b9e5 2
joe4465 2:be66a4cd86c0 3 LidarLitePwm::LidarLitePwm(PinName pin) : _interrupt(pin)
joe4465 1:32f0a592b9e5 4 {
joe4465 2:be66a4cd86c0 5 _pulseStartTime = 0;
joe4465 2:be66a4cd86c0 6 _range = 0;
joe4465 3:0b1f4404cb21 7 _lidarFilter = new filter(5);
joe4465 2:be66a4cd86c0 8 _timer.start();
joe4465 1:32f0a592b9e5 9 _interrupt.rise(this, &LidarLitePwm::pulseStart);
joe4465 1:32f0a592b9e5 10 _interrupt.fall(this, &LidarLitePwm::pulseStop);
joe4465 1:32f0a592b9e5 11 }
joe4465 1:32f0a592b9e5 12
joe4465 2:be66a4cd86c0 13 LidarLitePwm::~LidarLitePwm(){}
joe4465 2:be66a4cd86c0 14
joe4465 1:32f0a592b9e5 15 int LidarLitePwm::read()
joe4465 1:32f0a592b9e5 16 {
joe4465 3:0b1f4404cb21 17 if(_range < 30) return 0;
joe4465 3:0b1f4404cb21 18 else return _range - 30;
joe4465 1:32f0a592b9e5 19 }
joe4465 1:32f0a592b9e5 20
joe4465 1:32f0a592b9e5 21 LidarLitePwm::operator int()
joe4465 1:32f0a592b9e5 22 {
joe4465 1:32f0a592b9e5 23 return read();
joe4465 1:32f0a592b9e5 24 }
joe4465 1:32f0a592b9e5 25
joe4465 1:32f0a592b9e5 26 void LidarLitePwm::pulseStart()
joe4465 1:32f0a592b9e5 27 {
joe4465 1:32f0a592b9e5 28 _pulseStartTime = _timer.read_us();
joe4465 1:32f0a592b9e5 29 }
joe4465 1:32f0a592b9e5 30
joe4465 1:32f0a592b9e5 31 void LidarLitePwm::pulseStop()
joe4465 1:32f0a592b9e5 32 {
joe4465 1:32f0a592b9e5 33 int endTime = _timer.read_us();
joe4465 1:32f0a592b9e5 34 if (endTime < _pulseStartTime) return; // Escape if there's been a roll over
joe4465 3:0b1f4404cb21 35 int range = (endTime - _pulseStartTime) / 10; // 10uS per CM
joe4465 3:0b1f4404cb21 36 _range = _lidarFilter->process(range);
joe4465 1:32f0a592b9e5 37 }