Thread Tools
Nov 12, 2018, 11:57 PM
Registered Lurker :)
Thread OP
Discussion

LUA Program that Plots Altitude on Taranis X9D,+


This is a LUA program which graphs altitude vs. time. A notable feature is that after a flight, you can pause it and select any two points on the graph to get the vertical speed between them. This can be used to easily measure the sink rate for testing glider setups in dead air. Or it can be used to see and measure altitude changes, when flying around in thermals.

Features:
  • Generates a real-time plot of altitude in meters vs. time. The altitude axis auto-scales up and down to always show the full graph at highest resolution.
  • Starts with 5 minute timespan: You can add or subtract minutes with the +/- buttons (this will reset the graph.)
  • Pause the graph with the Exit button (short press), continue it again with the Enter button (short press). The long press actions of these buttons are not affected.
  • When running, it displays the climb/sink rate for the previous 10 seconds.
  • When paused, the climb/sink rate between any two graph points can be displayed. Select the desired graph points by moving the Rud & Ail sticks. This makes it possible to determine the vertical speed during exactly the portion of flight you are interested in.
  • Always displays the live altitude, and the maximum altitude on the screen.
  • Does not use any global variables, or physical / logical switches. Should be compatible with any model setup.


Live view: Climb rate of 1.9 m/s is the average of the previous 10 seconds. The vertical dotted lines are 1-minute intervals.



Paused view: Sink rate of -0.6 m/s is for the interval between the two solid vertical cursors, which you can place anywhere by moving the Rud and Ail sticks.




Requirements:
  • Taranis X9D or X9D+
  • OpenTX 2.1.9, or 2.2.x. It may also work with earlier versions, but I have not tested them. I am using it with 2.1.9. For 2.2 I have only verified it on the Companion simulator, so please let me know if there are any issues.
  • Altitude telemetry is required of course (high precision varios work best) and the altitude sensor must be named "Alt" in Telemetry Sensors section of the model.
Download and unzip the attached file to get AltPlt.lua.

Comments and questions are welcome.

Cheers,
- John
Last edited by filago; Jan 03, 2019 at 10:04 AM.
Sign up now
to remove ads between posts
Nov 13, 2018, 05:15 PM
Aussie F5J Team
Awesome John, can't wait to try it. I'm really looking forward to the sink rate average over 10s and the graph reading option. Great for tuning glider performance and optimising flap settings.
Thank you.
Cheers,
Marcus
Dec 13, 2018, 08:29 PM
Will fly for Bourbon
DBSkyout's Avatar
This is awesome. Can it be adapted for the Horus X10?
Dec 14, 2018, 08:42 AM
Registered Lurker :)
Thread OP
Quote:
Originally Posted by DBSkyout
This is awesome. Can it be adapted for the Horus X10?
I know very little about the Horus, but I don't see why not.
Dec 14, 2018, 10:08 AM
Honorable Deplorable
Was just going to ask about the x10...… have been trying to decide between a couple different controllers. This would be a huge selling point for the Horus side of things.
Dec 15, 2018, 12:17 PM
iVoid Warranties
flyinghedgehogs's Avatar
Nice code. Very clean. Thanks for putting all your variables up at the top for easy modification.
Dec 15, 2018, 12:58 PM
Honorable Deplorable
Reading through some things about the Horus x10 radios and it sounds like as of right now the LUA script is not available on the controller. It may be in an update at some time, but not able to as of now.
Dec 15, 2018, 11:23 PM
Adam
xStatiCa's Avatar
It would need to be adapted to be a Widget for Horus.
Dec 20, 2018, 01:40 AM
Registered User
The script when executed on my X10s says Bad argument #6 to 'drawline'........
Havent gotten beyond that
Dec 31, 2018, 08:16 PM
Ron Smith
smithre6's Avatar

need some help


John, Thanks for posting this LUA. I am excited to see if I can get it to work. Right now I have it loaded on my Taranis X9D plus. I am running Open TX 2.1.9

I renamed the file to .LUA and saved it scripts/mixes folder on my taranis. I have added it as a custom script in the model. It tells me there is an error. I have tried to execute it from the SD card. It tells me

Script Syntax error
MIXES/AltPlt.lua:1
unexpected symbol near char(255)

I tried to add it as a script on a telemetry screen but it says that no scripts on SD.

I am not sure what I am doing wrong. I am not an expert on LUA so I could be making a very basic mistake. I appreciate any help you can provide.

Thanks
Ron

I read thru the LUA again and realized that the file needs to go on the SCRIPTS/TELEMETRY folder. I have done that and mapped the script to a telemetry screen. I am still getting the Script Syntax error. Thanks
Last edited by smithre6; Dec 31, 2018 at 09:11 PM. Reason: more information
Jan 01, 2019, 03:53 PM
Registered Lurker :)
Thread OP
Quote:
Originally Posted by smithre6
I am still getting the Script Syntax error.
Hello Ron,

