Author Topic: Lua Request/Idea  (Read 8620 times)

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #50 on: July 01, 2016, 07:24:02 PM »
@A1ex

Thanks for the pointers. I'll play around with things this weekend and see if I can divine a solution  ;)

BBA

  • Member
  • ***
  • Posts: 125
Re: Lua Request/Idea
« Reply #51 on: July 01, 2016, 10:07:08 PM »
@garry23

I didn't mean to shoot with AF, which would "blow the focus stack away".

I only meant that lens.focus is called with "false" = without waiting for it (this command) to finish before continuing =>  many commands could be queued because of the repeat loop.

But.. lens.focus returns a value to the soft_err variable whose value must be tested for the repeat loop (except when b2<a1) :  doesn't it imply that it is necessary to wait for the lens.focus command to finish at each loop ?

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #52 on: July 02, 2016, 08:10:36 AM »
@BBA/A1ex/David

Final confirmation: I've tried various delays and focus steps, but calling camera.shoot seems to generate a false return from lens.focus.

I've used this short test script to 'prove' the above:

Code: [Select]
soft_err = true
b2 = lens.dof_far
a2 = lens.dof_near


function move(direction)
lv.start()
local a1 = 0
local b1 = 0
local fp = lens.focus_distance
local old_fp = fp
if direction == -1 then -- test focus stack to infinity soft stop
a1 = a2
b1 = b2
fp = lens.focus_distance
repeat
lv.resume() -- just to be sure
old_fp = fp
soft_err = lens.focus(-1,3,false)
b2 = lens.dof_far
a2 = lens.dof_near
fp = lens.focus_distance
until a2> b1 or soft_err == false
msleep(1000)  -- this works
-- camera.shoot(64, false)  -- this doesn't
else  -- test focus stack to macro soft stop
a1 = a2
b1 = b2
fp = lens.focus_distance
repeat
lv.resume() -- just to be sure
old_fp = fp
soft_err = lens.focus(1,3,false)
b2 = lens.dof_far
a2 = lens.dof_near
fp = lens.focus_distance
until b2 < a1 or soft_err == false
-- msleep(1000)  -- this works
camera.shoot(64, false)  -- this doesn't
end
end

function start() -- test out focus stacking works through the soft stop error return
move(-1)
move(1)
move(-1)
end

scrnshot_menu = menu.new
{
    name = "Test",
select = function(this)
task.create(start)
end
}

The script stops after the first camera.shoot generates a lens.focus false return.

BBA

  • Member
  • ***
  • Posts: 125
Re: Lua Request/Idea
« Reply #53 on: July 02, 2016, 12:05:10 PM »
? Don't you think it would be easier with a simplified algorithm ?
Unless you really want to know what goes wrong, but maybe it will go wrong when simplified too.

cf. above, fp is a step function : we only need to test when it's value changes (no need to work with intervals a1b1 and a2b2 anymore) , something like
Code: [Select]
fp1=lens.focus_distance
shoot()
while true do -- loop to scan when to shoot
   soft = lens.focus(dir,1,false) -- go in given direction
   fp2=lens.focus_distance -- check new focal point

   if fp2<>fp1 then shoot() end -- new step of step function -> shoot
   if soft then shoot() break end -- software limit reached --> shoot & leave

   fp2=fp1
end

function shoot()
   msleep
   camera.shoot
   msleep
end
Maybe there are errors but we have less things to check...

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #54 on: July 02, 2016, 12:15:34 PM »
@BBA

Just for you  :)

This still fails after camera.shoot

Code: [Select]
soft_err = true


function move(direction)
lv.start()
if direction == -1 then -- test focus stack to infinity soft stop
repeat
lv.resume() -- just to be sure
soft_err = lens.focus(-1,3,false)
until soft_err == false
msleep(1000)  -- this works
-- camera.shoot(64, false)  -- this doesn't
else  -- test focus stack to macro soft stop
repeat
lv.resume() -- just to be sure
soft_err = lens.focus(1,3,false)
until soft_err == false
-- msleep(1000)  -- this works
camera.shoot(64, false)  -- this doesn't
end
end

