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!
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua interpreter in openTx

Post by Kilrah »

It currently looks like it may not even be for sky9x unless someone wants to start playing hide and seek with flash bytes again...

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

Re: Lua interpreter in openTx

Post by bertrand35 »

@Rob: would you allow .lua scripts to be attached on the forum?
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 »

Example of use of LUA for a delta mix ...

The script:
delta.lua
(650 Bytes) Downloaded 468 times
snapshot_01.png
snapshot_01.png (2.04 KiB) Viewed 15098 times
snapshot_03.png
snapshot_03.png (1.41 KiB) Viewed 15098 times
snapshot_02.png
snapshot_02.png (1.69 KiB) Viewed 15098 times
(it's only an example, not to be used for flying, a delta mix should not use LUA ...)

Bertrand.
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 »

bertrand35 wrote:@Rob: would you allow .lua scripts to be attached on the forum?
Done
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!
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 »

For those who want to test, you have to checkout the "branches/lua" branch

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 »

Question - before I flash.

Will it automatically upgrade my epprom?

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!
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 »

No. This is an unstable branch. EEPROM will change again before going to trunk.
fireball
Posts: 39
Joined: Wed Dec 28, 2011 11:49 am
Country: -

Re: Lua interpreter in openTx

Post by fireball »

This is awesome and really great to hear.

May I throw in some ideas for LUA functions?

* write access to telemetry screen
* read/write access to s.port data stream

With those 2, it shold be very easy to implement own telemetry functions. If it would be possible to add some kind of virtual screen, any additional data would be possible to transfer and display.

Any thoughts? :)


Best regards,
Marcus
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 »

So, how do those scripts work? I think I'm still missing some magic here.
How do they know what input and output and run functions are? Who calls them and when?
Where is getSourceValue() defined?

And I see awesomness in the input values. Can they be non-numeric though? (drop down to select tail type for example)
And can they be dynamic? (Like only ask for v-tail ratios if v-tail is selected.)

And, I can't find the code in the repo. There is lua stuff, but nothing in opentx.cpp.
My SVN is a bit rusty, svn update not enough to get that stuff?

Thanks bertrand35, I owe you a few beers. Or for you frogeaters that is whine, fine with me. :)
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 »

SVN I curse you!
svn checkout http://opentx.googlecode.com/svn/branches/lua opentx-read-only

Time to read up on the SVN git bridge before I go bugnutty :)
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 »

Ah, scriptnameInputs, scriptnameOutputs and scriptnameRun
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 »

And I just had a look at the VALUES. It's numbers only.

I think for total world domination, two things are important.
A Setup function that can draw user input forms to ask more complex information. (Wizard driven, graphical, whatever) - Which is hard to do portable, and lua code would have to draw the menues which is perhaps overkill even if the base menu functions are used.
Or a input values definition that knows unions and ideally conditions. (Example, only ask for V-tail ratio when tail type v-tail is selected)

And secondly of course a persistent settings store. Serialising lua tables is quite easy. And more easy with added conditions like no hierarchy of tables and no function type values.
This settings store could be loaded in the global environment or so before the script is run.
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 »

Am I doing anything wrong?
make simu PCB=TARANIS LUA=YES

I get no Scripts menu in the simulator.
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 »

PS: Addendum to my remarks about my 'one to rule them all' script idea.
I guess once I get that out of my head, we would be quite well served by having individual little scripts for certain functional parts. Like Delta Mix, V-Tail Mix, 4-servo Wing. Those individual bits would not have to be as dynamic setup wise as only the used components would be used.
Some plumbing will be required to put them together though. But that does not sound too scary.
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 »

This pictures on this post:


http://openrcforums.com/forum/viewtopic ... 127#p56127

Really show how it could be used.

I imagine it would be possible go define a type of model, but probably more flexible to have separate functions.

Now... One for Bertrand.

How do these in interact with flight phases?

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 »

fireball wrote: * write access to telemetry screen
Probably not intended to be dynamic yet, but sure not a bad idea.
fireball wrote: * read/write access to s.port data stream
Well a few access methods for telemetry values already exist.
Someone needs to do some time copying and pasting to implement them all.
That is not access to the data stream. But defined values can be read.
archer183
Posts: 97
Joined: Mon Oct 08, 2012 4:31 am
Country: -

Re: Lua interpreter in openTx

Post by archer183 »

So pardon the dumb question, as I am trying to wrap my head around what this enables.

am I correct in seeing the ability to basically write a mix (for example) that takes in any number of inputs, does some math on it, and returns 1 or more outputs?

