Lua: Lens to Lens variation

Started by garry23, February 23, 2016, 07:55:42 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

I thought some may be interested in the results of some Lua script-based testing I have been doing with 5D3, a Canon 24-105 F/4L and a Sigma 12-24 F4.5-5.6 II DG.

Both lenses behave well with ML, eg reporting position and DoF etc.

Using this script with both gives different results:

--[[
Manual Landscape bracketing helper script
Version 0.3.4
Garry George Feb 2016
http://photography.grayheron.net/
Workflow helper script for focus and exposure bracketing.
Try using ML follow focus to control the lens, as opposed to rotating lens by hand.
Yellow means move more towards the infinity end, Red means move more towards macro end,
Green means at the sweet spot. If Green not seen, move to just being in the Yellow from being in the Red.
************************
* Must be in liveview! *
************************
--]]
a1 = lens.dof_near
b1 = lens.dof_far
c1 = 0
fp = lens.focal_distance
inf = 1000000
started = false
bookended = true
current_tv = camera.shutter.apex
current_av = camera.aperture.apex

event.keypress = function(key)
if keymenu.submenu["Turn On/Off"].value == "Off" then
return true
else
if key == KEY.RATE then
if keymenu.submenu["Bookends"].value == "yes"
then
if bookended then
current_tv = camera.shutter.apex
current_av = camera.aperture.apex
camera.shutter.apex = 100
camera.aperture.apex = 90
task.yield(100)
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",0) end
bookended = false
else
camera.aperture.apex = current_av
camera.shutter.apex = current_tv
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",1) end
task.yield(100)
bookended = true
end
return false
else
return true
end
end
if keymenu.submenu["Turn On/Off"].value == "Off" then started = false end
if fp ~= 0 then
if key == KEY.FULLSHUTTER
then
b1 = lens.dof_far -- in mm
fp = lens.focal_distance -- in cm
if keymenu.submenu["Bracket to bracket overlap"].value == "20%" then
factor = .2
elseif keymenu.submenu["Bracket to bracket overlap"].value == "10%" then
factor = .1
else
factor = .05
end
c1 = b1 - (b1 - fp*10)*factor
started = true
return true
end
end
end
end

lv.info
{
    name = "Landscape Stacker Info",
    value = "",
    priority = 100,
    update = function(this)
    this.value = ""
if fp == 0 then
this.value = ""
else
    if keymenu.submenu["Turn On/Off"].value == "On"
    then
    if started then
a2 = lens.dof_near
this.value = ""
if a2 > b1 then
this.background = COLOR.RED
elseif a2 < c1 then
this.background = COLOR.YELLOW
this.foreground = COLOR.BLACK
else
this.background = COLOR.GREEN1
end
if lens.dof_far >= inf then
this.value = "Inf"
else
this.value = "   "
end
end
else
this.value = ""
end
end
end
}

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacking Helper",
help = "First focus at nearest point in bracket set",
help2 = "and take first picture",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Turn On/Off",
help = "Switches the script on/off",
help2 = "Simply enables addition button functionality",
depends_on = DEPENDS_ON.LIVEVIEW,
choices = {"Off","On"},
},
{
name = "Bracket to bracket overlap",
help = "Amount to overlap each bracket",
help2 = "% of FP-2-DoF(far) distance",
choices = {"20%","10%", "5%"},
},
{
name = "Bookends",
help = "Toggles a dark frame",
choices = {"no","yes"},
},
{
name = "Exposure bracketing",
help = "Set options in the ML bracketing menu",
choices = {"None","From here", "From ETTR"},
update = function(this)
if keymenu.submenu["Exposure bracketing"].value == "None" then
i = menu.set("Shoot","Advanced Bracket",0)
else
i = menu.set("Shoot","Advanced Bracket",1)
if keymenu.submenu["Exposure bracketing"].value == "From ETTR" then i = menu.set("Advanced Bracket","Sequence",2) end
if keymenu.submenu["Exposure bracketing"].value == "From here" then i = menu.set("Advanced Bracket","Sequence",1) end
end
end
}
}
}


The Canon lens 'only' generates random (ie non predictable) Semaphore errors (which is down to my script and my ignorance at how to handle the complexities of semaphore handling).

When I attach the Sigma, this block of code, round line 40, does strange things:


camera.aperture.apex = current_av
camera.shutter.apex = current_tv


The shutter always changes to the previously stored current value, but the aperture doesn't.

As I say, both Tv and Av values change with a Canon lens.

BTW the Sigma also generates the 'random' semaphore errors.

As I say, just some feedback from the field  ;)


dmilligan

Stop putting task.yields everywhere. Just randomly putting them places makes the errors *more* likely to occur. Definitely do not put them in your key event handler, it should return quickly. Really the only place you should task.yield is inside a long running loop.

Lenses and semaphore errors have nothing to do with each other.

garry23

David

Thanks!!!!  :)

I know you must think me stupid and a pain in the $@#%

