Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up temperature msg fields #24272

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

haumarco
Copy link
Contributor

Solved Problem

Currently, multiple temperature measurements are used across different functionalities to represent ambient temperature. This creates ambiguity regarding which temperature measurement should be designated as vehicle_temperature. We lack dedicated temperature sensors or topics to consistently rely on a single source.

Solution

Implement a prioritized selection of temperature sensors. When an external airspeed sensor is available, its temperature is used as the primary source. If an external barometer is present, its temperature serves as the secondary option. The temperature from the internal barometer is disregarded due to its unreliability, which is caused by inconsistent PCB heat dissipation across different flight controllers.

Changelog Entry

Create a distinct ambient_temperature field in the VehicleAirData message.

Alternatives

An alternative approach would be to create a dedicated temperature uORB topic to centralize ambient temperature data.

Test Coverage

Tested with various setups and hardcoded measurements in simulation environments to ensure reliability and accuracy.

@haumarco haumarco requested a review from sfuhrer January 30, 2025 10:51
@haumarco haumarco force-pushed the pr_clean_temperature_usage branch from e60a339 to 695bfb9 Compare January 30, 2025 12:58
Copy link

github-actions bot commented Jan 30, 2025

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: -112 byte (-0.01 %)]
    FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%     +56  [ = ]       0    .debug_abbrev
   +11%     +56  [ = ]       0    ../../src/lib/version/version.c
-0.0%     -16  [ = ]       0    .debug_aranges
  -5.0%      -8  [ = ]       0    ../../src/lib/version/version.c
  -3.1%      -8  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
-0.0%     -16  [ = ]       0    .debug_frame
+0.0%    +101  [ = ]       0    .debug_info
  -0.1%     -13  [ = ]       0    ../../src/drivers/telemetry/frsky_telemetry/frsky_data.cpp
  -0.1%     -13  [ = ]       0    ../../src/drivers/telemetry/frsky_telemetry/frsky_telemetry.cpp
  -0.1%     -13  [ = ]       0    ../../src/drivers/telemetry/frsky_telemetry/sPort_data.cpp
  -0.1%     -13  [ = ]       0    ../../src/drivers/telemetry/hott/messages.cpp
  +0.0%      +3  [ = ]       0    ../../src/drivers/uavcan/remoteid.cpp
  +0.0%     +16  [ = ]       0    ../../src/drivers/uavcan/sensors/airspeed.cpp
  -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/fw_pos_control/FixedwingPositionControl.cpp
  -0.1%    -130  [ = ]       0    ../../src/modules/sensors/sensors.cpp
  +0.2%    +117  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  -0.0%     -13  [ = ]       0    ../../src/modules/vtol_att_control/vtol_att_control_main.cpp
  +0.2%     +16  [ = ]       0    msg/topics_sources/airspeed.cpp
  -0.1%     -18  [ = ]       0    msg/topics_sources/uORBMessageFieldsGenerated.cpp
  -0.1%     -13  [ = ]       0    msg/topics_sources/vehicle_air_data.cpp
  -0.0%     -13  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%    +218  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
-0.0%     -45  [ = ]       0    .debug_line
  +0.3%      +7  [ = ]       0    ../../src/drivers/telemetry/hott/messages.cpp
  -0.2%     -16  [ = ]       0    ../../src/drivers/uavcan/sensors/airspeed.cpp
  -1.3%     -25  [ = ]       0    ../../src/lib/version/version.c
  -0.9%    -114  [ = ]       0    ../../src/modules/sensors/sensors.cpp
  +0.7%     +54  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  -0.0%     -10  [ = ]       0    ../../src/modules/simulation/simulator_sih/sih.cpp
  +0.0%     +56  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
  +0.3%      +3  [ = ]       0    task/task_cancelpt.c
+0.0%    +187  [ = ]       0    .debug_loc
  -0.0%      -2  [ = ]       0    ../../src/drivers/uavcan/uavcan_main.cpp
  +0.0%     +20  [ = ]       0    ../../src/drivers/uavcan/uavcan_servers.cpp
  -0.1%     -64  [ = ]       0    ../../src/modules/fw_pos_control/FixedwingPositionControl.cpp
  -1.1%    -115  [ = ]       0    ../../src/modules/sensors/sensors.cpp
  +3.3%    +234  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%      +2  [ = ]       0    [section .debug_loc]
  +0.0%     +23  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%     +89  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
+0.0%     +64  [ = ]       0    .debug_ranges
  -2.6%      -8  [ = ]       0    ../../src/lib/version/version.c
  +3.0%     +72  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
