Lua Scripting (lua.mo)

Started by dmilligan, March 29, 2015, 04:44:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dmilligan

A. There's currently no way to do this.

2. Hint: If a script doesn't load, check the console for errors. (I might also suggest a script editor that does syntax checking, such as: http://www.eclipse.org/ldt )

surami

@dmilligan: Could you please help me out, that how could I update the Force Delay script for working well with the updated LUA module?

550D + nightly ML

dmilligan

Ah, yes, I changed the event API slightly:


force_delay_menu = menu.new
{
parent = "Intervalometer",
name = "Force Delay",
help = "Add an extra delay to each interval",
min = 0,
max = 300,
unit = UNIT.TIME,
}

event.intervalometer = function(count) msleep(force_delay_menu.value * 1000) return true end



surami

Thanks, I will try as soon as I can compile a new build from the LUA repository.
550D + nightly ML

dmilligan

Just an update:

The API is really coming together, and is more or less complete and working. So I've started working on an in camera text editor written in lua: https://bitbucket.org/hudson/magic-lantern/commits/9c47101480ce7a1e64152a40666c3373d37c8e87 It's very preliminary at this point, you can select files and view them, but it shouldn't be too much longer until it's a fully functioning editor with the ability to insert text and save files. Thanks to lua's regex like capabilities, cool things like syntax coloring and basic auto-complete shouldn't be too hard either, and with lua's built-in debugging capabilities, things like setting breakpoints, stepping through code and an "immediate console" are also possibilities.

Audionut

In camera editing with some stupidity debugging sounds great.

Looking forward to trying this out.

nikfreak

you have been definitely been on a run getting LUA to work on ML. Chapeau! Checking how chdk people use lua for scripting this will definitely help lots of people.
[size=8pt]70D.112 & 100D.101[/size]

DeafEyeJedi

5D3.113 | 5D3.123 | EOSM.203 | 7D.203 | 70D.112 | 100D.101 | EOSM2.* | 50D.109

EBurke

I am new to ML and have little background in Lua. I am excited that I am going to learn both soon.

I have installed ML on a 5D2 camera through standard build. Reading the posts here I assume I have to replace it with a Lua compatible build. Is there a link to an already existing build or I must build it from the source, is it sufficient to try and build lua branch?

dmilligan

@EBurke,
correct, see the OP




Updates:

Yesterday, I managed to write a script and then debug/step through it entirely in camera! (and all of this from a program that is itself just a lua script!) This is very cool and exciting (and quite meta!), there are many possibilities...


garry23

@dmilligan

As you say, this is really exciting.

Like others, I'm sure, I'm waiting for the sign (from the coders/gurus above) that things are stable enough to begin 'playing'.

Thanks for all your efforts (and those others that are adding value here).

:)


g3gg0

@dmilligan:

do you need some changes to IME for integrating it into your editor?
Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

dmilligan

no, I think I prefer just doing my own input in lua, I already have stuff like copy and paste, and I'll probably be working on things like autocomplete. Eventually a lot of the code from the editor could become a high-level, object-oriented UI API for lua.

dmilligan

Updates:

Most floating point stuff seems to be working now (previously, parsing and printing floats would crash the interpreter due to some non-standards-compliant libc functions).

Keep in mind that doing floating point math can be quite slow. Fortunately for us, new in lua 5.3 is a lot of stuff for doing integer only math. For example // will do integer division (a normal single / will automatically promote to floating point).

I have improved the API for basic exposure settings with various units (some floating point, some integer).
So now instead of camera.shutter you have the following:

camera.shutter.raw
camera.shutter.apex
camera.shutter.apexf
camera.shutter.ms
camera.shutter.value
camera.shutter:tostring()

aperture, iso, and ec also follow the same basic pattern. See the updated docs for more info.

DeafEyeJedi

All this is looking positive so far... Keep up the great work everyone!
5D3.113 | 5D3.123 | EOSM.203 | 7D.203 | 70D.112 | 100D.101 | EOSM2.* | 50D.109

Totte

How is the program control in modules in general and in this LUA implementation in particular? Is the LUA script in full control when it is running or are there system tasks that can mess up the timing of simple LUA while loops and/or timer interrupts? I can see this replacing the advanced intervalometer module completely for my kind of use, if timing can be trusted.

chris_overseas

There's a minor bug in the docs I think: The docs for ec.raw and ec.apex both refer to aperture rather than exposure compensation.

