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

Dependents:   LidarLite_test

Fork of MaxbotixDriver by Daniel Casner

Files at this revision

API Documentation at this revision

Comitter:
joe4465
Date:
Wed Apr 01 11:18:45 2015 +0000
Parent:
2:be66a4cd86c0
Commit message:
...

Changed in this revision

LidarLitePwm.cpp Show annotated file Show diff for this revision Revisions of this file
LidarLitePwm.h Show annotated file Show diff for this revision Revisions of this file
--- a/LidarLitePwm.cpp	Wed Mar 18 09:17:13 2015 +0000
+++ b/LidarLitePwm.cpp	Wed Apr 01 11:18:45 2015 +0000
@@ -4,6 +4,7 @@
 {
     _pulseStartTime = 0;
     _range = 0;
+    _lidarFilter = new filter(5);
     _timer.start();
     _interrupt.rise(this, &LidarLitePwm::pulseStart);
     _interrupt.fall(this, &LidarLitePwm::pulseStop);
@@ -13,7 +14,8 @@
 
 int LidarLitePwm::read()
 {
-    return _range;
+    if(_range < 30) return 0;
+    else return _range - 30;
 }
 
 LidarLitePwm::operator int()
@@ -30,5 +32,6 @@
 {
     int endTime = _timer.read_us();
     if (endTime < _pulseStartTime) return; // Escape if there's been a roll over
-    _range = (endTime - _pulseStartTime) / 10; // 10uS per CM
+    int range = (endTime - _pulseStartTime) / 10; // 10uS per CM
+    _range = _lidarFilter->process(range);
 }
\ No newline at end of file
--- a/LidarLitePwm.h	Wed Mar 18 09:17:13 2015 +0000
+++ b/LidarLitePwm.h	Wed Apr 01 11:18:45 2015 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include "filter.h"
 
 #ifndef LidarLitePwm_H
 #define LidarLitePwm_H
@@ -12,6 +13,7 @@
     /// Returns range in cm as int
     int read();
     
+    
     /// Returns the range in CM as an int
     operator int();
     
@@ -30,6 +32,8 @@
     int _pulseStartTime;
     /// The most recent sample
     int _range;
+    
+    filter* _lidarFilter;
 };
  
 #endif
\ No newline at end of file