set a button to a focus distance (for hyperfocal scenaris)

Started by knoodrake, October 28, 2016, 09:59:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

knoodrake

Hello all.  :)

Ability to register AF focus distances and set them to buttons. ..is what I need.

The goal is quite simple: having a quick way to switch to an acceptable "hyperfocal" focus distance for that lens/aperture/..

I have a 5dIII. This is not a feature request since I need it quickly ( in 20 days ) but couple of question:


  • Is that doable ? I mean, by starting with something simple, like juste focus to something, register it somehow, and then set that focus distance to a button.
    Maybe later add some nice stuff like embeded DoF calculation regarding to lens, aperture, ...  But to keep it simple, it is at least doable ? 
  • Do you think it is doable by someone who never touched ML development that quickly ? and where to start ? ( I mean, I am a java dev at work, so I can find my way arround languages I don't know yet but I won't be efficient ) 
  • Again, please, where to start ? I just noticed this post http://www.magiclantern.fm/forum/index.php?topic=7189.0 and maybe I can grab a few hints in this code
  • does writing new modules require to recompile ML ?

Thanks for any tips or directions !

Sorry if I miss obvious posts that already answered my questions. I gave a look in the forum but didn't find.


a1ex

1. Yes; I prefer hooking it to a menu (many buttons can be model-dependent, so it's harder to make it portable that way)
2. I'd say it's best to start with a Lua script; the DOF and focus APIs are present.
3. See also http://www.magiclantern.fm/forum/index.php?topic=4997 ; the module you linked should be converted to a script IMO.
4. As long as you don't require changes to core features, no.

knoodrake

Thanks a lot a1ex, I will look into all that :)
( and I completely forgot the support for lua scripts !  )

( by the way, also thank you for everything else you do arround here / ML  :) )

garry23

@knoodrake

You may be interested in looking at my humble attempts at using Lua to access lens control, including DoF positioning: http://photography.grayheron.net and https://gist.github.com/pigeonhill/e008f051681885bc6ff84de637cb1d8e

Also others are making progress to control lens positioning to a specified point, rather than my approach of just stopping the lens motor when a position is reached.

Cheers

Garry

knoodrake

Thank you very much garry.

Right now, I made my very first baby steps: updating ML to a new nighly that have lua scripting: Done.

And now I'm struggling to understand anything  :'(
First, I don't know lua. Maybe I should look at some tutos first.. But That's not my biggest problem.

Mostly, I don't yet get how the whole thing works. Don't understand when the console is supposed to be shown (I saw it some time)
I tried to debug and set some breakpoint (those red marks on the left are breakpoints right ?) from within the lua text editor, but.. no. nope. I don't understand anything :) I just am under the impression that I do some writting in (main) loop in the console, console that I cannot even get how to see !


My first goal was to do a hello world while showing lens infos instead of hello ( lens.focal_length for instance ).

I'm also struggling between coding stuff on computer, then popping the CF out and in the camera, and that is tedious, and trying to do some stuff with the build-in lua editor but I struggle to remember the buttons/shortcuts.

Since I'm only trying for less than an hour, I'm not yet desperate, but I would love to be able to at least grab a sense of the whole workflow, and be able to do my hello world :)

I'm used to code on java, so, all is nice, JVM, easy debug, easy IDE, everything documented, and here, I feel like I'm in the jungle, trying to find infos in various forum posts dating from 2015 I don't know if up to date, ...

If you please, have any insight for me to "kickstart" the whole stuff about making a module or a lua script. Please share :)


Anyway, thank you for your link, I'll get a look and maybe that'll help me understand some stuff.

garry23

I'm more than happy to help, but first have you read through these postings: http://www.magiclantern.fm/forum/index.php?topic=14828.0

I was in a similar position to you a short while ago :-)

Cheers

Garry

garry23

@knoodrake

After you have scanned the postings, you may wish to read through this: https://www.lua.org/manual/5.1/

