Thread Tools
Jun 05, 2014, 02:00 PM
Registered User
Fig Newton's Avatar
Thread OP
Discussion

LUA scripting - Technical discussion


I wanted to start a new thread dedicated to Lua scripting so that it doesn't get tangeled up in the OpenTX threads or specific radio threads. I will start this off with a link to a little game I came up with using Lua scripting and the OpenTX v2.0 on my Taranis radio.

https://www.rcgroups.com/forums/show....php?t=2180470

I am by no means an expert on this, but have programmed for most of my life. I will put in some placeholder posts for things like a FAQ, or some bookmarks. Let's also make sure that we clearly state which script we are talking about in our posts. I can see this getting quite confusing as the thread advances and more and more scripts are written.
Last edited by Fig Newton; Jun 05, 2014 at 02:40 PM.
Sign up now
to remove ads between posts
Jun 05, 2014, 02:01 PM
Registered User
Fig Newton's Avatar
Thread OP
Placeholder 1. Maybe for a FAQ.
Jun 05, 2014, 02:02 PM
Registered User
Fig Newton's Avatar
Thread OP
Placeholder 2. Some good bookmarks.

2.1 Lua Reference manual - https://opentx.gitbooks.io/opentx-lu...-overview.html

2.2 Lua Reference manual - https://www.gitbook.com/book/opentx/...-guide/details

OpenTX - LUA Reference Guide
https://docs.google.com/document/d/1...ilebasic?pli=1

projectkk2glider's Lua instructions for OpenTx
https://github.com/opentx/opentx/wik...ting-in-OpenTX

Lua script repository on rcsettings.com
http://rcsettings.com/index.php/view...13-lua-scripts

Lua Gotchas
http://www.luafaq.org/gotchas.html

New Wizard script from davidppoole7 for v2.0.4
https://www.rcgroups.com/forums/show...1&postcount=58

F3K Toolset for Lua written by I shems
https://www.rcgroups.com/forums/show....php?t=2551450
Last edited by Fig Newton; Feb 10, 2017 at 10:06 PM.
Jun 08, 2014, 01:46 PM
nigelsheffield's Avatar
For the full instruction and all available fields etc opentx docs for lua

https://docs.google.com/document/d/1...ilebasic?pli=1





OK thanks, I'm in, now what do I need to download to make a script from start?
I might be in over my head thinking I could do one but I have programmed for fun a lot of years ago in basic, machine code on zx 81 and spectrum, and a little masm on a PC, so the logic is in there but the knowledge and tools specific to this are not.

Is there a free download which would give me the tools to do the job and some basic instructions/tutorials and are there limitations etc specific to the Taranis?

If this is not really doable then perhaps suggestions and requests for scripts could be posted and built by those that can and then put in at the starting posts for others to use?
Last edited by nigelsheffield; Sep 13, 2014 at 11:19 AM.
Jun 08, 2014, 02:13 PM
nigelsheffield's Avatar
Do you think my idea of having dlg flight times defined by pulling a momentary switch displayed in a list is possible? Have followed the links and read through the opentx part but not really sure what's doable and what is not?
I thought it would be a simple case of when the switch is pulled it triggers the script to take the timer 1 and put the results on the screen and then scroll down and do it again next time switch is pulled etc etc, obviously disabling the normal screen while this script is running end only ending when user flicks another switch or something.
Is it more complicated then that , does the screen reset itself every time or something?

Case opened here to see if any advice could be offered.
https://github.com/opentx/opentx/iss...mment-45438770
Latest blog entry: Eachine E160 3d helicopter
Jun 08, 2014, 06:23 PM
Registered User
Fig Newton's Avatar
Thread OP
Quote:
Originally Posted by nigelsheffield
OK thanks, I'm in, now what do I need to download to make a script from start?
I might be in over my head thinking I could do one but I have programmed for fun a lot of years ago in basic, machine code on zx 81 and spectrum, and a little masm on a PC, so the logic is in there but the knowledge and tools specific to this are not.

Is there a free download which would give me the tools to do the job and some basic instructions/tutorials and are there limitations etc specific to the Taranis?

If this is not really doable then perhaps suggestions and requests for scripts could be posted and built by those that can and then put in at the starting posts for others to use?
Nigel,
Shouldn't need anything special to download. The .lua files are just text files saved in the /SCRIPTS folder on your SD card. The transmitter compiles them for you. I am using a simple text editor and saving them to the scripts folder on the sd card subdir I am pointing CompanionTX to. So when I go to CompanionTX and simulate the radio the scripts are there. You navigate to the lua page and select them.

Update, it's important to note that there are two kinds of lua scripts. Model and One Time. Model scripts are run multiple times a second and sound have certain rules applied to them. They are spelled out in projectkk2glider's instructions I posted above. One time scripts are like the wizard that asks for user input and makes changes to settings.
Last edited by Fig Newton; Jun 08, 2014 at 07:15 PM.
Jun 08, 2014, 06:27 PM
Registered User
Fig Newton's Avatar
Thread OP
Quote:
Originally Posted by nigelsheffield
Do you think my idea of having dlg flight times defined by pulling a momentary switch displayed in a list is possible? Have followed the links and read through the opentx part but not really sure what's doable and what is not?
I thought it would be a simple case of when the switch is pulled it triggers the script to take the timer 1 and put the results on the screen and then scroll down and do it again next time switch is pulled etc etc, obviously disabling the normal screen while this script is running end only ending when user flicks another switch or something.
Is it more complicated then that , does the screen reset itself every time or something?

