Using joystick buttons in Lua scripts

Hi all, I have been experimenting with Lua scripts and wanted a way to access the joystick buttons to trigger functionality.

Here is a way to create up to 4 “script buttons”. These buttons will keep track of how many times they have been pressed, and you can query the current state of the button and the number of button presses inside a Lua script. There’s an example Lua script to show how they work.

If this is generally useful I’ll submit a PR to continue the discussion. If there is a better way to access the joystick buttons, please let me know!

/Clyde

1 Like

Hi @clyde

That is great! I like it as is. Please open a PR =]

Cool, thx. Sub: Lua scripts can query joystick button state by clydemcqueen · Pull Request #24347 · ArduPilot/ardupilot · GitHub

I have been trying to find a way to use joystick button presses in my lua scripts. Are you able to give me an idea of how i can get this working? I have manual_control sending joystick axis and button presses to my OrangeCube. What code needs to be implemented in my lua script to check the status of these buttons? Thanks in advance for your time.

Hi @moptop219 -
Welcome to the forums!

You can see some examples of how to read buttons via Lua script here, however I’m not sure if lua scripts work with BlueOS and the OrangeCube - they don’t with the Pixhawk! Are you running ArduSub 4.5?

1 Like

Thanks Tony for sending that link through, will give it a go.
Yes I am currently trialling ArduSub 4.5.