I took your advice and stripped the event.keypress handler down to a minimum, ie trying to speed it up. And of course removed those task.yield calls.

The script appears stable now and seems to work with both the Canon and Sigma lenses.

For completeness here it is. BTW I still am a little confused regarding the update call. Have I used the 'correct' format for the bracket-to-bracket menu, ie setting the global variable called 'factor'

Once again: thanks - I'm so pleased to have got this, my first script, running -- thanks to you and your support.

Cheers

Garry

--[[
Manual Landscape bracketing helper script
Version 0.3.5
Garry George Feb 2016
http://photography.grayheron.net/
Workflow helper script for focus and exposure bracketing.
Try using ML follow focus to control the lens, as opposed to rotating lens by hand.
Yellow means move more towards the infinity end, Red means move more towards macro end,
Green means at the sweet spot. If Green not seen, move to just being in the Yellow from being in the Red.
************************
* Must be in liveview! *
************************
--]]
a1 = lens.dof_near
b1 = lens.dof_far
c1 = 0
fp = lens.focal_distance
inf = 1000000
started = false
bookended = true
current_tv = camera.shutter.apex
current_av = camera.aperture.apex
factor = .2

event.keypress = function(key)
if keymenu.submenu["Turn On/Off"].value == "Off" then
started = false
return true
else
if key == KEY.RATE then
if keymenu.submenu["Bookends"].value == "yes"
then
if bookended then
current_tv = camera.shutter.apex
current_av = camera.aperture.apex
camera.shutter.apex = 100
camera.aperture.apex = 90
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",0) end
bookended = false
else
camera.aperture.apex = current_av
camera.shutter.apex = current_tv
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",1) end
bookended = true
end
return false
else
return true
end
end
if fp ~= 0 then
if key == KEY.FULLSHUTTER
then
b1 = lens.dof_far -- in mm
fp = lens.focal_distance -- in cm
c1 = b1 - (b1 - fp*10)*factor
started = true
return true
end
end
end
end

lv.info
{
    name = "Landscape Stacker Info",
    value = "",
    priority = 100,
    update = function(this)
    this.value = ""
if fp == 0 then
this.value = ""
else
    if keymenu.submenu["Turn On/Off"].value == "On"
    then
    if started then
a2 = lens.dof_near
this.value = ""
if a2 > b1 then
this.background = COLOR.RED
elseif a2 < c1 then
this.background = COLOR.YELLOW
this.foreground = COLOR.BLACK
else
this.background = COLOR.GREEN1
end
if lens.dof_far >= inf then
this.value = "Inf"
else
this.value = "   "
end
end
else
this.value = ""
end
end
end
}

keymenu = menu.new
{
parent = "Audio",
name = "Landscape Stacking Helper",
help = "First focus at nearest point in bracket set",
help2 = "and take first picture",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Turn On/Off",
help = "Switches the script on/off",
help2 = "Simply enables addition button functionality",
depends_on = DEPENDS_ON.LIVEVIEW,
choices = {"Off","On"},
},
{
name = "Bracket to bracket overlap",
help = "Amount to overlap each bracket",
help2 = "% of FP-2-DoF(far) distance",
choices = {"20","10", "5"},
update = function(this)
factor = tonumber(keymenu.submenu["Bracket to bracket overlap"].value)/100
end,
},
{
name = "Bookends",
help = "Toggles a dark frame",
choices = {"no","yes"},
},
{
name = "Exposure bracketing",
help = "Set options in the ML bracketing menu",
choices = {"None","From here", "From ETTR"},
update = function(this)
if keymenu.submenu["Exposure bracketing"].value == "None" then
i = menu.set("Shoot","Advanced Bracket",0)
else
i = menu.set("Shoot","Advanced Bracket",1)
if keymenu.submenu["Exposure bracketing"].value == "From ETTR" then i = menu.set("Advanced Bracket","Sequence",2) end
if keymenu.submenu["Exposure bracketing"].value == "From here" then i = menu.set("Advanced Bracket","Sequence",1) end
end
end
}
}
}

garry23

David

Further testing and I think I have a hypothesis regarding why I sometimes see semaphore errors with a Sigma lens, but not my 24-105 F4/L lens.

The theory goes like this: the current script change shutter and aperture, and I get errors...sometimes.

If I only change shutter, like this, I don't get semaphore errors, even with the Sigma.

if key == KEY.RATE then
if keymenu.submenu["Bookends"].value == "yes"
then
if bookended then
current_tv = camera.shutter.apex
camera.shutter.apex = 100
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",0) end
bookended = false
else
camera.shutter.apex = current_tv
if keymenu.submenu["Exposure bracketing"].value ~= "None" then i = menu.set("Shoot","Advanced Bracket",1) end
bookended = true
end
return false
else
return true
end
end


My theory is that the Sigma lens aperture change is taking longer than the Canon, and thus the process is taking too long inside the event.keypress function.

Bottom line: my script's functionality still works with only the shutter toggle, so I'm going with that.

Just thought I would report my theory, based on my experiments.