Magic Lantern Forum

Using Magic Lantern => General Help Q&A => Topic started by: dbalex on January 17, 2016, 10:49:57 PM

Title: Custom HDR sequence?
Post by: dbalex on January 17, 2016, 10:49:57 PM
Hi guys,

Is it possible to use a custom HDR sequence? I would like to shoot the following sequence.

f/4, 1s
f/4, 1/4 s
f/4, 1/32 s
f/16, 1/16 s
f/16, 1/125 s
f/16, 1/1000 s
f/16, 1/8000 s

Is there a way to do that with Magic Lantern?

Thanks!
Title: Re: Custom HDR sequence?
Post by: dmilligan on January 18, 2016, 03:40:19 AM
Yes! (http://www.magiclantern.fm/forum/index.php?topic=14828)


menu.new
{
  name = "Run Bracket",
  select = function() task.create(run_bracket) end,
  depends_on = DEPENDS_ON.M_MODE,
}

local run_bracket = function()
  camera.aperture.value = 4.0
  camera.shutter.value = 1.0
  camera.shoot()
 
  camera.shutter.value = 1/4
  camera.shoot()
 
  camera.shutter.value = 1/32
  camera.shoot()
 
  camera.aperture.value = 16.0
  camera.shutter.value = 1/16
  camera.shoot()

  -- and so forth...
end
Title: Re: Custom HDR sequence?
Post by: dfort on January 18, 2016, 04:21:23 AM
That looks like a lua script. Cool!

@dbalex you might want to take a look at the Magic Lantern Lua API Documentation (http://davidmilligan.github.io/ml-lua/)
Title: Re: Custom HDR sequence?
Post by: dbalex on January 18, 2016, 11:49:13 AM
Great! I will look into lua scripts.
Can I make tests of scripts on my camera or do I risk something if the script has some errors?

Thanks!
Title: Re: Custom HDR sequence?
Post by: dmilligan on January 18, 2016, 04:02:22 PM
Errors should print to the console, and this is the most likely thing to happen if there is an error. You should get a description, filename, and line number, and also a stack trace if it's a runtime error. However, it's not impossible to crash the camera from a script (the scripting engine is pretty defensive and tries to prevent you from doing anything bad, but it's not absolutely perfect). If that happens, you just need to pull the battery and reinsert it.
Title: Re: Custom HDR sequence?
Post by: dbalex on January 19, 2016, 10:32:04 PM
Great thanks !  Will test it out this weekend when I have some time to understand how all this works :)
Title: Re: Custom HDR sequence?
Post by: dbalex on January 19, 2016, 10:57:06 PM
Ok I just made a little test but I must say I'm not really understanding everything here. Is there a tutorial somwhere that explains step by step how to use .lua scripts with magic lantern? I tried writing the code you wrote in notepad on my computer saved the file, changed the .txt in .lua and put it in ml/scripts folder but when I switch my camera on I don't really see anything different, can't find a new menu to trigger the script.

Can someone point me in the right direction?

Thanks!

Title: Re: Custom HDR sequence?
Post by: dmilligan on January 19, 2016, 11:24:50 PM
Did you load the lua module?
Title: Re: Custom HDR sequence?
Post by: dbalex on January 20, 2016, 06:26:18 PM
Euhm... No... I'm not sure but I looked in all the menus and can't find anything to load the modules. How do I load it? Is there a tutorial explaining all this somewhere that I've missed?
Sorry for all the questions but this is all new for me :)
Title: Re: Custom HDR sequence?
Post by: Walter Schulz on January 20, 2016, 07:00:59 PM
Click! (http://lmgtfy.com/?q=how+to+load+modules+magic+lantern)
Title: Re: Custom HDR sequence?
Post by: dbalex on January 20, 2016, 07:43:54 PM
Ok loading a module I already tried with the other modules, but in my list, I can't find the lua module or the script I put on my cf card.
Title: Re: Custom HDR sequence?
Post by: Walter Schulz on January 20, 2016, 07:49:50 PM
Cam type? If it is not a 600D or 1100D you may download latest nightly build and copy files over.
Title: Re: Custom HDR sequence?
Post by: dbalex on January 20, 2016, 07:58:09 PM
Yes thanks that was it, I have a too old build. I thought since it's only one month old it was ok, but it seems it was already outdated :)

Title: Re: Custom HDR sequence?
Post by: Walter Schulz on January 20, 2016, 08:04:29 PM
It's quite calm right now. Between 01.Jan.2014 and 31.Mar.2014 there were about 76 builds ...
Title: Re: Custom HDR sequence?
Post by: dbalex on January 20, 2016, 08:08:36 PM
haha quite calm I see :)

now I have the lua module but I get the error: When loading bad argument #1 to 'create' (function expected) stack traceback [c] in function 'ta_
any idea what this could be?
Title: Re: Custom HDR sequence?
Post by: axelcine on January 20, 2016, 10:50:59 PM
It is a very good idea to visit https://builds.magiclantern.fm/jenkins/ from time to time, and the updating process are a mere trivial 2 minutes, to keep your cam updated with the latest ML. LUA was introduced almost a year ago and provides an opportunity to actually program your cam more or less like if you were writing in Business Basic. As a tool LUA is extremely powerful and a Godsent. Canon's are just about the only cams, you can master this way.

http://www.magiclantern.fm/forum/index.php?topic=14828.0
Title: Re: Custom HDR sequence?
Post by: dmilligan on January 21, 2016, 01:01:54 AM
Quote from: dbalex on January 20, 2016, 08:08:36 PM
any idea what this could be?

My bad. Remove the local from the function definition


menu.new
{
  name = "Run Bracket",
  select = function() task.create(run_bracket) end,
  depends_on = DEPENDS_ON.M_MODE,
}

run_bracket = function()
  camera.aperture.value = 4.0
  camera.shutter.value = 1.0
  camera.shoot()
 
  camera.shutter.value = 1/4
  camera.shoot()
 
  camera.shutter.value = 1/32
  camera.shoot()
 
  camera.aperture.value = 16.0
  camera.shutter.value = 1/16
  camera.shoot()

  -- and so forth...
end
Title: Re: Custom HDR sequence?
Post by: dbalex on January 22, 2016, 06:38:42 PM
Awesome it runs now ! I will try now on my own to customize the script even more to my needs. But it's a great start, Thanks for the help !
Title: Re: Custom HDR sequence?
Post by: garry23 on January 23, 2016, 04:02:54 PM
@dbalex

I, like many I'm sure, would welcome you publishing your progress. In fact I would welcome anyone publishing their experience with lua, especially 'doing' image capture.

I'm not a programmer but I'm good at bootstraping off others :-)

