Library for the LidarLite, gets distance in cm using the pwm output
Fork of MaxbotixDriver by
LidarLitePwm.cpp
- Committer:
- joe4465
- Date:
- 2015-04-01
- Revision:
- 3:0b1f4404cb21
- Parent:
- 2:be66a4cd86c0
File content as of revision 3:0b1f4404cb21:
#include "LidarLitePwm.h" LidarLitePwm::LidarLitePwm(PinName pin) : _interrupt(pin) { _pulseStartTime = 0; _range = 0; _lidarFilter = new filter(5); _timer.start(); _interrupt.rise(this, &LidarLitePwm::pulseStart); _interrupt.fall(this, &LidarLitePwm::pulseStop); } LidarLitePwm::~LidarLitePwm(){} int LidarLitePwm::read() { if(_range < 30) return 0; else return _range - 30; } LidarLitePwm::operator int() { return read(); } void LidarLitePwm::pulseStart() { _pulseStartTime = _timer.read_us(); } void LidarLitePwm::pulseStop() { int endTime = _timer.read_us(); if (endTime < _pulseStartTime) return; // Escape if there's been a roll over int range = (endTime - _pulseStartTime) / 10; // 10uS per CM _range = _lidarFilter->process(range); }