function start() -- test out focus stacking works through the soft stop error return
move(-1)
move(1)
move(-1)
end

scrnshot_menu = menu.new
{
    name = "Test",
select = function(this)
task.create(start)
end
}

BBA

  • Member
  • ***
  • Posts: 125
Re: Lua Request/Idea
« Reply #55 on: July 02, 2016, 12:47:30 PM »
@garry23

I will try with "true" in "lens.focus" ( lens.focus(_,_,true) ) because mine doesn't work either with "false" : it doesn't "see" the step changes.
What if you use both "sleep" and "camera.shoot" like "sleep(1000) camera.shoot(64,false) sleep(2000)".
And if you use "true" in "lens.focus" like me ?

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #56 on: July 02, 2016, 12:59:31 PM »
@BBA

I tried various delays, and none worked, but I would welcome you trying.

Cheers

Garry

BBA

  • Member
  • ***
  • Posts: 125
Re: Lua Request/Idea
« Reply #57 on: July 02, 2016, 01:34:33 PM »
To share

I got 2 errors in the console: the same error "twice in a row":

Lua semaphore timeout: menu.updt (100ms)
Lua semaphore timeout: menu.updt (100ms)

my script with logging:

Code: [Select]
require('logger')
focus_log = nil

fp1 = 0
fp2 = 0
soft_err= false

function move( dir)
 
  printf(" start move : fp1,fp2 =  %s , %s  direction  = %s \n",fp1,fp2,dir)
  fp1 = lens.focus_distance
  shoot()
 
  while true do
   
    soft_err=false
    msleep(200)
    soft_err = lens.focus(dir,1)
    msleep(200)
    fp2 = lens.focus_distance
    msleep(200)
    printf(" loop : fp1,fp2 =  %s , %s    soft_err focus = %s \n",fp1,fp2,soft_err)
   
    if not fp2==fp1 then  -- if new step (step function)
      printf(" - fp2<>fp1 : fp1,fp2 =  %s , %s    soft_err focus = %s \n",fp1,fp2,soft_err)
      shoot()
    end
 
    if soft_err then -- if focus limit reached
      printf(" - soft_err focus reached : fp1,fp2 =  %s , %s    soft_err focus = %s \n",fp1,fp2,soft_err)
      shoot()
      break
    end
   
    fp1 = fp2
   
  end
end


function printf( format_string, ...)
    focus_log:writef( format_string, ...)
end

function shoot()
      msleep(1000) -- wait for other tasks to finish
      printf("   shoot : fp1,fp2 =  %s , %s    soft_err focus = %s \n",fp1,fp2,soft_err)
      camera.shoot(64, false)
      msleep(3000) -- wait for camera.shoot to finish
end

function start()
  lv.start()
  focus_log = logger("test_wt.log")
  move(-1)
  move(1)
  move(-1)
  focus_log:close()
 end
 
scrnshot_menu = menu.new
{
    name = "Test",
    select = function(this)
       task.create(start)
   end
}
 

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #58 on: July 02, 2016, 02:15:06 PM »
@BBA

My gut feeling is that there is something happening 'behind' the scenes and that you and I mucking about in Lua scripting will not find.

Let's hope the gurus can work it out  ;)

Cheers

Garry

BBA

  • Member
  • ***
  • Posts: 125
Re: Lua Request/Idea
« Reply #59 on: July 02, 2016, 02:17:45 PM »
@garry23

When I try your script:
- one picture is taken
- immediately after, the live view mode is left (is it ?) (mirror sound)
and the script seems to have stopped.

Is it the same as you ?

I need to go for some food.

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #60 on: July 02, 2016, 02:32:37 PM »
Yes that's the problem.

Replace camera.shoot with, say, msleep and the s rapt completes fine.

BBA

  • Member
  • ***
  • Posts: 125
