From f620ff45bba8d472a9f81cd0218ff33b66f831d3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 May 2024 18:03:55 +1000 Subject: [PATCH] AP_Scripting: added notch_switch example switch between two notch setups using attenuation change --- .../AP_Scripting/examples/notch_switch.lua | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libraries/AP_Scripting/examples/notch_switch.lua diff --git a/libraries/AP_Scripting/examples/notch_switch.lua b/libraries/AP_Scripting/examples/notch_switch.lua new file mode 100644 index 00000000000000..325cf3accc26af --- /dev/null +++ b/libraries/AP_Scripting/examples/notch_switch.lua @@ -0,0 +1,33 @@ +--[[ + + example script to switch between two notch setups by changing the + attenuation to zero on the notch to disable. This allows for easy + in-flight switching between two different notch setups +--]] +local INS_HNTCH_ATT = Parameter('INS_HNTCH_ATT') +local INS_HNTC2_ATT = Parameter('INS_HNTC2_ATT') + +local last_sw = -1 +local AUX_FN = 300 + +local attenuation = INS_HNTCH_ATT:get() + +function update() + local sw_current = rc:get_aux_cached(AUX_FN) + if sw_current ~= last_sw then + last_sw = sw_current + if sw_current == 0 then + INS_HNTC2_ATT:set(0) + INS_HNTCH_ATT:set(attenuation) + gcs:send_text(0, string.format("Switched to notch1 %.2f", attenuation)) + else + INS_HNTC2_ATT:set(attenuation) + INS_HNTCH_ATT:set(0) + gcs:send_text(0, string.format("Switched to notch2 %.2f", attenuation)) + end + end + return update,100 +end + +return update() +