Case opened here to see if any advice could be offered.
https://github.com/opentx/opentx/iss...mment-45438770
I think this goes into the conversation between model and one time scripts. I am sure what you want is doable, but not sure that you would want a model script popping up text over the main screen. The solution to this would be to be able to put the lua output on the Telemetry page. The script could count your flights and display them on the telemetry page along with other info you want. Bertrand is working on this according to his reply when I brought this up on openrcforums.
Jun 09, 2014, 02:46 AM
nigelsheffield's Avatar
Thanks ,
So one time scripts no good for it and model scripts arent for displaying anything - yet.
I guess the telemetry page would work, a bit limiting but will do, you could could have a page of telemtry with all the flight times on maybe but how would we log each one and then move to the next slot to log the next?.
Sure would be simpler if we could have a direct output to the screen, for instance your GPS heading program could have arrows pointing to where the plane is if you stand facing north!

The main screen could be disabled when scripts want to use the screen, we have voice for alarms etc so never really have to look at the screen anymore for much at all!

Hopefully bertrand will come up with something workable,

How much can be done remains to be seen I suppose, but would be VERY cool if "task" or games based on flight times could be done, for instance dlg ladder task where you must get 30 seconds flight and then a 45 seconds flight and then 1 min etc up to whatever time you want in a given time frame scored according to whatever rules might apply.
There are various other tasks too and could be a great deal of fun for both ales and dlg, take into account GPS and altimeters and games based on reaching certain heights and or waypoints could be conceivable.
Last edited by nigelsheffield; Jun 09, 2014 at 03:05 AM.
Jun 09, 2014, 07:52 AM
nigelsheffield's Avatar
I've tried using note to make a file.lua in scripts with a simple screen massage then pointing to it in companion but nothing comes up, your follow me Lua does though but my PC knows yours is a Lua file, does the tx itself need to compile it?
Latest blog entry: Eachine E160 3d helicopter
Jun 09, 2014, 10:51 PM
Registered User
Fig Newton's Avatar
Thread OP
You shouldn't have to compile the .lua script. The transmitter or simulator should automatically interpret the file. The catch is that if there is an error, you will just have the page where the script is selected sit there. If you hit the exit button, it will show the main lua page with your script and (error) over on the right hand side. This means there is some kind of syntax error usually. Since we don't have any other real tools for it at this point, it's kind of a search and rescue. For my gps heading script, I had to completely tear it down and add the pieces back in until I got the bugs out.

I am happy to say that my V1.4 was flown and tested tonight with excellent results. A slow moving Radian was the test plane, and I thought it did an awesome job. Not that I am bragging, just very thrilled to see it come to life. I have been writing software for years and years and it still gives you that rush when something that took a lot of brainstorming works.

On to the previous comments about the types of scripts. I too am eager to see what Bertrand comes up with. Right now for model scripts the recommendation is not to pop up on the screen, don't adjust values that could affect flight, and be ready for your program to be killed at any time. I think a lot of cool ideas are yet to come, and will make this platform a real game changer (not that it already isn't...)!
Jun 10, 2014, 02:13 AM
nigelsheffield's Avatar
Great, I think you are right about it being a game changer again!
Think of the lua like an app feature for phones, the Taranis is now a smart tx lol.
Regarding my attempts not working, I will try again today and maybe use different text editor or it might be the save type file , but if not I will probably be better waiting till more is decided and know about the lua format etc with some instructions for us.
But good to know you and others can make programs and share them with us and we can pick and choose what ones we want!
Latest blog entry: Eachine E160 3d helicopter
Jun 11, 2014, 02:47 AM
nigelsheffield's Avatar
Sorry wrong post.
Latest blog entry: Eachine E160 3d helicopter
Jun 11, 2014, 05:39 AM
Registered User
mikeshellim's Avatar
Quote:
Originally Posted by Fig Newton
I think a lot of cool ideas are yet to come, and will make this platform a real game changer (not that it already isn't...)!
Not exactly sexy, but it would be really useful to be able to write one time scripts for modifying multiple setups quickly. The sort of thing which happens is you think of a good idea, implement it in one model, and are then faced with replicating the changes in several others.

This is a particular problem which users of my F3F glider setup are having, as I've just released a new version to handle the different mixer processing in OpenTx version 2. Only a few mixers are affected by the changes, but it's enough to make manual modification error prone.

As it stands, I'm not clear if the API already supports the kind of operations needed to implement upgrade scripts (reading, writing and deleting mixers, special functions etc.). It doesn't appear so from the documentation. I guess the focus lately has been (rightly) the core features of v. 2.x. However it would be great if development of the API and documentation were to progress to enable this.
Last edited by mikeshellim; Jun 11, 2014 at 07:25 PM.
Jun 11, 2014, 08:31 AM
nigelsheffield's Avatar
Good idea, if you have lots of models all based one the same programming and mixes and only trims etc are different it would make it easy to update them all.
If we can have a lua script to set up a whole model for us then should be able to do that IF znd when developers allow it to be implemented.
Latest blog entry: Eachine E160 3d helicopter
Jun 11, 2014, 03:02 PM
Registered User
scott page's Avatar
Quote:
Originally Posted by nigelsheffield
Good idea, if you have lots of models all based one the same programming and mixes and only trims etc are different it would make it easy to update them all.
If we can have a lua script to set up a whole model for us then should be able to do that IF znd when developers allow it to be implemented.
I think the Tx script for model setup stopped short - it should have also had rates, and expo - not just channels. Perhaps a separate script just for winged aircraft ??


Quick Reply
Message:

Thread Tools