Here is my code (if it can help).
For the moment, I don't actually see what is wrong with your code.
require('logger')
scan_log = nil
-- Declare a few global variables for the script
a1 = 0
b1 = 0
a2 = 0
b2 = 0
fp = 0
fp1 = 0
fp2 = 0
inf = 100000
ic = 0
istep = 0
num_steps = 0
delay = 3000
BB_ST1 = "TEST"
BB_ST2 = "TEST"
BB_ST3 = "TEST"
BB_ST4 = "TEST"
-- BB_move_focus (num_steps[, step_size=2[, wait=true[, extra_delay=0]]])
-- with log
function BB_move_focus(num_steps, step_size, wait, extra_delay)
local ret = true
local stret = "true"
msleep(300) -- BBA
fp1 = lens.focus_distance
-- lens.focus (num_steps[, step_size=2[, wait=true[, extra_delay=0]]])
--[[
Moves the focus motor a specified number of steps. Only works in LV.
Parameters:
num_steps int
step_size int (default 2)
wait bool (default true)
extra_delay int (default 0)
--]]
[color=green]ret = lens.focus(num_steps, step_size, wait, extra_delay) -- step size fixed at 1 to count steps and detect changes
stret = "false"
if ret then stret = "true" end[/color]
istep = istep+num_steps
msleep(400) -- BBA
fp2 = lens.focus_distance
scan_log:writef("%d,\" move_focus(%d,%d) : before = \",%d,\" / after = \",%d %5s",istep,num_steps,step_size,fp1,fp2,stret)
scan_log:writef(",\" dof near = \",%s,\" dof far = \",%s\n", lens.dof_near, lens.dof_far)
return ret
end
function BB_scan_focus_range()
local ret = true
menu.close()
scan_log = logger("ML/logs/scan.log") -- if file already exists in /ML/LOGS dir, new log lines will be appended
ic = 0 -- steps counter
istep = 0
scan_log:writef("lens = %s\n\n",lens.name)
BB_ST1 = tostring(camera.aperture.value)
scan_log:writef(" aperture = %s \n",BB_ST1)
BB_ST2 = tostring(lens.hyperfocal)
scan_log:writef(" hyperfocal = %s mmm\n",BB_ST2)
lv.start()
msleep(delay)
while ( ic <= 30 ) do
fp = lens.focus_distance
if fp >= inf -- dépasser 100000
then
ic = ic + 1
end
ret = BB_move_focus(-1,1,true,0) -- vers infini(-1), 1 step, wait for focus motor to stabilize
end
scan_log:close()
end
BB_scan_menu = menu.new
{
parent = "Shoot",
name = "Scan focus range ",
help = "Remember: FROM Macro end TO Infinity+",
-- depends_on = DEPENDS_ON.LIVEVIEW,
submenu =
{
{
name = "Run Script",
help = "Does what it says after pressing SET",
select = function(this)
task.create(BB_scan_focus_range)
end,
}
}
}