Script Arming control servo

Hi all, I need some help,
Can someone write me a simple script to control a servo according to the motor arming status?
What I need is to set the servo number 10 to minimum, lets say 1100us when disarmed and to 1900us when armed.
I know it is a simple code that can be written in a few seconds but I have zero knowledge about coding Lua
Thank you in advance
Kind regards

A great opportunity to learn something new :wink: It is not hard to do.
Here is lua scripting documentation , you can debug lua scripts and there are many examples available.
You will need to use the latest firmware or press Ctrl-Q in MissionPlanner

I spent way too much time trying already and thats why I am asking for help on the comunity so, if it is that much easy for you why don’t you help me?
Programming is not for me.

Nuno, näo tenho tempo nem para me coĉar (näo tenho um teclado portugês)

Bom dia, muito sinceramente e não querendo ser rude, não entendi a sua intervenção ao estilo “eu sei mas não digo, descobre por ti” ainda mais num grupo OpenSource como é este onde o objectivo é entre-ajuda…
Enfim…
Obrigado Ă  mesma.
P.S. eu também não tenho teclado portugues, não entendi.

É uma comunidate OpenSource onde as pessoas se ajudam mutuamente, sim.
Desculpa lá se te ofendi.

P.S. NĂŁo tenho teclado protuguĂŞs e como tal nĂŁo consigo escrever c de cedilha.

You can also just set SERVO10_FUNCTION to 29 (LandingGear)

@giantpt, we spoke briefly today in the comments of my YouTube video where you mentioned this post. I gave you the following example as a reply:

function update()

    if not arming:is_armed() then
        SRV_Channels:set_output_pwm(94, 1100)
    end   

    if arming:is_armed() then
        SRV_Channels:set_output_pwm(94, 1900)     
    end

    return update, 100
end

return update()

You said it worked well for you, but I’ll offer this slightly more advanced version that uses pseudo-constant variables instead of “magic numbers” and doesn’t continuously reset the servo value:

local SERVO_FN     = 94
local DISARMED_PWM = 1100
local ARMED_PWM    = 1900
local FREQUENCY    = 100

function do_disarmed()
    if arming:is_armed() then
        SRV_Channels:set_output_pwm(SERVO_FN, ARMED_PWM)
        return do_armed, FREQUENCY
    end

    return do_disarmed, FREQUENCY
end

function do_armed()
    if not arming:is_armed() then
        SRV_Channels:set_output_pwm(SERVO_FN, DISARMED_PWM)
        return do_disarmed, FREQUENCY
    end

    return do_armed, FREQUENCY
end

return do_armed()

(I edited this post a few times with some slight updates to the example script that made it more efficient)

2 Likes

Hi Yuri,
Thank you once again for your time and patience with me on this issue in particular.
You had an exemplar attitude, thats exactly what I consider these forums are for…
Can’t thank you enough
Take care & Stay safe

1 Like