Lua interpreter in openTx

openTx has introduced a range of new features, ideas and bling. It is fast becoming the firmware of choice for many users. openTx will run on ALL current hardware platforms, including the gruvin9x and sky9x boards. Work has already started to support the new FrSky X9D radio!
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Lua interpreter in openTx

Post by bertrand35 » Wed Jun 26, 2013 8:33 pm

I am thinking about a lua interpreter embedded in Taranis. Well there will be some work though...


User avatar
Rob Thomson
Site Admin
Posts: 4542
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: Antennatracking with opentx

Post by Rob Thomson » Wed Jun 26, 2013 9:01 pm

Interesting. You will make Tilman happy!

Sent from my GT-I9300 using Tapatalk 2
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!

User avatar
tilmanb
Posts: 347
Joined: Thu Oct 11, 2012 9:36 pm
Country: Germany
Location: Karlsruhe, Germany

Re: Antennatracking with opentx

Post by tilmanb » Wed Jun 26, 2013 9:13 pm

I was brainstorming the lua idea myself over the last few days.

Hell yea!
Should be quite easy. Except that lua needs malloc() or rather realloc()
I don't think we have that right now at all, right?
I have seen some malloc implementations that use a static byte array as a memory pool. Easy way out I guess.

The current lua version can yield in an out of lua via coroutines. That might be a good way of feeding data in and out...

Bertrand, we only use threads from that mini os right? Any plans of going to dynamic memory or so?
At least for auxiliary tasks.

User avatar
dvogonen
Posts: 453
Joined: Tue Jan 31, 2012 9:38 pm
Country: Sweden
Location: Stockholm

Re: Sv: Antennatracking with opentx

Post by dvogonen » Wed Jun 26, 2013 10:01 pm

Dynamic memory management + Hard Real Time Requirements + Small Processor => Doom and Destruction

Been there, done that. Several times actually

User avatar
tilmanb
Posts: 347
Joined: Thu Oct 11, 2012 9:36 pm
Country: Germany
Location: Karlsruhe, Germany

Re: Antennatracking with opentx

Post by tilmanb » Wed Jun 26, 2013 10:20 pm

I don't see the connection. It's already got tasks, which should take care of the real time aspect.
I would say dynamic memory is a reliability issue if not handled right. But not a timing issue.
As long as all that fancy scripted stuff can be easily preempted. I mean lua will be nowhere near real time, I just say garbage collection. :)


bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Antennatracking with opentx

Post by bertrand35 » Thu Jun 27, 2013 5:16 am

Yes we already have malloc on Taranis / sky9x. But only used in DEBUG mode (printf functions family).

User avatar
tilmanb
Posts: 347
Joined: Thu Oct 11, 2012 9:36 pm
Country: Germany
Location: Karlsruhe, Germany

Re: Antennatracking with opentx

Post by tilmanb » Thu Jun 27, 2013 7:33 am

Oh, I thought that was only used in the sim and on s PC host.
Cool, well then I see little problems.

bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Antennatracking with opentx

Post by bertrand35 » Thu Jun 27, 2013 8:01 am

Do you want to give a try at integrating lua before I go deeper in this topic?

User avatar
tilmanb
Posts: 347
Joined: Thu Oct 11, 2012 9:36 pm
Country: Germany
Location: Karlsruhe, Germany

Re: Antennatracking with opentx

Post by tilmanb » Thu Jun 27, 2013 2:02 pm

Well, I think I will do some more testing and brainstorming about it. But I don't manage my free time very well and I'm not very well focused on the problem.
I will try some out of opentx lua integrations first. And then we should perhaps think about how we integrate this and where we put hooks.
I will have a few questions I'm sure...

Generally, I would say, let's add another task for Lua or put it into the mixer task. I suppose we don't want to risk locking up the mixer task?

As for the lua api. I don't know yet. Passing data in and out can be done in different ways, and I don't grokk it quite yet.
But I suppose we could have a input and output coroutine which yields back into C. (Yield is a bit like a pipe. Python has a similar concept)
But maybe global variables would work better...

As like grand scheme goes and what to expose to lua and how to integrate it, I don't really know.
It will do mostly what mixes do right now. I don't want to replace mixes, but I would also like to bypass them in a way that is not confusing.
I would like to do something like writing in ex_chans[], but either it should be clear that channels that are being written to either have no mix, or it is integrated with that mix in a sane way.

