MAVLINKHUD

Overview

The TCAL parameter group configures the Sensor Temperature Calibration system. All MEMS sensors (Accelerometers, Gyroscopes, Barometers) suffer from "Thermal Drift"—their zero-point and scale changes as the board heats up.

TCAL uses mathematical models to compensate for this drift in real-time, ensuring a stable horizon and altitude reference from a cold startup through to high-power flight.

Key Concepts

1. Calibration Models

The autopilot records sensor behavior across a range of temperatures (defined by TCAL_TEMP_MIN and MAX) and fits a polynomial curve to the data.

  • TCAL_BARO_EXP: The learned exponent for barometer temperature correction.

2. Auto-Learning

Modern ArduPilot can "learn" these coefficients automatically during the warm-up period while the drone is disarmed.

Parameter Breakdown

  • TCAL_ENABLED: Master switch.
  • TCAL_OPTIONS: Bitmask for learning behaviors.
  • TCAL_TEMP_MIN / MAX: The valid temperature range for the calibration model.

Integration Guide

  • Recommendation: Leave TCAL_ENABLED = 1 for most modern hardware. If you see a drifting horizon after takeoff, perform a factory temperature calibration (requires a freezer and a heat source—see Wiki).

Developer Notes

  • Library: libraries/AP_TempCalibration.

TCAL_BARO_EXP

Default 0

Temperature Calibration barometer exponent (TCAL_BARO_EXP)

Description

This parameter represents the Learned Exponent for the barometer's temperature calibration curve. It is automatically adjusted by the AP_TempCalibration library when the vehicle is disarmed and undergoing temperature changes (e.g., self-heating after boot). It ensures that the altitude reading remains stable even as the autopilot's temperature fluctuates.

The Mathematics

The calibration model corrects the raw pressure reading based on the temperature difference from a reference point:
$$ P\_{corrected} \approx P\_{raw} + \text{TCAL\_BARO\_EXP} \cdot (T - T\_{cal}) $$
(Note: This is a simplified representation of the internal polynomial fit).

The Engineer's View

Defined in libraries/AP_TempCalibration/AP_TempCalibration.cpp. It is part of the AP_TempCalibration system which monitors IMU and Baro drift vs. temperature.

  • Do Not Edit: This value is learned. Manually changing it will invalidate the calibration.
  • Reset: Setting to 0 resets the learning for this term.

Tuning & Behavior

  • Default Value: 0
  • Behavior: Should converge to a non-zero value over time if the board has significant temperature sensitivity.

TCAL_ENABLED

Option
Default 0
Range 0 2

Temperature calibration enable (TCAL_ENABLED)

Description

This parameter enables the advanced temperature calibration system. Many MEMS sensors (especially barometers like the ICM-20789) suffer from "thermal drift," where the reported values change significantly as the electronics heat up during operation.

Setting this parameter allows the autopilot to either "Learn" a correction model for your specific hardware or "Apply" previously learned corrections to ensure stable altitude and attitude estimates across varying temperatures.

The Mathematics

The system operates as a simple state machine:

  • 0: Disabled. No thermal corrections are applied.
  • 1: Enabled (Use Learned). The autopilot applies the learned exponent (e.g., BARO_EXP) to the raw sensor data.
  • 2: Enable and Learn. While the vehicle is stationary and disarmed, the system records sensor drift vs. temperature and uses a least-squares fit to calculate the correction model. Once a sufficient temperature range is covered, it updates the calibration parameters.

The Engineer's View

In AP_TempCalibration.cpp, the update() function runs at 10Hz:

  1. If set to TC_ENABLE_LEARN (2), it calls learn_calibration(). This requires the vehicle to be perfectly still (AP::ins().is_still()) and disarmed.
  2. If set to TC_ENABLE_USE (1) or TC_ENABLE_LEARN (2), it calls apply_calibration().
  3. The actual correction is applied to the barometer driver via baro.set_pressure_correction().

Tuning & Behavior

  • Learning Procedure: To calibrate a new board, set TCAL_ENABLED=2 and let the vehicle sit stationary for 10-15 minutes while it warms up.
  • Verification: Check the TCAL_TEMP_MIN and TCAL_TEMP_MAX parameters to see the range covered during learning.
  • Final Step: Once you are happy with the stability, you can set this to 1 to stop the learning process and just use the saved model.

TCAL_OPTIONS

Bitmask
Default 0
Range null

Temperature Calibration Options (TCAL_OPTIONS)

Description