Happy new year. A couple of questions to help troubleshoot things.
  • When do see the error? Is it when you long-press on the PAGE button to get the telemetry screen, after the model is loaded?
  • Does the error now indicate that it is coming from SCRIPTS/TELEMETRY ?
  • Did you remove the file from the MIXES folder? I don't know if/why that would matter though...
  • Did you make any edits to the file?
  • How did you rename it? File extension change only from the operating system, or open it in an application and then Save As ?
  • Can you verify that the only characters in the first line of the file on the SD card are "--[[" (without the quotes.) It should be viewable from any text editor.

Cheers,
- John
Jan 01, 2019, 07:15 PM
Ron Smith
smithre6's Avatar
John,

Thanks for your help. Below are the answers to your questions.


When do see the error? Is it when you long-press on the PAGE button to get the telemetry screen, after the model is loaded?

-----Yes. I loaded the script to my second telemetry screen. All I see on that screen is the syntax error.

Does the error now indicate that it is coming from SCRIPTS/TELEMETRY ?

---- Yes, see photo attached

Did you remove the file from the MIXES folder? I don't know if/why that would matter though...

--- yes

Did you make any edits to the file?

---no

How did you rename it? File extension change only from the operating system, or open it in an application and then Save As ?

--- opened it with notepad and save as a unicode file.

Can you verify that the only characters in the first line of the file on the SD card are "--[[" (without the quotes.) It should be viewable from any text editor.

---yes

Thanks
Ron
Last edited by smithre6; Jan 01, 2019 at 07:17 PM. Reason: Adding photo
Jan 01, 2019, 08:13 PM
Registered Lurker :)
Thread OP
Quote:
Originally Posted by smithre6
John,

Thanks for your help. Below are the answers to your questions.

. . .

How did you rename it? File extension change only from the operating system, or open it in an application and then Save As ?
--- opened it with notepad and save as a unicode file.

. . .
OK, thanks to your detailed reply I think I have the answer for you. I can re-create the issue if I save it as a Unicode file from Notepad. This is encoding additional hidden characters that LUA isn't happy with.

Start again with the file in the first post, and remove the .txt extension directly from the file manager (don't save it from Notepad) and let me know how that works.

I've got some learning to do here, in order to help others avoid the same issue - thanks for being an unplanned contributor to my knowledge!

Cheers,
- John
Last edited by filago; Jan 04, 2019 at 04:05 PM.
Jan 02, 2019, 06:29 PM
Ron Smith
smithre6's Avatar

It Works !


John,

It works! When I renamed the file in File Explorer by editing the name it worked.

The issue that I had was that the file name extensions were hidden in File Explorer, which originally did not allow me to simply edit the name. So in File Explorer you need to pick the View menu and then make sure that the File Name Extensions box is clicked in the show/hide menu section. I found this out thru a Google search. Once the file name extensions are visible, then you can simply rename the file.

Thanks for your help and I hope this can help others too,

Ron
Jan 03, 2019, 09:34 AM
Registered Lurker :)
Thread OP

File Encoding for LUA Scripts


Following up with what I found when investigating the issue that Ron experienced.

The Windows Notepad app offers several encoding options when doing a "Save As". The options I see are ANSI, Unicode, Unicode big endian, and UFT-8. Of these, ANSI seems to work OK for saving LUA scripts, but is not what I recommend for editing scripts (see below.) The other Notepad encoding options definitely add non-visible characters which cause syntax errors on the Taranis and OpenTX Companion. The extra characters can be seen using a hex editor.

I changed the file in the first post to a ZIP file, to hopefully reduce the risk of others running into the same issue (RCGroups doesn't include .lua in the supported file types.)

For editing LUA scripts, I recommend the free application ZeroBrane Studio. It has a small footprint, is portable, open-source, cross-platform (Windows, macOS, and Linux) and is easy to use.

Cheers,
- John
Last edited by filago; Jan 03, 2019 at 10:12 AM.


Quick Reply
Message:

Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Download An Ardupilot frsky telemetry LUA script for the Horus X10/ X12 and Taranis X9D/E/QX7 yaapu Radios 356 May 21, 2019 03:11 PM
Discussion F5J program for Taranis QX7 and X9D with Lua scripts jfrickmann Electric Competition Soaring-F5J/ALES/e-Soaring 107 May 11, 2019 01:49 PM
Discussion Taranis (x9d) how to program two switches on one channel (different levels)? markm75 Radios 1 May 07, 2016 12:48 AM
Discussion How to program one switch to initiate commands on another channel? Taranis x9d markm75 Radios 0 May 04, 2016 10:32 PM