End goal would be to have a lua script that has a setup script that presents the user with a setup screen and a functional part that runs in the background.
The setup screen should allow very high level template like configuration.
But there are basic questions to answer first of course...

bobosch
Posts: 10
Joined: Fri Jun 07, 2013 5:35 pm
Country: -

Re: Antennatracking with opentx

Post by bobosch » Thu Jun 27, 2013 6:51 pm

Do a stock 9x have enough memory for the lua interpreter?
thomas9x wrote:The calibration could be off-loaded to a PC app, but it would be more convenient if it was a Tx menu feature.
The calibration could be done in the MIXER menu (with Weight/Offset), if it is defined as a new Source.
And the "Set home" could be configured over a switch in the CUSTOM FUNCTIONS menu.
So no extra menu screen is needed.

User avatar
tilmanb
Posts: 347
Joined: Thu Oct 11, 2012 9:36 pm
Country: Germany
Location: Karlsruhe, Germany

Re: Antennatracking with opentx

Post by tilmanb » Thu Jun 27, 2013 6:55 pm

bobosch wrote:Do a stock 9x have enough memory for the lua interpreter?
No way.
Also lua integers are 16 bit AFAIK.

bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Antennatracking with opentx

Post by bertrand35 » Fri Jun 28, 2013 6:17 am

I have my first lua script working on Taranis :)

User avatar
tilmanb
Posts: 347
Joined: Thu Oct 11, 2012 9:36 pm
Country: Germany
Location: Karlsruhe, Germany

Re: Antennatracking with opentx

Post by tilmanb » Fri Jun 28, 2013 7:25 am

Oh wow. You are fast.

User avatar
Rob Thomson
Site Admin
Posts: 4542
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: Antennatracking with opentx

Post by Rob Thomson » Fri Jun 28, 2013 9:56 am

tilmanb wrote:Oh wow. You are fast.
You have no idea! Why do you think I don't code too much anymore.

Bertrand wipes my a$$ with speed and ability!

Sent from my GT-I9300 using Tapatalk 2
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!

User avatar
tilmanb
Posts: 347
Joined: Thu Oct 11, 2012 9:36 pm
Country: Germany
Location: Karlsruhe, Germany

Re: Antennatracking with opentx

Post by tilmanb » Fri Jun 28, 2013 7:36 pm

Rob Thomson wrote:
tilmanb wrote:Oh wow. You are fast.
You have no idea! Why do you think I don't code too much anymore.

Bertrand wipes my a$$ with speed and ability!

Sent from my GT-I9300 using Tapatalk 2
Seriously. I was thinking in the area weeks for this project.
Well Bertrand, I will contribute scripts and other improvements. I work quite will existing code. Getting something off the ground is always a drag, though I love doing it.

bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Antennatracking with opentx

Post by bertrand35 » Fri Jun 28, 2013 8:04 pm

I did something quick and dirty just to check that the concept will work. And it did. Now I will create a task with a low priority for the lua interpreter. It will fills some values in an array that will be accessible through the mixer (no lua scripts will run outside this task). The main thread of the program will check the duration of the lua routine. If too long, the task will be killed with an error displayed on screen.

It will not be the definitive solution, because I see these scripts as inputs to the mixer. So at the end of the day, the values coming from the lua interpreter will be accessible on the DR/Expos screen (which will be named INPUTS).

That's what I have in mind right now. I think I need a whole week to have something ready for beta testing.

Meanwhile don't hesitate to share your scripts so that we can discuss around them and see if the concept is ok!

Bertrand.

User avatar
thomas9x
Posts: 230
Joined: Wed Feb 29, 2012 3:12 am
Country: -
Location: USA

Re: Antennatracking with opentx

Post by thomas9x » Fri Jun 28, 2013 9:09 pm

That's what I have in mind right now. I think I need a whole week to have something ready for beta testing.
That is amazing!

- Thomas

User avatar
Kilrah
Posts: 10799
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua interpreter in openTx

Post by Kilrah » Fri Jun 28, 2013 9:31 pm

Thread split.

Yes, Bertrand is insanely efficient at integrating libraries, always impresses me!

User avatar
Rob Thomson
Site Admin
Posts: 4542
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: Lua interpreter in openTx

