Go to the documentation of this file.
21 #define MODULE "example_hand_motion_detection"
71 if (
config->presence_config == NULL)
85 if (
config->presence_config != NULL)
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;
110 config->algo_config.hwaas = 32U;
112 config->algo_config.sweep_rate = 1000.0f;
113 config->algo_config.frame_rate = 10.0f;
129 config->hand_detection_timeout = 5.0f;
130 config->use_presence_detection =
true;
142 bool status =
handle != NULL;
146 handle->config = *hand_motion_detection_config;
147 handle->prepare_needed =
true;
149 handle->sensor_id = sensor_id;
151 handle->hand_motion_detection_timeout_duration =
153 handle->hand_motion_detection_timer = 0U;
162 status =
handle->hand_motion_detection_sensor_config != NULL &&
handle->hand_motion_detection_presence_processing_config != NULL;
171 handle->hand_motion_detection_presence_processor =
173 handle->hand_motion_detection_sensor_config);
175 status =
handle->hand_motion_detection_presence_processor != NULL;
180 if (
handle->config.use_presence_detection)
186 status =
handle->presence_detector != NULL;
193 uint32_t sleep_time_ms = (uint32_t)(1000.0f /
handle->config.algo_config.frame_rate);
211 if (
handle->presence_detector != NULL)
216 if (
handle->hand_motion_detection_presence_processor != NULL)
221 if (
handle->sensor_processing != NULL)
226 if (
handle->hand_motion_detection_presence_processing_config != NULL)
231 if (
handle->hand_motion_detection_sensor_config != NULL)
251 printf(
"hwaas: %" PRIu16
"\n",
handle->config.algo_config.hwaas);
252 printf(
"sweeps_per_frame: %" PRIu16
"\n",
handle->config.algo_config.sweeps_per_frame);
256 printf(
"use_presence_detection: %s\n",
handle->config.use_presence_detection ?
"True" :
"False");
258 printf(
"Sensor config:\n");
261 if (
handle->config.use_presence_detection)
263 printf(
"Presence config:\n");
271 uint32_t hand_motion_detection_buffer_size = 0U;
272 uint32_t presence_detector_buffer_size = 0U;
280 if (
handle->config.use_presence_detection)
289 (hand_motion_detection_buffer_size > presence_detector_buffer_size) ? hand_motion_detection_buffer_size : presence_detector_buffer_size;
304 if (
handle->prepare_needed || force_prepare)
316 handle->prepare_needed =
false;
344 &presence_processing_result);
358 handle->has_detected =
false;
359 handle->update_index = 0U;
360 handle->update_index_at_detection = 0U;
367 uint16_t step_length = 6U;
369 uint8_t subsweep_idx = 0U;
375 int32_t start_point =
392 uint16_t num_points =
440 handle->has_detected =
true;
441 handle->update_index_at_detection =
handle->update_index;
446 ((
handle->update_index -
handle->update_index_at_detection) <
handle->detection_retention_duration))
453 return detection_state;
469 if (
handle->config.use_presence_detection)
473 handle->hand_motion_detection_timer = 0U;
475 else if (
handle->hand_motion_detection_timeout_duration <
handle->hand_motion_detection_timer)
481 handle->hand_motion_detection_timer++;
486 if (new_app_mode !=
handle->app_mode)
494 handle->prepare_needed =
true;
495 handle->app_mode = new_app_mode;
501 handle->hand_motion_detection_timer = 0U;
503 uint32_t sleep_time_ms = (uint32_t)(1000.0f /
handle->config.algo_config.frame_rate);
void * acc_integration_mem_calloc(size_t nmemb, size_t size)
Allocate dynamic memory.
void acc_config_inter_frame_idle_state_set(acc_config_t *config, acc_config_idle_state_t idle_state)
Set inter frame idle state.
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.
acc_detector_presence_processing_config_t * hand_motion_detection_presence_processing_config
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.
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
void hand_motion_detection_handle_destroy(hand_motion_detection_handle_t *handle)
Destroy a hand_motion handle.
static void set_sensor_config(const hand_motion_detection_config_t *hand_motion_detection_config, acc_config_t *sensor_config)
void acc_processing_destroy(acc_processing_t *handle)
Destroy a processing instance identified with the provided processing handle.
acc_detector_presence_metadata_t presence_metadata
void acc_detector_presence_destroy(acc_detector_presence_handle_t *presence_handle)
Destroy a presence detector identified with the provided handle.
struct acc_detector_presence_processing_config acc_detector_presence_processing_config_t
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.
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.
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.
float detection_retention_duration
uint16_t sweeps_per_frame
acc_detector_presence_result_t presence_result
acc_processing_t * sensor_processing
void acc_config_sweeps_per_frame_set(acc_config_t *config, uint16_t sweeps)
Set sweeps per frame.
void acc_config_destroy(acc_config_t *config)
Destroy a configuration freeing any resources allocated.
Hand motion algo configuration.
acc_processing_result_t processing_result
hand_motion_detection_algo_config_t algo_config
The result from a completed calibration.
void acc_detector_presence_config_frame_rate_set(acc_detector_presence_config_t *presence_config, float frame_rate)
Set the frame rate.
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.
acc_detector_presence_handle_t * presence_detector
void acc_config_inter_sweep_idle_state_set(acc_config_t *config, acc_config_idle_state_t idle_state)
Set inter sweep idle state.
float sensor_to_water_distance
acc_config_t * acc_config_create(void)
Create a configuration.
@ HAND_MOTION_DETECTION_STATE_RETENTION
float measurement_range_end
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.
uint16_t hand_motion_detection_timer
bool hand_motion_detection_get_buffer_size(hand_motion_detection_handle_t *handle, uint32_t *buffer_size)
Get buffer size needed.
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_app_mode_t app_mode
void acc_config_frame_rate_set(acc_config_t *config, float frame_rate)
Set the frame rate.
void hand_motion_detection_config_log(hand_motion_detection_handle_t *handle)
Print configuration.
uint16_t sweeps_per_frame
acc_sensor_id_t sensor_id
acc_processing_result_t proc_result
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
static void set_processing_config(const hand_motion_detection_config_t *hand_motion_detection_config, acc_detector_presence_processing_config_t *processing_config)
Presence detector results container.
void hand_motion_detection_set_config(hand_motion_detection_preset_t preset, hand_motion_detection_config_t *config)
Set config specified by the preset.
hand_motion_detection_app_mode_t app_mode
bool acc_detector_presence_processing_reset(acc_detector_presence_processing_handle_t *processing_handle)
Reset existing processing buffers.
struct acc_detector_presence_processing_handle acc_detector_presence_processing_handle_t
static void swap_app_mode(hand_motion_detection_handle_t *handle, hand_motion_detection_app_mode_t new_app_mode)
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.
void hand_motion_detection_config_destroy(hand_motion_detection_config_t *config)
Destroy a hand motion configuration.
void acc_detector_presence_config_destroy(acc_detector_presence_config_t *presence_config)
Destroy a presence detector configuration.
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.
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.
@ HAND_MOTION_DETECTION_APP_MODE_PRESENCE
void acc_detector_presence_processing_config_inter_detection_set(acc_detector_presence_processing_config_t *processing_config, bool enable)
Set inter-frame presence detection.
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.
void acc_detector_presence_processing_config_frame_rate_set(acc_detector_presence_processing_config_t *processing_config, float frame_rate)
Set the frame rate.
void acc_detector_presence_processing_destroy(acc_detector_presence_processing_handle_t *processing_handle)
Destroy a processing handle.
struct acc_config acc_config_t
@ HAND_MOTION_DETECTION_PRESET_FAUCET
acc_detector_presence_processing_config_t * acc_detector_presence_processing_config_create(void)
Create a configuration for a presence processor.
void acc_config_num_subsweeps_set(acc_config_t *config, uint8_t num_subsweeps)
Set the number of subsweeps to use.
acc_detector_presence_processing_handle_t * hand_motion_detection_presence_processor
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_t * hand_motion_detection_config_create(void)
Create a hand motion configuration.
hand_motion_detection_config_t config
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.
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.
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.
void acc_config_sweep_rate_set(acc_config_t *config, float sweep_rate)
Set the sweep rate.
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.
void acc_config_subsweep_profile_set(acc_config_t *config, acc_config_profile_t profile, uint8_t index)
Set a profile.
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.
static void determine_app_mode(hand_motion_detection_handle_t *handle, hand_motion_detection_result_t *result)
#define ACC_APPROX_BASE_STEP_LENGTH_M
Approximate minimum step length for a sensor measurement in meters.
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.
uint16_t hand_motion_detection_timeout_duration
acc_detector_presence_config_t * presence_config
acc_int16_complex_t * frame
@ HAND_MOTION_DETECTION_STATE_DETECTION
acc_processing_metadata_t sensor_processing_metadata
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.
uint32_t acc_sensor_id_t
Type representing a sensor ID.
hand_motion_detection_preset_t
struct acc_processing_handle acc_processing_t
#define ACC_LOG_FLOAT_TO_INTEGER(a)
acc_detector_presence_metadata_t presence_metadata
static void reinit_hand_motion_detection_state(hand_motion_detection_handle_t *handle)
hand_motion_detection_detection_state_t detection_state
bool presence_result_available
uint32_t update_index_at_detection
@ HAND_MOTION_DETECTION_STATE_NO_DETECTION
void acc_detector_presence_config_log(acc_detector_presence_config_t *presence_config)
Print a configuration to the log.
hand_motion_detection_algo_result_t algo_result
void acc_config_subsweep_receiver_gain_set(acc_config_t *config, uint8_t gain, uint8_t index)
Set receiver gain setting.
float acc_detector_presence_config_frame_rate_get(const acc_detector_presence_config_t *presence_config)
Get the frame rate.
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.
float acc_algorithm_get_fwhm(acc_config_profile_t profile)
Get the envelope Full Width Half Maximum in meters given a profile.
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
hand_motion_detection_detection_state_t
acc_config_profile_t
Profile.
Presence detector results container.
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.
void acc_config_subsweep_hwaas_set(acc_config_t *config, uint16_t hwaas, uint8_t index)
Set the hardware accelerated average samples (HWAAS)
void acc_config_log(const acc_config_t *config)
Print a configuration to the log.
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.
uint16_t detection_retention_duration
@ ACC_CONFIG_IDLE_STATE_SLEEP
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.
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.
struct acc_detector_presence_handle acc_detector_presence_handle_t
hand_motion_detection_app_mode_t
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.
acc_config_t * hand_motion_detection_sensor_config
acc_detector_presence_config_t * acc_detector_presence_config_create(void)
Create a configuration for a presence detector.
#define PRIfloat
Specifier for printing float type using integers.
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.
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.
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.
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.
bool algo_result_available
@ HAND_MOTION_DETECTION_PRESET_NONE
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.
float hand_detection_timeout
struct acc_sensor acc_sensor_t
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.
uint32_t acc_detector_presence_processing_get_buffer_size(const acc_config_t *sensor_config)
Get the buffer size needed for presence processing.
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.
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.
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)
Configuration for hand_motion.