forked from tridge/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_HAL_ChibiOS: Add rally timeout script
- Loading branch information
1 parent
1872d8d
commit 191e292
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
libraries/AP_HAL_ChibiOS/hwdef/CubeOrangePlus-Target/scripts/rally_timeout.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local PARAM_TABLE_KEY = 117 | ||
|
||
-- create custom parameter set | ||
local function add_params(key, prefix, tbl) | ||
assert(param:add_table(key, prefix, #tbl), string.format('Could not add %s param table.', prefix)) | ||
for num = 1, #tbl do | ||
assert(param:add_param(key, num, tbl[num][1], tbl[num][2]), string.format('Could not add %s%s.', prefix, tbl[num][1])) | ||
end | ||
end | ||
|
||
-- edit this function call to suit your use case | ||
add_params(PARAM_TABLE_KEY, 'FS_RALLY', { | ||
{ '_TIMEOUT', 30*60 }, | ||
}) | ||
|
||
local timeout = Parameter() | ||
timeout:init('FS_RALLY_TIMEOUT') | ||
local rally_start_time = nil | ||
|
||
function update() | ||
if vehicle:get_mode() == 11 then | ||
-- we are in rally | ||
if rally_start_time == nil then | ||
-- we weren't tracking time, so start it | ||
rally_start_time = millis() | ||
else | ||
local timeout_v = timeout:get() | ||
if (timeout_v > 0) and (millis() - rally_start_time >= timeout_v*1000) then | ||
if mission:jump_to_landing_sequence() then | ||
-- only change to auto if we could pick a landing | ||
vehicle:set_mode(10) -- jump to auto | ||
else | ||
gcs:send_text(4, "Rally Failsafe: No landing sequence available") | ||
rally_start_time = nil | ||
end | ||
end | ||
end | ||
else | ||
rally_start_time = nil | ||
end | ||
|
||
return update, 500 -- run at 2Hz | ||
end | ||
|
||
return update() |