CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/CHDK-Scripts/kap_uav.lua
Views: 1798
1
--[[
2
3
KAP UAV Exposure Control Script v3.1
4
-- Released under GPL by waterwingz and wayback/peabody
5
http://chdk.wikia.com/wiki/KAP_%26_UAV_Exposure_Control_Script
6
7
@title KAP UAV 3.1
8
@param i Shot Interval (sec)
9
@default i 15
10
@range i 2 120
11
@param s Total Shots (0=infinite)
12
@default s 0
13
@range s 0 10000
14
@param j Power off when done?
15
@default j 0
16
@range j 0 1
17
@param e Exposure Comp (stops)
18
@default e 6
19
@values e -2.0 -1.66 -1.33 -1.0 -0.66 -0.33 0.0 0.33 0.66 1.00 1.33 1.66 2.00
20
@param d Start Delay Time (sec)
21
@default d 0
22
@range d 0 10000
23
@param y Tv Min (sec)
24
@default y 0
25
@values y None 1/60 1/100 1/200 1/400 1/640
26
@param t Target Tv (sec)
27
@default t 5
28
@values t 1/100 1/200 1/400 1/640 1/800 1/1000 1/1250 1/1600 1/2000
29
@param x Tv Max (sec)
30
@default x 3
31
@values x 1/1000 1/1250 1/1600 1/2000 1/5000 1/10000
32
@param f Av Low(f-stop)
33
@default f 4
34
@values f 1.8 2.0 2.2 2.6 2.8 3.2 3.5 4.0 4.5 5.0 5.6 6.3 7.1 8.0
35
@param a Av Target (f-stop)
36
@default a 7
37
@values a 1.8 2.0 2.2 2.6 2.8 3.2 3.5 4.0 4.5 5.0 5.6 6.3 7.1 8.0
38
@param m Av Max (f-stop)
39
@default m 13
40
@values m 1.8 2.0 2.2 2.6 2.8 3.2 3.5 4.0 4.5 5.0 5.6 6.3 7.1 8.0
41
@param p ISO Min
42
@default p 1
43
@values p 80 100 200 400 800 1250 1600
44
@param q ISO Max1
45
@default q 2
46
@values q 100 200 400 800 1250 1600
47
@param r ISO Max2
48
@default r 3
49
@values r 100 200 400 800 1250 1600
50
@param n Allow use of ND filter?
51
@default n 1
52
@values n No Yes
53
@param z Zoom position
54
@default z 0
55
@values z Off 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
56
@param c Focus @ Infinity Mode
57
@default c 0
58
@values c None @Shot AFL MF
59
@param v Video Interleave (shots)
60
@default v 0
61
@values v Off 1 5 10 25 50 100
62
@param w Video Duration (sec)
63
@default w 10
64
@range w 5 300
65
@param u USB Shot Control?
66
@default u 0
67
@values u None On/Off OneShot PWM
68
@param b Backlight Off?
69
@default b 0
70
@range b 0 1
71
@param l Logging
72
@default l 3
73
@values l Off Screen SDCard Both
74
--]]
75
76
props=require("propcase")
77
capmode=require("capmode")
78
79
-- convert user parameter to usable variable names and values
80
tv_table = { -320, 576, 640, 736, 832, 896, 928, 960, 992, 1024, 1056, 1180, 1276}
81
tv96target = tv_table[t+3]
82
tv96max = tv_table[x+8]
83
tv96min = tv_table[y+1]
84
sv_table = { 381, 411, 507, 603, 699, 761, 795 }
85
sv96min = sv_table[p+1]
86
sv96max1 = sv_table[q+2]
87
sv96max2 = sv_table[r+2]
88
av_table = { 171, 192, 218, 265, 285, 322, 347, 384, 417, 446, 477, 510, 543, 576 }
89
av96target = av_table[a+1]
90
av96minimum = av_table[f+1]
91
av96max = av_table[m+1]
92
ec96adjust = (e - 6)*32
93
video_table = { 0, 1, 5, 10, 25, 50, 100 }
94
video_mode = video_table[v+1]
95
video_duration = w
96
interval = i*1000
97
max_shots = s
98
poff_if_done = j
99
start_delay = d
100
backlight = b
101
log_mode= l
102
focus_mode = c
103
usb_mode = u
104
if ( z==0 ) then zoom_setpoint = nil else zoom_setpoint = (z-1)*10 end
105
106
-- initial configuration values
107
nd96offset=3*96 -- ND filter's number of equivalent f-stops (f * 96)
108
infx = 50000 -- focus lock distance in mm (approximately 55 yards)
109
shot_count = 0 -- shot counter
110
blite_timer = 300 -- backlight off delay in 100mSec increments
111
old_console_timeout = get_config_value( 297 )
112
shot_request = false -- pwm mode flag to request a shot be taken
113
114
-- check camera Av configuration ( variable aperture and/or ND filter )
115
if n==0 then -- use of nd filter allowed?
116
if get_nd_present()==1 then -- check for ND filter only
117
Av_mode = 0 -- 0 = ND disabled and no iris available
118
else
119
Av_mode = 1 -- 1 = ND disabled and iris available
120
end
121
else
122
Av_mode = get_nd_present()+1 -- 1 = iris only , 2=ND filter only, 3= both ND & iris
123
end
124
125
function printf(...)
126
if ( log_mode == 0) then return end
127
local str=string.format(...)
128
if (( log_mode == 1) or (log_mode == 3)) then print(str) end
129
if ( log_mode > 1 ) then
130
local logname="A/KAP.log"
131
log=io.open(logname,"a")
132
log:write(os.date("%Y%b%d %X ")..string.format(...),"\n")
133
log:close()
134
end
135
end
136
137
tv_ref = { -- note : tv_ref values set 1/2 way between shutter speed values
138
-608, -560, -528, -496, -464, -432, -400, -368, -336, -304,
139
-272, -240, -208, -176, -144, -112, -80, -48, -16, 16,
140
48, 80, 112, 144, 176, 208, 240, 272, 304, 336,
141
368, 400, 432, 464, 496, 528, 560, 592, 624, 656,
142
688, 720, 752, 784, 816, 848, 880, 912, 944, 976,
143
1008, 1040, 1072, 1096, 1129, 1169, 1192, 1225, 1265, 1376 }
144
145
tv_str = {
146
">64",
147
"64", "50", "40", "32", "25", "20", "16", "12", "10", "8.0",
148
"6.0", "5.0", "4.0", "3.2", "2.5", "2.0", "1.6", "1.3", "1.0", "0.8",
149
"0.6", "0.5", "0.4", "0.3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13",
150
"1/15", "1/20", "1/25", "1/30", "1/40", "1/50", "1/60", "1/80", "1/100", "1/125",
151
"1/160", "1/200", "1/250", "1/320", "1/400", "1/500", "1/640", "1/800", "1/1000","1/1250",
152
"1/1600","1/2000","1/2500","1/3200","1/4000","1/5000","1/6400","1/8000","1/10000","hi" }
153
154
function print_tv(val)
155
if ( val == nil ) then return("-") end
156
local i = 1
157
while (i <= #tv_ref) and (val > tv_ref[i]) do i=i+1 end
158
return tv_str[i]
159
end
160
161
av_ref = { 160, 176, 208, 243, 275, 304, 336, 368, 400, 432, 464, 480, 496, 512, 544, 592, 624, 656, 688, 720, 752, 784 }
162
av_str = {"n/a","1.8", "2.0","2.2","2.6","2.8","3.2","3.5","4.0","4.5","5.0","5.6","5.9","6.3","7.1","8.0","9.0","10.0","11.0","13.0","14.0","16.0","hi"}
163
164
function print_av(val)
165
if ( val == nil ) then return("-") end
166
local i = 1
167
while (i <= #av_ref) and (val > av_ref[i]) do i=i+1 end
168
return av_str[i]
169
end
170
171
sv_ref = { 370, 397, 424, 456, 492, 523, 555, 588, 619, 651, 684, 731, 779, 843, 907 }
172
sv_str = {"n/a","80","100","120","160","200","250","320","400","500","640","800","1250","1600","3200","hi"}
173
174
function print_sv(val)
175
if ( val == nil ) then return("-") end
176
local i = 1
177
while (i <= #sv_ref) and (val > sv_ref[i]) do i=i+1 end
178
return sv_str[i]
179
end
180
181
function pline(message, line) -- print line function
182
fg = 258 bg=259
183
184
end
185
186
-- switch between shooting and playback modes
187
function switch_mode( m )
188
if ( m == 1 ) then
189
if ( get_mode() == false ) then
190
set_record(1) -- switch to shooting mode
191
while ( get_mode() == false ) do
192
sleep(100)
193
end
194
sleep(1000)
195
end
196
else
197
if ( get_mode() == true ) then
198
set_record(0) -- switch to playback mode
199
while ( get_mode() == true ) do
200
sleep(100)
201
end
202
sleep(1000)
203
end
204
end
205
end
206
207
-- focus lock and unlock
208
function lock_focus()
209
if (focus_mode > 1) then -- focus mode requested ?
210
if ( focus_mode == 2 ) then -- method 1 : set_aflock() command enables MF
211
if (chdk_version==120) then
212
set_aflock(1)
213
set_prop(props.AF_LOCK,1)
214
else
215
set_aflock(1)
216
end
217
if (get_prop(props.AF_LOCK) == 1) then printf(" AFL enabled") else printf(" AFL failed ***") end
218
else -- mf mode requested
219
if (chdk_version==120) then -- CHDK 1.2.0 : call event proc or levents to try and enable MF mode
220
if call_event_proc("SS.Create") ~= -1 then
221
if call_event_proc("SS.MFOn") == -1 then
222
call_event_proc("PT_MFOn")
223
end
224
elseif call_event_proc("RegisterShootSeqEvent") ~= -1 then
225
if call_event_proc("PT_MFOn") == -1 then
226
call_event_proc("MFOn")
227
end
228
end
229
if (get_prop(props.FOCUS_MODE) == 0 ) then -- MF not set - try levent PressSw1AndMF
230
post_levent_for_npt("PressSw1AndMF")
231
sleep(500)
232
end
233
elseif (chdk_version >= 130) then -- CHDK 1.3.0 : set_mf()
234
if ( set_mf(1) == 0 ) then set_aflock(1) end -- as a fall back, try setting AFL is set_mf fails
235
end
236
if (get_prop(props.FOCUS_MODE) == 1) then printf(" MF enabled") else printf(" MF enable failed ***") end
237
end
238
sleep(1000)
239
set_focus(infx)
240
sleep(1000)
241
end
242
end
243
244
function unlock_focus()
245
if (focus_mode > 1) then -- focus mode requested ?
246
if (focus_mode == 2 ) then -- method 1 : AFL
247
if (chdk_version==120) then
248
set_aflock(0)
249
set_prop(props.AF_LOCK,0)
250
else
251
set_aflock(0)
252
end
253
if (get_prop(props.AF_LOCK) == 0) then printf(" AFL unlocked") else printf(" AFL unlock failed") end
254
else -- mf mode requested
255
if (chdk_version==120) then -- CHDK 1.2.0 : call event proc or levents to try and enable MF mode
256
if call_event_proc("SS.Create") ~= -1 then
257
if call_event_proc("SS.MFOff") == -1 then
258
call_event_proc("PT_MFOff")
259
end
260
elseif call_event_proc("RegisterShootSeqEvent") ~= -1 then
261
if call_event_proc("PT_MFOff") == -1 then
262
call_event_proc("MFOff")
263
end
264
end
265
if (get_prop(props.FOCUS_MODE) == 1 ) then -- MF not reset - try levent PressSw1AndMF
266
post_levent_for_npt("PressSw1AndMF")
267
sleep(500)
268
end
269
elseif (chdk_version >= 130) then -- CHDK 1.3.0 : set_mf()
270
if ( set_mf(0) == 0 ) then set_aflock(0) end -- fall back so reset AFL is set_mf fails
271
end
272
if (get_prop(props.FOCUS_MODE) == 0) then printf(" MF disabled") else printf(" MF disable failed") end
273
end
274
sleep(100)
275
end
276
end
277
278
-- zoom position
279
function update_zoom(zpos)
280
local count = 0
281
if(zpos ~= nil) then
282
zstep=((get_zoom_steps()-1)*zpos)/100
283
printf("setting zoom to "..zpos.." percent step="..zstep)
284
sleep(200)
285
set_zoom(zstep)
286
sleep(2000)
287
press("shoot_half")
288
repeat
289
sleep(100)
290
count = count + 1
291
until (get_shooting() == true ) or (count > 40 )
292
release("shoot_half")
293
end
294
end
295
296
-- restore camera settings on shutdown
297
function restore()
298
set_config_value(121,0) -- USB remote disable
299
set_config_value(297,old_console_timeout) -- restore console timeout value
300
if (backlight==1) then set_lcd_display(1) end -- display on
301
unlock_focus()
302
if( zoom_setpoint ~= nil ) then update_zoom(0) end
303
if( shot_count >= max_shots) and ( max_shots > 1) then
304
if ( poff_if_done == 1 ) then -- did script ending because # of shots done ?
305
printf("power off - shot count at limit") -- complete power down
306
sleep(2000)
307
post_levent_to_ui('PressPowerButton')
308
else
309
set_record(0) end -- just retract lens
310
end
311
end
312
313
-- Video mode
314
function check_video(shot)
315
local capture_mode
316
if ((video_mode>0) and(shot>0) and (shot%video_mode == 0)) then
317
unlock_focus()
318
printf("Video mode started. Button:"..tostring(video_button))
319
if( video_button ) then
320
click "video"
321
else
322
capture_mode=capmode.get()
323
capmode.set('VIDEO_STD')
324
press("shoot_full")
325
sleep(300)
326
release("shoot_full")
327
end
328
local end_second = get_day_seconds() + video_duration
329
repeat
330
wait_click(500)
331
until (is_key("menu")) or (get_day_seconds() > end_second)
332
if( video_button ) then
333
click "video"
334
else
335
press("shoot_full")
336
sleep(300)
337
release("shoot_full")
338
capmode.set(capture_mode)
339
end
340
printf("Video mode finished.")
341
sleep(1000)
342
lock_focus()
343
return(true)
344
else
345
return(false)
346
end
347
end
348
349
-- PWM USB pulse functions
350
351
function ch1up()
352
printf(" * usb pulse = ch1up")
353
shot_request = true
354
end
355
356
function ch1mid()
357
printf(" * usb pulse = ch1mid")
358
if ( get_mode() == false ) then
359
switch_mode(1)
360
lock_focus()
361
end
362
end
363
364
function ch1down()
365
printf(" * usb pulse = ch1down")
366
switch_mode(0)
367
end
368
369
function ch2up()
370
printf(" * usb pulse = ch2up")
371
update_zoom(100)
372
end
373
374
function ch2mid()
375
printf(" * usb pulse = ch2mid")
376
if ( zoom_setpoint ~= nil ) then update_zoom(zoom_setpoint) else update_zoom(50) end
377
end
378
379
function ch2down()
380
printf(" * usb pulse = ch2down")
381
update_zoom(0)
382
end
383
384
function pwm_mode(pulse_width)
385
if pulse_width > 0 then
386
if pulse_width < 5 then ch1up()
387
elseif pulse_width < 8 then ch1mid()
388
elseif pulse_width < 11 then ch1down()
389
elseif pulse_width < 14 then ch2up()
390
elseif pulse_width < 17 then ch2mid()
391
elseif pulse_width < 20 then ch2down()
392
else printf(" * usb pulse width error") end
393
end
394
end
395
396
-- Basic exposure calculation using shutter speed and ISO only
397
-- called for Tv-only and ND-only cameras (cameras without an iris)
398
function basic_tv_calc()
399
tv96setpoint = tv96target
400
av96setpoint = nil
401
local min_av = get_prop(props.MIN_AV)
402
-- calculate required ISO setting
403
sv96setpoint = tv96setpoint + min_av - bv96meter
404
-- low ambient light ?
405
if (sv96setpoint > sv96max2 ) then -- check if required ISO setting is too high
406
sv96setpoint = sv96max2 -- clamp at max2 ISO if so
407
tv96setpoint = math.max(bv96meter+sv96setpoint-min_av,tv96min) -- recalculate required shutter speed down to Tv min
408
-- high ambient light ?
409
elseif (sv96setpoint < sv96min ) then -- check if required ISO setting is too low
410
sv96setpoint = sv96min -- clamp at minimum ISO setting if so
411
tv96setpoint = bv96meter + sv96setpoint - min_av -- recalculate required shutter speed and hope for the best
412
end
413
end
414
415
416
-- Basic exposure calculation using shutter speed, iris and ISO
417
-- called for iris-only and "both" cameras (cameras with an iris & ND filter)
418
function basic_iris_calc()
419
tv96setpoint = tv96target
420
av96setpoint = av96target
421
-- calculate required ISO setting
422
sv96setpoint = tv96setpoint + av96setpoint - bv96meter
423
-- low ambient light ?
424
if (sv96setpoint > sv96max1 ) then -- check if required ISO setting is too high
425
sv96setpoint = sv96max1 -- clamp at first ISO limit
426
av96setpoint = bv96meter + sv96setpoint - tv96setpoint -- calculate new aperture setting
427
if ( av96setpoint < av96min ) then -- check if new setting is goes below lowest f-stop
428
av96setpoint = av96min -- clamp at lowest f-stop
429
sv96setpoint = tv96setpoint + av96setpoint - bv96meter -- recalculate ISO setting
430
if (sv96setpoint > sv96max2 ) then -- check if the result is above max2 ISO
431
sv96setpoint = sv96max2 -- clamp at highest ISO setting if so
432
tv96setpoint = math.max(bv96meter+sv96setpoint-av96setpoint,tv96min) -- recalculate required shutter speed down to tv minimum
433
end
434
end
435
-- high ambient light ?
436
elseif (sv96setpoint < sv96min ) then -- check if required ISO setting is too low
437
sv96setpoint = sv96min -- clamp at minimum ISO setting if so
438
tv96setpoint = bv96meter + sv96setpoint - av96setpoint -- recalculate required shutter speed
439
if (tv96setpoint > tv96max ) then -- check if shutter speed now too fast
440
tv96setpoint = tv96max -- clamp at maximum shutter speed if so
441
av96setpoint = bv96meter + sv96setpoint - tv96setpoint -- calculate new aperture setting
442
if ( av96setpoint > av96max ) then -- check if new setting is goes above highest f-stop
443
av96setpoint = av96max -- clamp at highest f-stop
444
tv96setpoint = bv96meter + sv96setpoint - av96setpoint -- recalculate shutter speed needed and hope for the best
445
end
446
end
447
end
448
end
449
450
-- calculate exposure for cams without adjustable iris or ND filter
451
function exposure_Tv_only()
452
insert_ND_filter = nil
453
basic_tv_calc()
454
end
455
456
-- calculate exposure for cams with ND filter only
457
function exposure_NDfilter()
458
insert_ND_filter = false
459
basic_tv_calc()
460
if (tv96setpoint > tv96max ) then -- check if shutter speed now too fast
461
insert_ND_filter = true -- flag the ND filter to be inserted
462
bv96meter = bv96meter - nd96offset -- adjust meter for ND offset
463
basic_tv_calc() -- start over, but with new meter value
464
bv96meter = bv96meter + nd96offset -- restore meter for later logging
465
end
466
end
467
468
-- calculate exposure for cams with adjustable iris only
469
function exposure_iris()
470
insert_ND_filter = nil
471
basic_iris_calc()
472
end
473
474
-- calculate exposure for cams with both adjustable iris and ND filter
475
function exposure_both()
476
insert_ND_filter = false -- NOTE : assume ND filter never used automatically by Canon firmware
477
basic_iris_calc()
478
if (tv96setpoint > tv96max ) then -- check if shutter speed now too fast
479
insert_ND_filter = true -- flag the ND filter to be inserted
480
bv96meter = bv96meter - nd96offset -- adjust meter for ND offset
481
basic_iris_calc() -- start over, but with new meter value
482
bv96meter = bv96meter + nd96offset -- restore meter for later logging
483
end
484
end
485
486
-- ========================== Main Program =================================
487
488
set_console_layout(1 ,1, 45, 14 )
489
490
printf("KAP 3.1 started - press MENU to exit")
491
bi=get_buildinfo()
492
printf("%s %s-%s %s %s %s", bi.version, bi.build_number, bi.build_revision, bi.platform, bi.platsub, bi.build_date)
493
chdk_version= tonumber(string.sub(bi.build_number,1,1))*100 + tonumber(string.sub(bi.build_number,3,3))*10 + tonumber(string.sub(bi.build_number,5,5))
494
if ( tonumber(bi.build_revision) > 0 ) then
495
build = tonumber(bi.build_revision)
496
else
497
build = tonumber(string.match(bi.build_number,'-(%d+)$'))
498
end
499
500
if ((chdk_version<120) or ((chdk_version==120)and(build<3276)) or ((chdk_version==130)and(build<3383))) then
501
printf("CHDK 1.2.0 build 3276 or higher required")
502
else
503
if( props.CONTINUOUS_AF == nil ) then caf=-999 else caf = get_prop(props.CONTINUOUS_AF) end
504
if( props.SERVO_AF == nil ) then saf=-999 else saf = get_prop(props.SERVO_AF) end
505
cmode = capmode.get_name()
506
printf("Mode:%s,Continuous_AF:%d,Servo_AF:%d", cmode,caf,saf)
507
printf(" Tv:"..print_tv(tv96target).." max:"..print_tv(tv96max).." min:"..print_tv(tv96min).." ecomp:"..(ec96adjust/96).."."..(math.abs(ec96adjust*10/96)%10) )
508
printf(" Av:"..print_av(av96target).." minAv:"..print_av(av96minimum).." maxAv:"..print_av(av96max) )
509
printf(" ISOmin:"..print_sv(sv96min).." ISO1:"..print_sv(sv96max1).." ISO2:"..print_sv(sv96max2) )
510
printf(" MF mode:"..focus_mode.." Video:"..video_mode.." USB:"..usb_mode)
511
printf(" AvM:"..Av_mode.." int:"..(interval/1000).." Shts:"..max_shots.." Dly:"..start_delay.." B/L:"..backlight)
512
sleep(500)
513
514
if (start_delay > 0 ) then
515
printf("entering start delay of ".. start_delay.." seconds")
516
sleep( start_delay*1000 )
517
end
518
519
-- enable USB remote in USB remote moded
520
if (usb_mode > 0 ) then
521
set_config_value(121,1) -- make sure USB remote is enabled
522
if (get_usb_power(1) == 0) then -- can we start ?
523
printf("waiting on USB signal")
524
repeat wait_click(20) until ((get_usb_power(1) == 1) or ( is_key("menu")))
525
else sleep(1000) end
526
printf("USB signal received")
527
end
528
529
-- switch to shooting mode
530
switch_mode(1)
531
532
-- set zoom position
533
update_zoom(zoom_setpoint)
534
-- lock focus at infinity
535
lock_focus()
536
-- disable flash and AF assist lamp
537
set_prop(props.FLASH_MODE, 2) -- flash off
538
set_prop(props.AF_ASSIST_BEAM,0) -- AF assist off if supported for this camera
539
set_config_value( 297, 60) -- set console timeout to 60 seconds
540
541
if (usb_mode > 2 ) then repeat until (get_usb_power(2) == 0 ) end -- flush pulse buffer
542
next_shot_time = get_tick_count()
543
script_exit = false
544
if( get_video_button() == 1) then video_button = true else video_button = false end
545
set_console_layout(2 ,0, 45, 4 )
546
repeat
547
548
if( ( (usb_mode < 2 ) and ( next_shot_time <= get_tick_count() ) )
549
or ( (usb_mode == 2 ) and (get_usb_power(2) > 0 ) )
550
or ( (usb_mode == 3 ) and (shot_request == true ) ) ) then
551
552
-- time to insert a video sequence ?
553
if( check_video(shot_count) == true) then next_shot_time = get_tick_count() end
554
555
-- intervalometer timing
556
next_shot_time = next_shot_time + interval
557
558
-- set focus at infinity ? (maybe redundant for AFL & MF mode but makes sure it's set right)
559
if (focus_mode > 0) then
560
set_focus(infx)
561
sleep(100)
562
end
563
564
-- check exposure
565
local count = 0
566
local timeout = false
567
press("shoot_half")
568
repeat
569
sleep(50)
570
count = count + 1
571
if (count > 40 ) then timeout = true end
572
until (get_shooting() == true ) or (timeout == true)
573
574
-- shoot in auto mode if meter reading invalid, else calculate new desired exposure
575
if ( timeout == true ) then
576
release("shoot_half")
577
repeat sleep(50) until get_shooting() == false
578
shoot() -- shoot in Canon auto mode if we don't have a valid meter reading
579
shot_count = shot_count + 1
580
printf(string.format('IMG_%04d.JPG',get_exp_count()).." : shot in auto mode, meter reading invalid")
581
else
582
-- get meter reading values (and add in exposure compensation)
583
bv96raw=get_bv96()
584
bv96meter=bv96raw-ec96adjust
585
tv96meter=get_tv96()
586
av96meter=get_av96()
587
sv96meter=get_sv96()
588
589
-- set minimum Av to larger of user input or current min for zoom setting
590
av96min= math.max(av96minimum,get_prop(props.MIN_AV))
591
if (av96target < av96min) then av96target = av96min end
592
593
-- calculate required setting for current ambient light conditions
594
if (Av_mode == 1) then exposure_iris()
595
elseif (Av_mode == 2) then exposure_NDfilter()
596
elseif (Av_mode == 3) then exposure_both()
597
else exposure_Tv_only()
598
end
599
600
-- set up all exposure overrides
601
set_tv96_direct(tv96setpoint)
602
set_sv96(sv96setpoint)
603
if( av96setpoint ~= nil) then set_av96_direct(av96setpoint) end
604
605
if(Av_mode > 1) and (insert_ND_filter == true) then -- ND filter available and needed?
606
set_nd_filter(1) -- activate the ND filter
607
nd_string="NDin"
608
else
609
set_nd_filter(2) -- make sure the ND filter does not activate
610
nd_string="NDout"
611
end
612
613
-- and finally shoot the image
614
press("shoot_full_only")
615
sleep(100)
616
release("shoot_full")
617
repeat sleep(50) until get_shooting() == false
618
shot_count = shot_count + 1
619
620
-- update shooting statistic and log as required
621
shot_focus=get_focus()
622
if(shot_focus ~= -1) and (shot_focus < 20000) then
623
focus_string=" foc:"..(shot_focus/1000).."."..(((shot_focus%1000)+50)/100).."m"
624
if(focus_mode>0) then
625
error_string=" **WARNING : focus not at infinity**"
626
end
627
else
628
focus_string=" foc:infinity"
629
error_string=nil
630
end
631
printf(string.format('%d) IMG_%04d.JPG',shot_count,get_exp_count()))
632
printf(" meter : Tv:".. print_tv(tv96meter) .." Av:".. print_av(av96meter) .." Sv:"..print_sv(sv96meter).." "..bv96raw ..":"..bv96meter)
633
printf(" actual: Tv:".. print_tv(tv96setpoint).." Av:".. print_av(av96setpoint).." Sv:"..print_sv(sv96setpoint))
634
printf(" AvMin:".. print_av(av96min).." NDF:"..nd_string..focus_string )
635
636
if ((max_shots>0) and (shot_count >= max_shots)) then script_exit = true end
637
638
shot_request = false -- reset shot request flag
639
640
end
641
collectgarbage()
642
end
643
644
-- check if USB remote enabled in intervalometer mode and USB power is off -> pause if so
645
if ((usb_mode == 1 ) and (get_usb_power(1) == 0)) then
646
printf("waiting on USB signal")
647
unlock_focus()
648
switch_mode(0)
649
repeat wait_click(20) until ((get_usb_power(1) == 1) or ( is_key("menu")))
650
switch_mode(1)
651
lock_focus()
652
if ( is_key("menu")) then script_exit = true end
653
printf("USB wait finished")
654
sleep(100)
655
end
656
657
if (usb_mode == 3 ) then pwm_mode(get_usb_power(2)) end
658
659
if (blite_timer > 0) then
660
blite_timer = blite_timer-1
661
if ((blite_timer==0) and (backlight==1)) then set_lcd_display(0) end
662
end
663
664
if( error_string ~= nil) then
665
draw_string( 16, 144, string.sub(error_string.." ",0,42), 258, 259)
666
end
667
668
wait_click(100)
669
670
if( not( is_key("no_key"))) then
671
if ((blite_timer==0) and (backlight==1)) then set_lcd_display(1) end
672
blite_timer=300
673
if ( is_key("menu") ) then script_exit = true end
674
end
675
676
until (script_exit==true)
677
printf("script halt requested")
678
restore()
679
end
680
681
--[[ end of file ]]--
682
683
684
685