From 3c7da206c2ba389dd2e806017b19d7e887085a0e Mon Sep 17 00:00:00 2001 From: ES-Alexander Date: Sat, 16 May 2026 00:03:43 +0800 Subject: [PATCH] scripts: BlueBoat: add leak failsafe --- scripts/ardupilot/ArduRover/4.x/leak.lua | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/ardupilot/ArduRover/4.x/leak.lua diff --git a/scripts/ardupilot/ArduRover/4.x/leak.lua b/scripts/ardupilot/ArduRover/4.x/leak.lua new file mode 100644 index 0000000..3085b43 --- /dev/null +++ b/scripts/ardupilot/ArduRover/4.x/leak.lua @@ -0,0 +1,40 @@ +-- Leak detection/failsafe functionality for the Navigator +-- Intended for use with ArduRover (e.g. on a BlueBoat) + +---- USER CONFIG ---- +local warning_interval_ms = uint32_t(15000) -- warn every 15s + +-- specify 1-2 failsafe modes for desired behaviour +RoverMode = { + Hold = 4, + Loiter = 5, + RTL = 11, + SmartRTL = 12, +} +local failsafe_mode = {RoverMode.Loiter, RoverMode.Hold} -- try to loiter, otherwise hold +--------------------- + +-- perform setup +local navigator_leak_pin = 27 +gpio:pinMode(navigator_leak_pin,0) -- configure as a digital input +local warning_last_sent = uint32_t() + +-- define the loop +function update() + if gpio:read(navigator_leak_pin) then + -- warn the operator, if they haven't been warned recently + if millis() - warning_last_sent > warning_interval_ms then + gcs:send_text(2, "Leak detected!") -- critical level announcement + warning_last_sent = millis() + end + -- change mode, with an optional fallback + if not vehicle:set_mode(failsafe_mode[1]) and failsafe_mode[2] then + vehicle:set_mode(failsafe_mode[2]) + end + end + + return update, 1000 -- check again after 1s +end + +-- start the loop (immediately) +return update()