Post by Rob Thomson » Fri Jun 28, 2013 10:30 pm

Will the scripts just go in a folder on the sd card?

Sent from my GT-I9300 using Tapatalk 2
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!

User avatar
tilmanb
Posts: 347
Joined: Thu Oct 11, 2012 9:36 pm
Country: Germany
Location: Karlsruhe, Germany

Re: Lua interpreter in openTx

Post by tilmanb » Sat Jun 29, 2013 12:05 am

Eventually certainly.
On the topic of storage. I see a need for those lua scripts to store configuration data. (Lua data structures can be serialized, kind of like json)
That will have to go on SD in some smart way add well, as I can't really see that fit in the well structured model memory blocks.

bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 » Sat Jun 29, 2013 5:49 am

Rob Thomson wrote:Will the scripts just go in a folder on the sd card?

Sent from my GT-I9300 using Tapatalk 2
Right. SCRIPTS folder. You will choose one script per model, the same way you select a bitmap.

bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 » Sat Jun 29, 2013 5:52 am

tilmanb wrote:Eventually certainly.
On the topic of storage. I see a need for those lua scripts to store configuration data. (Lua data structures can be serialized, kind of like json)
That will have to go on SD in some smart way add well, as I can't really see that fit in the well structured model memory blocks.
Right! And no for the EEPROM, I won't give an access to EEPROM read/write from the interpreter, that's too dangerous.

User avatar
Kilrah
Posts: 10799
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua interpreter in openTx

Post by Kilrah » Sat Jun 29, 2013 7:00 am

bertrand35 wrote:Right. SCRIPTS folder. You will choose one script per model, the same way you select a bitmap.
That's where I would see my dedicated page:
http://openrcforums.com/forum/viewtopic ... 176#p45056

The goal being to allow using several different scripts you have downloaded on the same model without having to modify / merge them, as well as also providing a way to map the script's input/outputs without editing the script (which you can't do on the radio, remember!), and adjusting script settings. For example the example antenna tracking script will require telling it in which direction you've oriented your antenna mount, which may need to be different for every flight.

User avatar
algo
Posts: 117
Joined: Sun Sep 02, 2012 3:11 pm
Country: -

Re: Lua interpreter in openTx

Post by algo » Tue Jul 02, 2013 2:08 pm

I hope you considered LuaJIT instead of vanilla Lua. It's like Lua but better, a lot better. For many things like math algorithms and such it's as fast as compiled C code and it has one of the best the FFI libraries I have ever seen for accessing the native code systems. It runs on arm processors although I don't know about the one used on the Taranis specifically.

Or maybe that is what you are already using. :) I think not since you said "interpreter" though.

In fact I have been considering the possibility of developing an entire Taranis firmware based on LuaJIT.

bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 » Mon Jul 08, 2013 1:13 pm

I will have a look to it once the first (simple) integration is done.

User avatar
algo
Posts: 117
Joined: Sun Sep 02, 2012 3:11 pm
Country: -

Re: Lua interpreter in openTx

Post by algo » Mon Jul 08, 2013 1:42 pm

Just be aware there are some differences in the API between Lua 5.2 and LuaJIT because LuaJIT is more like Lua 5.1 (although it does have some 5.2 features). This could make "upgrading" to LuaJIT more difficult if you are using Lua 5.2.

bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 » Wed Jul 17, 2013 7:29 am

LUA interpreter is now in openTX in the branches/lua branch! You have to compile with LUA=YES. With a variable number of inputs / outputs.
I will provide some examples later today.

User avatar
Rob Thomson
Site Admin
Posts: 4542
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: Lua interpreter in openTx

Post by Rob Thomson » Wed Jul 17, 2013 9:54 am

Wow! Quite keen to see how this will work!

Sent from my GT-I9300 using Tapatalk 2
Slope Soaring, FPV, and pretty much anything 'high tech'
...........if you think it should be in the wiki.. ask me for wiki access, then go add it!

ReSt
Posts: 1556
Joined: Tue Dec 27, 2011 11:34 pm
Country: -

Re: Lua interpreter in openTx

Post by ReSt » Wed Jul 17, 2013 10:16 am

Will this also work on the standard board with a M128 ?

Reinhard

bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 » Wed Jul 17, 2013 3:23 pm

No! It needs more vitamines.


Post Reply

Return to “openTx”