Re: Lua Request/Idea
« Reply #61 on: July 02, 2016, 09:06:52 PM »
This one works.
I don't exactly know why but I have added another test just before the lens move (fp2 too late in case fp2=lens.focus_distance is refreshed later); it appears that it is this test that triggers the shots !
It is to be simplified (debug, strong typing, slow timings)
In the infinity range, a photo is taken at each step of the focus motor (manage infinity shots : to be modified)
Here is the script (to share if needed)
Code: [Select]

-- strict type : number/string not interchangeable
-- timings : 2nd chance for fp2

require('logger')
focus_log = nil

soft_limit = false

infinity = 100000
epsilon = 0.00001

dir=0

function move()
 
  local fp1,fp2 = 0,0
  local st_fp1,st_fp2 = "void","void"
  local st_dir = "void"
  local istep = 0

  st_fp2 = tostring(fp2)
  st_dir = tostring(dir)
 
  fp2 = tonumber(lens.focus_distance)
  st_fp2 = tostring( fp2)
  printf(" --- start move : fp1,fp2 =  %s , %s  direction  = %s \n",st_fp1,st_fp2,st_dir)
 
  istep = 0
 
  while true do
   
    msleep(100) -- to let things stabilize if needed
   
    fp2 = tonumber(lens.focus_distance)
    st_fp2 = tostring( fp2)
    printf("- reenter loop : step = %s - fp1,fp2 =  %s , %s \n",istep, st_fp1, st_fp2)
   
    if ( tonumber(fp1) < tonumber(fp2) ) then -- last time test if fp2 was refreshed too late
      printf("     - fp2<>fp1 (fp2 too late) fp1,fp2 =  %s , %s \n",st_fp1,st_fp2)
      shoot()
    elseif (tonumber(fp2) > infinity) and soft_limit then -- near infinity
      printf("     - near infinity (fp2 too late) fp1,fp2 =  %s , %s \n",st_fp1,st_fp2)
      manage_infinity_shots()
      break
    elseif not soft_limit then
      printf("     - near infinity (fp2 too late) error : did not manage infinity shots")
      break
    end
   
    fp1 = tonumber(fp2) -- transfer values just before the move
    st_fp1 = tostring( fp1)
   
    -- move
    soft_limit = lens.focus( dir, 1, true) -- HERE it is !!!!!!!!!!!!!!!!!!!!!!
   
    istep = istep+1
    msleep(100) -- with hope to get fp2 refreshed
   
    fp2 = tonumber(lens.focus_distance)
    st_fp2=tostring( fp2)
   
    printf("- loop after lens move: step = %s - fp1,fp2 =  %s , %s \n",istep, st_fp1,st_fp2)
   
   
    if ( tonumber(fp1) < tonumber(fp2) )  then  -- if new big step (step function)
      printf("     - fp2<>fp1 : fp1,fp2 =  %s , %s \n",st_fp1,st_fp2)
      shoot()
      fp1 = tonumber(fp2)
      st_fp1 = tostring( fp1)
    elseif (tonumber(fp2) > infinity) and soft_limit then -- near infinity
      printf("     - near infinity : fp1,fp2 =  %s , %s \n",st_fp1,st_fp2)
      manage_infinity_shots()
      break
    elseif not soft_limit then
      printf("     - near infinity : error : did not manage infinity shots")
      break
    end
   
  end
  printf(" end of move : fp1,fp2 =  %s , %s \n",st_fp1,st_fp2)
 
end

-- new algorithm to be implemented for infinity range
function manage_infinity_shots()
  while lens.focus( dir, 1, true) do
    shoot()
  end
end

function printf( format_string, ...)
    focus_log:writef( format_string, ...)
end

function shoot()
      msleep(1000) -- wait for other tasks to finish
      printf("   shoot \n")
      camera.shoot(64, false)
      msleep(3000) -- wait for camera.shoot to finish
end
 