+0.0%    +149  [ = ]       0    .debug_str
  -0.3%      -6  [ = ]       0    ../../src/drivers/telemetry/frsky_telemetry/frsky_telemetry.cpp
  -0.1%     -24  [ = ]       0    ../../src/drivers/uavcan/sensors/airspeed.cpp
  +0.1%     +24  [ = ]       0    ../../src/modules/airspeed_selector/airspeed_selector_main.cpp
  +3.3%     +65  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%      +8  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%     +82  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
+1.0%      +2  [ = ]       0    .shstrtab
+0.0%      +2  [ = ]       0    .strtab
  -8.1%     -32  [ = ]       0    ../../src/lib/version/version.c
  +0.3%      +2  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +32  [ = ]       0    [section .strtab]
-0.0%     -16  [ = ]       0    .symtab
  -1.2%     -16  [ = ]       0    ../../src/drivers/uavcan/sensors/airspeed.cpp
  -7.0%     -64  [ = ]       0    ../../src/lib/version/version.c
  -6.7%     -16  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/modeCheck.cpp
  +0.3%     +16  [ = ]       0    ../../src/modules/fw_pos_control/FixedwingPositionControl.cpp
  +2.2%     +16  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.1%     +48  [ = ]       0    [section .symtab]
+1.0%    +112  [ = ]       0    [Unmapped]
-0.0%    -112  -0.0%    -112    .text
  +1.8%     +52  +1.8%     +52    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +32  +0.0%     +32    src/modules/mavlink/modules__mavlink_unity.cpp
  +0.4%      +4  +0.4%      +4    ../../src/modules/sensors/vehicle_gps_position/VehicleGPSPosition.cpp
  +0.2%      +3  +0.2%      +3    ../../src/systemcmds/ver/ver.cpp
  -0.0%      -3  -0.0%      -3    [section .text]
  -0.0%      -8  -0.0%      -8    ../../src/modules/simulation/simulator_sih/sih.cpp
  -0.9%     -24  -0.9%     -24    ../../src/drivers/uavcan/sensors/airspeed.cpp
  -3.4%    -168  -3.4%    -168    ../../src/modules/sensors/sensors.cpp
+0.0%    +468  -0.0%    -112    TOTAL

px4_fmu-v6x [Total VM Diff: -120 byte (-0.01 %)]
    FILE SIZE        VM SIZE    
--------------  -------------- 
+0.0%     +56  [ = ]       0    .debug_abbrev
   +11%     +56  [ = ]       0    ../../src/lib/version/version.c
-0.0%     -16  [ = ]       0    .debug_aranges
  -5.0%      -8  [ = ]       0    ../../src/lib/version/version.c
  -3.1%      -8  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
-0.0%     -16  [ = ]       0    .debug_frame
+0.0%    +153  [ = ]       0    .debug_info
  +0.0%      +3  [ = ]       0    ../../src/drivers/uavcan/remoteid.cpp
  +0.0%     +16  [ = ]       0    ../../src/drivers/uavcan/sensors/airspeed.cpp
  -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/fw_pos_control/FixedwingPositionControl.cpp
  -0.1%    -130  [ = ]       0    ../../src/modules/sensors/sensors.cpp
  +0.2%    +117  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  -0.0%     -13  [ = ]       0    ../../src/modules/vtol_att_control/vtol_att_control_main.cpp
  +0.2%     +16  [ = ]       0    msg/topics_sources/airspeed.cpp
  -0.1%     -18  [ = ]       0    msg/topics_sources/uORBMessageFieldsGenerated.cpp
  -0.1%     -13  [ = ]       0    msg/topics_sources/vehicle_air_data.cpp
  -0.0%     -13  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%    +218  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
-0.0%     -49  [ = ]       0    .debug_line
  -0.2%     -16  [ = ]       0    ../../src/drivers/uavcan/sensors/airspeed.cpp
  -1.3%     -25  [ = ]       0    ../../src/lib/version/version.c
  -0.9%    -114  [ = ]       0    ../../src/modules/sensors/sensors.cpp
  +0.7%     +54  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +56  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
  -0.4%      -4  [ = ]       0    task/task_cancelpt.c
+0.0%    +133  [ = ]       0    .debug_loc
  -0.0%      -2  [ = ]       0    ../../src/drivers/uavcan/uavcan_main.cpp
  -0.0%     -13  [ = ]       0    ../../src/drivers/uavcan/uavcan_servers.cpp
  -0.1%     -80  [ = ]       0    ../../src/modules/fw_pos_control/FixedwingPositionControl.cpp
  -1.1%    -115  [ = ]       0    ../../src/modules/sensors/sensors.cpp
  +3.1%    +219  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +35  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%     +89  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
+0.0%     +66  [ = ]       0    .debug_ranges
  -2.6%      -8  [ = ]       0    ../../src/lib/version/version.c
  +3.0%     +72  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +3.1%      +2  [ = ]       0    task/task_cancelpt.c
