mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-22 00:28:30 -04:00
AP_Scripting: added servo movement example script
This commit is contained in:
parent
ca584943a5
commit
ea9316c2b5
15
libraries/AP_Scripting/examples/servo_scan.lua
Normal file
15
libraries/AP_Scripting/examples/servo_scan.lua
Normal file
@ -0,0 +1,15 @@
|
||||
-- move a servo in a sinisoidal fashion
|
||||
|
||||
local SERVO_FUNCTION = 94
|
||||
local PERIOD = 0.5
|
||||
|
||||
function update() -- this is the loop which periodically runs
|
||||
local t = 0.001 * millis():tofloat()
|
||||
local pi = 3.1415
|
||||
local output = math.sin(pi * t * PERIOD * 2.0)
|
||||
local pwm = math.floor(1500 + 500 * output)
|
||||
SRV_Channels:set_output_pwm(SERVO_FUNCTION, pwm)
|
||||
return update, 20 -- reschedules the loop at 50Hz
|
||||
end
|
||||
|
||||
return update() -- run immediately before starting to reschedule
|
Loading…
Reference in New Issue
Block a user