Go to the documentation of this file.
25 #define SENSOR_TIMEOUT_MS 1000U
26 #define DEFAULT_UPDATE_RATE 1.0f
27 #define CLOSE_RANGE_START 0.07f
30 #define SMALL_TANK_MEDIAN_FILTER_LENGTH 3U
31 #define SMALL_TANK_NUM_MEDIANS_TO_AVERAGE 2U
32 #define SMALL_TANK_RANGE_START_M 0.03f
33 #define SMALL_TANK_RANGE_END_M 0.5f
34 #define SMALL_TANK_MAX_STEP_LENGTH 12U
35 #define SMALL_TANK_MAX_PROFILE ACC_CONFIG_PROFILE_3
36 #define SMALL_TANK_NUM_FRAMES_REC 50U
37 #define SMALL_TANK_PEAK_SORTING ACC_DETECTOR_DISTANCE_PEAK_SORTING_CLOSEST
38 #define SMALL_TANK_REFLECTOR_SHAPE ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_PLANAR
39 #define SMALL_TANK_THRESHOLD_METHOD ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_CFAR
40 #define SMALL_TANK_FIXED_AMPLITUDE_THRESHOLD 100.0f
41 #define SMALL_TANK_FIXED_STRENGTH_THRESHOLD 0.0f
42 #define SMALL_TANK_THRESHOLD_SENSITIVITY 0.0f
43 #define SMALL_TANK_SIGNAL_QUALITY 3.0f
44 #define SMALL_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION false
47 #define MEDIUM_TANK_MEDIAN_FILTER_LENGTH 3U
48 #define MEDIUM_TANK_NUM_MEDIANS_TO_AVERAGE 1U
49 #define MEDIUM_TANK_RANGE_START_M 0.05f
50 #define MEDIUM_TANK_RANGE_END_M 6.0f
51 #define MEDIUM_TANK_MAX_STEP_LENGTH 0U // 0 means no limit
52 #define MEDIUM_TANK_MAX_PROFILE ACC_CONFIG_PROFILE_5
53 #define MEDIUM_TANK_NUM_FRAMES_REC 50U
54 #define MEDIUM_TANK_PEAK_SORTING ACC_DETECTOR_DISTANCE_PEAK_SORTING_STRONGEST
55 #define MEDIUM_TANK_REFLECTOR_SHAPE ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_PLANAR
56 #define MEDIUM_TANK_THRESHOLD_METHOD ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_CFAR
57 #define MEDIUM_TANK_FIXED_AMPLITUDE_THRESHOLD 100.0f
58 #define MEDIUM_TANK_FIXED_STRENGTH_THRESHOLD 3.0f
59 #define MEDIUM_TANK_THRESHOLD_SENSITIVITY 0.0f
60 #define MEDIUM_TANK_SIGNAL_QUALITY 19.0f
61 #define MEDIUM_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION false
64 #define LARGE_TANK_MEDIAN_FILTER_LENGTH 1U
65 #define LARGE_TANK_NUM_MEDIANS_TO_AVERAGE 1U
66 #define LARGE_TANK_RANGE_START_M 0.1f
67 #define LARGE_TANK_RANGE_END_M 15.0f
68 #define LARGE_TANK_MAX_STEP_LENGTH 0U // 0 means no limit
69 #define LARGE_TANK_MAX_PROFILE ACC_CONFIG_PROFILE_5
70 #define LARGE_TANK_NUM_FRAMES_REC 50U
71 #define LARGE_TANK_PEAK_SORTING ACC_DETECTOR_DISTANCE_PEAK_SORTING_STRONGEST
72 #define LARGE_TANK_REFLECTOR_SHAPE ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_PLANAR
73 #define LARGE_TANK_THRESHOLD_METHOD ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_CFAR
74 #define LARGE_TANK_FIXED_AMPLITUDE_THRESHOLD 100.0f
75 #define LARGE_TANK_FIXED_STRENGTH_THRESHOLD 5.0f
76 #define LARGE_TANK_THRESHOLD_SENSITIVITY 0.0f
77 #define LARGE_TANK_SIGNAL_QUALITY 20.0f
78 #define LARGE_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION false
115 #define DEFAULT_PRESET_CONFIG TANK_LEVEL_PRESET_CONFIG_SMALL_TANK
180 static float median(
float *array, uint16_t array_length);
182 static float nanmean(
float *array, uint16_t array_length);
209 if (context.
app_config->distance_config == NULL)
211 printf(
"acc_detector_distance_config_create() failed\n");
224 printf(
"Initializing detector context failed\n");
234 if (context.
sensor == NULL)
236 printf(
"acc_sensor_create() failed\n");
245 printf(
"Sensor calibration failed\n");
252 printf(
"Detector calibration failed\n");
264 printf(
"Could not get next result\n");
274 printf(
"Sensor recalibration and detector calibration update needed ... \n");
278 printf(
"Sensor calibration failed\n");
286 printf(
"Detector calibration update failed\n");
291 printf(
"Sensor recalibration and detector calibration update done!\n");
308 printf(
"Application finished OK\n");
326 if (context->
sensor != NULL)
421 printf(
"acc_detector_distance_create() failed\n");
427 printf(
"acc_detector_distance_get_sizes() failed\n");
432 if (context->
buffer == NULL)
434 printf(
"sensor buffer allocation failed\n");
441 printf(
"calibration buffer allocation failed\n");
450 printf(
"level history buffer allocation failed\n");
459 printf(
"median vector allocation failed\n");
474 bool cal_complete =
false;
475 const uint16_t calibration_retries = 1U;
478 for (uint16_t i = 0; !status && (i <= calibration_retries); i++)
488 if (status && !cal_complete)
492 }
while (status && !cal_complete);
503 printf(
"acc_sensor_calibrate() failed\n");
570 bool result_available =
false;
581 printf(
"acc_detector_distance_prepare() failed\n");
587 printf(
"acc_sensor_measure() failed\n");
593 printf(
"Sensor interrupt timeout\n");
599 printf(
"acc_sensor_read() failed\n");
610 printf(
"acc_detector_distance_process() failed\n");
613 }
while (!result_available);
618 static float median(
float *array, uint16_t array_length)
623 for (uint16_t i = 0U; i < array_length && status; i++)
640 static float nanmean(
float *array, uint16_t array_length)
642 uint16_t samples = 0U;
645 for (uint16_t i = 0U; i < array_length; i++)
647 if (!isnan(array[i]))
654 return samples > 0U ? sum / (float)samples : (
float)NAN;
661 app_result->
level = 0.0f;
707 else if ((level > (context->
app_config->tank_range_end_m - context->
app_config->tank_range_start_m)) &&
715 app_result->
level = level;
726 app_result->
level = (float)NAN;
740 printf(
"Level within range\n");
#define SMALL_TANK_FIXED_AMPLITUDE_THRESHOLD
#define SMALL_TANK_RANGE_START_M
static bool full_detector_calibration(app_context_t *context, const acc_cal_result_t *sensor_cal_result)
#define SMALL_TANK_SIGNAL_QUALITY
void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id)
Power off sensor supply.
uint16_t level_history_length
@ TANK_LEVEL_PRESET_CONFIG_MEDIUM_TANK
acc_detector_cal_result_dynamic_t detector_cal_result_dynamic
bool acc_detector_distance_get_sizes(const acc_detector_distance_handle_t *handle, uint32_t *buffer_size, uint32_t *detector_cal_result_static_size)
Get the memory size needed to use the Distance Detector API functions.
#define MEDIUM_TANK_FIXED_STRENGTH_THRESHOLD
uint16_t median_filter_length
acc_ref_app_smart_presence_config_t * app_config
void acc_detector_distance_config_peak_sorting_set(acc_detector_distance_config_t *config, acc_detector_distance_peak_sorting_t peak_sorting)
Set peak sorting method.
peak_status_t peak_status
#define MEDIUM_TANK_THRESHOLD_METHOD
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
static float nanmean(float *array, uint16_t array_length)
@ TANK_LEVEL_PRESET_CONFIG_SMALL_TANK
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
#define MEDIUM_TANK_FIXED_AMPLITUDE_THRESHOLD
#define LARGE_TANK_SIGNAL_QUALITY
acc_cal_result_t sensor_cal_result
#define SMALL_TANK_MAX_STEP_LENGTH
static void process_detector_result(const acc_detector_distance_result_t *distance_result, app_result_t *app_result, app_context_t *context)
#define SMALL_TANK_PEAK_SORTING
void acc_detector_distance_config_threshold_method_set(acc_detector_distance_config_t *config, acc_detector_distance_threshold_method_t threshold_method)
Set threshold method.
static void set_config(acc_ref_app_tank_level_config_t *app_config, tank_level_preset_config_t preset)
#define MEDIUM_TANK_MAX_STEP_LENGTH
The result from a completed calibration.
void acc_detector_distance_config_start_set(acc_detector_distance_config_t *config, float start_m)
Set start of measured interval (m)
#define MEDIUM_TANK_MAX_PROFILE
void acc_detector_distance_config_fixed_amplitude_threshold_value_set(acc_detector_distance_config_t *config, float fixed_threshold_value)
Set fixed amplitude threshold value.
#define SMALL_TANK_RANGE_END_M
#define MEDIUM_TANK_PEAK_SORTING
acc_ref_app_tank_level_config_t * app_config
static float get_detector_end_m(acc_ref_app_tank_level_config_t *app_config)
static float median(float *array, uint16_t array_length)
acc_detector_distance_handle_t * detector_handle
acc_detector_distance_handle_t * acc_detector_distance_create(const acc_detector_distance_config_t *config)
Create Distance Detector handle using the provided Distance Detector configuration.
#define LARGE_TANK_PEAK_SORTING
#define LARGE_TANK_FIXED_AMPLITUDE_THRESHOLD
void acc_detector_distance_config_destroy(acc_detector_distance_config_t *config)
Destroy Distance Detector configuration.
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
#define SMALL_TANK_NUM_FRAMES_REC
uint16_t mean_edge_status_count
#define MEDIUM_TANK_MEDIAN_FILTER_LENGTH
#define SMALL_TANK_FIXED_STRENGTH_THRESHOLD
@ TANK_LEVEL_PRESET_CONFIG_LARGE_TANK
bool acc_detector_distance_calibrate(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, uint8_t *detector_cal_result_static, uint32_t detector_cal_result_static_size, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *calibration_complete)
Calibrate detector.
#define SMALL_TANK_THRESHOLD_METHOD
uint8_t * detector_cal_result_static
@ PEAK_STATUS_NO_DETECTION
bool acc_detector_distance_process(acc_detector_distance_handle_t *handle, void *buffer, uint8_t *detector_cal_result_static, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *result_available, acc_detector_distance_result_t *result)
Process sensor data into a Detector result.
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
#define LARGE_TANK_RANGE_START_M
#define MEDIUM_TANK_THRESHOLD_SENSITIVITY
static bool update_detector_calibration(app_context_t *context, const acc_cal_result_t *sensor_cal_result)
#define SMALL_TANK_NUM_MEDIANS_TO_AVERAGE
#define LARGE_TANK_MAX_PROFILE
#define MEDIUM_TANK_SIGNAL_QUALITY
#define CLOSE_RANGE_START
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
static bool detector_get_next(app_context_t *context, const acc_cal_result_t *sensor_cal_result, acc_detector_distance_result_t *detector_result)
The result from a completed calibration update.
void acc_detector_distance_config_close_range_leakage_cancellation_set(acc_detector_distance_config_t *config, bool enable)
Enable close range leakage cancellation.
int acconeer_main(int argc, char *argv[])
Assembly test example.
#define LARGE_TANK_REFLECTOR_SHAPE
void acc_detector_distance_config_max_profile_set(acc_detector_distance_config_t *config, acc_config_profile_t max_profile)
Set maximum Profile.
uint32_t detector_cal_result_static_size
void acc_detector_distance_destroy(acc_detector_distance_handle_t *handle)
Destroy Distance Detector handle, freeing its resources.
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
#define LARGE_TANK_THRESHOLD_METHOD
void acc_detector_distance_config_signal_quality_set(acc_detector_distance_config_t *config, float signal_quality)
Set signal quality (dB)
const char * acc_version_get(void)
Get the version of the Acconeer software.
uint16_t median_vector_length
static bool sensor_calibration(acc_sensor_t *sensor, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
#define LARGE_TANK_NUM_FRAMES_REC
#define SMALL_TANK_THRESHOLD_SENSITIVITY
uint16_t num_medians_to_average
@ TANK_LEVEL_PRESET_CONFIG_NONE
bool acc_detector_distance_prepare(const acc_detector_distance_handle_t *handle, const acc_detector_distance_config_t *config, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size)
Prepare the Detector for measurements.
acc_detector_distance_config_t * distance_config
Distance Detector result returned from acc_detector_distance_process.
#define SMALL_TANK_MAX_PROFILE
#define MEDIUM_TANK_RANGE_END_M
#define MEDIUM_TANK_REFLECTOR_SHAPE
#define MEDIUM_TANK_RANGE_START_M
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
void acc_detector_distance_config_end_set(acc_detector_distance_config_t *config, float end_m)
Set end of measured interval (m)
uint16_t median_edge_status_count
#define DEFAULT_UPDATE_RATE
static bool initialize_application_resources(app_context_t *context)
static void cleanup(app_context_t *context)
void acc_detector_distance_config_num_frames_recorded_threshold_set(acc_detector_distance_config_t *config, uint16_t num_frames)
Set number of frames to use for recorded threshold.
#define LARGE_TANK_NUM_MEDIANS_TO_AVERAGE
struct acc_detector_distance_handle acc_detector_distance_handle_t
Distance Detector handle.
#define LARGE_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
#define SMALL_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
tank_level_preset_config_t
#define ACC_LOG_FLOAT_TO_INTEGER(a)
float acc_algorithm_median_f32(float *data, uint16_t length)
Calculate median of input data.
#define LARGE_TANK_RANGE_END_M
void acc_sensor_status(const acc_sensor_t *sensor)
Check the status of the sensor.
bool acc_detector_distance_update_calibration(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *calibration_complete)
Perform a subset of the full Detector calibration.
bool near_start_edge_status
#define LARGE_TANK_FIXED_STRENGTH_THRESHOLD
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
void acc_detector_distance_config_reflector_shape_set(acc_detector_distance_config_t *config, acc_detector_distance_reflector_shape_t reflector_shape)
Set reflector shape.
#define MEDIUM_TANK_NUM_FRAMES_REC
void acc_integration_sleep_until_periodic_wakeup(void)
Put the system in sleep until the periodic timer triggers.
void acc_detector_distance_config_threshold_sensitivity_set(acc_detector_distance_config_t *config, float threshold_sensitivity)
Set threshold sensitivity.
acc_detector_distance_config_t * acc_detector_distance_config_create(void)
Create a Distance Detector configuration.
void acc_detector_distance_config_fixed_strength_threshold_value_set(acc_detector_distance_config_t *config, float fixed_threshold_value)
Set fixed strength threshold value.
#define SMALL_TANK_MEDIAN_FILTER_LENGTH
bool acc_sensor_calibrate(acc_sensor_t *sensor, bool *cal_complete, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Calibrate a sensor.
#define PRIfloat
Specifier for printing float type using integers.
#define SENSOR_TIMEOUT_MS
struct acc_detector_distance_config acc_detector_distance_config_t
Distance Detector configuration.
#define LARGE_TANK_THRESHOLD_SENSITIVITY
#define LARGE_TANK_MEDIAN_FILTER_LENGTH
void acc_detector_distance_config_max_step_length_set(acc_detector_distance_config_t *config, uint16_t max_step_length)
Set maximum step length.
static void print_result(const app_result_t *app_result, const acc_ref_app_tank_level_config_t *app_config)
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
static float get_detector_start_m(acc_ref_app_tank_level_config_t *app_config)
@ PEAK_STATUS_OUT_OF_RANGE
#define MEDIUM_TANK_NUM_MEDIANS_TO_AVERAGE
struct acc_sensor acc_sensor_t
#define DEFAULT_PRESET_CONFIG
#define MEDIUM_TANK_CLOSE_RANGE_LEAKAGE_CANCELLATION
#define SMALL_TANK_REFLECTOR_SHAPE
void acc_sensor_destroy(acc_sensor_t *sensor)
Destroy a sensor instance freeing any resources allocated.
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.
#define LARGE_TANK_MAX_STEP_LENGTH