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