function start()
  lv.start()
  focus_log = logger("test_wt.log")
  dir = -1
  move()
  dir = 1
  --move()
  dir = -1
  --move()
  focus_log:close()
 end
 
 scrnshot_menu = menu.new
{
  name = "myTest",
  select = function(this)
   task.create(start)
  end
}

If needed, the log to show that the "fp2 too late" is used !

Code: [Select]

===============================================================================
ML/SCRIPTS/TSTSTACK.LUA - 2016-7-2 20:25:01
===============================================================================

 --- start move : fp1,fp2 =  void , 380  direction  = -1
- reenter loop : step = 0 - fp1,fp2 =  void , 380
     - fp2<>fp1 (fp2 too late) fp1,fp2 =  void , 380
   shoot
- loop after lens move: step = 1 - fp1,fp2 =  380 , 380
- reenter loop : step = 1 - fp1,fp2 =  380 , 380
- loop after lens move: step = 2 - fp1,fp2 =  380 , 380
- reenter loop : step = 2 - fp1,fp2 =  380 , 400
     - fp2<>fp1 (fp2 too late) fp1,fp2 =  380 , 400
   shoot
- loop after lens move: step = 3 - fp1,fp2 =  400 , 400
- reenter loop : step = 3 - fp1,fp2 =  400 , 400
- loop after lens move: step = 4 - fp1,fp2 =  400 , 400
- reenter loop : step = 4 - fp1,fp2 =  400 , 400
- loop after lens move: step = 5 - fp1,fp2 =  400 , 400
- reenter loop : step = 5 - fp1,fp2 =  400 , 400
- loop after lens move: step = 6 - fp1,fp2 =  400 , 400
- reenter loop : step = 6 - fp1,fp2 =  400 , 400
- loop after lens move: step = 7 - fp1,fp2 =  400 , 400
- reenter loop : step = 7 - fp1,fp2 =  400 , 400
- loop after lens move: step = 8 - fp1,fp2 =  400 , 400
- reenter loop : step = 8 - fp1,fp2 =  400 , 400
- loop after lens move: step = 9 - fp1,fp2 =  400 , 400
- reenter loop : step = 9 - fp1,fp2 =  400 , 400
- loop after lens move: step = 10 - fp1,fp2 =  400 , 400
- reenter loop : step = 10 - fp1,fp2 =  400 , 400
- loop after lens move: step = 11 - fp1,fp2 =  400 , 400
- reenter loop : step = 11 - fp1,fp2 =  400 , 400
- loop after lens move: step = 12 - fp1,fp2 =  400 , 400
- reenter loop : step = 12 - fp1,fp2 =  400 , 400
- loop after lens move: step = 13 - fp1,fp2 =  400 , 400
- reenter loop : step = 13 - fp1,fp2 =  400 , 400
- loop after lens move: step = 14 - fp1,fp2 =  400 , 400
- reenter loop : step = 14 - fp1,fp2 =  400 , 400
- loop after lens move: step = 15 - fp1,fp2 =  400 , 400
- reenter loop : step = 15 - fp1,fp2 =  400 , 400
- loop after lens move: step = 16 - fp1,fp2 =  400 , 400
- reenter loop : step = 16 - fp1,fp2 =  400 , 400
- loop after lens move: step = 17 - fp1,fp2 =  400 , 400
- reenter loop : step = 17 - fp1,fp2 =  400 , 400
- loop after lens move: step = 18 - fp1,fp2 =  400 , 400
- reenter loop : step = 18 - fp1,fp2 =  400 , 400
- loop after lens move: step = 19 - fp1,fp2 =  400 , 400
- reenter loop : step = 19 - fp1,fp2 =  400 , 400
- loop after lens move: step = 20 - fp1,fp2 =  400 , 400
- reenter loop : step = 20 - fp1,fp2 =  400 , 400
- loop after lens move: step = 21 - fp1,fp2 =  400 , 400
- reenter loop : step = 21 - fp1,fp2 =  400 , 400
- loop after lens move: step = 22 - fp1,fp2 =  400 , 400
- reenter loop : step = 22 - fp1,fp2 =  400 , 400
- loop after lens move: step = 23 - fp1,fp2 =  400 , 400
- reenter loop : step = 23 - fp1,fp2 =  400 , 400
- loop after lens move: step = 24 - fp1,fp2 =  400 , 400
- reenter loop : step = 24 - fp1,fp2 =  400 , 400
- loop after lens move: step = 25 - fp1,fp2 =  400 , 400
- reenter loop : step = 25 - fp1,fp2 =  400 , 400
- loop after lens move: step = 26 - fp1,fp2 =  400 , 400
- reenter loop : step = 26 - fp1,fp2 =  400 , 400
- loop after lens move: step = 27 - fp1,fp2 =  400 , 400
- reenter loop : step = 27 - fp1,fp2 =  400 , 400
- loop after lens move: step = 28 - fp1,fp2 =  400 , 400
- reenter loop : step = 28 - fp1,fp2 =  400 , 400
- loop after lens move: step = 29 - fp1,fp2 =  400 , 400
- reenter loop : step = 29 - fp1,fp2 =  400 , 400
- loop after lens move: step = 30 - fp1,fp2 =  400 , 400
- reenter loop : step = 30 - fp1,fp2 =  400 , 400
- loop after lens move: step = 31 - fp1,fp2 =  400 , 400
- reenter loop : step = 31 - fp1,fp2 =  400 , 400
- loop after lens move: step = 32 - fp1,fp2 =  400 , 400
- reenter loop : step = 32 - fp1,fp2 =  400 , 400
- loop after lens move: step = 33 - fp1,fp2 =  400 , 400
- reenter loop : step = 33 - fp1,fp2 =  400 , 400
- loop after lens move: step = 34 - fp1,fp2 =  400 , 400
- reenter loop : step = 34 - fp1,fp2 =  400 , 400
- loop after lens move: step = 35 - fp1,fp2 =  400 , 400
- reenter loop : step = 35 - fp1,fp2 =  400 , 400
- loop after lens move: step = 36 - fp1,fp2 =  400 , 430
     - fp2<>fp1 : fp1,fp2 =  400 , 430
   shoot
