Skip to content

Commit 1afaa03

Browse files
committed
AP_InertialSensor: Added hook to read the temperature compensation enum and control temp compensation
1 parent e6398cc commit 1afaa03

2 files changed

Lines changed: 52 additions & 23 deletions

File tree

libraries/AP_InertialSensor/AP_InertialSensor.cpp

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,10 @@ AP_InertialSensor::init(uint16_t loop_rate)
11031103
/*
11041104
see if user has setup for on-boot enable of temperature learning
11051105
*/
1106-
if (temperature_cal_running()) {
1107-
tcal_learning = true;
1106+
if (IsTempCalibrated == false){
1107+
if (temperature_cal_running()) {
1108+
tcal_learning = true;
1109+
}
11081110
}
11091111
#endif
11101112
}
@@ -1733,9 +1735,11 @@ AP_InertialSensor::_init_gyro()
17331735
// has just been powered on, so the temperature may be changing
17341736
// rapidly. We use the average between start and end temperature
17351737
// as the calibration temperature to minimise errors
1736-
for (uint8_t k=0; k<num_gyros; k++) {
1737-
start_temperature[k] = get_temperature(k);
1738-
}
1738+
if (IsTempCalibrated == false){
1739+
for (uint8_t k=0; k<num_gyros; k++) {
1740+
start_temperature[k] = get_temperature(k);
1741+
}
1742+
}
17391743
#endif
17401744

17411745
// the strategy is to average 50 points over 0.5 seconds, then do it
@@ -1823,7 +1827,9 @@ AP_InertialSensor::_init_gyro()
18231827
_gyro_cal_ok[k] = true;
18241828
_gyro_offset(k).set(new_gyro_offset[k]);
18251829
#if HAL_INS_TEMPERATURE_CAL_ENABLE
1826-
caltemp_gyro(k).set(0.5 * (get_temperature(k) + start_temperature[k]));
1830+
if (IsTempCalibrated == false){
1831+
caltemp_gyro(k).set(0.5 * (get_temperature(k) + start_temperature[k]));
1832+
}
18271833
#endif
18281834
}
18291835
}
@@ -1846,14 +1852,18 @@ void AP_InertialSensor::_save_gyro_calibration()
18461852
_gyro_offset(i).save();
18471853
_gyro_id(i).save();
18481854
#if HAL_INS_TEMPERATURE_CAL_ENABLE
1849-
caltemp_gyro(i).save();
1855+
if (IsTempCalibrated == false){
1856+
caltemp_gyro(i).save();
1857+
}
18501858
#endif
18511859
}
18521860
for (uint8_t i=_gyro_count; i<INS_MAX_INSTANCES; i++) {
18531861
_gyro_offset(i).set_and_save(Vector3f());
18541862
_gyro_id(i).set_and_save(0);
18551863
#if HAL_INS_TEMPERATURE_CAL_ENABLE
1856-
caltemp_gyro(i).set_and_save_ifchanged(-300);
1864+
if (IsTempCalibrated == false){
1865+
caltemp_gyro(i).set_and_save_ifchanged(-300);
1866+
}
18571867
#endif
18581868
}
18591869
}
@@ -1980,12 +1990,14 @@ void AP_InertialSensor::update(void)
19801990
_have_sample = false;
19811991

