AP_Scripting: use cached in AHRS_switch example

and use EKF2/EKF3, more likely to be useful
This commit is contained in:
Andrew Tridgell 2024-10-12 10:56:08 +11:00
parent e15f72ce58
commit 02fd1f3561

View File

@ -1,18 +1,21 @@
-- switch between DCM and EKF3 on a switch
-- switch between EKF2 and EKF3 on a switch
---@diagnostic disable: need-check-nil
local scripting_rc1 = rc:find_channel_for_option(300)
local AUX_FUNCTION_NUM = 300
local EKF_TYPE = Parameter('AHRS_EKF_TYPE')
function update()
local sw_pos = scripting_rc1:get_aux_switch_pos()
if sw_pos == 0 then
local sw_pos = rc:get_aux_cached(AUX_FUNCTION_NUM)
if not sw_pos then
return update, 100
end
if sw_pos == 2 then
EKF_TYPE:set(3)
else
EKF_TYPE:set(0)
EKF_TYPE:set(2)
end
return update, 100
end
gcs:send_text(0, "Loaded AHRS switch for EKF3/EKF2")
return update()