- reenter loop : step = 36 - fp1,fp2 =  430 , 430
- loop after lens move: step = 37 - fp1,fp2 =  430 , 430
- reenter loop : step = 37 - fp1,fp2 =  430 , 430
- loop after lens move: step = 38 - fp1,fp2 =  430 , 430
- reenter loop : step = 38 - fp1,fp2 =  430 , 430
- loop after lens move: step = 39 - fp1,fp2 =  430 , 430
- reenter loop : step = 39 - fp1,fp2 =  430 , 430
- loop after lens move: step = 40 - fp1,fp2 =  430 , 430
- reenter loop : step = 40 - fp1,fp2 =  430 , 430
- loop after lens move: step = 41 - fp1,fp2 =  430 , 430
- reenter loop : step = 41 - fp1,fp2 =  430 , 430
- loop after lens move: step = 42 - fp1,fp2 =  430 , 430
- reenter loop : step = 42 - fp1,fp2 =  430 , 430
- loop after lens move: step = 43 - fp1,fp2 =  430 , 430
- reenter loop : step = 43 - fp1,fp2 =  430 , 430
- loop after lens move: step = 44 - fp1,fp2 =  430 , 430
- reenter loop : step = 44 - fp1,fp2 =  430 , 430
- loop after lens move: step = 45 - fp1,fp2 =  430 , 430
- reenter loop : step = 45 - fp1,fp2 =  430 , 430
- loop after lens move: step = 46 - fp1,fp2 =  430 , 430
- reenter loop : step = 46 - fp1,fp2 =  430 , 430
- loop after lens move: step = 47 - fp1,fp2 =  430 , 430
- reenter loop : step = 47 - fp1,fp2 =  430 , 430
- loop after lens move: step = 48 - fp1,fp2 =  430 , 430
- reenter loop : step = 48 - fp1,fp2 =  430 , 430
- loop after lens move: step = 49 - fp1,fp2 =  430 , 430
- reenter loop : step = 49 - fp1,fp2 =  430 , 430
- loop after lens move: step = 50 - fp1,fp2 =  430 , 430
- reenter loop : step = 50 - fp1,fp2 =  430 , 430
- loop after lens move: step = 51 - fp1,fp2 =  430 , 430
- reenter loop : step = 51 - fp1,fp2 =  430 , 430
- loop after lens move: step = 52 - fp1,fp2 =  430 , 430
- reenter loop : step = 52 - fp1,fp2 =  430 , 430
- loop after lens move: step = 53 - fp1,fp2 =  430 , 430
- reenter loop : step = 53 - fp1,fp2 =  430 , 430
- loop after lens move: step = 54 - fp1,fp2 =  430 , 430
- reenter loop : step = 54 - fp1,fp2 =  430 , 430
- loop after lens move: step = 55 - fp1,fp2 =  430 , 430
- reenter loop : step = 55 - fp1,fp2 =  430 , 430
- loop after lens move: step = 56 - fp1,fp2 =  430 , 430
- reenter loop : step = 56 - fp1,fp2 =  430 , 430
- loop after lens move: step = 57 - fp1,fp2 =  430 , 430
- reenter loop : step = 57 - fp1,fp2 =  430 , 430
- loop after lens move: step = 58 - fp1,fp2 =  430 , 430
- reenter loop : step = 58 - fp1,fp2 =  430 , 430
- loop after lens move: step = 59 - fp1,fp2 =  430 , 430
- reenter loop : step = 59 - fp1,fp2 =  430 , 430
- loop after lens move: step = 60 - fp1,fp2 =  430 , 430
- reenter loop : step = 60 - fp1,fp2 =  430 , 430
- loop after lens move: step = 61 - fp1,fp2 =  430 , 430
- reenter loop : step = 61 - fp1,fp2 =  430 , 430
- loop after lens move: step = 62 - fp1,fp2 =  430 , 430
- reenter loop : step = 62 - fp1,fp2 =  430 , 430
- loop after lens move: step = 63 - fp1,fp2 =  430 , 430
- reenter loop : step = 63 - fp1,fp2 =  430 , 430
- loop after lens move: step = 64 - fp1,fp2 =  430 , 430
- reenter loop : step = 64 - fp1,fp2 =  430 , 430
- loop after lens move: step = 65 - fp1,fp2 =  430 , 430
- reenter loop : step = 65 - fp1,fp2 =  430 , 430
- loop after lens move: step = 66 - fp1,fp2 =  430 , 430
- reenter loop : step = 66 - fp1,fp2 =  430 , 470
     - fp2<>fp1 (fp2 too late) fp1,fp2 =  430 , 470
   shoot
