Author Topic: Auto HFD Script: UPDATED  (Read 2023 times)

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1772
Auto HFD Script: UPDATED
« on: December 05, 2016, 11:27:28 PM »
The latest version of my Auto HFD lens positioning script may be found here: https://gist.github.com/pigeonhill/92df2d0ae7b69b4223cd802eedee3db1

This version is interactive and allows the user to select three aperture options: optimised for max DoF, widest the lens will go or the currently set value (which the user can change at any time). Select exit does nothing, ie doesn't move the lens.

Feedback, whilst in interactive mode, is provided in the upper right of the ML menu bar.

In interactive mode all keys, other than the two controlling the script are inoperable.

For those that don't wish to look further, here is the script:

Code: [Select]
--[[
Script moves lens to HFD giving user various aperture options
Version 0.8 (should work on all ML enabled cameras with the Lua module)
Allows user to select aperture options to auto position the lens to the HFD
Garry George Dec 2016
http://photography.grayheron.net/
For the HFD functionality must be in AF mode and lens must report distance
LV needs to be on
Also make sure ML DoF set up as you require it, eg diffraction on
As script may change aperture, you still need to finalise shutter for exposure
To use, simply go into LV and press the mod_button_1 followed by the mod_button_2 buttons...
then keep pressing the mod_button_2 button until the required aperture option is reached...
then press mod_button_1 to either exit script or move the lens with the selected aperture option
Pressing mod_button_1 twice simply functions the mod_button_1 in normal mode
Script has 'only' been tested on a 5D3
This version of the script does some (sic) error checking ;-)
--]]

-- Declare some globals
mod_button_1 = KEY.MENU -- key to modify
mod_button_2 = KEY.INFO -- interactive key
last_key_pressed = 999 -- used to reset mod_button pairing
hfd_move_requested = false
imode = false
imode_condition = 0
options = {"Exit"," Set"," Opt","Wide"} -- for aperture

-- Choose buttons of your choice for mod_button_1 or _2, eg KEY.RATE, KEY.UP, KEY.INFO or KEY.PLAY.
-- See http://davidmilligan.github.io/ml-lua/modules/constants.html for key constants

function check_lens_ready() -- just in case
if hfd_move_menu.submenu["Turn On/Off"].value == "On" then-- check lens is ready to be moved
if lens.focus_distance ~= 0 and lens.af then -- lens is OK
repeat
msleep(100)
until lens.focus(0,1,false)
end
end
end

function optimise() -- change aperture if needed
if imode_condition == 3 then
local current_aperture = camera.aperture.min.apex
local current_dof_near = lens.dof_near
local delta_aperatue = 0.5 -- change aperture in half stops
repeat
current_dof_near = lens.dof_near -- current dof_near
current_aperture = camera.aperture.apex -- store current aperture
camera.aperture.apex = camera.aperture.apex + delta_aperatue -- close down the aperture by a 1/2 stop
msleep(100) -- give the system a chance to do some stuff, just in case
until lens.dof_near >= current_dof_near -- that is until diffraction starts getting the better of you
camera.aperture.apex = current_aperture -- set aperture to DoF optimised value
elseif imode_condition == 2 then
-- use current set value
elseif imode_condition == 4 then
camera.aperture.apex = camera.aperture.min.apex -- set aperture to widest
end
end

function move()
if lens.focus_distance ~= 0 and lens.af then -- lens is OK
if lens.dof_far ~= lens.dof_near then -- ok to move
if lens.focus_distance < lens.hyperfocal then
repeat
lens.focus(-1,2,false)
until lens.focus_distance >= lens.hyperfocal
repeat
lens.focus(1,1,false)
until lens.focus_distance <= lens.hyperfocal
repeat
lens.focus(-1,1,false)
until lens.focus_distance >= lens.hyperfocal
else
repeat
lens.focus(1,2,false)
until lens.focus_distance <= lens.hyperfocal
repeat
lens.focus(-1,1,false)
until lens.focus_distance >= lens.hyperfocal
end
else
beep (3, 200 , 500)  -- warning message
display.notify_box("Check aperture", 3000)
end
else
beep (3, 200 , 500)  -- warning message
display.notify_box("Check lens settings", 3000)
end
end

