≡ Menu

PictUAV2.lua

 

Copy everything below the line and using a text editor paste it into a file titled, “PictUAV2.lua”

Or….I seem to be having difficulties posting this block of code while still maintaining the proper indentation and line spacing which makes it sort of crap to read. And it’s pissing me off! So if you want to download the file with the proper indentations, click here and do a “File save as”. Sorry about that…I’m just dense.

Back to the Remotely actuated intervalometer for aerial mapping page

____________________________________________________________________________

 

–[[
@title PictUAV2
@param s Secs/frame
@default s 2
@param h Sequence hours
@default h 1
@param m Sequence minutes
@default m 5
@param e Endless? 0=No 1=Yes
@default e 1
@param f Focus: 0=Every 1=Start
@default f 1
@param d Display off frame 0=never
@default d 0
–]]
print( “PictUAV2 Started ” )
— convert parameters into readable variable names
secs_frame, hours, minutes, endless, focus_at_start, display_off_frame = s, h, m, (e > 0), (f > 0), d

props = require “propcase”

— derive actual running parameters from the more human-friendly input
— parameters
function calculate_parameters (seconds_per_frame, hours, minutes, start_ticks)
local ticks_per_frame = 1000 * secs_frame — ticks per frame
local total_frames = (hours * 3600 + minutes * 60) / secs_frame — total frames
local end_ticks = start_ticks + total_frames * ticks_per_frame — ticks at end of sequence
return ticks_per_frame, total_frames, end_ticks
end

function print_status (frame, total_frames, ticks_per_frame, end_ticks, endless)
local free = get_jpg_count()
if endless then
local h, m, s = ticks_to_hms(frame * ticks_per_frame)
print(“#” .. frame .. “, ” .. h .. “h ” .. m .. “m ” .. s .. “s”)
else
local h, m, s = ticks_to_hms(end_ticks – get_tick_count())
print(frame .. “/” .. total_frames .. “, ” .. h .. “h” .. m .. “m” .. s .. “s/” .. free .. ” left”)
end
end

function ticks_to_hms (ticks)
local secs = (ticks + 500) / 1000 — round to nearest seconds
local s = secs % 60
secs = secs / 60
local m = secs % 60
local h = secs / 60
return h, m, s
end

— sleep, but using wait_click(); return true if a key was pressed, else false
function next_frame_sleep (frame, start_ticks, ticks_per_frame)
— this calculates the number of ticks between now and the time of
— the next frame
local sleep_time = (start_ticks + frame * ticks_per_frame) – get_tick_count()
if sleep_time < 1 then
sleep_time = 1
end
wait_click(sleep_time)
return not is_key(“no_key”)
end

— delay for the appropriate amount of time, but respond to
— the display key (allows turning off display to save power)
— return true if we should exit, else false
function frame_delay (frame, start_ticks, ticks_per_frame)
— this returns true while a key has been pressed, and false if
— none
while next_frame_sleep (frame, start_ticks, ticks_per_frame) do
— honour the display button
if is_key(“print”) then
click(“print”)
end
— if set key is pressed, indicate that we should stop
if is_key(“set”) then
return true
end
end
return false
end

— click “print” to turn on/off display
function seek_display_mode()
click “print”
end

— switch to autofocus mode, pre-focus, then go to manual focus mode
function pre_focus()
local focused = false
local try = 1
while not focused and try <= 5 do
print(“Pre-focus attempt ” .. try)
press(“shoot_half”)
sleep(2000)
if get_prop(18) > 0 then
focused = true
set_aflock(1)
end
release(“shoot_half”)
sleep(500)
try = try + 1
end
return focused
end
— This is the program core, a loop:
Started = 0
print( “PictUAV2 loop ” )
a = -1;
repeat
aold = a
a = get_usb_power()
if (a ~= aold) then
print(“a = ” .. a)
end

— If pulses are 90 msec or greater, shutdown directly and end.
if (a>8) then
print( “shutting down ” )
shut_down()
sleep(1500)
end

— If pulses are greater than 30 msec start recording
if (a>3) or (Started == 1) then
if Started == 0 then
print( “recording Started ” )

sleep(1500)
Started = 1
if focus_at_start then
if not pre_focus() then
print “Unable to reach pre-focus”
end
end

start_ticks = get_tick_count()

ticks_per_frame, total_frames, end_ticks = calculate_parameters(secs_frame, hours, minutes, start_ticks)

frame = 1

print “Press SET to exit”
end
print_status(frame, total_frames, ticks_per_frame, end_ticks, endless)
shoot()

if frame_delay(frame, start_ticks, ticks_per_frame) then
print “User quit”
break
end
frame = frame + 1

end
until ( false )
print( “PictUAV2 ended ” )