2024-04-02 18:07:55 -03:00
|
|
|
-- move a servo in a sinusoidal fashion
|
2020-04-17 02:37:11 -03:00
|
|
|
|
|
|
|
local SERVO_FUNCTION = 94
|
2024-04-02 18:07:55 -03:00
|
|
|
local FREQUENCY = 0.125
|
2020-04-17 02:37:11 -03:00
|
|
|
|
|
|
|
function update() -- this is the loop which periodically runs
|
|
|
|
local t = 0.001 * millis():tofloat()
|
2024-04-02 18:07:55 -03:00
|
|
|
local output = math.sin(math.pi * t * FREQUENCY * 2.0)
|
2020-04-17 02:37:11 -03:00
|
|
|
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
|