- loop after lens move: step = 67 - fp1,fp2 =  470 , 430
- reenter loop : step = 67 - fp1,fp2 =  470 , 470
- loop after lens move: step = 68 - fp1,fp2 =  470 , 470
- reenter loop : step = 68 - fp1,fp2 =  470 , 470
- loop after lens move: step = 69 - fp1,fp2 =  470 , 470
 
......



- loop after lens move: step = 368 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 368 - fp1,fp2 =  5950 , 5950
- loop after lens move: step = 369 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 369 - fp1,fp2 =  5950 , 5950
- loop after lens move: step = 370 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 370 - fp1,fp2 =  5950 , 5950
- loop after lens move: step = 371 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 371 - fp1,fp2 =  5950 , 5950
- loop after lens move: step = 372 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 372 - fp1,fp2 =  5950 , 5950
- loop after lens move: step = 373 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 373 - fp1,fp2 =  5950 , 5950
- loop after lens move: step = 374 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 374 - fp1,fp2 =  5950 , 5950
- loop after lens move: step = 375 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 375 - fp1,fp2 =  5950 , 5950
- loop after lens move: step = 376 - fp1,fp2 =  5950 , 5950
- reenter loop : step = 376 - fp1,fp2 =  5950 , 655350
     - fp2<>fp1 (fp2 too late) fp1,fp2 =  5950 , 655350
   shoot
