Servo movements with Lua scripts

Hi everyone,

I want to write a Lua script that moves some servos. I’m using ArduPlane v4.3.5 (although I am open to updating this firmware to a more recent stable release) with my Cube Orange autopilot on a quadplane frame drone.

When started, I would like this Lua script to “wave” the ailerons on the drone (so first move the left aileron up / right aileron down, then center both servos for a second, and move the left aileron down / right aileron up).

Is this possible to do in Lua with ArduPlane? (I heard some information that ArduPilot does not support servo movements using Lua scripts?)

@Yuri_Rage , I’ve watched your Lua tutorials so I feel like you may have the answer (or know where to look!). I also see you’ve worked on something similar @oaamaas , so tagging you in in case you want to share your experiences! Thanks :slight_smile:

Use the RC override bindings - just use them with care, since you are directly overriding the RC transmitter, and you wouldn’t want this script to accidentally trigger while airborne. You’d probably want to let this script completely return/exit after its “waving” rather than continuing to reschedule indefinitely like many of the examples do.

ardupilot/libraries/AP_Scripting/examples/RC_override.lua at master · ArduPilot/ardupilot (github.com)

1 Like

Lovely, thank you for this @Yuri_Rage

To follow up, my usage had low risk. I wanted a visual confirmation from a bait boat when a servo that drops bait was opened:
Turning lights on and off in a rapid pattern for a couple of seconds.

And got it to work as well with some help here. This was my first ever Lua script. And I just wanted to succeed to learn and to get experience. I only implemented this in a boat I “rebuilt” from scratch to learn how to use various components successfully. The boats I do use (I have a few) do not have this script installed.

I would love to learn more about Lua, but time is limited. And last time I looked, some abilities for what I might actually find useful were missing. Like the ability to utilize the mission item reached message as a trigger. Because that I could have used to trigger the servo to open instead of just flashing some LEDs. Provided i also could set some conditions using a GCS (I obviously would not want this executed every time a mission item is reached, only when desired). Main missing ability was the ability to act on mission item reached, though…

1 Like

But if I understand these RC override bindings correctly, then it seems like this method would only work for moving servos that are connected to some RC channel. So it would work to move the aileron / elevator for example, but would it work to move e.g. servo 10 or servo 12 (which are not linked to an RC channel) ?

I used an rc channel change as a trigger. The servo (light switch) I then set by directly altering the pwm value of another channel. To my best knowledge this did not have to be a channel I control by rc at all, it just must not be disabled.

1 Like

So it does not have to be a real live RC channel linked to the RC via radio, it can just has to configured on the autopilot yes?

You asked how to control the ailerons - it’s easiest to send RC overrides for that. There are servo bindings as well. However, you will probably find that any servo that is tied to an output function other than scripting does not respond to scripted output because it has a conflicting input source.

Look through the documentation.

ServoChannels

ardupilot/libraries/AP_Scripting/generator/description/bindings.desc

1 Like

Thank you for this Yuri, I appreciate it