@@ -1101,8 +1101,10 @@ AP_InertialSensor::init(uint16_t loop_rate)
11011101 /*
11021102 see if user has setup for on-boot enable of temperature learning
11031103 */
1104- if (temperature_cal_running ()) {
1105- tcal_learning = true ;
1104+ if (IsTempCalibrated == false ){
1105+ if (temperature_cal_running ()) {
1106+ tcal_learning = true ;
1107+ }
11061108 }
11071109#endif
11081110}
@@ -1731,9 +1733,11 @@ AP_InertialSensor::_init_gyro()
17311733 // has just been powered on, so the temperature may be changing
17321734 // rapidly. We use the average between start and end temperature
17331735 // as the calibration temperature to minimise errors
1734- for (uint8_t k=0 ; k<num_gyros; k++) {
1735- start_temperature[k] = get_temperature (k);
1736- }
1736+ if (IsTempCalibrated == false ){
1737+ for (uint8_t k=0 ; k<num_gyros; k++) {
1738+ start_temperature[k] = get_temperature (k);
1739+ }
1740+ }
17371741#endif
17381742
17391743 // the strategy is to average 50 points over 0.5 seconds, then do it
@@ -1821,7 +1825,9 @@ AP_InertialSensor::_init_gyro()
18211825 _gyro_cal_ok[k] = true ;
18221826 _gyro_offset (k).set (new_gyro_offset[k]);
18231827#if HAL_INS_TEMPERATURE_CAL_ENABLE
1824- caltemp_gyro (k).set (0.5 * (get_temperature (k) + start_temperature[k]));
1828+ if (IsTempCalibrated == false ){
1829+ caltemp_gyro (k).set (0.5 * (get_temperature (k) + start_temperature[k]));
1830+ }
18251831#endif
18261832 }
18271833 }
@@ -1844,14 +1850,18 @@ void AP_InertialSensor::_save_gyro_calibration()
18441850 _gyro_offset (i).save ();
18451851 _gyro_id (i).save ();
18461852#if HAL_INS_TEMPERATURE_CAL_ENABLE
1847- caltemp_gyro (i).save ();
1853+ if (IsTempCalibrated == false ){
1854+ caltemp_gyro (i).save ();
1855+ }
18481856#endif
18491857 }
18501858 for (uint8_t i=_gyro_count; i<INS_MAX_INSTANCES; i++) {
18511859 _gyro_offset (i).set_and_save (Vector3f ());
18521860 _gyro_id (i).set_and_save (0 );
18531861#if HAL_INS_TEMPERATURE_CAL_ENABLE
1854- caltemp_gyro (i).set_and_save_ifchanged (-300 );
1862+ if (IsTempCalibrated == false ){
1863+ caltemp_gyro (i).set_and_save_ifchanged (-300 );
1864+ }
18551865#endif
18561866 }
18571867}
@@ -1978,12 +1988,14 @@ void AP_InertialSensor::update(void)
19781988 _have_sample = false ;
19791989
19801990#if HAL_INS_TEMPERATURE_CAL_ENABLE
1981- if (tcal_learning && !temperature_cal_running ()) {
1982- AP_Notify::flags.temp_cal_running = false ;
1983- AP_Notify::events.temp_cal_saved = 1 ;
1984- tcal_learning = false ;
1985- GCS_SEND_TEXT (MAV_SEVERITY_WARNING, " TCAL finished all IMUs" );
1986- }
1991+ if (IsTempCalibrated == false ){
1992+ if (tcal_learning && !temperature_cal_running ()) {
1993+ AP_Notify::flags.temp_cal_running = false ;
1994+ AP_Notify::events.temp_cal_saved = 1 ;
1995+ tcal_learning = false ;
1996+ GCS_SEND_TEXT (MAV_SEVERITY_WARNING, " TCAL finished all IMUs" );
1997+ }
1998+ }
19871999#endif
19882000#if AP_SERIALMANAGER_IMUOUT_ENABLED
19892001 if (uart.imu_out_uart ) {
@@ -2292,11 +2304,13 @@ bool AP_InertialSensor::calibrating() const
22922304bool AP_InertialSensor::temperature_cal_running () const
22932305{
22942306#if HAL_INS_TEMPERATURE_CAL_ENABLE
2295- for (uint8_t i=0 ; i<INS_MAX_INSTANCES; i++) {
2296- if (tcal (i).enable == AP_InertialSensor_TCal::Enable::LearnCalibration) {
2297- return true ;
2307+ if (IsTempCalibrated == false ){
2308+ for (uint8_t i=0 ; i<INS_MAX_INSTANCES; i++) {
2309+ if (tcal (i).enable == AP_InertialSensor_TCal::Enable::LearnCalibration) {
2310+ return true ;
2311+ }
2312+ }
22982313 }
2299- }
23002314#endif
23012315 return false ;
23022316}
@@ -2390,13 +2404,17 @@ void AP_InertialSensor::_acal_save_calibrations()
23902404 _accel_id (i).save ();
23912405 _accel_id_ok[i] = true ;
23922406#if HAL_INS_TEMPERATURE_CAL_ENABLE
2393- caltemp_accel (i).set_and_save (get_temperature (i));
2407+ if (IsTempCalibrated == false ){
2408+ caltemp_accel (i).set_and_save (get_temperature (i));
2409+ }
23942410#endif
23952411 } else {
23962412 _accel_offset (i).set_and_save (Vector3f ());
23972413 _accel_scale (i).set_and_save (Vector3f ());
23982414#if HAL_INS_TEMPERATURE_CAL_ENABLE
2399- caltemp_accel (i).set_and_save (-300 );
2415+ if (IsTempCalibrated == false ){
2416+ caltemp_accel (i).set_and_save (-300 );
2417+ }
24002418#endif
24012419 }
24022420 }
@@ -2407,7 +2425,9 @@ void AP_InertialSensor::_acal_save_calibrations()
24072425 _accel_offset (i).set_and_save (Vector3f ());
24082426 _accel_scale (i).set_and_save (Vector3f ());
24092427#if HAL_INS_TEMPERATURE_CAL_ENABLE
2410- caltemp_accel (i).set_and_save_ifchanged (-300 );
2428+ if (IsTempCalibrated == false ){
2429+ caltemp_accel (i).set_and_save_ifchanged (-300 );
2430+ }
24112431#endif
24122432 }
24132433
@@ -2660,7 +2680,9 @@ MAV_RESULT AP_InertialSensor::simple_accel_cal()
26602680 _accel_id (k).save ();
26612681 _accel_id_ok[k] = true ;
26622682#if HAL_INS_TEMPERATURE_CAL_ENABLE
2663- caltemp_accel (k).set_and_save (get_temperature (k));
2683+ if (IsTempCalibrated == false ){
2684+ caltemp_accel (k).set_and_save (get_temperature (k));
2685+ }
26642686#endif
26652687 }
26662688 for (uint8_t k=num_accels; k<INS_MAX_INSTANCES; k++) {
@@ -2791,6 +2813,10 @@ void AP_InertialSensor::send_uart_data(void)
27912813#if AP_EXTERNAL_AHRS_ENABLED
27922814void AP_InertialSensor::handle_external (const AP_ExternalAHRS::ins_data_message_t &pkt)
27932815{
2816+ TempCalibration = pkt.TempCalibration ;
2817+ if (TempCalibration == AP_ExternalAHRS::TempCal::IsTempCalibrated){
2818+ IsTempCalibrated = true ;
2819+ }
27942820 for (uint8_t i = 0 ; i < _backend_count; i++) {
27952821 _backends[i]->handle_external (pkt);
27962822 }
0 commit comments