LUA SRV_Channels:get_output_pwm returns "nil"

Hello every one,
I am trying to read the output pwm of AP by using Lua scripts,
this is my sample code,
where the function SRV_Channels:get_output_pwm(num) returns nil always.
I tries change “num” many times, I tried 3,4 (servo output number), and from 50 to 61(GPIO number).

function update()
    output_pwm1 = SRV_Channels:get_output_pwm(53)
    gcs:send_text(0, tostring (output_pwm1))

    return update, 1000
end
return update, 1000

The Adrupilot firmware is ArduRover V4.2.3 (2172cfb3)
can you help me,
Thanks.

SRV_Channels:get_output_pwm reads by function not pin number. So 53 is RCIN 3.

1 Like

is there a documentation that resumes the number for which function ?

1 Like

It is the same as the servo output function parameters, see:

https://ardupilot.org/copter/docs/parameters.html#servo1-function-servo-output-function

2 Likes

function update()

gcs:send_text(0, tostring(SRV_Channels:get_output_pwm(36)))

return update, 1000

end

return update()

– tested on firmware 4.4 copter
– working code to fetch motor4 pwm during motor test on servo 4, the number 36 is taken from param value servo4_function, i hyave set it for motor 4 , which is 36, and now itll continuesly return pwm output of servo4

1 Like