- loop after lens move: step = 377 - fp1,fp2 =  655350 , 655350
     - near infinity : fp1,fp2 =  655350 , 655350
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
   shoot
 end of move : fp1,fp2 =  655350 , 655350

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #62 on: July 02, 2016, 09:38:42 PM »
@BBA

I looked at your script, but it will require me to backout the 'real meat' from all the logger stuff.

Any chance of a minimalist version without any logger stuff?

I can then look at your ideas and play around with them.

Cheers

Garry

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #63 on: July 02, 2016, 10:02:41 PM »
@BBA

Actually it didn't take me long to work out your 'solution', ie a delay before and after camera.shoot.

Here is my working focus stacking test script:

Code: [Select]
soft_err = true
b2 = lens.dof_far
a2 = lens.dof_near

function shoot()
      msleep(1000) -- wait for other tasks to finish
      camera.shoot(64, false)
      msleep(3000) -- wait for camera.shoot to finish
end

function move(direction)
lv.start()
local a1 = 0
local b1 = 0
if direction == -1 then -- focus stack to infinity soft stop
repeat
a1 = a2
b1 = b2
repeat
lv.resume()
soft_err = lens.focus(-1,1,false)
b2 = lens.dof_far
a2 = lens.dof_near
until a2> b1 or soft_err == false
shoot()
until soft_err == false
else  -- focus stack to macro soft stop
repeat
a1 = a2
b1 = b2
repeat
lv.resume()
soft_err = lens.focus(1,1,false)
b2 = lens.dof_far
a2 = lens.dof_near
until b2 < a1 or soft_err == false
shoot()
until soft_err == false
end
end

function start() -- test out focus stacking works through the soft stop error return
move(-1)
move(1)
move(-1)
end

scrnshot_menu = menu.new
{
    name = "Test",
select = function(this)
task.create(start)
end
}

I must say, it would be 'nice' if the Lua backend handled the delays, rather than having to do it with msleeps. I don't know if 1000 and 3000 are 'optimum' and will work with all cameras?

Thanks for all your work and feedback.

I build your 'recipe' into my full focus stacking script.

Cheers

Garry

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3203
  • 60Da / 1100D / EOSM
Re: Lua Request/Idea
« Reply #64 on: July 02, 2016, 10:08:54 PM »
Why would you want to remove all the "logger stuff" at this point? BBA has the right idea here. When you're trying to debug and understand a problem with code, logging is extremely helpful (sometimes the best and/or only alternative to having a "live debugger" attached). It helps you know what actually happened, and helps eliminate potentially false assumptions you have made.

I like to say you have to write to to write code. In other words there's often a lot of code that you write that will never be in the "production version" that you use to simply inform and debug the writing of the actual "production code".

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #65 on: July 02, 2016, 10:21:27 PM »
Sorry I wasn't being insulting, it was just all the logger  code 'got in the way' of me reading the script.

I now believe the 'problem' is that lens.focus doesn't wait for camera.shoot to do it's stuff, this is why the 'hard' delays help.

I still wonder if such delay/checks should be hard wired in.

Thanks to BBA at least I should be able to get my full script working.

Once again, my comment on longer was more a reflection of my ignorance.

Cheers

Garry

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #66 on: July 03, 2016, 08:30:55 AM »
@BBA

Thanks to your experimenting, I now have my script up and running: https://gist.github.com/pigeonhill/6620121ebe1548eb1bdaa6bea8598fac

This is an all in one bracketing script and I have tested it ONLY on a 5D3.

It works for me and my workflow.

The only observation I have for the developers is that, as you found out, I need to code in delays to make the lens.focus work with the camera.shoot. My concern with this approach is that it could be camera specific. It would better, IMHO, if lens.focus and camera.shoot where 'aware' of each other and handled their interactions in the 'backend'.