As to taking the card in and out, I also have to live with this approach :-(

However, one help is to use this App: https://studio.zerobrane.com/

I also use this text editor: https://notepad-plus-plus.org/

As for your need, my coding could get you started, ie you could adapt from there. But remember we can't command the lens to move to a specific position, not yet, although others are working on this. Thus my approach is to twist the lens to, say, the macro end and move the lens until the HFD position is satisfied.

Bottom line: Lua is a great way to get started with extending ML.

Cheers

Garry

garry23

@knoodrake

As I had a few minutes today I hacked out a demo script for your use case.

I tested it on my 5D3 and a 24-105 F4/L.

Lens must report focus distance and be in AF. You must also be in LV.

Ensure DoF set up, ie diffraction on.

Note, until we are able to position the lens to a stated position (some are working this), this iterative approach is the best you can do. aving said that you may be able to optimize the move algorithm, ie I simply used single steps.

See what you think and experiment and report your findings :-)

--[[
Still photography HFD script
Version 0.1 (should work on all ML enabled cameras with the Lua module)
Garry George Oct 2016
http://photography.grayheron.net/
Must be in LV and lens must report distance
--]]

-- Declare globals

hfd = KEY.RATE

-- Change HFD value to your choice of button, eg KEY.RATE, KEY.UP, KEY.INFO or KEY.PLAY.
-- See http://davidmilligan.github.io/ml-lua/modules/constants.html for key constants
-- Default is KEY.RATE

function move()
if lens.focus_distance < lens.hyperfocal then
repeat
lens.focus(-1,1,false)
until lens.focus_distance >= lens.hyperfocal
else
repeat
lens.focus(1,1,false)
until lens.focus_distance <= lens.hyperfocal
repeat -- ensures lens is positioned with a bias towards INF
lens.focus(-1,1,false)
until lens.focus_distance >= lens.hyperfocal
end
end

event.keypress = function(key)
if keymenu.submenu["Turn On/Off"].value == "Off" then
return true -- key works as normal
elseif key == hfd and  lv.enabled -- user asking for a hfd move
then
move()
return false -- steal the button push
end
end


keymenu = 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"},
}
}
}

knoodrake

@garry23 Awesome !
Thank you very much for the huge help.

Many things I didn't know like

  • Lens must report focus distance: seems obvious, but I thought most lenses did.
  • Must be in LV
  • we can't command the lens to move to a specific position

Anyway, I'll dig into the links you provided me.
Meanwhile, I tried you script, and it's awesome because:

  • It seems to work just fine !
  • I can understand it waay more easily than others since I know exactly what it does ! It's perfect

That's a very very helpfull starting (and already working) point, thanks again.

One last question thou, I don't get where does the API's lens.hyperfocal value comes from ?
since it depends on many factors, does that mean that ML already actually does the maths for me (CoC, current aperture, ..) ?

( BTW, the lens I'm using it with is a new Tamron 15-30 2.8 vc.  )
( BTW2, np++ is already my everyday text editor when not bothering with an IDE :) )

knoodrake

Quoteyou may be able to optimize the move algorithm, ie I simply used single steps.
Good point. And I'm sure I can start by borrowing ideas from sorting algorithms for instance  :)

garry23

@knoodrale

Yes ML has the difraction correction built in, in fact I helped put the code in, see http://photography.grayheron.net/2015/04/customising-magic-lantern.html

Look under focus menu.

Cheers

Garry

knoodrake

Thanks @garry23,
I was also just about to post that I found DoF calculation code http://a1ex.bitbucket.io/ML/5D/lens_8c_source.html#l00132
And I'm slowly getting a general sense of what ML does and does not :)

knoodrake

Random (but kinda related) thought :

Could it be interesting/possible (probably possible at least) to estimate the SNR and correlate that to the CoC ?

What I mean is, the detail resolution in the final image is also heavily dependant on the noise. So let's say I'm at 12k ISO, is that still relevant to compute the DoF with the real CoC since anyway, the details won't be there. So couln't it be interesting to "adapt"  the maths with a fake, larger CoC than the real one when in high iso ?
That may be of little use for landscape photographers and crip D810 images, but when shooting in low light, 6400 ISO, I am not sure the blur will be visible as it would be in base iso.

Is that a stupid Idea ? And was that understandable ? (I struggle expressing myself in english sometimes :) )

knoodrake

Please excuse me for the many posts, do you know if there is any way to know/test/log/whatever the length of an AF step ?
After some reading, I learned that those steps vary greatly from one lens to another.

So Can I "measure" (or find) that length for my lens ?

And Is there ways trough lua scripting to store that info associated with my lens ID/model other than doing dirty stuff with writing in some files ?

garry23

@knoodrake

