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 »

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

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

Re: Antennatracking with opentx

Post by Rob Thomson »

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 »

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 »

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 »

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 »

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 »

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 »

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 »

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 »

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 »

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 »

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 »

Oh wow. You are fast.
User avatar
Rob Thomson
Site Admin
Posts: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: Antennatracking with opentx

Post by Rob Thomson »

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 »

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 »

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 »

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: 11108
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua interpreter in openTx

Post by Kilrah »

Thread split.

Yes, Bertrand is insanely efficient at integrating libraries, always impresses me!
User avatar
Rob Thomson
Site Admin
Posts: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: Lua interpreter in openTx

Post by Rob Thomson »

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 »

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 »

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 »

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: 11108
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua interpreter in openTx

Post by Kilrah »

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 »

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 »

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 »

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 »

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: 4543
Joined: Tue Dec 27, 2011 11:34 am
Country: United Kingdom
Location: Albury, Guildford
Contact:

Re: Lua interpreter in openTx

Post by Rob Thomson »

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: 1581
Joined: Tue Dec 27, 2011 11:34 pm
Country: -

Re: Lua interpreter in openTx

Post by ReSt »

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 »

No! It needs more vitamines.

Post Reply

Return to “openTx”