diff --git a/libraries/AP_Scripting/examples/AHRS_switch.lua b/libraries/AP_Scripting/examples/AHRS_switch.lua index a9f06c5a57..72d85703a0 100644 --- a/libraries/AP_Scripting/examples/AHRS_switch.lua +++ b/libraries/AP_Scripting/examples/AHRS_switch.lua @@ -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()