I am trying to set up a Lua script to execute “on demand,” so that I can activate it from a mission, for example, when executing a trigger. Step by step, I have managed to configure the mount to move and take pictures with the script; what I need now is to be able to invoke it when needed from the mission.
I have seen examples where they invoke it from an RC, but that wouldn’t be the case here.
An interesting idea would also be for it to execute upon detecting that the drone stops for a time, say 3 seconds, and then it executes at that moment.
For practical purposes, using a “do set servo” to activate it would be ideal.
I have searched, read, and experimented without success.
"Hi @Robotic , I want to activate my Lua script only when I flip a switch on my controller. For example, when I’m near the area where I want to use the script, I can just flip the switch to activate it. Is it possible to set it up like that?
The script must execute in a callback loop, polling for the switch position to change. Include logic to execute your custom functions when the switch is in the position you desire.
That approach could work, but I’m not sure which command to use in a Lua script to check the status of a switch on my controller. I’ve looked through the common Lua scripts for Rover but didn’t find a command for this
It’s the only approach that will work with the current Lua engine.
Here’s one where you’d set RCx_OPTION = 300 and use the cached aux state bindings to switch EKF versions. It’d be better practice to use a global variable to keep track of the switch state and only update values on switch change, but the example gets you the basic idea: