example_hand_motion_detection.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2024-2025
2 // All rights reserved
3 // This file is subject to the terms and conditions defined in the file
4 // 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
5 // of this source code package.
6
7 #include <math.h>
8 #include <stddef.h>
9 #include <stdio.h>
10
11 #include "acc_algorithm.h"
12 #include "acc_config.h"
13 #include "acc_detector_presence.h"
14 #include "acc_detector_presence_processing.h"
15 #include "acc_integration.h"
16 #include "acc_integration_log.h"
17 #include "acc_processing.h"
18 #include "acc_rss_a121.h"
19 #include "example_hand_motion_detection.h"
20
21 #define MODULE "example_hand_motion_detection"
22
23 struct hand_motion_detection_handle
24 {
25 hand_motion_detection_config_t config;
26 bool prepare_needed;
27
28 bool has_detected;
29 uint32_t update_index;
30 uint32_t update_index_at_detection;
31
32 acc_sensor_id_t sensor_id;
33 acc_config_t *hand_motion_detection_sensor_config;
34 acc_processing_t *sensor_processing;
35 acc_processing_metadata_t sensor_processing_metadata;
36 acc_detector_presence_processing_config_t *hand_motion_detection_presence_processing_config;
37 acc_detector_presence_processing_handle_t *hand_motion_detection_presence_processor;
38
39 acc_detector_presence_handle_t *presence_detector;
40 acc_detector_presence_metadata_t presence_metadata;
41
42 hand_motion_detection_app_mode_t app_mode;
43 uint16_t hand_motion_detection_timeout_duration;
44 uint16_t hand_motion_detection_timer;
45 uint16_t detection_retention_duration;
46 };
47
48 static void reinit_hand_motion_detection_state(hand_motion_detection_handle_t *handle);
49
50 static void set_sensor_config(const hand_motion_detection_config_t *hand_motion_detection_config, acc_config_t *sensor_config);
51
52 static void set_processing_config(const hand_motion_detection_config_t *hand_motion_detection_config,
53 acc_detector_presence_processing_config_t *processing_config);
54
55 static hand_motion_detection_detection_state_t process_presence_processing_result(
56 hand_motion_detection_handle_t *handle,
57 const acc_detector_presence_processing_result_t *presence_processing_result);
58
59 static void determine_app_mode(hand_motion_detection_handle_t *handle, hand_motion_detection_result_t *result);
60
61 static void swap_app_mode(hand_motion_detection_handle_t *handle, hand_motion_detection_app_mode_t new_app_mode);
62
63 hand_motion_detection_config_t *hand_motion_detection_config_create(void)
64 {
65 hand_motion_detection_config_t *config = acc_integration_mem_calloc(1U, sizeof(*config));
66
67 if (config != NULL)
68 {
69 config->presence_config = acc_detector_presence_config_create();
70
71 if (config->presence_config == NULL)
72 {
73 hand_motion_detection_config_destroy(config);
74 config = NULL;
75 }
76 }
77
78 return config;
79 }
80
81 void hand_motion_detection_config_destroy(hand_motion_detection_config_t *config)
82 {
83 if (config != NULL)
84 {
85 if (config->presence_config != NULL)
86 {
87 acc_detector_presence_config_destroy(config->presence_config);
88 }
89
90 acc_integration_mem_free(config);
91 }
92 }
93
94 void hand_motion_detection_set_config(hand_motion_detection_preset_t preset, hand_motion_detection_config_t *config)
95 {
96 switch (preset)
97 {
98 case HAND_MOTION_DETECTION_PRESET_NONE:
99 break;
100 case HAND_MOTION_DETECTION_PRESET_FAUCET:
101 // Hand motion algo settings
102 config->algo_config.sensor_to_water_distance = 0.12f;
103 config->algo_config.water_jet_width = 0.02f;
104 config->algo_config.measurement_range_end = 0.2f;
105 config->algo_config.filter_time_const = 0.3f;
106 config->algo_config.threshold = 1.5f;
107 config->algo_config.detection_retention_duration = 1.0f;
108
109 // Sensor settings
110 config->algo_config.hwaas = 32U;
111 config->algo_config.sweeps_per_frame = 64U;
112 config->algo_config.sweep_rate = 1000.0f;
113 config->algo_config.frame_rate = 10.0f;
114
115 // Presence settings
116 acc_detector_presence_config_reset_filters_on_prepare_set(config->presence_config, true);
117 acc_detector_presence_config_frame_rate_set(config->presence_config, 2.0f);
118 acc_detector_presence_config_start_set(config->presence_config, 0.7f);
119 acc_detector_presence_config_end_set(config->presence_config, 0.7f);
120 acc_detector_presence_config_sweeps_per_frame_set(config->presence_config, 32U);
121 acc_detector_presence_config_inter_frame_deviation_time_const_set(config->presence_config, 0.01f);
122 acc_detector_presence_config_inter_output_time_const_set(config->presence_config, 0.01f);
123 acc_detector_presence_config_intra_frame_time_const_set(config->presence_config, 0.01f);
124 acc_detector_presence_config_intra_output_time_const_set(config->presence_config, 0.01f);
125
126 acc_detector_presence_config_frame_rate_app_driven_set(config->presence_config, true);
127
128 // Application settings
129 config->hand_detection_timeout = 5.0f;
130 config->use_presence_detection = true;
131 break;
132 default:
133 break;
134 }
135 }
136
137 hand_motion_detection_handle_t *hand_motion_detection_handle_create(const hand_motion_detection_config_t *hand_motion_detection_config,
138 acc_sensor_id_t sensor_id)
139 {
140 hand_motion_detection_handle_t *handle = acc_integration_mem_calloc(1U, sizeof(*handle));
141
142 bool status = handle != NULL;
143
144 if (status)
145 {
146 handle->config = *hand_motion_detection_config;
147 handle->prepare_needed = true;
148 handle->app_mode = HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION;
149 handle->sensor_id = sensor_id;
150
151 handle->hand_motion_detection_timeout_duration =
152 (uint16_t)(roundf(hand_motion_detection_config->hand_detection_timeout * hand_motion_detection_config->algo_config.frame_rate));
153 handle->hand_motion_detection_timer = 0U;
154 handle->detection_retention_duration = (uint16_t)(roundf(hand_motion_detection_config->algo_config.detection_retention_duration *
155 hand_motion_detection_config->algo_config.frame_rate));
156
157 reinit_hand_motion_detection_state(handle);
158
159 handle->hand_motion_detection_sensor_config = acc_config_create();
160 handle->hand_motion_detection_presence_processing_config = acc_detector_presence_processing_config_create();
161
162 status = handle->hand_motion_detection_sensor_config != NULL && handle->hand_motion_detection_presence_processing_config != NULL;
163 }
164
165 if (status)
166 {
167 set_sensor_config(hand_motion_detection_config, handle->hand_motion_detection_sensor_config);
168 set_processing_config(hand_motion_detection_config, handle->hand_motion_detection_presence_processing_config);
169
170 handle->sensor_processing = acc_processing_create(handle->hand_motion_detection_sensor_config, &handle->sensor_processing_metadata);
171 handle->hand_motion_detection_presence_processor =
172 acc_detector_presence_processing_create(handle->hand_motion_detection_presence_processing_config,
173 handle->hand_motion_detection_sensor_config);
174
175 status = handle->hand_motion_detection_presence_processor != NULL;
176 }
177
178 if (status)
179 {
180 if (handle->config.use_presence_detection)
181 {
182 handle->app_mode = HAND_MOTION_DETECTION_APP_MODE_PRESENCE;
183
184 handle->presence_detector = acc_detector_presence_create(handle->config.presence_config, &handle->presence_metadata);
185
186 status = handle->presence_detector != NULL;
187
188 uint32_t sleep_time_ms = (uint32_t)(1000.0f / acc_detector_presence_config_frame_rate_get(handle->config.presence_config));
189 acc_integration_set_periodic_wakeup(sleep_time_ms);
190 }
191 else
192 {
193 uint32_t sleep_time_ms = (uint32_t)(1000.0f / handle->config.algo_config.frame_rate);
194 acc_integration_set_periodic_wakeup(sleep_time_ms);
195 }
196 }
197
198 if (!status)
199 {
200 hand_motion_detection_handle_destroy(handle);
201 handle = NULL;
202 }
203
204 return handle;
205 }
206
207 void hand_motion_detection_handle_destroy(hand_motion_detection_handle_t *handle)
208 {
209 if (handle != NULL)
210 {
211 if (handle->presence_detector != NULL)
212 {
213 acc_detector_presence_destroy(handle->presence_detector);
214 }
215
216 if (handle->hand_motion_detection_presence_processor != NULL)
217 {
218 acc_detector_presence_processing_destroy(handle->hand_motion_detection_presence_processor);
219 }
220
221 if (handle->sensor_processing != NULL)
222 {
223 acc_processing_destroy(handle->sensor_processing);
224 }
225
226 if (handle->hand_motion_detection_presence_processing_config != NULL)
227 {
228 acc_detector_presence_processing_config_destroy(handle->hand_motion_detection_presence_processing_config);
229 }
230
231 if (handle->hand_motion_detection_sensor_config != NULL)
232 {
233 acc_config_destroy(handle->hand_motion_detection_sensor_config);
234 }
235
236 acc_integration_mem_free(handle);
237 }
238 }
239
240 void hand_motion_detection_config_log(hand_motion_detection_handle_t *handle)
241 {
242 if (handle != NULL)
243 {
244 printf("App config:\n");
245 printf("sensor_to_water_distance: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.algo_config.sensor_to_water_distance));
246 printf("water_jet_width: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.algo_config.water_jet_width));
247 printf("measurement_range_end: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.algo_config.measurement_range_end));
248 printf("filter_time_const: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.algo_config.filter_time_const));
249 printf("threshold: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.algo_config.threshold));
250 printf("detection_retention_duration: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.algo_config.detection_retention_duration));
251 printf("hwaas: %" PRIu16 "\n", handle->config.algo_config.hwaas);
252 printf("sweeps_per_frame: %" PRIu16 "\n", handle->config.algo_config.sweeps_per_frame);
253 printf("sweep_rate: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.algo_config.sweep_rate));
254 printf("frame_rate: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.algo_config.frame_rate));
255 printf("hand_detection_timeout: %" PRIfloat "\n", ACC_LOG_FLOAT_TO_INTEGER(handle->config.hand_detection_timeout));
256 printf("use_presence_detection: %s\n", handle->config.use_presence_detection ? "True" : "False");
257
258 printf("Sensor config:\n");
259 acc_config_log(handle->hand_motion_detection_sensor_config);
260
261 if (handle->config.use_presence_detection)
262 {
263 printf("Presence config:\n");
264 acc_detector_presence_config_log(handle->config.presence_config);
265 }
266 }
267 }
268
269 bool hand_motion_detection_get_buffer_size(hand_motion_detection_handle_t *handle, uint32_t *buffer_size)
270 {
271 uint32_t hand_motion_detection_buffer_size = 0U;
272 uint32_t presence_detector_buffer_size = 0U;
273
274 bool status = acc_rss_get_buffer_size(handle->hand_motion_detection_sensor_config, &hand_motion_detection_buffer_size);
275
276 if (status)
277 {
278 hand_motion_detection_buffer_size += acc_detector_presence_processing_get_buffer_size(handle->hand_motion_detection_sensor_config);
279
280 if (handle->config.use_presence_detection)
281 {
282 status = acc_detector_presence_get_buffer_size(handle->presence_detector, &presence_detector_buffer_size);
283 }
284 }
285
286 if (status)
287 {
288 *buffer_size =
289 (hand_motion_detection_buffer_size > presence_detector_buffer_size) ? hand_motion_detection_buffer_size : presence_detector_buffer_size;
290 }
291
292 return status;
293 }
294
295 bool hand_motion_detection_prepare(hand_motion_detection_handle_t *handle,
296 acc_sensor_t *sensor,
297 const acc_cal_result_t *cal_result,
298 void *buffer,
299 uint32_t buffer_size,
300 bool force_prepare)
301 {
302 bool status = true;
303
304 if (handle->prepare_needed || force_prepare)
305 {
306 if (handle->app_mode == HAND_MOTION_DETECTION_APP_MODE_PRESENCE)
307 {
308 status =
309 acc_detector_presence_prepare(handle->presence_detector, handle->config.presence_config, sensor, cal_result, buffer, buffer_size);
310 }
311 else // HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION
312 {
313 status = acc_sensor_prepare(sensor, handle->hand_motion_detection_sensor_config, cal_result, buffer, buffer_size);
314 }
315
316 handle->prepare_needed = false;
317 }
318
319 return status;
320 }
321
322 void hand_motion_detection_process(hand_motion_detection_handle_t *handle, void *buffer, hand_motion_detection_result_t *hand_motion_detection_result)
323 {
324 acc_detector_presence_result_t presence_result;
325
326 if (handle->app_mode == HAND_MOTION_DETECTION_APP_MODE_PRESENCE)
327 {
328 acc_detector_presence_process(handle->presence_detector, buffer, &presence_result);
329
330 hand_motion_detection_result->presence_result_available = true;
331 hand_motion_detection_result->presence_result = presence_result;
332 hand_motion_detection_result->algo_result_available = false;
333
334 hand_motion_detection_result->proc_result = presence_result.processing_result;
335 }
336 else // HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION
337 {
338 acc_detector_presence_processing_result_t presence_processing_result;
339 acc_processing_execute(handle->sensor_processing, buffer, &hand_motion_detection_result->proc_result);
340
341 acc_detector_presence_processing_process(handle->hand_motion_detection_presence_processor,
342 buffer,
343 hand_motion_detection_result->proc_result.frame,
344 &presence_processing_result);
345
346 hand_motion_detection_result->algo_result_available = true;
347 hand_motion_detection_result->algo_result.detection_state = process_presence_processing_result(handle, &presence_processing_result);
348 hand_motion_detection_result->presence_result_available = false;
349 }
350
351 hand_motion_detection_result->app_mode = handle->app_mode;
352
353 determine_app_mode(handle, hand_motion_detection_result);
354 }
355
356 static void reinit_hand_motion_detection_state(hand_motion_detection_handle_t *handle)
357 {
358 handle->has_detected = false;
359 handle->update_index = 0U;
360 handle->update_index_at_detection = 0U;
361 }
362
363 static void set_sensor_config(const hand_motion_detection_config_t *hand_motion_detection_config, acc_config_t *sensor_config)
364 {
365 const hand_motion_detection_algo_config_t *algo_config = &hand_motion_detection_config->algo_config;
366 acc_config_profile_t profile = ACC_CONFIG_PROFILE_1;
367 uint16_t step_length = 6U;
368 float water_jet_half_width = algo_config->water_jet_width / 2.0f;
369 uint8_t subsweep_idx = 0U;
370 float profile_envelope_fwhm_m = acc_algorithm_get_fwhm(profile);
371
372 // Determine if subsweep between sensor and water jet is feasible
373 if (profile_envelope_fwhm_m < (algo_config->sensor_to_water_distance - water_jet_half_width))
374 {
375 int32_t start_point =
376 (int32_t)roundf((algo_config->sensor_to_water_distance - profile_envelope_fwhm_m - water_jet_half_width) / ACC_APPROX_BASE_STEP_LENGTH_M);
377 acc_config_subsweep_start_point_set(sensor_config, start_point, subsweep_idx);
378 acc_config_subsweep_num_points_set(sensor_config, 1U, subsweep_idx);
379 acc_config_subsweep_step_length_set(sensor_config, step_length, subsweep_idx);
380 acc_config_subsweep_profile_set(sensor_config, profile, subsweep_idx);
381 acc_config_subsweep_hwaas_set(sensor_config, algo_config->hwaas, subsweep_idx);
382 acc_config_subsweep_receiver_gain_set(sensor_config, 4U, subsweep_idx);
383
384 subsweep_idx++;
385 }
386
387 // Determine if subsweep after water jet is required
388 if (profile_envelope_fwhm_m + water_jet_half_width + algo_config->sensor_to_water_distance < algo_config->measurement_range_end)
389 {
390 float start_m = algo_config->sensor_to_water_distance + water_jet_half_width + profile_envelope_fwhm_m;
391 int32_t start_point = (int32_t)roundf(start_m / ACC_APPROX_BASE_STEP_LENGTH_M);
392 uint16_t num_points =
393 (uint16_t)roundf(fmaxf(1.0f, (algo_config->measurement_range_end - start_m) / ((float)step_length * ACC_APPROX_BASE_STEP_LENGTH_M)));
394
395 acc_config_subsweep_start_point_set(sensor_config, start_point, subsweep_idx);
396 acc_config_subsweep_num_points_set(sensor_config, num_points, subsweep_idx);
397 acc_config_subsweep_step_length_set(sensor_config, step_length, subsweep_idx);
398 acc_config_subsweep_profile_set(sensor_config, profile, subsweep_idx);
399 acc_config_subsweep_hwaas_set(sensor_config, algo_config->hwaas, subsweep_idx);
400 acc_config_subsweep_receiver_gain_set(sensor_config, 4U, subsweep_idx);
401
402 subsweep_idx++;
403 }
404
405 acc_config_num_subsweeps_set(sensor_config, subsweep_idx);
406 acc_config_frame_rate_set(sensor_config, 0.0f);
407 acc_config_sweep_rate_set(sensor_config, algo_config->sweep_rate);
408 acc_config_sweeps_per_frame_set(sensor_config, algo_config->sweeps_per_frame);
409 acc_config_inter_frame_idle_state_set(sensor_config, ACC_CONFIG_IDLE_STATE_SLEEP);
410 acc_config_inter_sweep_idle_state_set(sensor_config, ACC_CONFIG_IDLE_STATE_SLEEP);
411 }
412
413 static void set_processing_config(const hand_motion_detection_config_t *hand_motion_detection_config,
414 acc_detector_presence_processing_config_t *processing_config)
415 {
416 const hand_motion_detection_algo_config_t *algo_config = &hand_motion_detection_config->algo_config;
417
418 acc_detector_presence_processing_config_frame_rate_set(processing_config, algo_config->frame_rate);
419 acc_detector_presence_processing_config_intra_detection_set(processing_config, true);
420 acc_detector_presence_processing_config_inter_detection_set(processing_config, true);
421 acc_detector_presence_processing_config_intra_detection_threshold_set(processing_config, algo_config->threshold);
422 acc_detector_presence_processing_config_inter_detection_threshold_set(processing_config, algo_config->threshold);
423 acc_detector_presence_processing_config_inter_frame_presence_timeout_set(processing_config, 0U);
424 acc_detector_presence_processing_config_inter_frame_fast_cutoff_set(processing_config, 3.0f);
425 acc_detector_presence_processing_config_inter_frame_slow_cutoff_set(processing_config, 0.8f);
426 acc_detector_presence_processing_config_inter_frame_deviation_time_const_set(processing_config, 0.5f);
427 acc_detector_presence_processing_config_inter_output_time_const_set(processing_config, algo_config->filter_time_const);
428 acc_detector_presence_processing_config_intra_frame_time_const_set(processing_config, 0.15f);
429 acc_detector_presence_processing_config_intra_output_time_const_set(processing_config, algo_config->filter_time_const);
430 }
431
432 static hand_motion_detection_detection_state_t process_presence_processing_result(
433 hand_motion_detection_handle_t *handle,
434 const acc_detector_presence_processing_result_t *presence_processing_result)
435 {
436 hand_motion_detection_detection_state_t detection_state = HAND_MOTION_DETECTION_STATE_NO_DETECTION;
437
438 if (presence_processing_result->presence_detected)
439 {
440 handle->has_detected = true;
441 handle->update_index_at_detection = handle->update_index;
442 detection_state = HAND_MOTION_DETECTION_STATE_DETECTION;
443 }
444
445 if (handle->has_detected && detection_state != HAND_MOTION_DETECTION_STATE_DETECTION &&
446 ((handle->update_index - handle->update_index_at_detection) < handle->detection_retention_duration))
447 {
448 detection_state = HAND_MOTION_DETECTION_STATE_RETENTION;
449 }
450
451 handle->update_index++;
452
453 return detection_state;
454 }
455
456 static void determine_app_mode(hand_motion_detection_handle_t *handle, hand_motion_detection_result_t *result)
457 {
458 hand_motion_detection_app_mode_t new_app_mode = handle->app_mode;
459
460 if (handle->app_mode == HAND_MOTION_DETECTION_APP_MODE_PRESENCE)
461 {
462 if (result->presence_result.presence_detected)
463 {
464 new_app_mode = HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION;
465 }
466 }
467 else // HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION
468 {
469 if (handle->config.use_presence_detection)
470 {
471 if (result->algo_result.detection_state != HAND_MOTION_DETECTION_STATE_NO_DETECTION)
472 {
473 handle->hand_motion_detection_timer = 0U;
474 }
475 else if (handle->hand_motion_detection_timeout_duration < handle->hand_motion_detection_timer)
476 {
477 new_app_mode = HAND_MOTION_DETECTION_APP_MODE_PRESENCE;
478 }
479 else
480 {
481 handle->hand_motion_detection_timer++;
482 }
483 }
484 }
485
486 if (new_app_mode != handle->app_mode)
487 {
488 swap_app_mode(handle, new_app_mode);
489 }
490 }
491
492 static void swap_app_mode(hand_motion_detection_handle_t *handle, hand_motion_detection_app_mode_t new_app_mode)
493 {
494 handle->prepare_needed = true;
495 handle->app_mode = new_app_mode;
496
497 if (handle->app_mode == HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION)
498 {
499 acc_detector_presence_processing_reset(handle->hand_motion_detection_presence_processor);
500 reinit_hand_motion_detection_state(handle);
501 handle->hand_motion_detection_timer = 0U;
502
503 uint32_t sleep_time_ms = (uint32_t)(1000.0f / handle->config.algo_config.frame_rate);
504 acc_integration_set_periodic_wakeup(sleep_time_ms);
505 }
506 else
507 {
508 uint32_t sleep_time_ms = (uint32_t)(1000.0f / acc_detector_presence_config_frame_rate_get(handle->config.presence_config));
509 acc_integration_set_periodic_wakeup(sleep_time_ms);
510 }
511 }
acc_detector_presence_processing.h
acc_integration_mem_calloc
void * acc_integration_mem_calloc(size_t nmemb, size_t size)
Allocate dynamic memory.
Definition: acc_integration_stm32.c:597
acc_config_inter_frame_idle_state_set
void acc_config_inter_frame_idle_state_set(acc_config_t *config, acc_config_idle_state_t idle_state)
Set inter frame idle state.
acc_detector_presence_config_sweeps_per_frame_set
void acc_detector_presence_config_sweeps_per_frame_set(acc_detector_presence_config_t *presence_config, uint16_t sweeps_per_frame)
Set the number of sweeps per frame.
hand_motion_detection_handle::hand_motion_detection_presence_processing_config
acc_detector_presence_processing_config_t * hand_motion_detection_presence_processing_config
Definition: example_hand_motion_detection.c:36
acc_detector_presence_processing_create
acc_detector_presence_processing_handle_t * acc_detector_presence_processing_create(const acc_detector_presence_processing_config_t *processing_config, const acc_config_t *sensor_config)
Create a processing handle with the provided base configuration.
acc_detector_presence_processing_config_destroy
void acc_detector_presence_processing_config_destroy(acc_detector_presence_processing_config_t *processor_config)
Destroy a presence processor configuration.
HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION
@ HAND_MOTION_DETECTION_APP_MODE_HAND_MOTION
Definition: example_hand_motion_detection.h:32
hand_motion_detection_handle_destroy
void hand_motion_detection_handle_destroy(hand_motion_detection_handle_t *handle)
Destroy a hand_motion handle.
Definition: example_hand_motion_detection.c:207
set_sensor_config
static void set_sensor_config(const hand_motion_detection_config_t *hand_motion_detection_config, acc_config_t *sensor_config)
Definition: example_hand_motion_detection.c:363
acc_rss_a121.h
hand_motion_detection_algo_config_t::threshold
float threshold
Definition: example_hand_motion_detection.h:51
acc_processing_destroy
void acc_processing_destroy(acc_processing_t *handle)
Destroy a processing instance identified with the provided processing handle.
hand_motion_detection_handle::presence_metadata
acc_detector_presence_metadata_t presence_metadata
Definition: example_hand_motion_detection.c:40
acc_detector_presence_destroy
void acc_detector_presence_destroy(acc_detector_presence_handle_t *presence_handle)
Destroy a presence detector identified with the provided handle.
acc_detector_presence_processing_config_t
struct acc_detector_presence_processing_config acc_detector_presence_processing_config_t
Definition: acc_detector_presence_processing.h:25
acc_detector_presence_processing_config_inter_frame_fast_cutoff_set
void acc_detector_presence_processing_config_inter_frame_fast_cutoff_set(acc_detector_presence_processing_config_t *processing_config, float inter_frame_fast_cutoff)
Set the cutoff frequency of the low pass filter for the fast filtered absolute sweep mean.
hand_motion_detection_process
void hand_motion_detection_process(hand_motion_detection_handle_t *handle, void *buffer, hand_motion_detection_result_t *hand_motion_detection_result)
Process Sparse IQ data.
Definition: example_hand_motion_detection.c:322
buffer
void * buffer
Definition: i2c_example_cargo.c:40
acc_detector_presence_config_inter_frame_deviation_time_const_set
void acc_detector_presence_config_inter_frame_deviation_time_const_set(acc_detector_presence_config_t *presence_config, float inter_frame_deviation_time_const)
Set the time constant of the low pass filter for the inter-frame deviation between fast and slow.
acc_rss_get_buffer_size
bool acc_rss_get_buffer_size(const acc_config_t *config, uint32_t *buffer_size)
Get the buffer size needed for the specified config.
hand_motion_detection_algo_config_t::detection_retention_duration
float detection_retention_duration
Definition: example_hand_motion_detection.h:52
hand_motion_detection_algo_config_t::sweeps_per_frame
uint16_t sweeps_per_frame
Definition: example_hand_motion_detection.h:54
hand_motion_detection_algo_config_t::hwaas
uint16_t hwaas
Definition: example_hand_motion_detection.h:53
hand_motion_detection_result_t::presence_result
acc_detector_presence_result_t presence_result
Definition: example_hand_motion_detection.h:85
hand_motion_detection_handle::sensor_processing
acc_processing_t * sensor_processing
Definition: example_hand_motion_detection.c:34
acc_config_sweeps_per_frame_set
void acc_config_sweeps_per_frame_set(acc_config_t *config, uint16_t sweeps)
Set sweeps per frame.
acc_config_destroy
void acc_config_destroy(acc_config_t *config)
Destroy a configuration freeing any resources allocated.
hand_motion_detection_algo_config_t
Hand motion algo configuration.
Definition: example_hand_motion_detection.h:45
acc_detector_presence_result_t::processing_result
acc_processing_result_t processing_result
Definition: acc_detector_presence.h:82
hand_motion_detection_handle::prepare_needed
bool prepare_needed
Definition: example_hand_motion_detection.c:26
hand_motion_detection_config_t::algo_config
hand_motion_detection_algo_config_t algo_config
Definition: example_hand_motion_detection.h:64
acc_cal_result_t
The result from a completed calibration.
Definition: acc_definitions_a121.h:30
acc_detector_presence_config_frame_rate_set
void acc_detector_presence_config_frame_rate_set(acc_detector_presence_config_t *presence_config, float frame_rate)
Set the frame rate.
acc_processing_execute
void acc_processing_execute(acc_processing_t *handle, void *buffer, acc_processing_result_t *result)
Process the data according to the configuration used in create.
hand_motion_detection_handle::presence_detector
acc_detector_presence_handle_t * presence_detector
Definition: example_hand_motion_detection.c:39
acc_config_inter_sweep_idle_state_set
void acc_config_inter_sweep_idle_state_set(acc_config_t *config, acc_config_idle_state_t idle_state)
Set inter sweep idle state.
hand_motion_detection_algo_config_t::sensor_to_water_distance
float sensor_to_water_distance
Definition: example_hand_motion_detection.h:47
acc_config_create
acc_config_t * acc_config_create(void)
Create a configuration.
HAND_MOTION_DETECTION_STATE_RETENTION
@ HAND_MOTION_DETECTION_STATE_RETENTION
Definition: example_hand_motion_detection.h:39
hand_motion_detection_algo_config_t::measurement_range_end
float measurement_range_end
Definition: example_hand_motion_detection.h:49
acc_integration.h
hand_motion_detection_result_t
Result type.
Definition: example_hand_motion_detection.h:81
acc_detector_presence_get_buffer_size
bool acc_detector_presence_get_buffer_size(const acc_detector_presence_handle_t *presence_handle, uint32_t *buffer_size)
Get the buffer size needed for the provided presence detector handle.
hand_motion_detection_handle::hand_motion_detection_timer
uint16_t hand_motion_detection_timer
Definition: example_hand_motion_detection.c:44
hand_motion_detection_get_buffer_size
bool hand_motion_detection_get_buffer_size(hand_motion_detection_handle_t *handle, uint32_t *buffer_size)
Get buffer size needed.
Definition: example_hand_motion_detection.c:269
acc_detector_presence_processing_config_inter_frame_presence_timeout_set
void acc_detector_presence_processing_config_inter_frame_presence_timeout_set(acc_detector_presence_processing_config_t *processing_config, uint16_t inter_frame_presence_timeout)
Set the inter-frame presence timeout in seconds.
hand_motion_detection_result_t::app_mode
hand_motion_detection_app_mode_t app_mode
Definition: example_hand_motion_detection.h:83
config
cargo_config_t config
Definition: i2c_example_cargo.c:34
acc_config_frame_rate_set
void acc_config_frame_rate_set(acc_config_t *config, float frame_rate)
Set the frame rate.
acc_processing_metadata_t
Metadata that will be populated by the processing module during creation.
Definition: acc_processing.h:36
hand_motion_detection_config_log
void hand_motion_detection_config_log(hand_motion_detection_handle_t *handle)
Print configuration.
Definition: example_hand_motion_detection.c:240
cargo_config_t::sweeps_per_frame
uint16_t sweeps_per_frame
Definition: example_cargo.h:80
hand_motion_detection_handle::sensor_id
acc_sensor_id_t sensor_id
Definition: example_hand_motion_detection.c:32
hand_motion_detection_result_t::proc_result
acc_processing_result_t proc_result
Definition: example_hand_motion_detection.h:88
acc_integration_set_periodic_wakeup
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
Definition: acc_integration_stm32.c:496
set_processing_config
static void set_processing_config(const hand_motion_detection_config_t *hand_motion_detection_config, acc_detector_presence_processing_config_t *processing_config)
Definition: example_hand_motion_detection.c:413
acc_detector_presence_result_t
Presence detector results container.
Definition: acc_detector_presence.h:46
buffer_size
uint32_t buffer_size
Definition: i2c_example_cargo.c:41
hand_motion_detection_set_config
void hand_motion_detection_set_config(hand_motion_detection_preset_t preset, hand_motion_detection_config_t *config)
Set config specified by the preset.
Definition: example_hand_motion_detection.c:94
hand_motion_detection_handle::app_mode
hand_motion_detection_app_mode_t app_mode
Definition: example_hand_motion_detection.c:42
acc_detector_presence_processing_reset
bool acc_detector_presence_processing_reset(acc_detector_presence_processing_handle_t *processing_handle)
Reset existing processing buffers.
acc_detector_presence_processing_handle_t
struct acc_detector_presence_processing_handle acc_detector_presence_processing_handle_t
Definition: acc_detector_presence_processing.h:18
swap_app_mode
static void swap_app_mode(hand_motion_detection_handle_t *handle, hand_motion_detection_app_mode_t new_app_mode)
Definition: example_hand_motion_detection.c:492
sensor
acc_sensor_t * sensor
Definition: i2c_example_cargo.c:33
acc_detector_presence_processing_config_inter_output_time_const_set
void acc_detector_presence_processing_config_inter_output_time_const_set(acc_detector_presence_processing_config_t *processing_config, float inter_output_time_const)
Set the time constant for the output in the inter-frame part.
hand_motion_detection_config_destroy
void hand_motion_detection_config_destroy(hand_motion_detection_config_t *config)
Destroy a hand motion configuration.
Definition: example_hand_motion_detection.c:81
example_hand_motion_detection.h
hand_motion_detection_algo_config_t::water_jet_width
float water_jet_width
Definition: example_hand_motion_detection.h:48
acc_detector_presence_config_destroy
void acc_detector_presence_config_destroy(acc_detector_presence_config_t *presence_config)
Destroy a presence detector configuration.
acc_detector_presence_metadata_t
Definition: acc_detector_presence.h:88
acc_detector_presence_config_end_set
void acc_detector_presence_config_end_set(acc_detector_presence_config_t *presence_config, float end)
Set the end point of measurement interval in meters.
acc_detector_presence_config_intra_output_time_const_set
void acc_detector_presence_config_intra_output_time_const_set(acc_detector_presence_config_t *presence_config, float intra_output_time_const)
Set the time constant for the output in the intra-frame part.
handle
cargo_handle_t * handle
Definition: i2c_example_cargo.c:35
HAND_MOTION_DETECTION_APP_MODE_PRESENCE
@ HAND_MOTION_DETECTION_APP_MODE_PRESENCE
Definition: example_hand_motion_detection.h:31
acc_detector_presence_processing_config_inter_detection_set
void acc_detector_presence_processing_config_inter_detection_set(acc_detector_presence_processing_config_t *processing_config, bool enable)
Set inter-frame presence detection.
hand_motion_detection_prepare
bool hand_motion_detection_prepare(hand_motion_detection_handle_t *handle, acc_sensor_t *sensor, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size, bool force_prepare)
Prepare hand motion.
Definition: example_hand_motion_detection.c:295
acc_detector_presence_processing_config_frame_rate_set
void acc_detector_presence_processing_config_frame_rate_set(acc_detector_presence_processing_config_t *processing_config, float frame_rate)
Set the frame rate.
acc_detector_presence_processing_destroy
void acc_detector_presence_processing_destroy(acc_detector_presence_processing_handle_t *processing_handle)
Destroy a processing handle.
result
cargo_result_t result
Definition: i2c_example_cargo.c:43
acc_config_t
struct acc_config acc_config_t
Definition: acc_config.h:24
printf
#define printf
Definition: printf.h:60
HAND_MOTION_DETECTION_PRESET_FAUCET
@ HAND_MOTION_DETECTION_PRESET_FAUCET
Definition: example_hand_motion_detection.h:26
acc_detector_presence_processing_config_create
acc_detector_presence_processing_config_t * acc_detector_presence_processing_config_create(void)
Create a configuration for a presence processor.
acc_config_num_subsweeps_set
void acc_config_num_subsweeps_set(acc_config_t *config, uint8_t num_subsweeps)
Set the number of subsweeps to use.
hand_motion_detection_handle::hand_motion_detection_presence_processor
acc_detector_presence_processing_handle_t * hand_motion_detection_presence_processor
Definition: example_hand_motion_detection.c:37
acc_detector_presence_processing_config_intra_detection_set
void acc_detector_presence_processing_config_intra_detection_set(acc_detector_presence_processing_config_t *processing_config, bool enable)
Set intra-frame presence detection.
hand_motion_detection_config_create
hand_motion_detection_config_t * hand_motion_detection_config_create(void)
Create a hand motion configuration.
Definition: example_hand_motion_detection.c:63
hand_motion_detection_handle::config
hand_motion_detection_config_t config
Definition: example_hand_motion_detection.c:25
acc_config_subsweep_start_point_set
void acc_config_subsweep_start_point_set(acc_config_t *config, int32_t start_point, uint8_t index)
Set the starting point of the sweep.
acc_detector_presence_process
bool acc_detector_presence_process(acc_detector_presence_handle_t *presence_handle, void *buffer, acc_detector_presence_result_t *result)
Process the data according to the configuration used in acc_detector_presence_config_create.
acc_detector_presence_config_inter_output_time_const_set
void acc_detector_presence_config_inter_output_time_const_set(acc_detector_presence_config_t *presence_config, float inter_output_time_const)
Set the time constant for the output in the inter-frame part.
acc_config_sweep_rate_set
void acc_config_sweep_rate_set(acc_config_t *config, float sweep_rate)
Set the sweep rate.
acc_detector_presence_config_reset_filters_on_prepare_set
void acc_detector_presence_config_reset_filters_on_prepare_set(acc_detector_presence_config_t *presence_config, bool enable)
Set if the presence filters should reset on prepare.
acc_config_subsweep_profile_set
void acc_config_subsweep_profile_set(acc_config_t *config, acc_config_profile_t profile, uint8_t index)
Set a profile.
acc_detector_presence_processing_config_intra_detection_threshold_set
void acc_detector_presence_processing_config_intra_detection_threshold_set(acc_detector_presence_processing_config_t *processing_config, float intra_detection_threshold)
Set the detection threshold for the intra-frame presence detection.
determine_app_mode
static void determine_app_mode(hand_motion_detection_handle_t *handle, hand_motion_detection_result_t *result)
Definition: example_hand_motion_detection.c:456
ACC_APPROX_BASE_STEP_LENGTH_M
#define ACC_APPROX_BASE_STEP_LENGTH_M
Approximate minimum step length for a sensor measurement in meters.
Definition: acc_algorithm.h:19
acc_detector_presence_prepare
bool acc_detector_presence_prepare(const acc_detector_presence_handle_t *presence_handle, acc_detector_presence_config_t *presence_config, acc_sensor_t *sensor, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Prepare the detector to do a measurement.
hand_motion_detection_handle::has_detected
bool has_detected
Definition: example_hand_motion_detection.c:28
hand_motion_detection_handle::update_index
uint32_t update_index
Definition: example_hand_motion_detection.c:29
hand_motion_detection_handle::hand_motion_detection_timeout_duration
uint16_t hand_motion_detection_timeout_duration
Definition: example_hand_motion_detection.c:43
hand_motion_detection_algo_config_t::sweep_rate
float sweep_rate
Definition: example_hand_motion_detection.h:55
hand_motion_detection_algo_config_t::frame_rate
float frame_rate
Definition: example_hand_motion_detection.h:56
cargo_handle::presence_config
acc_detector_presence_config_t * presence_config
Definition: example_cargo.c:32
acc_processing_result_t::frame
acc_int16_complex_t * frame
Definition: acc_processing.h:91
HAND_MOTION_DETECTION_STATE_DETECTION
@ HAND_MOTION_DETECTION_STATE_DETECTION
Definition: example_hand_motion_detection.h:38
hand_motion_detection_handle::sensor_processing_metadata
acc_processing_metadata_t sensor_processing_metadata
Definition: example_hand_motion_detection.c:35
acc_detector_presence_processing_process
bool acc_detector_presence_processing_process(acc_detector_presence_processing_handle_t *processing_handle, void *buffer, const acc_int16_complex_t *frame, acc_detector_presence_processing_result_t *presence_result)
Process sensor data.
acc_sensor_id_t
uint32_t acc_sensor_id_t
Type representing a sensor ID.
Definition: acc_definitions_common.h:13
hand_motion_detection_preset_t
hand_motion_detection_preset_t
Definition: example_hand_motion_detection.h:21
acc_processing_t
struct acc_processing_handle acc_processing_t
Definition: acc_processing.h:30
acc_integration_log.h
ACC_LOG_FLOAT_TO_INTEGER
#define ACC_LOG_FLOAT_TO_INTEGER(a)
Definition: acc_integration_log.h:26
cargo_handle::presence_metadata
acc_detector_presence_metadata_t presence_metadata
Definition: example_cargo.c:34
reinit_hand_motion_detection_state
static void reinit_hand_motion_detection_state(hand_motion_detection_handle_t *handle)
Definition: example_hand_motion_detection.c:356
hand_motion_detection_algo_result_t::detection_state
hand_motion_detection_detection_state_t detection_state
Definition: example_hand_motion_detection.h:75
hand_motion_detection_result_t::presence_result_available
bool presence_result_available
Definition: example_hand_motion_detection.h:84
hand_motion_detection_handle::update_index_at_detection
uint32_t update_index_at_detection
Definition: example_hand_motion_detection.c:30
HAND_MOTION_DETECTION_STATE_NO_DETECTION
@ HAND_MOTION_DETECTION_STATE_NO_DETECTION
Definition: example_hand_motion_detection.h:37
acc_detector_presence_config_log
void acc_detector_presence_config_log(acc_detector_presence_config_t *presence_config)
Print a configuration to the log.
acc_detector_presence_processing_result_t::presence_detected
bool presence_detected
Definition: acc_detector_presence_processing.h:32
hand_motion_detection_result_t::algo_result
hand_motion_detection_algo_result_t algo_result
Definition: example_hand_motion_detection.h:87
acc_config_subsweep_receiver_gain_set
void acc_config_subsweep_receiver_gain_set(acc_config_t *config, uint8_t gain, uint8_t index)
Set receiver gain setting.
acc_algorithm.h
acc_detector_presence_config_frame_rate_get
float acc_detector_presence_config_frame_rate_get(const acc_detector_presence_config_t *presence_config)
Get the frame rate.
acc_sensor_prepare
bool acc_sensor_prepare(acc_sensor_t *sensor, const acc_config_t *config, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Prepare a sensor to do a measurement.
acc_algorithm_get_fwhm
float acc_algorithm_get_fwhm(acc_config_profile_t profile)
Get the envelope Full Width Half Maximum in meters given a profile.
Definition: acc_algorithm.c:745
acc_integration_mem_free
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
Definition: acc_integration_stm32.c:602
hand_motion_detection_detection_state_t
hand_motion_detection_detection_state_t
Definition: example_hand_motion_detection.h:35
acc_config_profile_t
acc_config_profile_t
Profile.
Definition: acc_definitions_a121.h:49
acc_detector_presence_processing_result_t
Presence detector results container.
Definition: acc_detector_presence_processing.h:30
acc_detector_presence_create
acc_detector_presence_handle_t * acc_detector_presence_create(acc_detector_presence_config_t *presence_config, acc_detector_presence_metadata_t *metadata)
Create a presence detector with the provided configuration.
acc_config_subsweep_hwaas_set
void acc_config_subsweep_hwaas_set(acc_config_t *config, uint16_t hwaas, uint8_t index)
Set the hardware accelerated average samples (HWAAS)
acc_config_log
void acc_config_log(const acc_config_t *config)
Print a configuration to the log.
acc_config_subsweep_step_length_set
void acc_config_subsweep_step_length_set(acc_config_t *config, uint16_t step_length, uint8_t index)
Set the step length in a sweep.
hand_motion_detection_handle::detection_retention_duration
uint16_t detection_retention_duration
Definition: example_hand_motion_detection.c:45
acc_config.h
ACC_CONFIG_IDLE_STATE_SLEEP
@ ACC_CONFIG_IDLE_STATE_SLEEP
Definition: acc_definitions_a121.h:74
acc_detector_presence_processing_config_intra_frame_time_const_set
void acc_detector_presence_processing_config_intra_frame_time_const_set(acc_detector_presence_processing_config_t *processing_config, float intra_frame_time_const)
Set the time constant for the depthwise filtering in the intra-frame part.
acc_detector_presence_processing_config_intra_output_time_const_set
void acc_detector_presence_processing_config_intra_output_time_const_set(acc_detector_presence_processing_config_t *processing_config, float intra_output_time_const)
Set the time constant for the output in the intra-frame part.
acc_detector_presence_handle_t
struct acc_detector_presence_handle acc_detector_presence_handle_t
Definition: acc_detector_presence.h:34
hand_motion_detection_app_mode_t
hand_motion_detection_app_mode_t
Definition: example_hand_motion_detection.h:29
acc_config_subsweep_num_points_set
void acc_config_subsweep_num_points_set(acc_config_t *config, uint16_t num_points, uint8_t index)
Set the number of data points to measure.
hand_motion_detection_handle::hand_motion_detection_sensor_config
acc_config_t * hand_motion_detection_sensor_config
Definition: example_hand_motion_detection.c:33
acc_detector_presence_config_create
acc_detector_presence_config_t * acc_detector_presence_config_create(void)
Create a configuration for a presence detector.
PRIfloat
#define PRIfloat
Specifier for printing float type using integers.
Definition: acc_integration_log.h:31
acc_detector_presence_processing_config_inter_frame_deviation_time_const_set
void acc_detector_presence_processing_config_inter_frame_deviation_time_const_set(acc_detector_presence_processing_config_t *processing_config, float inter_frame_deviation_time_const)
Set the time constant of the low pass filter for the inter-frame deviation between fast and slow.
acc_detector_presence_processing_config_inter_frame_slow_cutoff_set
void acc_detector_presence_processing_config_inter_frame_slow_cutoff_set(acc_detector_presence_processing_config_t *processing_config, float inter_frame_slow_cutoff)
Set the cutoff frequency of the low pass filter for the slow filtered absolute sweep mean.
cargo_result_t::presence_detected
bool presence_detected
Definition: example_cargo.h:134
hand_motion_detection_handle_create
hand_motion_detection_handle_t * hand_motion_detection_handle_create(const hand_motion_detection_config_t *hand_motion_detection_config, acc_sensor_id_t sensor_id)
Create a hand_motion handle.
Definition: example_hand_motion_detection.c:137
acc_detector_presence_config_start_set
void acc_detector_presence_config_start_set(acc_detector_presence_config_t *presence_config, float start)
Set the start point of measurement interval in meters.
hand_motion_detection_result_t::algo_result_available
bool algo_result_available
Definition: example_hand_motion_detection.h:86
ACC_CONFIG_PROFILE_1
@ ACC_CONFIG_PROFILE_1
Definition: acc_definitions_a121.h:52
hand_motion_detection_handle
Definition: example_hand_motion_detection.c:23
acc_detector_presence.h
HAND_MOTION_DETECTION_PRESET_NONE
@ HAND_MOTION_DETECTION_PRESET_NONE
Definition: example_hand_motion_detection.h:24
acc_processing_create
acc_processing_t * acc_processing_create(const acc_config_t *config, acc_processing_metadata_t *processing_metadata)
Create a processing instance with the provided configuration.
hand_motion_detection_config_t::hand_detection_timeout
float hand_detection_timeout
Definition: example_hand_motion_detection.h:66
hand_motion_detection_algo_config_t::filter_time_const
float filter_time_const
Definition: example_hand_motion_detection.h:50
acc_processing.h
acc_sensor_t
struct acc_sensor acc_sensor_t
Definition: acc_sensor.h:31
acc_detector_presence_config_intra_frame_time_const_set
void acc_detector_presence_config_intra_frame_time_const_set(acc_detector_presence_config_t *presence_config, float intra_frame_time_const)
Set the time constant for the depthwise filtering in the intra-frame part.
acc_detector_presence_processing_get_buffer_size
uint32_t acc_detector_presence_processing_get_buffer_size(const acc_config_t *sensor_config)
Get the buffer size needed for presence processing.
acc_detector_presence_processing_config_inter_detection_threshold_set
void acc_detector_presence_processing_config_inter_detection_threshold_set(acc_detector_presence_processing_config_t *processing_config, float inter_detection_threshold)
Set the detection threshold for the inter-frame presence detection.
acc_detector_presence_config_frame_rate_app_driven_set
void acc_detector_presence_config_frame_rate_app_driven_set(acc_detector_presence_config_t *presence_config, bool enable)
Set if the application should maintain the requested frame rate.
process_presence_processing_result
static hand_motion_detection_detection_state_t process_presence_processing_result(hand_motion_detection_handle_t *handle, const acc_detector_presence_processing_result_t *presence_processing_result)
Definition: example_hand_motion_detection.c:432
hand_motion_detection_config_t
Configuration for hand_motion.
Definition: example_hand_motion_detection.h:62