This module is looking impressive dmilligan, I'm looking forward to trying it out properly.
EOS R5 1.1.0 | Canon 16-35mm f4.0L | Tamron SP 24-70mm f/2.8 Di VC USD G2 | Canon 70-200mm f2.8L IS II | Canon 100-400mm f4.5-5.6L II | Canon 800mm f5.6L | Canon 100mm f2.8L macro | Sigma 14mm f/1.8 DG HSM Art | Yongnuo YN600EX-RT II

pholler

Hi David,

i am still working on my intervalometer-script. At the moment i want to manipulate the shutter speed that is determined by AETTR. The idea is that small changes in shutter speed are ignored.
The thing is that i cannot manage to do operations directly after a shooting-task. The following code is not started after pressing the shutter or using the intervalometer. I don't know why. Could you give me hint?
function event.post_shoot()
print("post_shoot()")
end

dmilligan

@chris_overseas,
yes, thanks, there are probably lots of typos in the docs (lots of copy/pasting). Every time I go back and read them it seems I find another typo.

@pholler,
it appears that cbr (as well as pre_shoot) is not actually implemented in the ML core, it's a simple fix, I will probably submit a patch to the main branch

@Totte,
It would certainly be possible to to implement the advanced intervalometer as script (in fact that was one of my goals when working on the API: what would I need to completely re-implement it in lua). Actually doing the re-implementation may take some time (it's sort of a low priority, but it's a good test case for the lua engine). Unless you're doing some really heavy processing (i.e. image analysis), I don't think "timing" is going to be an issue. Lua performance is actually pretty good. The text editor I wrote in lua does a lot of drawing and it works pretty smoothly.

Totte

Just to clarify, I'm not asking for a re-implementation of the advanced intervalometer in LUA just because it can be done (although that is usually reason good enough ;)). For me, writing a script will be much simpler than to generate a complex exposure sequence in the AI. And the scripts can also easily be saved and loaded again from the camera.

I'm looking at taking pictures with sub-second timing resolution. What worries me is whether the length of while-loops or msleep(ms) could possibly be unpredictable because other system tasks have priority when scripts are running? No processing involved for me, just set new exposure values, wait and fire again.

dmilligan

For simple things, I doubt you would be able to notice much difference between doing something in lua or doing it in native C. Also, most of the time spent for simple stuff is likely going to be in the API call itself, not your script code. You also have access to the vast majority of the ML core API calls, and if there's something in particular you need that's missing, it's pretty easy to add.

I see no reason you couldn't achieve pretty accurate timing in a script, but depending on exactly how precise you want it to be, it may be more a little more complicated than simply calling msleep in a while loop (which is what it sounds like you are asking). The issue there wouldn't really be the fact that it's a script, but simply the naïve approach to timing. However, the timing should be halfway decent even with a naïve approach like this, you're just probably going to see "drift" over time. More robust scenarios are certainly possible, and creating simple constructs for them in the API is also a possibility.

Alternatively, you can piggyback the existing ML intervalometer and modify it's behavior, or you have event.seconds_clock cbr, or you also have access to a milliseconds clock.

pholler

Hi David,

i read all your docu and alle the menu-samples but i still can't get the following thing working. I want a menu whos parent is "Intervalometer". When you press that menu it activates or deactivates the function. In the submenu i need decimal values to choose the minimal interval and to choose the minimal processing time between two shots. This can either be a decimal number or a time value. I tried it several times but i fail implementing such a menu structure. Could you give me a sample how to do that?

Best regards

Peter

dmilligan

It's not possible for items in a submenu to exhibit this behavior. Submenus can have submenus but if they do, they can't toggle their own values too (because SET goes into the submenu and Q goes back out). You have to make a submenu item for enabling/disabling the feature.


mymenu = menu.new
{
    parent = "Intervalometer",
    name = "Whatever",
    update = function(self) return self.submenu["Enabled"].value end
    submenu =
    {
        {
            name = "Enabled",
            choices = {"Off","On"},
        },
        {
             name = "Dec. Value",
             min = 0, max = 500,
             unit = UNIT.DEC,
         },
        {
             name = "Time Value",
             min = 0, max = 500,
             unit = UNIT.TIME,
         }
    }
}

pholler

Thanx david! With your input i just finished my intervalometer-script:
http://www.magiclantern.fm/forum/index.php?topic=15119.0

garry23

@dmilligan

Can you point me to the source where you code the various Lua functions and fields.

I tried looking in your bitbucket link but could find the source.

I'm trying to educate myself as to how you created the Lua to ML links, eg lens control.

Cheers