OK. I have blundered along through the LUA landscape and come up with this script:
-- This script is to set FC mode to STABILIZE when the button is pushed
-- SRC 12JAN2020
local button_number = 2 -- the button number we want to read, as defined in AP_Button
local button_active_state = true -- the 'pressed' state of the button
local last_button_state
-- flight mode numbers for Plane
local MODE_STAB = 2
--local MODE_MANU = 0
function switchstabon()
local button_new_state = button:get_button_state(button_number) == button_active_state
if button_new_state ~= last_button_state then
last_button_state = button_new_state -- update latched state for edge detection
if button_new_state then
gcs:send_text(0, "LUA: Button 2 Pressed")
vehicle:set_mode(MODE_STAB)
else
gcs:send_text(0, "LUA: Button Released") -- switching back to manual is otherwise accomplished
end
end
return switchstabon, 20 -- rescheduled loop every 20ms
end
return switchstabon() -- run immediately before starting to reschedule
I don’t have any hardware to try this on currently. If somebody spots any syntax or logical errors please let me know
Another alternative for this switching is to use the BUTTON functions to execute a script maybe. I can see that under RCn_OPTION there is the option for these to trigger scripts (300-307 for scripting1 to scripting8). Does anyone know how I link a script to the RCn_OPTION function? I assume it is just a script filename it executes but I have not been able to find what it might be in the documentation.
Having the ability to switch to stabilize with a straight button function in Plane would be much better. Can I add this as a feature request, please, developers?