This parameter provides advanced control over how thermal calibration data is stored and managed. It specifically enables the "Persistence" feature, which allows the autopilot to save calibrated sensor values into a special protected area of memory (the bootloader sector).

Saving values here ensures that your high-fidelity temperature calibration remains intact even if you perform a "Reset to Defaults" on all other parameters. It is highly recommended for industrial-grade vehicles where re-performing a 20-minute thermal calibration in the field is not practical.

The Mathematics

This is a bitmask ($B$):

  • Bit 0 (Value 1): PersistTemps. Saves the temperature-related calibration constants to the bootloader sector.
  • Bit 1 (Value 2): PersistAccels. Saves the accelerometer-related thermal constants to the bootloader sector.

The Engineer's View

In AP_InertialSensor.cpp, this maps to tcal_options.

  • Safety: The bootloader sector is used because it is rarely erased and exists outside the standard parameter storage area.
  • Transfer: During the next bootloader update or specific GCS command, the autopilot will copy the volatile RAM-based calibration into this persistent storage.
  • Recall: On every subsequent boot, ArduPilot checks the bootloader sector first. If valid calibration is found there, it is loaded into the active sensor drivers automatically.

Tuning & Behavior

  • Default Value: 0 (Persistence disabled; values stored in standard EEPROM only).
  • Recommended: Set to 3 (Bit 0 + Bit 1) once you have achieved a "Perfect" thermal calibration.
  • Industrial Use: This is standard for factory-calibrated aircraft where the sensor drift profiles are fixed for the life of the airframe.

TCAL_TEMP_MAX

degC
Default 0
Range null

Calibration temperature maximum (TCAL_TEMP_MAX)

Description

This parameter records the maximum temperature reached during a successful "Enable and Learn" session for temperature calibration.

Thermal calibration works by watching how a sensor drifts as the flight controller heats up from its starting temperature to its steady-state operating temperature. TCAL_TEMP_MAX tells you the "Top End" of the data set used to create your correction model.

The Mathematics

The system tracks the highest temperature ($T\_{max}$) encountered while the vehicle was stationary and learning:

$$ TCAL\_TEMP\_MAX = T\_{start} + (\text{LastValidIndex} \times \text{StepSize}) $$

The StepSize is typically 0.25°C. This value defines the upper boundary of the "Trusted Zone" for the correction exponent.

The Engineer's View

In AP_TempCalibration::calculate_calibration() (libraries/AP_TempCalibration/AP_TempCalibration.cpp):

  1. The code determines the current progress of the learning buffer (learn_i).
  2. It calculates the maximum temperature point reached in the data array.
  3. It updates temp_max and saves it to EEPROM along with the new calibration exponent.
  4. This provides a clear audit trail for the quality of the calibration.

Tuning & Behavior

  • Default Value: 0.
  • Automatic: Set by the system. Do not edit manually.
  • Troubleshooting: If this value is very close to TCAL_TEMP_MIN, it means the vehicle didn't have enough time to warm up (or the environment was too cold), and the resulting calibration might be inaccurate. Aim for at least a 10-15°C difference between MIN and MAX for a high-fidelity calibration.

TCAL_TEMP_MIN

degC
Default 0
Range null

Calibration temperature minimum (TCAL_TEMP_MIN)

Description

This parameter records the starting (lowest) temperature of the range over which the temperature calibration model was learned.

For a thermal correction model (like BARO_EXP) to be valid, it needs to be calculated based on data from a meaningful temperature change. This parameter, along with TCAL_TEMP_MAX, allows the pilot to verify that the learning process covered a wide enough range of temperatures to accurately model the sensor's drift.

The Mathematics

During the learning phase (TCAL_ENABLED=2), the system records the initial temperature ($T\_{start}$). Once the least-squares fit is calculated and the calibration is saved:

$$ TCAL\_TEMP\_MIN = T\_{start} $$

This serves as a geofence for the calibration validity; corrections applied far outside the MIN/MAX range may be less accurate.

The Engineer's View

In AP_TempCalibration::calculate_calibration() (libraries/AP_TempCalibration/AP_TempCalibration.cpp):

  1. The code calculates the optimal baro_exponent.
  2. Upon a successful calculation, it saves the learn_temp_start value into temp_min.
  3. The value is marked as Volatile in the parameter table, meaning it is expected to change during runtime as learning progresses.

Tuning & Behavior

  • Default Value: 0.
  • Automatic: This value is set automatically by the autopilot. You should not edit it manually.
  • Verification: If TCAL_TEMP_MAX minus TCAL_TEMP_MIN is less than 10 degrees, the calibration might not be robust enough for all seasons.