As an aside, if that is the case, would trig & root functions either be supported or lookup tables in the script?

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

Re: Lua interpreter in openTx

Post by Kilrah »

You'll be able to create functions with as many inputs and outputs as you want, and use all the library functions you'll find in the lua documentation :)

Sent via mobile
archer183
Posts: 97
Joined: Mon Oct 08, 2012 4:31 am
Country: -

Re: Lua interpreter in openTx

Post by archer183 »

interesting, is that the lua.org lua?
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Lua interpreter in openTx

Post by jhsa »

so, what real use could we do with this in real RC model world apart from launching missiles and send satellites to orbit?? ;) :)

Why would I want to have this on my radio?

Thanks,

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
rdeanchurch
Posts: 750
Joined: Tue Dec 27, 2011 11:22 pm
Country: United States
Location: Carson City, Nv

Re: Lua interpreter in openTx

Post by rdeanchurch »

Yes please. I'm sorry to ask but I need a bit of guidance on this, even more than Joao....I can't even figure out how to use my missile to shoot down Joao's satellites!

Well on second thought, he probably has a Lua script protective screen around them. Drat, maybe I can dredge up a Perl script to kill it.
Dean
OldDmbThms: 1. Takeoff, 2. Crash, 3. Repair, GOTO 1
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Lua interpreter in openTx

Post by jhsa »

You would have to find them first.. :mrgreen:
I give you a little clue.. they are all around Lua ;) :mrgreen:
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
fireball
Posts: 39
Joined: Wed Dec 28, 2011 11:49 am
Country: -

Re: AW: Lua interpreter in openTx

Post by fireball »

Since I didn't try out the Lua branch yet: is it possible to start a script by Custom Switch?
archer183
Posts: 97
Joined: Mon Oct 08, 2012 4:31 am
Country: -

Re: Lua interpreter in openTx

Post by archer183 »

here is how I hope to use it. My toy of choice is RC battleships. for years I have wanted to implement the following

TX input sticks specify range and bearing to target.
software in TX does the proper coordinate transform for each turret based on its position relative to ship 0,0
curve fit the output of that to take care of mechanical differences/details to ensure each turret points to the correct position (both bearing and range)

currently I have a modified version of opentx running on my 9x (works very well, no noticable speed impact, requried adding integer sine/cosine/arcsine/arccos and using the sweet square root function already in opentx) . this works for 2 turrets (1 master 1 slave) and was simplified greatly by normalizing off the turret spacing distance... I plan to move to a taranis soon as it opens up so many possibilities. I was planning to add the code needed for more to the firmware but if I can script it instead and not have to compile anything (and more readily share with others) that is even better

I will have to download this branch and figure out how to play with the scripts in simu. Now I get to learn another language variant, yay :)


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

Re: Lua interpreter in openTx

Post by Kilrah »

fireball wrote:Since I didn't try out the Lua branch yet: is it possible to start a script by Custom Switch?
Scripts run continously, on each cycle. Script outputs are however mapped to channels via usual mixer lines, to which you can of course assign a switch to activate or not.

Sent via mobile
WendoNZ
Posts: 50
Joined: Fri Dec 21, 2012 4:00 am
Country: -

Re: Lua interpreter in openTx

Post by WendoNZ »

Random question. Would this allow the imperial units compile option to be obseleted on platforms that support LUA? Would a simple LUA script be simpler to convert units? it would also mean for vario's (for example) that don't provide an imperial output the LUA script could do the conversion
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua interpreter in openTx

Post by Kilrah »

There is already no more compile option on those platforms, just a choice in the radio settings.
User avatar
algo
Posts: 117
Joined: Sun Sep 02, 2012 3:11 pm
Country: -

Re: Lua interpreter in openTx

Post by algo »

How does the Lua branch code differ from trunk?

I was just comparing the two and there are significant differences besides just the Lua changes.
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua interpreter in openTx

Post by bertrand35 »

It will be a MAJOR release, with many differences:
- LUA interpreter added
- The Expo/DR screen will be replaced by an INPUTS screen far more powerful
- The curves system will be different (with any number of points from 2 to 17)
- The outputs will have the possibilty of a curve associated
- Many little enhancements
User avatar
algo
Posts: 117
Joined: Sun Sep 02, 2012 3:11 pm
Country: -

Re: Lua interpreter in openTx

Post by algo »

So the Lua branch will eventually become mainline? If that's the case then I will switch over to the Lua branch.

I have been a Lua developer for many years so this definitely interests me. ;)

Post Reply

Return to “openTx”