This is an example on how the sensor and detector calibration can be cached
This example executes as follows:
- Retrieve and register HAL struct
- Create and initialize distance detector resources
- Create and calibrate sensor
- Calibrate detector
- Loop:
- Prepare, measure, read, process data using the detector
- Check 'calibration_needed' indication
- If needed, either use cached calibration or perform new calibration and store
- Destroy resources
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define SENSOR_ID (1U)
#define SENSOR_TIMEOUT_MS (2000U)
#define MAX_CAL_TEMP_DIFF (16)
#define MAX_TEMP_VARIATION (125)
#define MAX_CACHE_COUNT ((MAX_TEMP_VARIATION / MAX_CAL_TEMP_DIFF) + 1)
typedef struct
{
void *buffer;
uint32_t buffer_size;
static bool add_cache(uint16_t cache_index, int16_t temp);
{
(void)argc;
(void)argv;
{
return EXIT_FAILURE;
}
{
printf("Config creation failed\n");
return EXIT_FAILURE;
}
{
printf("Initializing detector resources failed\n");
return EXIT_FAILURE;
}
{
printf("Sensor creation failed\n");
return EXIT_FAILURE;
}
{
printf("Sensor or detector calibration failed\n");
return EXIT_FAILURE;
}
uint32_t update_count = 5U;
for (uint32_t i = 0U; i < update_count; i++)
{
{
printf("Could not get next result\n");
return EXIT_FAILURE;
}
{
printf("New calibrations needed due to temperature change\n");
{
printf("Calibration caching failed\n");
return EXIT_FAILURE;
}
}
else
{
printf("Distance result retrieved\n");
}
}
printf("Application finished OK\n");
return EXIT_SUCCESS;
}
{
}
{
if (resources->
handle == NULL)
{
printf("acc_detector_distance_create() failed\n");
return false;
}
{
printf("acc_detector_distance_get_sizes() failed\n");
return false;
}
if (resources->
buffer == NULL)
{
printf("sensor buffer allocation failed\n");
return false;
}
{
printf("static cal result allocation failed\n");
return false;
}
return true;
}
{
bool result_available = false;
do
{
{
printf("acc_detector_distance_prepare() failed\n");
return false;
}
{
printf("acc_sensor_measure() failed\n");
return false;
}
{
printf("Sensor interrupt timeout\n");
return false;
}
{
printf("acc_sensor_read() failed\n");
return false;
}
&result_available, result))
{
printf("acc_detector_distance_process() failed\n");
return false;
}
} while (!result_available);
return true;
}
{
if (resources->
sensor != NULL)
{
}
{
}
if (resources->
buffer != NULL)
{
}
if (resources->
handle != NULL)
{
}
if (resources->
config != NULL)
{
}
}
{
if (status)
{
}
if (status)
{
}
return status;
}
{
bool status = false;
bool cal_complete = false;
const uint16_t calibration_retries = 1U;
for (uint16_t i = 0; !status && (i <= calibration_retries); i++)
{
do
{
if (status && !cal_complete)
{
}
} while (status && !cal_complete);
}
if (status)
{
}
return status;
}
{
bool status = false;
bool cal_complete = false;
do
{
&cal_complete);
if (status && !cal_complete)
{
}
} while (status && !cal_complete);
return status;
}
{
bool status = false;
bool cal_complete = false;
do
{
&cal_complete);
if (status && !cal_complete)
{
}
} while (status && !cal_complete);
return status;
}
{
bool status = true;
uint16_t cache_index = 0;
if (!use_cache)
{
printf("New sensor calibration and detector calibration update is performed\n");
{
printf("No empty cache_index to store calibration result\n");
return false;
}
if (status)
{
}
if (status)
{
}
}
else
{
}
return status;
}
{
bool cache_found = false;
uint16_t min_temp_diff = UINT16_MAX;
{
uint16_t temp_diff = abs(
cal_temps[index] - temp);
{
min_temp_diff = temp_diff;
*cache_index = index;
cache_found = true;
}
}
return cache_found;
}
{
}
static bool add_cache(uint16_t cache_index, int16_t temp)
{
bool status = false;
{
status = true;
}
return status;
}
#define MAX_CAL_TEMP_DIFF
@ ACC_DETECTOR_DISTANCE_REFLECTOR_SHAPE_GENERIC
static bool calibration_caching(distance_detector_resources_t *resources, int16_t temp)
static acc_detector_cal_result_dynamic_t detector_cal_results_dynamic[(((125)/(16))+1)]
void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id)
Power off sensor supply.
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 sizes needed given the provided detector handle.
static bool get_next_empty_cache_index(uint16_t *cache_index)
void acc_detector_distance_config_peak_sorting_set(acc_detector_distance_config_t *config, acc_detector_distance_peak_sorting_t peak_sorting)
Set the peak sorting method.
static uint16_t cache_index_in_use
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
Information about calibration.
static acc_cal_result_t sensor_cal_results[(((125)/(16))+1)]
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
@ ACC_DETECTOR_DISTANCE_PEAK_SORTING_STRONGEST
static bool detector_get_next(distance_detector_resources_t *resources, acc_detector_distance_result_t *result)
void acc_detector_distance_config_threshold_method_set(acc_detector_distance_config_t *config, acc_detector_distance_threshold_method_t threshold_method)
Set the threshold method.
The result from a completed calibration.
void acc_detector_distance_config_start_set(acc_detector_distance_config_t *config, float start_m)
Set the start of measured interval in meters.
acc_detector_distance_handle_t * acc_detector_distance_create(const acc_detector_distance_config_t *config)
Create a distance detector with the provided configuration.
static bool sensor_and_detector_calibration(distance_detector_resources_t *resources, uint16_t cache_index)
@ ACC_DETECTOR_DISTANCE_THRESHOLD_METHOD_CFAR
void acc_detector_distance_config_destroy(acc_detector_distance_config_t *config)
Destroy a configuration for a distance detector.
static bool add_cache(uint16_t cache_index, int16_t temp)
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
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)
Do a detector calibration.
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 the data according to the configuration used in acc_detector_distance_config_create.
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
static bool detector_calibration_update(distance_detector_resources_t *resources, uint16_t cache_index)
static uint8_t * detector_cal_result_static
void acc_detector_distance_config_close_range_leakage_cancellation_set(acc_detector_distance_config_t *config, bool enable)
Enable the close range leakage cancellation logic.
void acc_detector_distance_config_max_profile_set(acc_detector_distance_config_t *config, acc_config_profile_t max_profile)
Set the max profile.
void acc_detector_distance_destroy(acc_detector_distance_handle_t *handle)
Destroy the 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.
void acc_detector_distance_config_signal_quality_set(acc_detector_distance_config_t *config, float signal_quality)
Set the signal quality.
const char * acc_version_get(void)
Get the version of the Acconeer software.
bool acc_sensor_get_cal_info(const acc_cal_result_t *cal_result, acc_cal_info_t *cal_info)
Gets calibration information from a calibration result.
static uint32_t detector_cal_result_static_size
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
static bool sensor_calibration(distance_detector_resources_t *resources, uint16_t cache_index)
static uint16_t curr_cache_count
void acc_detector_distance_config_log(const acc_detector_distance_handle_t *handle, const acc_detector_distance_config_t *config)
Print a configuration to the log.
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.
Distance detector result.
acc_detector_distance_config_t * config
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
static int16_t cal_temps[(((125)/(16))+1)]
void acc_detector_distance_config_end_set(acc_detector_distance_config_t *config, float end_m)
Set the end of measured interval in meters.
void acc_detector_distance_config_num_frames_recorded_threshold_set(acc_detector_distance_config_t *config, uint16_t num_frames)
Set the number frames to use for recorded threshold.
struct acc_detector_distance_handle acc_detector_distance_handle_t
static void cleanup(distance_detector_resources_t *resources)
static bool initialize_detector_resources(distance_detector_resources_t *resources)
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)
Update the calibration.
static bool detector_calibration_full(distance_detector_resources_t *resources, uint16_t cache_index)
static const acc_hal_a121_t hal
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.
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 configuration for a distance detector.
#define SENSOR_TIMEOUT_MS
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.
acc_detector_distance_handle_t * handle
struct acc_detector_distance_config acc_detector_distance_config_t
void acc_detector_distance_config_max_step_length_set(acc_detector_distance_config_t *config, uint16_t max_step_length)
Set the maximum step length.
static void set_config(acc_detector_distance_config_t *detector_config)
int app_main(int argc, char *argv[])
Assembly test example.
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
struct acc_sensor acc_sensor_t
static bool find_cache_index(int16_t temp, uint16_t *cache_index)
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.