Once again thanks for your feedback and help.

BTW I find you only need the delay after you call camera.shoot and a 2s delay works on my 5D3

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #67 on: July 03, 2016, 10:55:44 AM »
@BBA

I little more insight.

As I say, the delay before the camera.shoot does nothing, ie the script works with it at zero.

The delay after camera.shoot is critical.

If I use msleep(1000) the script fails on my 5D3.

If I use msleep(2000) the script works.

If I use msleep(2000) and Dual-ISO is on the script fails.

I need to raise the delay to msleep(4000) to use Dual-ISO.

I guess the more ML needs to process 'stuff', eg Dual-ISO, the longer the delay to ensure lens.focus is fit to run.

Cheers

Garry

BBA

  • Member
  • ***
  • Posts: 125
Re: Lua Request/Idea
« Reply #68 on: July 03, 2016, 11:48:17 AM »
@garry23/dmilligan

I have been asleep for a while. I was glad to have something working ... which had to be further improved.
I like to know what happens really behind the scenes. I have often found that I could be completely wrong without analyzing in the details.
It is often too much precautions at the beginning, till something is found.

Thanks for experimenting with the delays : it will help to further improve and go as fast as possible. Maybe it would be possible to test if some variable stabilizes to know that the camera.shoot or something else is complete.
I don't know if the "type precautions" like tonumber and tostring have to remain : I put them because the test fp1<>fp2 after the move did not work at all. I thought it could be comparing apples with peers (as Lua is not a strict "typed" language, some side effect...). I may be completely wrong on this.
I have in mind (read somewhere) that lens.focus_distance could be updated later. This is a problem as the algorithm depends on its value: we don't know if it has not changed because it will not change anyway or because we question it too fast for it to have changed.

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #69 on: July 03, 2016, 12:22:48 PM »
@BBA

I had already thought along your lines (great minds think a like  ;)) and came up with this camera-independent delay, rather than use msleep.

Code: [Select]
shoot()
repeat
err = lens.focus(1,1,false)
until err


This works on my 5D3  :)

All the repeat does is hang around until lens.focus returns a true, ie is not 'insulted' by camera.shoot anymore.

BBA

  • Member
  • ***
  • Posts: 125
Re: Lua Request/Idea
« Reply #70 on: July 03, 2016, 01:25:45 PM »
@garry23

So, the boolean value returned by lens.focus has two significances intermixed
In your code snippet:
1) the loop can be endless if the lens stepping motor cannot move anymore in the "asked" direction
2) you have to move the lens one step in the opposite direction when there is no task running for which a lens move could be harmful.
In this last case, it sounds like a "ressource" has to been taken by concurrent tasks to have access to the lens move.

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #71 on: July 03, 2016, 02:10:36 PM »
@BBA

Agreed, but I only use this err test after I have taken an image, eg like in this snippet of my script

Code: [Select]
my_shoot()
repeat
err = lens.focus(-1,1,false)
msleep(1000)
until err
err = lens.focus(1,1,false)
Seems to work  ;)

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 10180
  • 5D Mark Free
Re: Lua Request/Idea
« Reply #72 on: July 03, 2016, 02:11:53 PM »
@garry23: can you try the following waiting sequence after taking a picture?

Code: [Select]
while not lv.running do msleep(100) end
lv.wait(1)

This waits until Canon code goes back to LiveView (as reported by Canon property system) after taking a picture, then it makes sure LiveView is fully initialized and running (it waits for one LiveView frame).

BTW, my assert test above should have been "assert(lv.running)" instead of "assert(lv)".

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #73 on: July 03, 2016, 02:21:20 PM »
@A1ex

Tried your code snippet and got a lv.wait timeout error

garry23

  • Hero Member
  • *****
  • Posts: 1266
Re: Lua Request/Idea
« Reply #74 on: July 03, 2016, 02:23:35 PM »
...sorry tried again and no error, but no fix, ie script stops.