19821992
#if HAL_INS_TEMPERATURE_CAL_ENABLE
1983-
if (tcal_learning && !temperature_cal_running()) {
1984-
AP_Notify::flags.temp_cal_running = false;
1985-
AP_Notify::events.temp_cal_saved = 1;
1986-
tcal_learning = false;
1987-
GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "TCAL finished all IMUs");
1988-
}
1993+
if (IsTempCalibrated == false){
1994+
if (tcal_learning && !temperature_cal_running()) {
1995+
AP_Notify::flags.temp_cal_running = false;
1996+
AP_Notify::events.temp_cal_saved = 1;
1997+
tcal_learning = false;
1998+
GCS_SEND_TEXT(MAV_SEVERITY_WARNING, "TCAL finished all IMUs");
1999+
}
2000+
}
19892001
#endif
19902002
#if AP_SERIALMANAGER_IMUOUT_ENABLED
19912003
if (uart.imu_out_uart) {
@@ -2294,11 +2306,13 @@ bool AP_InertialSensor::calibrating() const
22942306
bool AP_InertialSensor::temperature_cal_running() const
22952307
{
22962308
#if HAL_INS_TEMPERATURE_CAL_ENABLE
2297-
for (uint8_t i=0; i<INS_MAX_INSTANCES; i++) {
2298-
if (tcal(i).enable == AP_InertialSensor_TCal::Enable::LearnCalibration) {
2299-
return true;
2309+
if (IsTempCalibrated == false){
2310+
for (uint8_t i=0; i<INS_MAX_INSTANCES; i++) {
2311+
if (tcal(i).enable == AP_InertialSensor_TCal::Enable::LearnCalibration) {
2312+
return true;
2313+
}
2314+
}
23002315
}
2301-
}
23022316
#endif
23032317
return false;
23042318
}
@@ -2392,13 +2406,17 @@ void AP_InertialSensor::_acal_save_calibrations()
23922406
_accel_id(i).save();
23932407
_accel_id_ok[i] = true;
23942408
#if HAL_INS_TEMPERATURE_CAL_ENABLE
2395-
caltemp_accel(i).set_and_save(get_temperature(i));
2409+
if (IsTempCalibrated == false){
2410+
caltemp_accel(i).set_and_save(get_temperature(i));
2411+
}
23962412
#endif
23972413
} else {
23982414
_accel_offset(i).set_and_save(Vector3f());
23992415
_accel_scale(i).set_and_save(Vector3f());
24002416
#if HAL_INS_TEMPERATURE_CAL_ENABLE
2401-
caltemp_accel(i).set_and_save(-300);
2417+
if (IsTempCalibrated == false){
2418+
caltemp_accel(i).set_and_save(-300);
2419+
}
24022420
#endif
24032421
}
24042422
}
@@ -2409,7 +2427,9 @@ void AP_InertialSensor::_acal_save_calibrations()
24092427
_accel_offset(i).set_and_save(Vector3f());
24102428
_accel_scale(i).set_and_save(Vector3f());
24112429
#if HAL_INS_TEMPERATURE_CAL_ENABLE
2412-
caltemp_accel(i).set_and_save_ifchanged(-300);
2430+
if (IsTempCalibrated == false){
2431+
caltemp_accel(i).set_and_save_ifchanged(-300);
2432+
}
24132433
#endif
24142434
}
24152435

@@ -2662,7 +2682,9 @@ MAV_RESULT AP_InertialSensor::simple_accel_cal()
26622682
_accel_id(k).save();
26632683
_accel_id_ok[k] = true;
26642684
#if HAL_INS_TEMPERATURE_CAL_ENABLE
2665-
caltemp_accel(k).set_and_save(get_temperature(k));
2685+
if (IsTempCalibrated == false){
2686+
caltemp_accel(k).set_and_save(get_temperature(k));
2687+
}
26662688
#endif
26672689
}
26682690
for (uint8_t k=num_accels; k<INS_MAX_INSTANCES; k++) {
@@ -2793,6 +2815,10 @@ void AP_InertialSensor::send_uart_data(void)
27932815
#if AP_EXTERNAL_AHRS_ENABLED
27942816
void AP_InertialSensor::handle_external(const AP_ExternalAHRS::ins_data_message_t &pkt)
27952817
{
2818+
TempCalibration = pkt.TempCalibration;
2819+
if(TempCalibration == AP_ExternalAHRS::TempCal::IsTempCalibrated){
2820+
IsTempCalibrated = true;
2821+
}
27962822
for (uint8_t i = 0; i < _backend_count; i++) {
27972823
_backends[i]->handle_external(pkt);
27982824
}

libraries/AP_InertialSensor/AP_InertialSensor.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ class AP_InertialSensor : AP_AccelCal_Client
233233

234234
// get the accel filter rate in Hz
235235
uint16_t get_accel_filter_hz(void) const { return _accel_filter_cutoff; }
236-
236+
private:
237+
bool IsTempCalibrated = false;
238+
public:
237239
#if AP_INERTIALSENSOR_HARMONICNOTCH_ENABLED
238240
// setup the notch for throttle based tracking
239241
bool setup_throttle_gyro_harmonic_notch(float center_freq_hz, float lower_freq_hz, float ref, uint8_t harmonics);
@@ -429,6 +431,7 @@ class AP_InertialSensor : AP_AccelCal_Client
429431
#if AP_EXTERNAL_AHRS_ENABLED
430432
// handle external AHRS data
431433
void handle_external(const AP_ExternalAHRS::ins_data_message_t &pkt);
434+
AP_ExternalAHRS::TempCal TempCalibration;
432435
#endif
433436

434437
#if HAL_INS_TEMPERATURE_CAL_ENABLE

0 commit comments

Comments
 (0)