Use accel of the same instance or primary baro for gyro instances that do not have valid temperature readings in temperature calibration data, use primary baro for magnetometers without valid temperature.

This commit is contained in:
mcsauder
2023-06-07 12:07:29 -04:00
committed by Daniel Agar
parent b8ad9bdbe5
commit af44da25f0
19 changed files with 814 additions and 717 deletions
+6 -6
View File
@@ -344,17 +344,17 @@ void LoggedTopics::add_estimator_replay_topics()
void LoggedTopics::add_thermal_calibration_topics()
{
add_topic_multi("sensor_accel", 100, 3);
add_topic_multi("sensor_baro", 100, 3);
add_topic_multi("sensor_gyro", 100, 3);
add_topic_multi("sensor_accel", 100, 4);
add_topic_multi("sensor_baro", 100, 4);
add_topic_multi("sensor_gyro", 100, 4);
add_topic_multi("sensor_mag", 100, 4);
}
void LoggedTopics::add_sensor_comparison_topics()
{
add_topic_multi("sensor_accel", 100, 3);
add_topic_multi("sensor_baro", 100, 3);
add_topic_multi("sensor_gyro", 100, 3);
add_topic_multi("sensor_accel", 100, 4);
add_topic_multi("sensor_baro", 100, 4);
add_topic_multi("sensor_gyro", 100, 4);
add_topic_multi("sensor_mag", 100, 4);
}
@@ -215,10 +215,12 @@ void VehicleAcceleration::Run()
// update corrections first to set _selected_sensor
bool selection_updated = SensorSelectionUpdate();
_calibration.SensorCorrectionsUpdate(selection_updated);
SensorBiasUpdate(selection_updated);
ParametersUpdate();
_calibration.SensorCorrectionsUpdate(selection_updated);
SensorBiasUpdate(selection_updated);
// require valid sensor sample rate to run
if (!PX4_ISFINITE(_filter_sample_rate)) {
CheckAndUpdateFilters();
@@ -790,6 +790,8 @@ void VehicleAngularVelocity::Run()
const hrt_abstime time_now_us = hrt_absolute_time();
ParametersUpdate();
// update corrections first to set _selected_sensor
const bool selection_updated = SensorSelectionUpdate(time_now_us);
@@ -801,9 +803,8 @@ void VehicleAngularVelocity::Run()
}
}
ParametersUpdate();
_calibration.SensorCorrectionsUpdate(selection_updated);
SensorBiasUpdate(selection_updated);
if (_reset_filters) {
@@ -369,8 +369,8 @@ void VehicleMagnetometer::UpdatePowerCompensation()
if (_vehicle_thrust_setpoint_0_sub.update(&vehicle_thrust_setpoint)) {
const matrix::Vector3f thrust_setpoint = matrix::Vector3f(vehicle_thrust_setpoint.xyz);
for (auto &cal : _calibration) {
cal.UpdatePower(thrust_setpoint.length());
for (int i = 0; i < MAX_SENSOR_COUNT; i++) {
_calibration[i].UpdatePower(thrust_setpoint.length());
}
}
@@ -382,14 +382,14 @@ void VehicleMagnetometer::UpdatePowerCompensation()
if (_battery_status_sub.update(&bat_stat)) {
float power = bat_stat.current_a * 0.001f; // current in [kA]
for (auto &cal : _calibration) {
cal.UpdatePower(power);
for (int i = 0; i < MAX_SENSOR_COUNT; i++) {
_calibration[i].UpdatePower(power);
}
}
} else {
for (auto &cal : _calibration) {
cal.UpdatePower(0.f);
for (int i = 0; i < MAX_SENSOR_COUNT; i++) {
_calibration[i].UpdatePower(0.f);
}
}
}
@@ -412,6 +412,10 @@ void VehicleMagnetometer::Run()
}
}
for (int i = 0; i < MAX_SENSOR_COUNT; i++) {
_calibration[i].SensorCorrectionsUpdate();
}
UpdatePowerCompensation();
UpdateMagBiasEstimate();
@@ -146,6 +146,7 @@ private:
Current_inst0,
Current_inst1
};
MagCompensationType _mag_comp_type{MagCompensationType::Disabled};
perf_counter_t _cycle_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")};
@@ -158,6 +159,7 @@ private:
uint64_t _timestamp_sample_sum[MAX_SENSOR_COUNT] {};
matrix::Vector3f _data_sum[MAX_SENSOR_COUNT] {};
int _data_sum_count[MAX_SENSOR_COUNT] {};
hrt_abstime _last_publication_timestamp[MAX_SENSOR_COUNT] {};
@@ -144,16 +144,16 @@ void TemperatureCompensationModule::accelPoll()
// For each accel instance
for (uint8_t uorb_index = 0; uorb_index < ACCEL_COUNT_MAX; uorb_index++) {
sensor_accel_s report;
sensor_accel_s sensor_accel;
// Grab temperature from report
if (_accel_subs[uorb_index].update(&report)) {
if (PX4_ISFINITE(report.temperature)) {
// Grab temperature from accel
if (_accel_subs[uorb_index].update(&sensor_accel)) {
if (PX4_ISFINITE(sensor_accel.temperature)) {
// Update the offsets and mark for publication if they've changed
if (_temperature_compensation.update_offsets_accel(uorb_index, report.temperature, offsets[uorb_index]) == 2) {
if (_temperature_compensation.update_offsets_accel(uorb_index, sensor_accel.temperature, offsets[uorb_index]) == 2) {
_corrections.accel_device_ids[uorb_index] = report.device_id;
_corrections.accel_temperature[uorb_index] = report.temperature;
_corrections.accel_device_ids[uorb_index] = sensor_accel.device_id;
_corrections.accel_temperature[uorb_index] = sensor_accel.temperature;
_corrections_changed = true;
}
}
@@ -167,16 +167,28 @@ void TemperatureCompensationModule::gyroPoll()
// For each gyro instance
for (uint8_t uorb_index = 0; uorb_index < GYRO_COUNT_MAX; uorb_index++) {
sensor_gyro_s report;
sensor_gyro_s sensor_gyro;
// Grab temperature from report
if (_gyro_subs[uorb_index].update(&report)) {
if (PX4_ISFINITE(report.temperature)) {
// Grab temperature from gyro
if (_gyro_subs[uorb_index].update(&sensor_gyro)) {
if (PX4_ISFINITE(sensor_gyro.temperature)) {
// Update the offsets and mark for publication if they've changed
if (_temperature_compensation.update_offsets_gyro(uorb_index, report.temperature, offsets[uorb_index]) == 2) {
if (_temperature_compensation.update_offsets_gyro(uorb_index, sensor_gyro.temperature, offsets[uorb_index]) == 2) {
_corrections.gyro_device_ids[uorb_index] = report.device_id;
_corrections.gyro_temperature[uorb_index] = report.temperature;
_corrections.gyro_device_ids[uorb_index] = sensor_gyro.device_id;
_corrections.gyro_temperature[uorb_index] = sensor_gyro.temperature;
_corrections_changed = true;
}
} else {
_corrections.gyro_device_ids[uorb_index] = sensor_gyro.device_id;
// Use accelerometer of the same instance if gyro temperature was NAN.
sensor_accel_s sensor_accel;
if (_accel_subs[uorb_index].update(&sensor_accel)) {
_corrections.gyro_temperature[uorb_index] = sensor_accel.temperature;
_corrections_changed = true;
}
}
@@ -190,16 +202,28 @@ void TemperatureCompensationModule::magPoll()
// For each mag instance
for (uint8_t uorb_index = 0; uorb_index < MAG_COUNT_MAX; uorb_index++) {
sensor_mag_s report;
sensor_mag_s sensor_mag;
// Grab temperature from report
if (_mag_subs[uorb_index].update(&report)) {
if (PX4_ISFINITE(report.temperature)) {
if (_mag_subs[uorb_index].update(&sensor_mag)) {
if (PX4_ISFINITE(sensor_mag.temperature)) {
// Update the offsets and mark for publication if they've changed
if (_temperature_compensation.update_offsets_mag(uorb_index, report.temperature, offsets[uorb_index]) == 2) {
if (_temperature_compensation.update_offsets_mag(uorb_index, sensor_mag.temperature, offsets[uorb_index]) == 2) {
_corrections.mag_device_ids[uorb_index] = report.device_id;
_corrections.mag_temperature[uorb_index] = report.temperature;
_corrections.mag_device_ids[uorb_index] = sensor_mag.device_id;
_corrections.mag_temperature[uorb_index] = sensor_mag.temperature;
_corrections_changed = true;
}
} else {
_corrections.mag_device_ids[uorb_index] = sensor_mag.device_id;
// Use primary baro instance if mag temperature was NAN.
sensor_baro_s sensor_baro;
if (_accel_subs[0].update(&sensor_baro)) {
_corrections.mag_temperature[uorb_index] = sensor_baro.temperature;
_corrections_changed = true;
}
}
@@ -213,16 +237,28 @@ void TemperatureCompensationModule::baroPoll()
// For each baro instance
for (uint8_t uorb_index = 0; uorb_index < BARO_COUNT_MAX; uorb_index++) {
sensor_baro_s report;
sensor_baro_s sensor_baro;
// Grab temperature from report
if (_baro_subs[uorb_index].update(&report)) {
if (PX4_ISFINITE(report.temperature)) {
if (_baro_subs[uorb_index].update(&sensor_baro)) {
if (PX4_ISFINITE(sensor_baro.temperature)) {
// Update the offsets and mark for publication if they've changed
if (_temperature_compensation.update_offsets_baro(uorb_index, report.temperature, offsets[uorb_index]) == 2) {
if (_temperature_compensation.update_offsets_baro(uorb_index, sensor_baro.temperature, offsets[uorb_index]) == 2) {
_corrections.baro_device_ids[uorb_index] = report.device_id;
_corrections.baro_temperature[uorb_index] = report.temperature;
_corrections.baro_device_ids[uorb_index] = sensor_baro.device_id;
_corrections.baro_temperature[uorb_index] = sensor_baro.temperature;
_corrections_changed = true;
}
} else {
_corrections.baro_device_ids[uorb_index] = sensor_baro.device_id;
// Use primary accelerometer instance if baro temperature was NAN.
sensor_accel_s sensor_accel;
if (_accel_subs[0].update(&sensor_accel)) {
_corrections.baro_temperature[uorb_index] = sensor_accel.temperature;
_corrections_changed = true;
}
}
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2022 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2017-2020 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2017-2020 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2017-2020 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2017-2020 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2017 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -1,6 +1,6 @@
/****************************************************************************
*
* Copyright (c) 2017 PX4 Development Team. All rights reserved.
* Copyright (c) 2022-2023 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -69,17 +69,13 @@ class TemperatureCalibration
{
public:
TemperatureCalibration(bool accel, bool gyro, bool mag, bool baro)
: _accel(accel)
, _gyro(gyro)
, _mag(mag)
, _baro(baro) {};
TemperatureCalibration(bool accel, bool gyro, bool mag, bool baro) :
_accel(accel), _gyro(gyro), _mag(mag), _baro(baro) {};
~TemperatureCalibration() = default;
/**
* Start task.
*
* @return OK on success.
*/
int start();