From 8eee7ba32117d62288c938efca01ef061cde82fc Mon Sep 17 00:00:00 2001 From: tumbili Date: Mon, 8 Jun 2015 09:15:50 +0200 Subject: [PATCH] compute atmospheric pressure from altitude --- src/modules/simulator/simulator_mavlink.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/simulator/simulator_mavlink.cpp b/src/modules/simulator/simulator_mavlink.cpp index d72d4d473c..65b73c2899 100644 --- a/src/modules/simulator/simulator_mavlink.cpp +++ b/src/modules/simulator/simulator_mavlink.cpp @@ -43,6 +43,10 @@ using namespace simulator; #define UDP_PORT 14550 #define PIXHAWK_DEVICE "/dev/ttyACM0" +#define PRESS_GROUND 101325.0f +#define DENSITY 1.2041f +#define GRAVITY 9.81f + static const uint8_t mavlink_message_lengths[256] = MAVLINK_MESSAGE_LENGTHS; static const uint8_t mavlink_message_crcs[256] = MAVLINK_MESSAGE_CRCS; @@ -183,7 +187,8 @@ void Simulator::update_sensors(struct sensor_combined_s *sensor, mavlink_hil_sen write_mag_data((void *)&mag); RawBaroData baro; - baro.pressure = imu->abs_pressure; + // calculate air pressure from altitude (valid for low altitude) + baro.pressure = PRESS_GROUND - GRAVITY * DENSITY * imu->pressure_alt; baro.altitude = imu->pressure_alt; baro.temperature = imu->temperature;