File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ void initUltrasonic() {
21
21
// pinMode(ECHO_RIGHT, INPUT);
22
22
};
23
23
24
+ void initVL53L8CX () {
25
+ Wire.begin ();
26
+ Wire.setClock (1000000 ); // Sensor has max I2C freq of 1MHz
27
+ sensor_vl53l8cx_top.begin ();
28
+ sensor_vl53l8cx_top.init_sensor ();
29
+ sensor_vl53l8cx_top.vl53l8cx_set_ranging_frequency_hz (30 );
30
+ sensor_vl53l8cx_top.vl53l8cx_set_resolution (VL53L8CX_RESOLUTION_8X8);
31
+ sensor_vl53l8cx_top.vl53l8cx_start_ranging ();
32
+ }
33
+
24
34
void initSPS () {
25
35
int errorCount = 0 ;
26
36
int16_t ret;
Original file line number Diff line number Diff line change 11
11
#include < NMEAGPS.h>
12
12
#include < Adafruit_MPU6050.h>
13
13
#include < NewPing.h> // http://librarymanager/All#NewPing
14
+ #include < vl53l8cx_class.h>
14
15
15
16
#define TRIGGER_LEFT 1
16
17
#define ECHO_LEFT 2
17
18
#define MAX_DISTANCE_A 400
18
19
NewPing sonarA (TRIGGER_LEFT, ECHO_LEFT, MAX_DISTANCE_A);
20
+ VL53L8CX sensor_vl53l8cx_top (&Wire, -1 , -1 );
19
21
static NMEAGPS gps;
20
22
// https://github.com/SlashDevin/NeoGPS/blob/master/extras/doc/Data%20Model.md
21
23
static gps_fix fix;
@@ -71,7 +73,8 @@ String name;
71
73
// todo: give feedback through LED if all is working?
72
74
void initsSensors () {
73
75
Serial.print (" Ultrasonic..." );
74
- initUltrasonic ();
76
+ // initUltrasonic();
77
+ initVL53L8CX ();
75
78
// ATTENTION! SPS Disabled for essen-auf-raedern
76
79
// Serial.print("SPS30...");
77
80
// initSPS(); Serial.println("done!");
@@ -98,7 +101,7 @@ void initsSensors() {
98
101
// set measurements for acceleration, distance, humidity and temperature
99
102
void setMeasurements () {
100
103
getAccAmplitudes (&sumAccX, &sumAccY, &sumAccZ);
101
- handleDistance ();
104
+ handleDistanceVL53L8CX ();
102
105
temp = HDC.readTemperature ();
103
106
humi = HDC.readHumidity ();
104
107
Original file line number Diff line number Diff line change @@ -25,6 +25,35 @@ void handleDistance() {
25
25
// }
26
26
}
27
27
28
+ /* To give a confidence rating, a target with status 5 is considered as 100% valid.
29
+ A status of 6 or 9 can be considered with a confidence value of 50%.
30
+ All other statuses are below the 50% confidence level. */
31
+ bool validTargetStatus (int status) {
32
+ return status == 5 || status == 6 || status == 9 ;
33
+ }
34
+
35
+ void handleDistanceVL53L8CX () {
36
+ VL53L8CX_ResultsData Results;
37
+ uint8_t NewDataReady = 0 ;
38
+ uint8_t status;
39
+
40
+ status = sensor_vl53l8cx_top.vl53l8cx_check_data_ready (&NewDataReady);
41
+
42
+ if ((!status) && (NewDataReady != 0 )) {
43
+ sensor_vl53l8cx_top.vl53l8cx_get_ranging_data (&Results);
44
+ float min = 1000.0 ; // larger than what the sensor could possibly see
45
+ for (int i = 0 ; i < VL53L8CX_RESOLUTION_8X8*VL53L8CX_NB_TARGET_PER_ZONE; i++) {
46
+ if (validTargetStatus ((int )(&Results)->target_status [i])){
47
+ float distance = ((&Results)->distance_mm [i])/10 ;
48
+ if (min > distance) {
49
+ min = distance;
50
+ }
51
+ }
52
+ }
53
+ dist_l = (min==1000.0 ) ? 400.0 : min; // in theory the sensor can measure up to 4m distance
54
+ }
55
+ }
56
+
28
57
void callSPS () {
29
58
// struct sps30_measurement m;
30
59
char serial[SPS30_MAX_SERIAL_LEN];
You can’t perform that action at this time.
0 commit comments