Skip to content

Commit 423878c

Browse files
committed
feat: update_rois. feat: get_avg_range_top_mm. mod: method to get rois don't call update
1 parent f9af4da commit 423878c

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-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: 33 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);
@@ -109,8 +117,19 @@ class SensorTofMatrix{
109117
return return_value;
110118
}
111119

120+
bool update_rois() {
121+
bool out = update();
122+
top = get_avg_range_top_mm();
123+
bottom = get_max_range_bottom_mm();
124+
left = get_avg_range_left_mm();
125+
right = get_avg_range_right_mm();
126+
center_left = get_avg_range_center_left_mm();
127+
center_right = get_avg_range_center_right_mm();
128+
center = get_avg_range_center_mm();
129+
return out;
130+
}
131+
112132
int get_min_range_top_mm() {
113-
update();
114133

115134
int16_t top_min = results.distance_mm[0];
116135

@@ -121,8 +140,20 @@ class SensorTofMatrix{
121140
return top_min;
122141
}
123142

143+
int get_avg_range_top_mm() {
144+
145+
int16_t _avg = 0;
146+
uint8_t n = 0;
147+
148+
for (int i=0; i < (_size==4?4:16) ;i++) {
149+
_avg += results.distance_mm[i];
150+
n++;
151+
}
152+
153+
return _avg/n;
154+
}
155+
124156
int get_max_range_bottom_mm() {
125-
update();
126157

127158
int16_t bottom_max = results.distance_mm[0];
128159

@@ -134,7 +165,6 @@ class SensorTofMatrix{
134165
}
135166

136167
int get_min_range_left_mm() {
137-
update();
138168

139169
int16_t _min = results.distance_mm[0];
140170

@@ -149,7 +179,6 @@ class SensorTofMatrix{
149179
}
150180

151181
int get_min_range_right_mm() {
152-
update();
153182

154183
int16_t _min = results.distance_mm[0];
155184

@@ -164,7 +193,6 @@ class SensorTofMatrix{
164193
}
165194

166195
int get_min_range_center_left_mm() {
167-
update();
168196

169197
int16_t _min = results.distance_mm[0];
170198

@@ -179,7 +207,6 @@ class SensorTofMatrix{
179207
}
180208

181209
int get_min_range_center_right_mm() {
182-
update();
183210

184211
int16_t _min = results.distance_mm[0];
185212

@@ -194,7 +221,6 @@ class SensorTofMatrix{
194221
}
195222

196223
int get_min_range_center_mm() {
197-
update();
198224

199225
int16_t _min = results.distance_mm[0];
200226

@@ -209,7 +235,6 @@ class SensorTofMatrix{
209235
// avgs
210236

211237
int get_avg_range_left_mm() {
212-
update();
213238

214239
int16_t _avg = 0;
215240
uint8_t n = 0;
@@ -227,7 +252,6 @@ class SensorTofMatrix{
227252
}
228253

229254
int get_avg_range_right_mm() {
230-
update();
231255

232256
int16_t _avg = 0;
233257
uint8_t n = 0;
@@ -245,7 +269,6 @@ class SensorTofMatrix{
245269
}
246270

247271
int get_avg_range_center_left_mm() {
248-
update();
249272

250273
int16_t _avg = 0;
251274
uint8_t n = 0;
@@ -263,7 +286,6 @@ class SensorTofMatrix{
263286
}
264287

265288
int get_avg_range_center_right_mm() {
266-
update();
267289

268290
int16_t _avg = 0;
269291
uint8_t n = 0;
@@ -281,7 +303,6 @@ class SensorTofMatrix{
281303
}
282304

283305
int get_avg_range_center_mm() {
284-
update();
285306

286307
int16_t _avg = 0;
287308
uint8_t n = 0;

0 commit comments

Comments
 (0)