+0.0%    +149  [ = ]       0    .debug_str
  -0.1%      -6  [ = ]       0    ../../src/drivers/uavcan/remoteid.cpp
  -0.1%     -24  [ = ]       0    ../../src/drivers/uavcan/sensors/airspeed.cpp
  +0.1%     +24  [ = ]       0    ../../src/modules/airspeed_selector/airspeed_selector_main.cpp
  +3.3%     +65  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%      +8  [ = ]       0    src/modules/ekf2/modules__ekf2_unity.cpp
  +0.0%     +82  [ = ]       0    src/modules/mavlink/modules__mavlink_unity.cpp
+0.9%      +2  [ = ]       0    .shstrtab
+0.0%      +2  [ = ]       0    .strtab
  -8.1%     -32  [ = ]       0    ../../src/lib/version/version.c
  +0.3%      +2  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +32  [ = ]       0    [section .strtab]
-0.0%     -16  [ = ]       0    .symtab
  -1.2%     -16  [ = ]       0    ../../src/drivers/uavcan/sensors/airspeed.cpp
  -7.0%     -64  [ = ]       0    ../../src/lib/version/version.c
  -6.7%     -16  [ = ]       0    ../../src/modules/commander/HealthAndArmingChecks/checks/modeCheck.cpp
  +0.3%     +16  [ = ]       0    ../../src/modules/fw_pos_control/FixedwingPositionControl.cpp
  +2.2%     +16  [ = ]       0    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.1%     +48  [ = ]       0    [section .symtab]
+0.2%    +120  [ = ]       0    [Unmapped]
-0.0%    -120  -0.0%    -120    .text
  +1.8%     +52  +1.8%     +52    ../../src/modules/sensors/vehicle_air_data/VehicleAirData.cpp
  +0.0%     +32  +0.0%     +32    src/modules/mavlink/modules__mavlink_unity.cpp
  +0.4%      +4  +0.4%      +4    ../../src/modules/sensors/vehicle_gps_position/VehicleGPSPosition.cpp
  -0.0%     -16  -0.0%     -16    [section .text]
  -0.9%     -24  -0.9%     -24    ../../src/drivers/uavcan/sensors/airspeed.cpp
  -3.4%    -168  -3.4%    -168    ../../src/modules/sensors/sensors.cpp
+0.0%    +464  -0.0%    -120    TOTAL

Updated: 2025-02-03T10:06:38

{
vehicle_air_data_s air_data;

if (_vehicle_air_data_sub.update(&air_data)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need a small edit of the comment in the MAVLink message.
"Air temperature from airspeed sensor" is no longer valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@sfuhrer It doesn't work that way - if this PR merges PX4 is no longer compliant with the MAVLink specification. The message itself is fine :-)

Whether we can update the message in MAVLink depends on whether there is a semantic difference that matters to consumers. I don't know, but that requires agreement with other stakeholders.

Copy link
Contributor

Choose a reason for hiding this comment

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

I know, and we'll update the wording on the mavlink RP. Never the less, we're convinced that this is the right approach.
@haumarco to be compliant with the mavlink message we can for now also subscribe to differential_pressure.temperature here.

src/modules/sensors/vehicle_air_data/VehicleAirData.cpp Outdated Show resolved Hide resolved
src/modules/sensors/vehicle_air_data/VehicleAirData.cpp Outdated Show resolved Hide resolved
src/modules/sensors/vehicle_air_data/VehicleAirData.cpp Outdated Show resolved Hide resolved
src/modules/sensors/vehicle_air_data/VehicleAirData.cpp Outdated Show resolved Hide resolved
src/drivers/uavcan/sensors/airspeed.cpp Show resolved Hide resolved
float32 baro_pressure_pa # Absolute pressure in Pascals
float32 ambient_temperature # Abient temperature in degrees Celsius
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a flag for the source of this field? Differential pressure, external baro, default ambient air temperature?

@@ -193,7 +193,7 @@ class MavlinkStreamHighresIMU : public MavlinkStream
msg.abs_pressure = air_data.baro_pressure_pa;
msg.diff_pressure = differential_pressure.differential_pressure_pa;
msg.pressure_alt = air_data.baro_alt_meter;
msg.temperature = air_data.baro_temp_celcius;
msg.temperature = air_data.ambient_temperature;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that field be filled with the IMU temperature? How about subscribing to vehicleImuStatus.msg/temperature_accel or _gyro?

vehicle_air_data_s air_data;

if (_vehicle_air_data_sub.update(&air_data)) {
_temperature.add_value(air_data.ambient_temperature, _update_rate_filtered);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we only publish a value if it's actually coming a sensor and is not the hard coded 15°C?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants