Skip to content

PR: baro auto calibration#24220

Closed
haumarco wants to merge 3 commits intomainfrom
pr-ekf2_baro_auto_rel_calib
Closed

PR: baro auto calibration#24220
haumarco wants to merge 3 commits intomainfrom
pr-ekf2_baro_auto_rel_calib

Conversation

@haumarco
Copy link
Copy Markdown
Contributor

Solved Problem

When we have multiple barometers, we currently do not perform any calibration. There already exists a do_baro_calibration function, but I guess nobody used it since the function call of getAltitudeFromPressure had the wrong arguments.

This fix adds a calibration procedure for handling relative offsets between multiple baros, avoiding vertical position jumps when one switches between baros mid-flight.
When GNSS is set as the height reference, the calibration offset is calculated in respect to the absolute height (currently in baro-bias).

The offset is now stored in the offset parameter since it's static and not a changing bias.

I checked various flight logs with durations of more than 3000s and could not observe non systematic drifts between baros. Therefore frequent recalibration does not make any sense.

with GNSS, calibration triggered at t=34:
Screenshot from 2025-01-15 17-43-09

Switch from baro0 to baro1:
Screenshot from 2025-01-15 17-17-03


Feedback needed:
I now trigger the calibration 1s after the first baro measurement. At this point in time the GNSS is not sending any data yet. Therefore a manual trigger from the user is necessary to perform an absolute calibration. This wouldnt be a problem though, since the baro bias would still handle this case... Should I change something about this?

@haumarco haumarco requested a review from bresch January 15, 2025 17:00
@github-actions
Copy link
Copy Markdown

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: 360 byte (0.02 %)]
    FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%    +360  +0.0%    +360    .text
   +17%    +200   +17%    +200    ../../src/modules/commander/baro_calibration.cpp
  +5.3%    +152  +5.3%    +152    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +16  +0.0%     +16    src/modules/ekf2/modules__ekf2_unity.cpp
  -0.0%      -8  -0.0%      -8    [section .text]
+0.0%    +425  [ = ]       0    .debug_abbrev
   +11%     +56  [ = ]       0    ../../src/lib/version/version.c
   +16%    +297  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +2.2%     +72  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
-0.0%      -8  [ = ]       0    .debug_aranges
  -5.0%      -8  [ = ]       0    ../../src/lib/version/version.c
+0.1% +17.0Ki  [ = ]       0    .debug_info
  -0.2%      -4  [ = ]       0    ../../src/lib/version/version.c
  +0.0%     +13  [ = ]       0    ../../src/modules/airspeed_selector/airspeed_selector_main.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/Commander.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/accelerometerCheck.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/baroCheck.cpp
  +0.0%     +29  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/gyroCheck.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/magnetometerCheck.cpp
   +75% +13.6Ki  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +6.4% +3.30Ki  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.1%     +13  [ = ]       0    msg/topics_sources/estimator_status.cpp
  +0.0%      +9  [ = ]       0    msg/topics_sources/uORBMessageFieldsGenerated.cpp
  +0.0%     +37  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%     +14  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
+0.0%    +982  [ = ]       0    .debug_line
  -1.3%     -25  [ = ]       0    ../../src/lib/version/version.c
   +22%    +732  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +3.3%    +252  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +26  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  -0.3%      -3  [ = ]       0    task/task_cancelpt.c
+0.0%   +1005  [ = ]       0    .debug_loc
  -0.3%      -4  [ = ]       0    ../../src/modules/commander/airspeed_calibration.cpp
   +36%    +828  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +4.2%    +286  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  -0.0%      -4  [ = ]       0    [section .debug_loc]
  -0.0%    -101  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
+0.1%    +674  [ = ]       0    .debug_ranges
  -2.6%      -8  [ = ]       0    ../../src/lib/version/version.c
   +88%    +456  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +9.2%    +224  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +3.1%      +2  [ = ]       0    task/task_cancelpt.c
+0.0%    +109  [ = ]       0    .debug_str
  +0.0%      +8  [ = ]       0    ../../src/modules/airspeed_selector/airspeed_selector_main.cpp
   +20%    +472  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +0.6%     +11  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  -0.1%    -382  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