My project is to write an auto bracketing script that covers the entire DoF.

Cheers

Garry
Title: Re: Custom HDR sequence?
Post by: axelcine on January 23, 2016, 08:01:29 PM
Wow! That'd do something for macro photographers - and in silent...?
Title: Re: Custom HDR sequence?
Post by: garry23 on January 23, 2016, 08:56:46 PM
@axelcine

Sorry, quite the opposite.

Macro bracketing is easy and already built into ML.

Macro bracketing is simply repeating a fixed lens refocus multiple times.

Landscape focus bracketing requires a little more programming :-)

Cheers

Garry

Title: Re: Custom HDR sequence?
Post by: axelcine on January 23, 2016, 09:01:41 PM
Yeah, well, of course you're quite right.

I love focus stacking, but it is still a setup with quite a handful of variables, but an auto way would be to script it, and I'm a hell of a lazy boy...! I also do landscape dof bracketing and it is more slow, yet simple. Just takes a lot of time and caution. Another area of auto via scripting. So: I'm still looking very much forward to see what comes out of this thread.
Title: Re: Custom HDR sequence?
Post by: dbalex on January 26, 2016, 08:01:08 PM
@Garry: I will if I make any progress, but I already tried some mods and can't seem to make them work. I don't really understand how to write the .lua code so I will need to dive into it before making any progress :)
Title: Re: Custom HDR sequence?
Post by: dbalex on January 28, 2016, 08:43:10 PM
Ok so now I'm trying to add a delay before the first picture. I think I'm doing it wrong because it tells me an error.
can someone tell me how I can interpret this ML LUA API? http://davidmilligan.github.io/ml-lua/modules/camera.html#shoot (http://davidmilligan.github.io/ml-lua/modules/camera.html#shoot)


I don't understand how I can translate those in .lua code. I read in the ML Lua API

"Functions

shoot ([wait=64[, should_af=true]])
Take a picture
Parameters:

wait int how long to wait for camera to be ready to take a picture (default 64)
should_af bool whether or not to use auto focus (default true)"




so I made a little change (in red) to the code written by dmilligan to try to add a delay (64=64 seconds?) and disable autofocus:

menu.new
{
  name = "Run Bracket",
  select = function() task.create(run_bracket) end,
  depends_on = DEPENDS_ON.M_MODE,
}

