forked from WRO-2021/Cassiopea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tof.cpp
82 lines (69 loc) · 1.59 KB
/
tof.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
#include "tof.h"
static VL6180X sensor[8];
static int tof_offset[] = {
0,//bbboh
-93,
-97,
-65,
-63,
-94,
-102,
-75
};
void MUX(uint8_t bus)
{
//set the transmission with the MUX
Wire.beginTransmission(0x70);
Wire.write(1<<bus);
Wire.endTransmission();
}
int tof_get_offset(uint8_t sens)
{
return tof_offset[sens];
}
int tof_read(uint8_t sens)
{
MUX(sens);
int ret = sensor[sens].readRangeContinuousMillimeters();
if (sensor[sens].timeoutOccurred())
{
tof_conf(sens);
ret = sensor[sens].readRangeContinuousMillimeters();
if (sensor[sens].timeoutOccurred())
return -1;
}
return ret;
}
void tof_conf_all()
{
for(int i=0; i<8; i++)
{
MUX(i);
//read the value of the sensor every 100ms
sensor[i].init();
sensor[i].configureDefault();
sensor[i].writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);
sensor[i].writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 50);
sensor[i].setTimeout(500);
sensor[i].stopContinuous();
}
delay(300);
for(int i=0; i<8; i++)
{
MUX(i);
sensor[i].startInterleavedContinuous(100);
}
}
void tof_conf(uint8_t sens)
{
MUX(sens);
//read the value of the sensor every 100ms
sensor[sens].init();
sensor[sens].configureDefault();
sensor[sens].writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);
sensor[sens].writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 50);
sensor[sens].setTimeout(500);
sensor[sens].stopContinuous();
delay(300);
sensor[sens].startInterleavedContinuous(100);
}