-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVL53L1X-ROI.cpp
106 lines (83 loc) · 2.36 KB
/
VL53L1X-ROI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "VL53L1X-ROI.h"
VL53L1X::VL53L1X()
{
}
bool VL53L1X::init()
{
bool done = true;
vl53base.setTimeout(500);
done = vl53base.init();
vl53base.setDistanceMode(VL53L1X_BASE::Short);
vl53base.setMeasurementTimingBudget(MEASUREMENT_BUDGET_MS * 1000);
vl53base.startContinuous(INTER_MEASUREMENT_PERIOD_MS);
return done;
}
void VL53L1X::readScan(VL53L1X_coordinate *posxy, uint8_t *zone_center, uint8_t width, uint8_t height, uint8_t incr, bool blocked)
{
//static uint8_t Zone = 0;
static uint8_t i = 0;
if (Zone >= NumOfZonesPerSensor)
{
Zone = 0;
i = 0;
}
vl53base.ClearInterrupt();
vl53base.SetROI(width, height);
vl53base.SetROICenter(zone_center[Zone]);
stockData(Zone, posxy, i);
Zone += incr;
i++;
if ((blocked) && (Zone < NumOfZonesPerSensor)) readScan(posxy, zone_center, width, height, incr, blocked);
}
bool VL53L1X::isScanComplete(void)
{
if (Zone >= NumOfZonesPerSensor) return true;
else return false;
}
void VL53L1X::readHorizontalScan(VL53L1X_coordinate *posxy, uint8_t incr, bool blocked)
{
readScan(posxy, zone_center_x, WidthOfSPADsPerZone, TotalWidthOfSPADS, incr, blocked);
}
void VL53L1X::readVerticalScan(VL53L1X_coordinate *posxy, uint8_t incr, bool blocked)
{
readScan(posxy, zone_center_y, TotalWidthOfSPADS, WidthOfSPADsPerZone, incr, blocked);
}
VL53L1X_coordinate VL53L1X::readMinimum()
{
return minimum;
}
//Acquire angle and distance for the current zone
void VL53L1X::stockData(uint8_t currentzone, VL53L1X_coordinate *pos, uint8_t counter)
{
double PartZoneAngle;
uint16_t Distance = 0;
Distance = vl53base.read();
if (Distance > 60000)
{
Distance = 0;
}
PartZoneAngle = (StartingZoneAngle + ZoneFOVChangePerStep*currentzone) - (HorizontalFOVofSensor / 2.0);
pos[counter].angle = PartZoneAngle;
pos[counter].distance = Distance;
pos[counter].y = cos((PartZoneAngle / 180) * PI) * Distance;
pos[counter].x = sin((PartZoneAngle / 180) * PI) * Distance;
if (currentzone == 0)
{
minimum = pos[counter];
}else if ((minimum.x > pos[counter].x) && (pos[counter].x > 0)) {
minimum = pos[counter];
}
}
uint16_t VL53L1X::readSimpleRanging(uint8_t FOV)
{
uint16_t Distance = 0;
vl53base.ClearInterrupt();
vl53base.SetROI(FOV, FOV);
vl53base.SetROICenter(FOVCenter);
Distance = vl53base.read();
if (Distance > 60000)
{
Distance = 0;
}
return Distance;
}