run_bracket = function()
  camera.aperture.value = 4.0
  camera.shutter.value = 1.0
  camera.shoot([wait=64[, should_af=false]])
 
  camera.shutter.value = 1/4
  camera.shoot()
 
  camera.shutter.value = 1/32
  camera.shoot()
 
  camera.aperture.value = 16.0
  camera.shutter.value = 1/16
  camera.shoot()

  camera.shutter.value = 1/125
  camera.shoot()

  camera.shutter.value = 1/1000
  camera.shoot()

  camera.shutter.value = 1/8000
  camera.shoot()

end


But this code doesn't work and tells me : error near [

Can someone tell me what's the problem or where I can learn this? I would really like to do this by myself but now I'm a bit stuck because I don't know how to translate the 'ML LUA API' to .lua code.

Thanks!
Title: Re: Custom HDR sequence?
Post by: Walter Schulz on January 28, 2016, 08:56:13 PM
shoot ([wait=64[, should_af=true]])

Brackets [] are used for optional arguments
Valid lines look like

shoot ()
shoot (wait=64)
shoot (wait=64, should_af=true)
Title: Re: Custom HDR sequence?
Post by: dmilligan on January 28, 2016, 09:04:28 PM
If you want to add a delay, just call msleep() (http://davidmilligan.github.io/ml-lua/modules/global.html#msleep) before calling camera.shoot(). The wait parameter to camera.shoot() means to wait no longer than this for the camera to be ready to shoot, but it will go ahead and take the picture as soon as the camera is ready.

Also, there's a bug with the should_af parameter. The fix should be available soon.
Title: Re: Custom HDR sequence?
Post by: dbalex on January 28, 2016, 10:32:50 PM
thanks msleep work like a charm, exactly what I needed. Now I understand a bit better, thanks guys! I added three beeps to tell me when the sequence starts :)

I just noticed now but it seems like the aperture settings is not correctly adjusted while running the sequence. At the 4th camera shot it's supposed to set it to f16 but it seems to set it to f22. Any idea why it's not adjusting to the correct aperture?

menu.new
{
  name = "Run Bracket",
  select = function() task.create(run_bracket) end,
  depends_on = DEPENDS_ON.M_MODE,
}

run_bracket = function()
  camera.aperture.value = 4.0
  camera.shutter.value = 1.0
  beep(3)
  msleep(6000)
  camera.shoot()
 
  camera.shutter.value = 1/4
  camera.shoot()
 
  camera.shutter.value = 1/32
  camera.shoot()
 
  camera.aperture.value = 16.0
  camera.shutter.value = 1/16
  camera.shoot()

  camera.shutter.value = 1/125
  camera.shoot()

  camera.shutter.value = 1/1000
  camera.shoot()

  camera.shutter.value = 1/8000
  camera.shoot()

end
Title: Re: Custom HDR sequence?
Post by: dmilligan on January 29, 2016, 01:11:33 AM
Yeah the conversion from f number to Canon raw units is wrong. I think I must have found it somewhere in ML code, then never tested it or sanity checked it. It's currently implemented as:
x * 8 + 8

The correct formula is:
log2(x) * 16 + 8
Title: Re: Custom HDR sequence?
Post by: dbalex on January 29, 2016, 10:48:32 AM
log2(16) * 16 + 8= 72, right ?  Because that's not working as well, a bit weird because f4 written as 4.0 works even if it's 40

Anything else that I'm missing?
Title: Re: Custom HDR sequence?
Post by: dmilligan on January 29, 2016, 01:26:59 PM
That formula is to convert it to a Canon raw value, so you'd need to use

camera.aperture.raw = 72


There will be a fix soon. There may also be a separate rounding issue (Canon firmware will only accept certain values).
Title: Re: Custom HDR sequence?
Post by: dbalex on January 29, 2016, 07:54:50 PM
Ok perfect, works great now! thanks for all the help!
Title: Re: Custom HDR sequence?
Post by: dbalex on December 05, 2016, 09:08:58 PM
Any news on a fix for this issue?
Title: Re: Custom HDR sequence?
Post by: a1ex on December 06, 2016, 11:01:50 PM
What issue?
Title: Re: Custom HDR sequence?
Post by: dmilligan on December 07, 2016, 06:02:42 PM
I'm pretty sure it was fixed in the first lua_fix that has already been merged (didn't check the commit history). That was a long time ago.
Title: Re: Custom HDR sequence?
Post by: adamfilip on June 01, 2019, 03:01:06 PM
This is awesome. didnt realize ML could do this.

If you dont specifiy the Aperture value and only set the Shutter duration.
will it use current camera settings if set in manual mode.. so if i have the camera set to F22 it will not change that i assume