Skip to content

Commit 923ac33

Browse files
authored
Merge pull request #11 from gbr1/roi_detection
All-at-once ROI detection
2 parents 6e7d660 + e9d2a0e commit 923ac33

File tree

2 files changed

+63
-29
lines changed

2 files changed

+63
-29
lines changed

examples/sensor_tof/sensor_tof.ino

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,34 @@ void setup() {
1818

1919
void loop() {
2020
bool updated = false;
21-
updated = tof.update();
21+
updated = tof.update_rois();
2222

2323
if (updated) {
2424
Serial.println(" ");
2525
Serial.print("TOP=");
26-
Serial.println(tof.get_min_range_top_mm());
26+
Serial.println(tof.top);
2727
Serial.print("BOT=");
28-
Serial.println(tof.get_max_range_bottom_mm());
28+
Serial.println(tof.bottom);
2929
Serial.print("LEFT=");
30-
Serial.println(tof.get_min_range_left_mm());
30+
Serial.println(tof.left);
3131
Serial.print("RIGHT=");
32-
Serial.println(tof.get_min_range_right_mm());
32+
Serial.println(tof.right);
3333
Serial.print("CLEFT=");
34-
Serial.println(tof.get_min_range_center_left_mm());
34+
Serial.println(tof.center_left);
3535
Serial.print("CRIGHT=");
36-
Serial.println(tof.get_min_range_center_right_mm());
36+
Serial.println(tof.center_right);
3737
Serial.print("CENTER=");
38+
Serial.println(tof.center);
39+
Serial.print("LEFT_MIN=");
40+
Serial.println(tof.get_min_range_left_mm());
41+
Serial.print("RIGHT_MIN=");
42+
Serial.println(tof.get_min_range_right_mm());
43+
Serial.print("CLEFT_MIN=");
44+
Serial.println(tof.get_min_range_center_left_mm());
45+
Serial.print("CRIGHT_MIN=");
46+
Serial.println(tof.get_min_range_center_right_mm());
47+
Serial.print("CENTER_MIN=");
3848
Serial.println(tof.get_min_range_center_mm());
39-
Serial.print("LEFT_AVG=");
40-
Serial.println(tof.get_avg_range_left_mm());
41-
Serial.print("RIGHT_AVG=");
42-
Serial.println(tof.get_avg_range_right_mm());
43-
Serial.print("CLEFT_AVG=");
44-
Serial.println(tof.get_avg_range_center_left_mm());
45-
Serial.print("CRIGHT_AVG=");
46-
Serial.println(tof.get_avg_range_center_right_mm());
47-
Serial.print("CENTER_AVG=");
48-
Serial.println(tof.get_avg_range_center_mm());
4949
}
5050

5151
delay(1000);

src/sensor_tof_matrix.h

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ class SensorTofMatrix{
2121
uint32_t _wire_base_clock;
2222

2323
public:
24+
int top;
25+
int bottom;
26+
int left;
27+
int right;
28+
int center_left;
29+
int center_right;
30+
int center;
31+
2432
SensorTofMatrix(TwoWire * wire, const uint8_t lpn_pin, const uint8_t i2c_rst_pin, const int size=4, const int ranging_freq=-1, const bool wire_boost = true, const uint32_t wire_base_clock=WIRE_BASE_CLOCK){
2533
_wire=wire;
2634
_sensor = new VL53L7CX(_wire,lpn_pin,i2c_rst_pin);
@@ -106,8 +114,19 @@ class SensorTofMatrix{
106114
return return_value;
107115
}
108116

117+
bool update_rois() {
118+
bool out = update();
119+
top = get_avg_range_top_mm();
120+
bottom = get_max_range_bottom_mm();
121+
left = get_avg_range_left_mm();
122+
right = get_avg_range_right_mm();
123+
center_left = get_avg_range_center_left_mm();
124+
center_right = get_avg_range_center_right_mm();
125+
center = get_avg_range_center_mm();
126+
return out;
127+
}
128+
109129
int get_min_range_top_mm() {
110-
update();
111130

112131
int16_t top_min = results.distance_mm[0];
113132

@@ -118,8 +137,20 @@ class SensorTofMatrix{
118137
return top_min;
119138
}
120139

140+
int get_avg_range_top_mm() {
141+
142+
int16_t _avg = 0;
143+
uint8_t n = 0;
144+
145+
for (int i=0; i < (_size==4?4:16) ;i++) {
146+
_avg += results.distance_mm[i];
147+
n++;
148+
}
149+
150+
return _avg/n;
151+
}
152+
121153
int get_max_range_bottom_mm() {
122-
update();
123154

124155
int16_t bottom_max = results.distance_mm[0];
125156

@@ -130,8 +161,20 @@ class SensorTofMatrix{
130161
return bottom_max;
131162
}
132163

164+
int get_avg_range_bottom_mm() {
165+
166+
int16_t _avg = 0;
167+
uint8_t n = 0;
168+
169+
for (int i=(_size==4?12:48); i < (_size==4?15:63) ;i++) {
170+
_avg += results.distance_mm[i];
171+
n++;
172+
}
173+
174+
return _avg/n;
175+
}
176+
133177
int get_min_range_left_mm() {
134-
update();
135178

136179
int16_t _min = results.distance_mm[0];
137180

@@ -146,7 +189,6 @@ class SensorTofMatrix{
146189
}
147190

148191
int get_min_range_right_mm() {
149-
update();
150192

151193
int16_t _min = results.distance_mm[0];
152194

@@ -161,7 +203,6 @@ class SensorTofMatrix{
161203
}
162204

163205
int get_min_range_center_left_mm() {
164-
update();
165206

166207
int16_t _min = results.distance_mm[0];
167208

@@ -176,7 +217,6 @@ class SensorTofMatrix{
176217
}
177218

178219
int get_min_range_center_right_mm() {
179-
update();
180220

181221
int16_t _min = results.distance_mm[0];
182222

@@ -191,7 +231,6 @@ class SensorTofMatrix{
191231
}
192232

193233
int get_min_range_center_mm() {
194-
update();
195234

196235
int16_t _min = results.distance_mm[0];
197236

@@ -206,7 +245,6 @@ class SensorTofMatrix{
206245
// avgs
207246

208247
int get_avg_range_left_mm() {
209-
update();
210248

211249
int16_t _avg = 0;
212250
uint8_t n = 0;
@@ -224,7 +262,6 @@ class SensorTofMatrix{
224262
}
225263

226264
int get_avg_range_right_mm() {
227-
update();
228265

229266
int16_t _avg = 0;
230267
uint8_t n = 0;
@@ -242,7 +279,6 @@ class SensorTofMatrix{
242279
}
243280

244281
int get_avg_range_center_left_mm() {
245-
update();
246282

247283
int16_t _avg = 0;
248284
uint8_t n = 0;
@@ -260,7 +296,6 @@ class SensorTofMatrix{
260296
}
261297

262298
int get_avg_range_center_right_mm() {
263-
update();
264299

265300
int16_t _avg = 0;
266301
uint8_t n = 0;
@@ -278,7 +313,6 @@ class SensorTofMatrix{
278313
}
279314

280315
int get_avg_range_center_mm() {
281-
update();
282316

283317
int16_t _avg = 0;
284318
uint8_t n = 0;

0 commit comments

Comments
 (0)