I don't think SNR and DoF are linked in any real sense.

One thing you soon learn on the ML forum is patience :-)

Have a read of the ground breaking work going on here: http://www.magiclantern.fm/forum/index.php?topic=4997.msg171205#msg171205

Cheers

Garry

dmilligan

Quote from: knoodrake on October 30, 2016, 08:48:54 PM
And Is there ways trough lua scripting to store that info associated with my lens ID/model other than doing dirty stuff with writing in some files ?
The only way to store data is in files, but there's a nice wrapper for you: http://davidmilligan.github.io/ml-lua/modules/config.html

knoodrake

@garry23
QuoteHave a read of the ground breaking work going on here: http://www.magiclantern.fm/forum/index.php?topic=4997.msg171205#msg171205
Yes, I have read this thoughtfully, and I do not understand yet very well the whole things with the lenses motors/steps but yes, and it looks very interesting and very promising ! Also still slowly learning the precise meaning of some of the domain-specific vocabulary used there !

QuoteI don't think SNR and DoF are linked in any real sense.
not directly, absolutely, I just meant that at the end, in the final picture, if the image is very very noisy, you won't be able to separate details, whether or not it should be optically acceptably sharp.
My thinking was that when relating to hyperfocal, if you can loose 5cm on the near end while going from 40m to infinity, and not being able to actually measure a difference in details in thoses 5cm, well, that can be usefull.

Not sure I made myself understandable :) ..Also, I may be completly wrong. But in such case I don't know where !

@dmilligan
Quotebut there's a nice wrapper for you
thank you ! perfect ! As long as the I/O part is abstracted, there is no problem using files from my side as user of the API !

knoodrake

Hello,

I tried to auto switch LV on before running the move() function and then auto switch it back to off (if it wasn't  already on) but I cannot..

basically, I check if lv.enabled, if not I lv.start().
My problem is that I cannot find a way to properly wait for LV to be really started before calling move().
For instance, if I do
lv.start()
lv.wait(1)

The console clearly tells me that the lv.wait fails because lv is stopped.

I tried the msleep way (with a repeat loop, and even with just a huge value of 10s) but msleep apparently blocks the execution of the lv.start().

I searched the API doc, looking for something like an "LV ready" event, but couldn't find.

Any hints ?  :o

Thanks.

EDIT: Please correct me if I'm wrong, but in the lua script, I'm single threaded, but the calls to ML/Canon API are asynchronous. I got this right ?

a1ex

lv_start() should return when LiveView is up and running (it already includes a msleep, but no closed-loop confirmation).

Have a minimal example that I could debug?

knoodrake


event.keypress = function(key)
if key == KEY.RATE then
   if not lv.enabled then
lv.start()
lv.wait(1)
  end
return false
end
end



and

http://imgur.com/a/e0E64

I did something wrong ?
Need more code/infos ?

garry23

@knoodrake

I looked into your lv.start strangeness, and I have it as well :-(

Here is my demo code snippet, used with LV off.

lv.start()
repeat
msleep(200)
until lv.enabled
move() -- to HFD position
lv.stop()


The camera freezes and I need to remove the battery.

knoodrake

@garry23

yep, I also had many strange behavior like the camera freeze or, semi-freeze (like I can still AF for instance) or other strange buggy behaviors, depending on how I tried things with code. But it was too hard to remember the steps to reproduce, and the exact camera behavior.

garry23

I wonder if the problem is related to it being called inside event.keypress call?

I'm sure A1ex or David will give us guidance.

Cheers

Garry

knoodrake

I remember however having tried to do something like you have

lv.start()
repeat
  msleep(200)
  until lv.enabled


but with the "fail-safe" counter ( something like )


local slept = 0
local threeshold = 3000
lv.start()
repeat
  slept = slept + 200
  msleep(200)
  until lv.enabled or slept >= threeshold


and the loop just stopped at he 3s threeshold without further bugs. Camera would work normaly after that (except the issue we'r discussing).
So it's just that lv.enabled was never updated or lv.start() did not start.


knoodrake

@garry23

maybe something to do with this sentence I read on the lua event api doc https://davidmilligan.github.io/ml-lua/modules/event.html
QuoteEvent handlers will not run if there's already a script or another event handler actively executing at the same time.
?

But yes, I hope A1ex or David will give us guidance.