Thanks and I have spent some time trying your suggestions but I am not convinced adding a function plus adding a delay on a return line works delaying two consecutive
SRV_Channels:set_output_pwm_chan_timeout(chan, 1330, 2500) lines?
It works for the second one but not the first.
Here a simple version with delays everywhere, but the Shutter Focus delay is skipped
If anyone can help it would be appreciated.
I would like to achieve is to focus for 2500ms and then trigger the shutter for 2500ms.
The code an attempt to adapt the #REC script posted by MadRC for the #REC2
– Seagull #REC2 Manual Photo
– This tests using a Herelink to trigger Seagull #REC2 Ch3 Manual Photo
– Herelink setup
– Set a button to Toggle channel 14 from 1100 to 1990
– #REC2 Manual photo pwm settings
– Neutral 1175
– Focus 1500 for 1 second
– Shutter 1800 100ms
local ShutterTrigger = false – ShutterTrigger is used in the short press action to check the Current state for short press input and is set by the script on loop.
local laststateShutter = false – Last state is used log the last position of channel 14 input and is set by the script on loop.
local SERVO_FUNCTION_SHUTTER = 95 – 94 is the Script 2 servo output in Ardupilot. Shutter
local chanShut = SRV_Channels:find_channel(SERVO_FUNCTION_SHUTTER) – sets chanShut to output servo action
gcs:send_text(0, “Seagull camera manual trigger Script for Herelink running”) – This sends a message to the ground station to say the script is running.
SRV_Channels:set_output_pwm_chan_timeout(chanShut, 1500, 2500) – This sets the time for the camera Focus trigger 2500ms.
gcs:send_text(0, “Shutter Focus”)
return shutter_fire(), 2500
SRV_Channels:set_output_pwm_chan_timeout(chanShut, 1800, 2500) – This sets the time for the camera shutter trigger 2500ms.
gcs:send_text(0, “Shutter Trigger”)
laststateShutter = ShutterTrigger
return update(), 2500
function update() – This is the loop section of the script.
pwmVShutter = rc:get_pwm(14) – gets pwm of ch 14, if less than or equal to 1500 then it sets ShutterTrigger to false
if pwmVShutter <= 1500 then
ShutterTrigger = false
elseif pwmVShutter >= 1501 then -- gets pwm of ch 14, if more than or equal to 1501 then it sets ShutterTrigger to true
ShutterTrigger = true
SRV_Channels:set_output_pwm(SERVO_FUNCTION_SHUTTER, 1175) -- Neutral for Manaul Focus
if not (ShutterTrigger == laststateShutter ) then -- This sets the output to 1300 momentary to trigger the camera shutter if the state on ch 14 changes ie has an input to trigger the shutter.
return shutter_focus(), 2500 -- waits the amount set in the time before calling function
return update, 500 – This loops the script every 500ms.
return update(), 3000 – This sets a delay to start the script on boot.