Skip to content

Commit 3c7da20

Browse files
committed
scripts: BlueBoat: add leak failsafe
1 parent d7203db commit 3c7da20

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-- Leak detection/failsafe functionality for the Navigator
2+
-- Intended for use with ArduRover (e.g. on a BlueBoat)
3+
4+
---- USER CONFIG ----
5+
local warning_interval_ms = uint32_t(15000) -- warn every 15s
6+
7+
-- specify 1-2 failsafe modes for desired behaviour
8+
RoverMode = {
9+
Hold = 4,
10+
Loiter = 5,
11+
RTL = 11,
12+
SmartRTL = 12,
13+
}
14+
local failsafe_mode = {RoverMode.Loiter, RoverMode.Hold} -- try to loiter, otherwise hold
15+
---------------------
16+
17+
-- perform setup
18+
local navigator_leak_pin = 27
19+
gpio:pinMode(navigator_leak_pin,0) -- configure as a digital input
20+
local warning_last_sent = uint32_t()
21+
22+
-- define the loop
23+
function update()
24+
if gpio:read(navigator_leak_pin) then
25+
-- warn the operator, if they haven't been warned recently
26+
if millis() - warning_last_sent > warning_interval_ms then
27+
gcs:send_text(2, "Leak detected!") -- critical level announcement
28+
warning_last_sent = millis()
29+
end
30+
-- change mode, with an optional fallback
31+
if not vehicle:set_mode(failsafe_mode[1]) and failsafe_mode[2] then
32+
vehicle:set_mode(failsafe_mode[2])
33+
end
34+
end
35+
36+
return update, 1000 -- check again after 1s
37+
end
38+
39+
-- start the loop (immediately)
40+
return update()

0 commit comments

Comments
 (0)