-2.8%    -360  [ = ]       0    [Unmapped]
+0.0% +20.2Ki  +0.0%    +360    TOTAL

px4_fmu-v6x [Total VM Diff: 376 byte (0.02 %)]
    FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%    +376  +0.0%    +376    .text
   +17%    +200   +17%    +200    ../../src/modules/commander/baro_calibration.cpp
  +5.3%    +152  +5.3%    +152    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +16  +0.0%     +16    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%      +5  +0.0%      +5    [section .text]
  +0.2%      +3  +0.2%      +3    ../../src/systemcmds/ver/ver.cpp
+0.0%    +425  [ = ]       0    .debug_abbrev
   +11%     +56  [ = ]       0    ../../src/lib/version/version.c
   +16%    +297  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +2.2%     +72  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
-0.0%      -8  [ = ]       0    .debug_aranges
  -5.0%      -8  [ = ]       0    ../../src/lib/version/version.c
+0.1% +17.0Ki  [ = ]       0    .debug_info
  -0.2%      -4  [ = ]       0    ../../src/lib/version/version.c
  +0.0%     +13  [ = ]       0    ../../src/modules/airspeed_selector/airspeed_selector_main.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/Commander.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/HealthAndArmingChecks.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/accelerometerCheck.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/baroCheck.cpp
  +0.0%     +29  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/estimatorCheck.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/gyroCheck.cpp
  +0.0%     +13  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/magnetometerCheck.cpp
   +75% +13.6Ki  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +6.4% +3.30Ki  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.1%     +13  [ = ]       0    msg/topics_sources/estimator_status.cpp
  +0.0%      +9  [ = ]       0    msg/topics_sources/uORBMessageFieldsGenerated.cpp
  +0.0%     +37  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%     +14  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
+0.0%    +990  [ = ]       0    .debug_line
  -1.3%     -25  [ = ]       0    ../../src/lib/version/version.c
   +22%    +732  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +3.3%    +252  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +26  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.4%      +5  [ = ]       0    task/task_cancelpt.c
+0.0% +1.10Ki  [ = ]       0    .debug_loc
  -0.4%     -15  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/accelerometerCheck.cpp
  -0.3%      -4  [ = ]       0    ../../src/modules/commander/airspeed_calibration.cpp
   +36%    +828  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +4.2%    +286  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +28  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
+0.1%    +672  [ = ]       0    .debug_ranges
  -2.6%      -8  [ = ]       0    ../../src/lib/version/version.c
   +88%    +456  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +9.2%    +224  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
+0.0%    +109  [ = ]       0    .debug_str
  +0.0%      +8  [ = ]       0    ../../src/modules/airspeed_selector/airspeed_selector_main.cpp
   +20%    +472  [ = ]       0    ../../src/modules/commander/baro_calibration.cpp
  +0.6%     +11  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  -0.1%    -382  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
-0.5%    -376  [ = ]       0    [Unmapped]
+0.0% +20.3Ki  +0.0%    +376    TOTAL

Updated: 2025-01-15T17:06:36

@dagar dagar self-requested a review January 15, 2025 18:24
Copy link
Copy Markdown
Member

@dagar dagar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but how about...

  1. Doing it from sensors/vehicle_air_data where you already have access to all sensor_baro subscriptions, calibrations, and vehicle_air_data output. https://github.com/PX4/PX4-Autopilot/blob/main/src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  2. Use vehicle_gps_position (or even all sensor_gps publications) rather than depend on an EKF2 dependency.

@haumarco
Copy link
Copy Markdown
Contributor Author

I like the idea, but how about...

  1. I first started to implement it in VehicleAirData.cpp but moved it to the commander to keep a nice workflow for the manually triggered calibration procedure. In the sensors module it would also create an overhead because i want to collect data for some time (list of measurement, start/stop handling), in the commander it just runs in a separate thread.
  2. not sure what you mean, currently it subscribes to sensor_gps?

@haumarco
Copy link
Copy Markdown
Contributor Author

handled this by separating the task:
#24314
#24859

@haumarco haumarco closed this Jul 15, 2025
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in PX4 Misc Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants