Hi, I am use nano board to do project which collects range data of Lidar Lite V3 and time period from micro optical sensor (Photointerrupter).
The Lidar API in github: GitHub - garmin/LIDARLite_Arduino_Library: High-performance optical distance sensing.
Here is the code:
#include <Wire.h>
#include "LIDARLite.h"
LIDARLite myLidarLite;
volatile bool encoder_flag = false;
volatile unsigned long Time = 0;
volatile int Duration = 0;
volatile unsigned long LastTime = 0;
void encoderTick(){
encoder_flag = true;
}
void setup() {
pinMode(3, INPUT);//monitor optical sensor read
attachInterrupt(digitalPinToInterrupt(3), encoderTick, CHANGE);
Serial.begin(115200);
myLidarLite.begin(0,true);
myLidarLite.configure(0);
}
void loop() {
if(encoder_flag){
encoder_flag =false;
/****record this encoder time****/
Time = millis();
Duration = Time-LastTime;
LastTime = Time;
Serial.println(Duration);
}
//int d =myLidarLite.distance();
}
Basically, the photo sensor will trig a interrupt as soon as something cover it or leave it. Then the Lidar rotate 360 degree I will get 30 time durations by optical sensor. 28 of them should be almost close, 29th is small and 30th is large to determine the zero position. Because most of covers are the normal size and one is small then normal size and one is larger than normal size. As you can see the code, without
int d =myLidarLite.distance(), the durations lists below:
7
8
7
7
6
8
6
9
6
8
6
8
6
9
6
8
6
8
8
7
7
7
7
7
8
7
7
7
3
11
Then I add int d =myLidarLite.distance(), the durations become ruleless and even not periodic. like this:
8
4
13
9
4
6
8
8
7
9
7
7
10
3
7
12
7
8
9
3
7
10
5
3
7
8
5
9
4
12
Obviously, this Lidar API cause interrupt function process inaccurate so that time duration calculations are wrong. Maybe you guys don't know about Lidar Lite sensor. But I think some of you are expert of arduino controller. Maybe you can give me some suggestions about that. Is that lidar API take too much time so that interrupts process wrong?
Thanks for your help.