Author Topic: Lua API test  (Read 2645 times)

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1740
Lua API test
« on: January 24, 2017, 08:47:35 AM »
@A1ex

I continue to have problems with moving the lens in my scripts. The issue is around lens.focus reporting back, ie ok or not, but specifically how to test it has reached the macro of infinity ends.

So I went back to the API test (which I believe you wrote?)

In looking at the code, I think there is an error in there (but I may be wrong). Here is te snippet:

Code: [Select]
for i,step in pairs{3,2,1} do
            for j,wait in pairs{true,false} do
                printf("Focusing forward with step size %d, wait=%s...\n", step, wait)
                local steps_front = 0
                while lens.focus(1,step,true) do
                    printf(".")
                    steps_front = steps_front + 1
                end
                printf("\n")
                printf("Focus distance: %s\n",  lens.focus_distance)
               
                msleep(500)
               
                printf("Focusing backward with step size %d, wait=%s...\n", step, wait)
                local steps_back = 0
                while lens.focus(-1,step,true) do
                    printf(".")
                    steps_back = steps_back + 1
                end
                printf("\n")
                printf("Focus distance: %s\n",  lens.focus_distance)

                msleep(500)

                printf("Focus range: %s steps forward, %s steps backward. \n",  steps_front, steps_back)
            end
        end

I think the lens.focus in the while loops should be:

Code: [Select]
lens.focus(-1,step,wait)
That is at the moment it only tests the AF true state.

Irrespective of this, however, your API worked (either way, ie with or without wait), and I keep getting issues, which I will keep trying to debug  ;)

BTW here is my code snippet, which moves the lens towards the macro, stopping when certain dof conditions are meet and (hopefully) exiting when the macr0 end soft error is meet: but it doesn't stop, it just hangs on the error reporting.

Code: [Select]
repeat
a1=a2
b1=b2
fp = lens.focus_distance
while (b2 > a1) do
if lens.focus(1,1,false) then
lens_ok = true
else
lens_ok = false
end
b2 = lens.dof_far
a2 = lens.dof_near
end
lens.focus(-1,1,false)  -- move one step forwards for focus bracket overlap
take_brackets()
until not lens_ok

Cheers

Garry

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12241
  • Maintenance mode
Re: Lua API test
« Reply #1 on: January 24, 2017, 08:56:59 AM »
Code: [Select]
lens.focus(-1,step,wait)

Correct.

Side note: if one would have made the same error in QEMU, it wouldn't compile (unused variable). Gotta learn from them.

Quote
BTW here is my code snippet...

Will look into it, but my first advice would be to try a larger step size, and wait enabled.

BTW,
Code: [Select]
repeat
...
if lens.focus(1,1,false) then
lens_ok = true
else
lens_ok = false
end
...
until not lens_ok

does the same as:
Code: [Select]
repeat
   ...
   lens_ok = lens.focus(1,1,false)
   ...
until not lens_ok

the only difference being that boolean conversion is done on the "until" line, instead of the if branches.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1740
Re: Lua API test
« Reply #2 on: January 24, 2017, 09:06:58 AM »
@A1ex

Yes I had previously used this approach:

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

But the same problems.

If I use wait = true, aren't I requesting a refocus? If so, that no good for me, as my script is controlling focus, ie I'm stacking and only taking images at fixed distances.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12241
  • Maintenance mode
Re: Lua API test
« Reply #3 on: January 24, 2017, 09:14:18 AM »
wait != refocus, it means wait until current focus command finishes, until queueing others.

Yes I had previously used this approach [...]
But the same problems.

Of course, this change doesn't modify the functionality at all. It just makes the code smaller and easier to read.

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1740
Re: Lua API test
« Reply #4 on: January 24, 2017, 09:48:53 AM »
A1ex

Thanks for the clarification: I'll look into the wait tonight.

This could be where I'm going 'wrong'.

I had thought it meant 'true = use/wait until AF complete' or 'false = don't use/wait for AF'.

Cheers

Garry

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12241
  • Maintenance mode
Re: Lua API test
« Reply #5 on: January 24, 2017, 01:20:04 PM »
I had thought it meant 'true = use/wait until AF complete' or 'false = don't use/wait for AF'.

What should be fixed in the documentation or in the API (parameter naming) to avoid this confusion?

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1740
Re: Lua API test
« Reply #6 on: January 24, 2017, 01:53:38 PM »
@A1ex

From my perspective/experience I would say the Lua API documentation needs a bit of a (quick) scrub, eg:

- Giving a hint at what things (really) mean without the developers inside knowledge, ie a few words or sentence. For example, wait currently says "wait: (bool) (default true)"; but wait for what - I'm sure I was told it was wait for AF, but now I know I'm wrong. So, as an example, could be "wait: (bool) (default true) until current lens move related commands finish. Also a few words on why use false or true, ie the impact of using false and (maybe) the use case. I'm only talking about short sentences, not paras of text;
- Equally important in the Lua API documentation, say what isn't implemented yet, or where there are 'limitation'. For example, not all the Event.x stuff is implemented, but, unless you were a developer, you wouldn't know. I've tried to trawl back through the ML C code to better understand the Lua calls/functions etc, but I simply lose my way.

I think you know I wish to support Lua developments, but I think the first cut (then people like me can test/comment/review/add value) would be for the developers, or those with knowledge of the ML C connectivity, putting a few more things in the Lua API parameter area. The test should be, would a non-developer know what this does/means?

Having said this, I appreciate the developers have other 'pressing needs'. However, I would argue that Lua is a real (ML) star and should be one of our 'priorities' in implementing/enhancing/fixing. Scripting allows customisation beyond the core ML intrinsic capability. For example, my landscape auto exposure & focus bracketing, with diffraction corrected dof info and Dual ISO etc, means Canon (ML) users have a unique tool; that no other camera system has, even with add-ons like Promote Remote. I wish to develop this further, ie make more intelligent/robust, but before I do I wish to know more about some of the Lua calls and, maybe flag up 'missing' functions/calls.

Cheers

Garry

DeafEyeJedi

  • Hero Member
  • *****
  • Posts: 3171
  • 5D3 / M1 / 7D / 70D / SL1 / M2
Re: Lua API test
« Reply #7 on: January 24, 2017, 07:06:13 PM »
...However, I would argue that Lua is a real (ML) star and should be one of our 'priorities' in implementing/enhancing/fixing. Scripting allows customisation beyond the core ML intrinsic capability. For example, my landscape auto exposure & focus bracketing, with diffraction corrected dof info and Dual ISO etc, means Canon (ML) users have a unique tool; that no other camera system has, even with add-ons like Promote Remote. I wish to develop this further, ie make more intelligent/robust, but before I do I wish to know more about some of the Lua calls and, maybe flag up 'missing' functions/calls...

I'm with you on this one @garry23!
5D3.113 • 5D3.123 • EOSM.203 • 7D.203 • 70D.112 • 100D.101 • EOSM2.*

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12241
  • Maintenance mode
Re: Lua API test
« Reply #8 on: January 25, 2017, 01:34:20 AM »
A list with the items that are confusing in the documentation would be very helpful.

Unfortunately this is not something I use often, so it's not obvious to me what exactly is missing or not matching the reality.