function test4mod(key)
--[[
Interactive mode states:
1. Exit and do nothing
2. Move to HFD with currently set aperture
3. Move to HFD and optimised aperture for max DoF
4. Move to HFD and aperture open as wide as possible
--]]
if lv.running then
if hfd_move_menu.submenu["Turn On/Off"].value == "On" and imode then -- stay in interactive mode
if key == mod_button_2 then
imode_condition = imode_condition + 1
if imode_condition > 4 then imode_condition = 1 end
return false -- steal key press
elseif key == mod_button_1 then -- flag HFD move or exit requested
hfd_move_requested = true
imode = false
last_key_pressed = 999 -- reset
return false
else
return false -- steal all other key presses
end
end
-- if not going into interactive mode then check other key sequences
if hfd_move_menu.submenu["Turn On/Off"].value == "Off" then
return true -- all keys work as normal
elseif key == mod_button_1 and last_key_pressed == mod_button_1 then -- use moded key as normal
last_key_pressed = 999 -- reset
return true
elseif key == mod_button_2 and last_key_pressed == mod_button_1 then -- go into interactive mode
imode = true -- go into interactive mode
imode_condition = 1
return false -- steal key press
elseif key == mod_button_1 then -- first press of modified key in new sequence
last_key_pressed = mod_button_1
return false -- steal key press
else
return true -- use all non-moded buttons in an unmodified way
end
else -- don't use script
return true
end
end

lv.info -- provide user feedback in interactive mode in the ML top menu bar
{
name = "HFD",
priority = 100,
value = "",
update = function(this)
this.background = COLOR.BLUE
this.foreground = COLOR.YELLOW
if hfd_move_menu.submenu["Turn On/Off"].value == "On" and imode then
this.value = options[imode_condition]
else
this.value = ""
end
end
}

function check_requests(arg)
if hfd_move_requested == true and not imode then -- move lens if requested
hfd_move_requested = false -- reset flag
if imode_condition == 1 then -- do nothing
return false
end
check_lens_ready() -- just in case it isn't
if imode_condition ~= 1 then -- check aperture and change if needed
optimise()
end
move() -- lens to maximised HFD position, but note shutter will need checking for optimised exposure
return false
end
end

event.keypress = test4mod
event.shoot_task = check_requests

hfd_move_menu = menu.new
{
parent = "Shoot",
name = "HFD",
help = "Moves lens to HFD focus distance",
depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Turn On/Off",
help = "Switches the script on/off",
choices = {"On","Off"},
}
}
}

The script has been tested 'only' on my 5D3.

As usual I welcome feedback of any kind  :)

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1772
Re: Auto HFD Script: UPDATED
« Reply #1 on: December 06, 2016, 07:45:30 AM »
@A1ex/@David

I just noticed a strangeness with my Auto HFD script. When in the interactive mode, only two keys are allowed to work. What I have noticed on my 5D3 is that this is true, apart the Picture Style button/key, which seems to work as normal, ie not blocked in this code snippet below:

 
Code: [Select]
if hfd_move_menu.submenu["Turn On/Off"].value == "On" and imode then -- stay in interactive mode
if key == mod_button_2 then
imode_condition = imode_condition + 1
if imode_condition > 4 then imode_condition = 1 end
return false -- steal key press
elseif key == mod_button_1 then -- flag HFD move or exit requested
hfd_move_requested = true
imode = false
last_key_pressed = 999 -- reset
return false
else
return false -- steal all other key presses
end

As I say, strange. It looks like the Picture Style button, which also on the 5D3 is a print button (I think), circumvents the ML key press handling.