• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

GPS Distance Trip Find Return Home Lua Script

Instead of running the script on the radio, run it on companio using the simulator.
After you run the script you will see a new file appear on the PC, GPS2.luac
Thanks.... That's not how Telemetry scripts are run...
Follow this....

You configure the script to run on the TX using the DISPLAY screen and on Companion using the Telemetry screen all the way at the bottom...

Lets start from scratch...
I remember now that you did send me an OTX configured correctly so you do know how to run a telemetry script. I probably confused you.

Set up and run the telemetry script in companion.
When you do this a GPS2.luac file gets created.
Rename this file to GPS2c.lua.
Put this file on the Tx.
Set up and use this file like you would a normal telemetry script; Using the DISPLAY screen.
Last edited:
Rav, Now sorted. Probably all my fault. I think that my confusion was due to using the Lua script to set up the S8R receiver, which has to be started the way I was trying to start yours. (Unless you know different). For some reason I could not get it to select GPS2c, so I changed the file name to GPS2, and all seems well. I have another glider using the same setup, which I may be able to fly tomorrow, so I will see how it goes.

Sorry to mess you around, and thanks again for your help, it is much appreciated.

Any time Barry...
Are you on Skype?
If you want we can do a Skype sometime if you want some help... E-mail me regarding Skype (any topic)... you have my e-mail.... for other questions continue to use the forums...
HI Rav,
Skype in the UK seems totally broken at present. It used to work fine, but good old MS did an upgrade and now it does not work. If they fix it, we will give it a try.

I have copied the files across to the SD card on my Horus X12s after editing them for my setup. When I run the GPS2.lua script it comes up with the following error:

attempt to call field 'getLastPos' (a nil
Try waiting till the gps has a lock and is returning readings.
I know i do check for nil values.
problem is I don’t get the same error on the Taranis series.

The GPS had a lock. I tried without the lock and the script failed at an earlier.

The Horus X12s has a built in GPS which is also called "GPS". I first tried changing the name of the GPS in the plane to GPS2 but the script still failed. I then changed it back to GPS and changed the radio GPS to "" but get the same result.

It also does not display any arrows on the screen but it does trigger the initial voice feedback messages.

I have been running the script by using the TX file manager to navigate to the lua script and then clicking on it and selecting execute.

I tried from Companion but it did not run the script it just created the .luac file. Should I be using this .luac file?

If I try to activate the script from the Special Functions menu, it can't find the script. It seems to look in a different folder.
I noticed from the debug window in companion that it tries to run the script from the "FUNCTIONS" folder, so I moved the lua script there. Here is the output from the debug window after running the script a few times:

found in map: /Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.luac
f_stat(/Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.luac) = OK
convertToSimuPath(): /SCRIPTS/FUNCTIONS/GPS.lua -> /Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.lua
findTrueFileName(/Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.lua)
found in map: /Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.lua
f_stat(/Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.lua) = OK
luaLoadScriptFileToState(/SCRIPTS/FUNCTIONS/GPS.lua, T): loading /SCRIPTS/FUNCTIONS/GPS.lua
convertToSimuPath(): /SCRIPTS/FUNCTIONS/GPS.lua -> /Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.lua
findTrueFileName(/Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.lua)
found in map: /Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.lua
f_open(/Users/peterberetta/Documents/RC/Companion SD/SCRIPTS/FUNCTIONS/GPS.lua, 1) = 0x7fff970a8328 (FIL 0x7000062e0208)
f_close(0x7fff970a8328) (FIL:0x7000062e0208)
Script GPS error: /SCRIPTS/FUNCTIONS/GPS.lua:971: attempt to call field 'getLastPos' (a nil value)
Hi , Having Just watched a fiends expensive plane disappear into the distance. I'm in the process off building some gps units and installing your Very impresive script on my 9xe. Due to the nature of the models I fly I think it would be very difficult to pilot them back. but what cou be very usefull would be the permanant storage of the last received gps position , which could then be entered in to a smartphone mapping application to help locate the wreckage. or does your script already do this? I know you can get the gps data from the log files but they are not easily accessible at the field.
Thanks for all the work you have already put in.


Posted a thousand or more times
You should also make sure to setup failsafe to switch off the throttle and bank left or right to try an get the plane to circle down asap. It is not safe to let a plane fly off into the distance and there is no excuse for not setting a failsafe. Any modern RC system that is any good supports it. It is not perfect but unless you have an onboard flight controller with GPS return to home it is the best you can do and it probably makes putting a simple GPS sensor on your plane unnecessary. Not reason not to do that too of course.

Note that most systems use HOLD and the default failsafe mode which is almost never what you want.
Sorry my turn of phrase at the beginning of my post was misleading. The pilot tripped while moving to the landing area ,He was slope soaring so no throttle. Who said that he did not have a fail safe set? It was not used initially as after he had regained his balance and shouted lost plane he tried to fly in wide gentle turns , we were hoping to see a flash of sun on the wings but no luck. I should also add that the pilot could be regarded as a expert.
Sloping is a very variable sport , the wind can change and lift disappear leaving you no chance of returning to the top of the hill. In summer the bracken can be 5 foot high and even if you "know" where you landed out it can be very difficult to find your model.
So if the model was fitted with a gps unit (15 gbp to make) and the last known position is reported back to the Frsky transmitter that position could be entered into a smartphonecmapping app to show the posibleclocation of the model
Thanks for this script. I set it up today and it works great. As i read some of the replies I just want to add my experience to get it running. First, on my 9D+ i simply followed the instructions and it worked. But for the QX7 I was getting out of memory errors until i changed the name to gps2c.lua and it then started working. I am using 2.2.3 with QX7 and 9D+, and HGLRC gps

But I have 2 issues that I hope can be resolved. 1. Although altitude for the voice announcement says meters it is actually reporting in cm. The announcement reports 41,000meters which obviously is incorrect. I am pretty sure this number is coming directly from the gps data. Converted from cm to meter 41,000/100 = 410m which is correct for my location. Can a math function be added to convert cm to m? 2) the altitude is reporting MSL. Is there a way to report altitude realitive to the home location? My OSD reports the altitude above sea level until I arm and then it shows altitude relative to the home location.
Thank you for you work to get this running.
Last edited: