44 #include <px4_platform_common/defines.h> 45 #include <px4_platform_common/log.h> 57 int32_t gyro_tc_enabled = 0;
60 if (ret == PX4_OK && gyro_tc_enabled) {
62 sprintf(nbuf,
"TC_G%d_ID", j);
65 for (
unsigned i = 0; i < 3; i++) {
66 sprintf(nbuf,
"TC_G%d_X3_%d", j, i);
68 sprintf(nbuf,
"TC_G%d_X2_%d", j, i);
70 sprintf(nbuf,
"TC_G%d_X1_%d", j, i);
72 sprintf(nbuf,
"TC_G%d_X0_%d", j, i);
74 sprintf(nbuf,
"TC_G%d_SCL_%d", j, i);
78 sprintf(nbuf,
"TC_G%d_TREF", j);
80 sprintf(nbuf,
"TC_G%d_TMIN", j);
82 sprintf(nbuf,
"TC_G%d_TMAX", j);
89 int32_t accel_tc_enabled = 0;
92 if (ret == PX4_OK && accel_tc_enabled) {
94 sprintf(nbuf,
"TC_A%d_ID", j);
97 for (
unsigned i = 0; i < 3; i++) {
98 sprintf(nbuf,
"TC_A%d_X3_%d", j, i);
100 sprintf(nbuf,
"TC_A%d_X2_%d", j, i);
102 sprintf(nbuf,
"TC_A%d_X1_%d", j, i);
104 sprintf(nbuf,
"TC_A%d_X0_%d", j, i);
106 sprintf(nbuf,
"TC_A%d_SCL_%d", j, i);
110 sprintf(nbuf,
"TC_A%d_TREF", j);
112 sprintf(nbuf,
"TC_A%d_TMIN", j);
114 sprintf(nbuf,
"TC_A%d_TMAX", j);
121 int32_t baro_tc_enabled = 0;
124 if (ret == PX4_OK && baro_tc_enabled) {
126 sprintf(nbuf,
"TC_B%d_ID", j);
128 sprintf(nbuf,
"TC_B%d_X5", j);
130 sprintf(nbuf,
"TC_B%d_X4", j);
132 sprintf(nbuf,
"TC_B%d_X3", j);
134 sprintf(nbuf,
"TC_B%d_X2", j);
136 sprintf(nbuf,
"TC_B%d_X1", j);
138 sprintf(nbuf,
"TC_B%d_X0", j);
140 sprintf(nbuf,
"TC_B%d_SCL", j);
142 sprintf(nbuf,
"TC_B%d_TREF", j);
144 sprintf(nbuf,
"TC_B%d_TMIN", j);
146 sprintf(nbuf,
"TC_B%d_TMAX", j);
180 for (
unsigned int i = 0; i < 3; i++) {
193 for (
unsigned int i = 0; i < 3; i++) {
197 PX4_WARN(
"FAIL GYRO %d CAL PARAM LOAD - USING DEFAULTS", j);
218 for (
unsigned int i = 0; i < 3; i++) {
231 for (
unsigned int i = 0; i < 3; i++) {
235 PX4_WARN(
"FAIL ACCEL %d CAL PARAM LOAD - USING DEFAULTS", j);
270 PX4_WARN(
"FAIL BARO %d CAL PARAM LOAD - USING DEFAULTS", j);
293 if (measured_temp > coef.
max_temp) {
297 }
else if (measured_temp < coef.
min_temp) {
302 delta_temp = measured_temp - coef.
ref_temp;
307 float temp_var = delta_temp;
308 offset = coef.
x0 + coef.
x1 * temp_var;
309 temp_var *= delta_temp;
310 offset += coef.
x2 * temp_var;
311 temp_var *= delta_temp;
312 offset += coef.
x3 * temp_var;
313 temp_var *= delta_temp;
314 offset += coef.
x4 * temp_var;
315 temp_var *= delta_temp;
316 offset += coef.
x5 * temp_var;
329 if (measured_temp > coef.
max_temp) {
333 }
else if (measured_temp < coef.
min_temp) {
338 delta_temp = measured_temp - coef.
ref_temp;
343 float delta_temp_2 = delta_temp * delta_temp;
344 float delta_temp_3 = delta_temp_2 * delta_temp;
346 for (uint8_t i = 0; i < 3; i++) {
347 offset[i] = coef.
x0[i] + coef.
x1[i] * delta_temp + coef.
x2[i] * delta_temp_2 + coef.
x3[i] * delta_temp_3;
383 const T *sensor_cal_data, uint8_t sensor_count_max)
385 for (
int i = 0; i < sensor_count_max; ++i) {
386 if (device_id == (uint32_t)sensor_cal_data[i].
ID) {
396 float temperature,
float *offsets,
float *scales)
404 if (mapping == 255) {
411 for (
unsigned axis_index = 0; axis_index < 3; axis_index++) {
413 sensor_data(axis_index) = (sensor_data(axis_index) - offsets[axis_index]) * scales[axis_index];
425 float temperature,
float *offsets,
float *scales)
433 if (mapping == 255) {
440 for (
unsigned axis_index = 0; axis_index < 3; axis_index++) {
442 sensor_data(axis_index) = (sensor_data(axis_index) - offsets[axis_index]) * scales[axis_index];
454 float *offsets,
float *scales)
462 if (mapping == 255) {
470 sensor_data = (sensor_data - *offsets) * *scales;
482 PX4_INFO(
"Temperature Compensation:");
float ref_temp
reference temperature used by the curve-fit
SensorCalData3D gyro_cal_data[GYRO_COUNT_MAX]
constexpr uint8_t GYRO_COUNT_MAX
int set_sensor_id_accel(uint32_t device_id, int topic_instance)
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
SensorCalData3D accel_cal_data[ACCEL_COUNT_MAX]
static int set_sensor_id(uint32_t device_id, int topic_instance, PerSensorData &sensor_data, const T *sensor_cal_data, uint8_t sensor_count_max)
SensorCalData1D baro_cal_data[BARO_COUNT_MAX]
SensorCalHandles3D accel_cal_handles[ACCEL_COUNT_MAX]
uint8_t device_mapping[SENSOR_COUNT_MAX]
PerSensorData _accel_data
static int32_t device_id[max_accel_sens]
bool calc_thermal_offsets_1D(SensorCalData1D &coef, float measured_temp, float &offset)
Calculate the offset required to compensate the sensor for temperature effects using a 5th order meth...
Global flash based parameter store.
float x1[3]
x^1 term of polynomial
constexpr uint8_t ACCEL_COUNT_MAX
int parameters_update(bool hil_enabled=false)
(re)load the parameters.
bool calc_thermal_offsets_3D(const SensorCalData3D &coef, float measured_temp, float offset[])
Calculate the offsets required to compensate the sensor for temperature effects If the measured tempe...
Sensor correction methods.
SensorCalHandles3D gyro_cal_handles[GYRO_COUNT_MAX]
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
float x0[3]
x^0 / offset term of polynomial
int set_sensor_id_gyro(uint32_t device_id, int topic_instance)
supply information which device_id matches a specific uORB topic_instance (needed if a system has mul...
float min_temp
minimum temperature with valid compensation data
void print_status()
output current configuration status to console
SensorCalHandles1D baro_cal_handles[BARO_COUNT_MAX]
float x2[3]
x^2 term of polynomial
int apply_corrections_baro(int topic_instance, float &sensor_data, float temperature, float *offsets, float *scales)
int apply_corrections_accel(int topic_instance, matrix::Vector3f &sensor_data, float temperature, float *offsets, float *scales)
float max_temp
maximum temperature with valid compensation data
float x3[3]
x^3 term of polynomial
int apply_corrections_gyro(int topic_instance, matrix::Vector3f &sensor_data, float temperature, float *offsets, float *scales)
Apply Thermal corrections to gyro (& other) sensor data.
float last_temperature[SENSOR_COUNT_MAX]
map a topic instance to the parameters index
int32_t ID
sensor device ID
static int initialize_parameter_handles(ParameterHandles ¶meter_handles)
initialize ParameterHandles struct
int set_sensor_id_baro(uint32_t device_id, int topic_instance)
constexpr uint8_t BARO_COUNT_MAX
float scale[3]
scale factor correction