diff --git a/ArduSub/ArduSub.cpp b/ArduSub/ArduSub.cpp index b11ee21c2b..1263593540 100644 --- a/ArduSub/ArduSub.cpp +++ b/ArduSub/ArduSub.cpp @@ -462,6 +462,10 @@ void Sub::three_hz_loop() { set_leak_status(water_detector.update()); + failsafe_internal_pressure_check(); + + failsafe_internal_temperature_check(); + // check if we've lost contact with the ground station failsafe_gcs_check(); diff --git a/ArduSub/Sub.h b/ArduSub/Sub.h index 9d7e34d1d3..73520644bb 100644 --- a/ArduSub/Sub.h +++ b/ArduSub/Sub.h @@ -303,6 +303,8 @@ private: uint8_t ekf : 1; // 5 // true if ekf failsafe has occurred uint8_t terrain : 1; // 6 // true if the missing terrain data failsafe has occurred uint8_t leak : 1; // true if leak recently detected + uint8_t internal_pressure : 1; + uint8_t internal_temperature :1; uint32_t last_leak_warn_ms; // last time a leak warning was sent to gcs uint32_t last_gcs_warn_ms; @@ -1043,6 +1045,8 @@ private: void accel_cal_update(void); void set_leak_status(bool status); + void failsafe_internal_pressure_check(); + void failsafe_internal_temperature_check(); bool surface_init(bool ignore_flags); void surface_run(); diff --git a/ArduSub/events.cpp b/ArduSub/events.cpp index 61d0aaeac7..fca3933306 100644 --- a/ArduSub/events.cpp +++ b/ArduSub/events.cpp @@ -1,7 +1,8 @@ // -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- #include "Sub.h" - +#define FS_INTERNAL_PRESSURE_MAX 105000 // 103000 pascal +#define FS_INTERNAL_TEMPERATURE_MAX 55 // 50 deg C /* * This event will be called when the failsafe changes * boolean failsafe reflects the current state @@ -73,6 +74,48 @@ void Sub::failsafe_battery_event(void) } +void Sub::failsafe_internal_pressure_check() { + uint32_t tnow = AP_HAL::millis(); + static uint32_t last_pressure_warn_ms; + static uint32_t last_pressure_good_ms; + if(barometer.get_pressure(0) < FS_INTERNAL_PRESSURE_MAX) { + last_pressure_good_ms = tnow; + last_pressure_warn_ms = tnow; + failsafe.internal_pressure = false; + return; + } + + if(tnow > last_pressure_good_ms + 2000) { + failsafe.internal_pressure = true; + } + + if(failsafe.internal_pressure && tnow > last_pressure_warn_ms + 5000) { + last_pressure_warn_ms = tnow; + gcs_send_text(MAV_SEVERITY_WARNING, "Internal pressure critical!"); + } +} + +void Sub::failsafe_internal_temperature_check() { + uint32_t tnow = AP_HAL::millis(); + static uint32_t last_temperature_warn_ms; + static uint32_t last_temperature_good_ms; + if(barometer.get_temperature(0) < FS_INTERNAL_TEMPERATURE_MAX) { + last_temperature_good_ms = tnow; + last_temperature_warn_ms = tnow; + failsafe.internal_temperature = false; + return; + } + + if(tnow > last_temperature_good_ms + 2000) { + failsafe.internal_temperature = true; + } + + if(failsafe.internal_temperature && tnow > last_temperature_warn_ms + 5000) { + last_temperature_warn_ms = tnow; + gcs_send_text(MAV_SEVERITY_WARNING, "Internal temperature critical!"); + } +} + void Sub::set_leak_status(bool status) { AP_Notify::flags.leak_detected = status;