example_vibration.h
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2023-2024
2 // All rights reserved
3
4 #ifndef EXAMPLE_VIBRATION_H_
5 #define EXAMPLE_VIBRATION_H_
6
7 #include <complex.h>
8 #include <stdbool.h>
9 #include <stdint.h>
10
11 #include "acc_config.h"
12 #include "acc_processing.h"
13
14 /**
15 * @brief Vibration presets
16 */
17 typedef enum
18 {
19 ACC_VIBRATION_PRESET_HIGH_FREQUENCY,
20 ACC_VIBRATION_PRESET_LOW_FREQUENCY,
21 } acc_vibration_preset_t;
22
23 /**
24 * @brief Specifies how displacement is reported
25 */
26 typedef enum
27 {
28 /** Reports displacement as amplitude */
29 ACC_VIBRATION_REPORT_DISPLACEMENT_AS_AMPLITUDE,
30 /** Reports displacement as peak-to-peak */
31 ACC_VIBRATION_REPORT_DISPLACEMENT_AS_PEAK2PEAK,
32 } acc_vibration_reported_displacement_mode_t;
33
34 /**
35 * @brief Vibration config container
36 */
37 typedef struct
38 {
39 /** The measured point */
40 int32_t measured_point;
41
42 /** Length of time series */
43 uint16_t time_series_length;
44
45 /** Filter coefficient of exponential filter */
46 float lp_coeff;
47
48 /** Threshold sensitivity */
49 float threshold_sensitivity;
50
51 /** Minimum amplitude for calculating vibration */
52 float amplitude_threshold;
53
54 /** Reported displacement mode: amplitude or peak2peak */
55 acc_vibration_reported_displacement_mode_t reported_displacement_mode;
56
57 /** Adds a loopback subsweep for phase correction to enhance low frequency detection */
58 bool low_frequency_enhancement;
59
60 /** The profile to use */
61 acc_config_profile_t profile;
62
63 /** The frame rate in Hz */
64 float frame_rate;
65
66 /** The sweep rate in Hz */
67 float sweep_rate;
68
69 /** The number of sweeps per frame */
70 uint16_t sweeps_per_frame;
71
72 /** The number of HWAAS */
73 uint16_t hwaas;
74
75 /** Wether to enable double buffering */
76 bool double_buffering;
77
78 /** Wether to enable continuous sweep mode */
79 bool continuous_sweep_mode;
80
81 /** The inter frame idle state */
82 acc_config_idle_state_t inter_frame_idle_state;
83
84 /** The inter sweep idle state */
85 acc_config_idle_state_t inter_sweep_idle_state;
86 } acc_vibration_config_t;
87
88 /**
89 * @brief Vibration processing result
90 */
91 typedef struct
92 {
93 float max_sweep_amplitude;
94 float max_displacement;
95 float max_displacement_freq;
96 float time_series_std;
97 } acc_vibration_result_t;
98
99 /**
100 * @brief Vibration processing handle
101 */
102 typedef struct acc_vibration_handle acc_vibration_handle_t;
103
104 /**
105 * @param[out] config The vibration config to set a preset for
106 * @param[in] preset The preset
107 */
108 void acc_vibration_preset_set(acc_vibration_config_t *config, acc_vibration_preset_t preset);
109
110 /**
111 * @param[in] config The config to log
112 */
113 void acc_vibration_config_log(const acc_vibration_config_t *config);
114
115 /**
116 * @param[in] config A vibration app config to set default settings to.
117 * @return A vibration processing handle
118 */
119 acc_vibration_handle_t *acc_vibration_handle_create(const acc_vibration_config_t *config);
120
121 /**
122 * @param[in] handle The handle
123 * @return pointer to a sensor config corresponding to the vibration config
124 * 'handle' was created with.
125 */
126 const acc_config_t *acc_vibration_handle_sensor_config_get(acc_vibration_handle_t *handle);
127
128 /**
129 * @param[in] handle A handle to get the internal displacement history from
130 * @param[out] num_elem The number of elements in the returned array
131 * @return An array with displacements if arguments are non-NULL
132 */
133 const float *acc_vibration_handle_displacement_history_get(acc_vibration_handle_t *handle, uint16_t *num_elem);
134
135 /**
136 * @param[in] handle A handle to get the internal setting from
137 * @param[out] continuous_data_acquisition Wether continuous data acquisition is enabled
138 * @return True is arguments are non-NULL, false otherwise
139 */
140 bool acc_vibration_handle_continuous_data_acquisition_get(acc_vibration_handle_t *handle, bool *continuous_data_acquisition);
141
142 /**
143 * @param[in] handle The vibration handle to destroy
144 */
145 void acc_vibration_handle_destroy(acc_vibration_handle_t *handle);
146
147 /**
148 * @param[in] proc_result Input for vibration processing
149 * @param[in] handle The vibration processing handle
150 * @param[in] config The vibration app config
151 * @param[out] result The vibration processing result
152 */
153 void acc_vibration_process(acc_processing_result_t *proc_result,
154 acc_vibration_handle_t *handle,
155 acc_vibration_config_t *config,
156 acc_vibration_result_t *result);
157
158 #endif
acc_vibration_config_t::double_buffering
bool double_buffering
Definition: example_vibration.h:76
acc_vibration_result_t::max_sweep_amplitude
float max_sweep_amplitude
Definition: example_vibration.h:93
acc_processing_result_t
Result provided by the processing module.
Definition: acc_processing.h:71
acc_vibration_config_t::frame_rate
float frame_rate
Definition: example_vibration.h:64
acc_vibration_reported_displacement_mode_t
acc_vibration_reported_displacement_mode_t
Specifies how displacement is reported.
Definition: example_vibration.h:26
acc_vibration_preset_set
void acc_vibration_preset_set(acc_vibration_config_t *config, acc_vibration_preset_t preset)
Definition: example_vibration.c:115
acc_vibration_result_t::max_displacement_freq
float max_displacement_freq
Definition: example_vibration.h:95
acc_vibration_config_log
void acc_vibration_config_log(const acc_vibration_config_t *config)
Definition: example_vibration.c:170
acc_vibration_handle::continuous_data_acquisition
bool continuous_data_acquisition
Definition: example_vibration.c:63
acc_vibration_config_t::hwaas
uint16_t hwaas
Definition: example_vibration.h:73
acc_vibration_result_t::max_displacement
float max_displacement
Definition: example_vibration.h:94
acc_vibration_config_t
Vibration config container.
Definition: example_vibration.h:37
acc_vibration_handle
Definition: example_vibration.c:58
acc_vibration_config_t::low_frequency_enhancement
bool low_frequency_enhancement
Definition: example_vibration.h:58
config
cargo_config_t config
Definition: i2c_example_cargo.c:34
acc_vibration_handle_create
acc_vibration_handle_t * acc_vibration_handle_create(const acc_vibration_config_t *config)
Definition: example_vibration.c:233
acc_vibration_config_t::threshold_sensitivity
float threshold_sensitivity
Definition: example_vibration.h:49
acc_vibration_result_t::time_series_std
float time_series_std
Definition: example_vibration.h:96
acc_vibration_handle_displacement_history_get
const float * acc_vibration_handle_displacement_history_get(acc_vibration_handle_t *handle, uint16_t *num_elem)
Definition: example_vibration.c:355
acc_vibration_handle_sensor_config_get
const acc_config_t * acc_vibration_handle_sensor_config_get(acc_vibration_handle_t *handle)
Definition: example_vibration.c:350
handle
cargo_handle_t * handle
Definition: i2c_example_cargo.c:35
result
cargo_result_t result
Definition: i2c_example_cargo.c:43
acc_vibration_config_t::sweep_rate
float sweep_rate
Definition: example_vibration.h:67
acc_config_t
struct acc_config acc_config_t
Definition: acc_config.h:24
ACC_VIBRATION_PRESET_LOW_FREQUENCY
@ ACC_VIBRATION_PRESET_LOW_FREQUENCY
Definition: example_vibration.h:20
ACC_VIBRATION_REPORT_DISPLACEMENT_AS_PEAK2PEAK
@ ACC_VIBRATION_REPORT_DISPLACEMENT_AS_PEAK2PEAK
Definition: example_vibration.h:31
acc_vibration_config_t::reported_displacement_mode
acc_vibration_reported_displacement_mode_t reported_displacement_mode
Definition: example_vibration.h:55
ACC_VIBRATION_REPORT_DISPLACEMENT_AS_AMPLITUDE
@ ACC_VIBRATION_REPORT_DISPLACEMENT_AS_AMPLITUDE
Definition: example_vibration.h:29
acc_vibration_process
void acc_vibration_process(acc_processing_result_t *proc_result, acc_vibration_handle_t *handle, acc_vibration_config_t *config, acc_vibration_result_t *result)
Definition: example_vibration.c:437
acc_vibration_config_t::inter_sweep_idle_state
acc_config_idle_state_t inter_sweep_idle_state
Definition: example_vibration.h:85
acc_vibration_config_t::time_series_length
uint16_t time_series_length
Definition: example_vibration.h:43
acc_vibration_handle_destroy
void acc_vibration_handle_destroy(acc_vibration_handle_t *handle)
Definition: example_vibration.c:381
acc_vibration_result_t
Vibration processing result.
Definition: example_vibration.h:91
acc_vibration_handle_continuous_data_acquisition_get
bool acc_vibration_handle_continuous_data_acquisition_get(acc_vibration_handle_t *handle, bool *continuous_data_acquisition)
Definition: example_vibration.c:369
acc_vibration_config_t::amplitude_threshold
float amplitude_threshold
Definition: example_vibration.h:52
acc_vibration_config_t::sweeps_per_frame
uint16_t sweeps_per_frame
Definition: example_vibration.h:70
acc_vibration_preset_t
acc_vibration_preset_t
Vibration presets.
Definition: example_vibration.h:17
acc_vibration_config_t::profile
acc_config_profile_t profile
Definition: example_vibration.h:61
ACC_VIBRATION_PRESET_HIGH_FREQUENCY
@ ACC_VIBRATION_PRESET_HIGH_FREQUENCY
Definition: example_vibration.h:19
acc_config_profile_t
acc_config_profile_t
Profile.
Definition: acc_definitions_a121.h:49
acc_config.h
acc_processing.h
acc_vibration_config_t::inter_frame_idle_state
acc_config_idle_state_t inter_frame_idle_state
Definition: example_vibration.h:82
acc_vibration_config_t::continuous_sweep_mode
bool continuous_sweep_mode
Definition: example_vibration.h:79
acc_vibration_config_t::lp_coeff
float lp_coeff
Definition: example_vibration.h:46
acc_vibration_config_t::measured_point
int32_t measured_point
Definition: example_vibration.h:40
acc_config_idle_state_t
acc_config_idle_state_t
Idle state.
Definition: acc_definitions_a121.h:70