Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MaxbotixDriver by
LidarLitePwm.cpp
00001 #include "LidarLitePwm.h" 00002 00003 LidarLitePwm::LidarLitePwm(PinName pin) : _interrupt(pin) 00004 { 00005 _pulseStartTime = 0; 00006 _range = 0; 00007 _lidarFilter = new filter(5); 00008 _timer.start(); 00009 _interrupt.rise(this, &LidarLitePwm::pulseStart); 00010 _interrupt.fall(this, &LidarLitePwm::pulseStop); 00011 } 00012 00013 LidarLitePwm::~LidarLitePwm(){} 00014 00015 int LidarLitePwm::read() 00016 { 00017 if(_range < 30) return 0; 00018 else return _range - 30; 00019 } 00020 00021 LidarLitePwm::operator int() 00022 { 00023 return read(); 00024 } 00025 00026 void LidarLitePwm::pulseStart() 00027 { 00028 _pulseStartTime = _timer.read_us(); 00029 } 00030 00031 void LidarLitePwm::pulseStop() 00032 { 00033 int endTime = _timer.read_us(); 00034 if (endTime < _pulseStartTime) return; // Escape if there's been a roll over 00035 int range = (endTime - _pulseStartTime) / 10; // 10uS per CM 00036 _range = _lidarFilter->process(range); 00037 }
Generated on Thu Jul 14 2022 12:04:14 by
1.7.2
