From a458f1bf5f402831178d35c00e07b55b346adfa7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 22 Jul 2014 18:07:48 +1000 Subject: [PATCH] AP_Baro: minor improvements to Baro HIL code health check --- libraries/AP_Baro/AP_Baro.cpp | 6 ++++-- libraries/AP_Baro/AP_Baro_HIL.cpp | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libraries/AP_Baro/AP_Baro.cpp b/libraries/AP_Baro/AP_Baro.cpp index 3f1f3dc69a..e4f40da04f 100644 --- a/libraries/AP_Baro/AP_Baro.cpp +++ b/libraries/AP_Baro/AP_Baro.cpp @@ -125,7 +125,8 @@ void AP_Baro::calibrate() */ void AP_Baro::update_calibration() { - _ground_pressure.set(get_pressure()); + float pressure = get_pressure(); + _ground_pressure.set(pressure); _ground_temperature.set(get_temperature()); } @@ -166,7 +167,8 @@ float AP_Baro::get_altitude(void) return _altitude + _alt_offset; } - _altitude = get_altitude_difference(_ground_pressure, get_pressure()); + float pressure = get_pressure(); + _altitude = get_altitude_difference(_ground_pressure, pressure); _last_altitude_t = _last_update; diff --git a/libraries/AP_Baro/AP_Baro_HIL.cpp b/libraries/AP_Baro/AP_Baro_HIL.cpp index a33b3c809e..835e8b9509 100644 --- a/libraries/AP_Baro/AP_Baro_HIL.cpp +++ b/libraries/AP_Baro/AP_Baro_HIL.cpp @@ -9,6 +9,7 @@ extern const AP_HAL::HAL& hal; // Public Methods ////////////////////////////////////////////////////////////// bool AP_Baro_HIL::init() { + healthy = false; return true; } @@ -35,11 +36,13 @@ uint8_t AP_Baro_HIL::read() void AP_Baro_HIL::setHIL(float pressure, float temperature) { - _count = 1; - _pressure_sum = pressure; - _temperature_sum = temperature; - _last_update = hal.scheduler->millis(); - healthy = true; + if (pressure > 0) { + _count = 1; + _pressure_sum = pressure; + _temperature_sum = temperature; + _last_update = hal.scheduler->millis(); + healthy = true; + } }