LUA Script for APM Plane & QuadPlane

I started to dust off my Ranger EX after sitting around all winter. It won’t be long now before I test my initial transitions so I decided to install a few more cables like my camera trigger for CHDK and my FrSky-to-Pixhawk telemetry cable from Craft & Theory.

I then realized that my favorite LUA script, called LuaPilot, was written for APM and PX4 copters, not plane, so I made some minor changes and came up with “LuaPlane” that correctly calls out Plane and QuadPlane flight modes. It’s still a work in progress as I hunt for better QuadPlane audibles but it works nicely now. You don’t need Mission Planner running to get positive feedback on a flight mode change from telemetry.

You can use APM Copter 3.x for LuaPilot without issue and use APM Plane 3.x or QuadPlane with LuaPlane without issue. The standard smartport telem setting 4 in Mission Planner. I’m using OpenTX 2.1.9 and the Pixhawk Telemetry 2 port with my Craft & Theory cable. No teensy is needed. Be sure to copy the the “TELEMETRY” directory inside the “SCRIPTS” directory and set up your lua script to “LuaPilot” or “LuaPlane” appropriately on the Telemetry tab screen for your particular model in OpenTX. You can pull LuaPilot from the links below and then just add my attached ZIP file. The PLANEWAV directory for sounds goes in the SCRIPTS folder and the LuaPlane.lua file goes in the TELEMETRY directory along side the LuaPilot.lua file.

Lua Script Links:

LuaPlane.zip (2.1 MB)

1 Like

Thanks for working on this…

Hello, is there a github repo for Luaplane?

For Lua Plane there is just the script :https://www.rcgroups.com/forums/showatt.php?attachmentid=9914295&d=1490893447

https://www.rcgroups.com/forums/showpost.php?p=37213943&postcount=48

The github repo for Lua Pilot is here
http://ilihack.github.io/LuaPilot_Taranis_Telemetry/

Hello Greg,
is it possible to change the unit for speed from Km/H to Ms ?

This would match Air speed and Ground speed units showed on Mission Planner .

Thanks !

Yes, the telemetry unit for speed is knots so instead of converting it to kmh, you can convert it to m/s. You can change it below as described or I can post a new file for you this weekend. The original file has spelling errors and few comments so it can be difficult to follow.

In the “Speed Drawing” section, change the highlighted text:

drawText(38,29, "Speed : ",SMLSIZE,0)

if settings[‘imperial’] ~=0 then
drawText(getLastPos(), 25, round(data.spd1.149), MIDSIZE)
drawText(getLastPos(), 29, “mph”, SMLSIZE)
else
**drawText(getLastPos(), 25, round(data.spd
1.851), MIDSIZE)**
drawText(getLastPos(), 29, “kmh”, SMLSIZE)
end

to this:

drawText(getLastPos(), 25, round(data.spd*0.514), MIDSIZE)
drawText(getLastPos(), 29, “m/s”, SMLSIZE)

Fantastic Greg , really thank you for that !

I think that LuaPlane is all you need when you flight with plane , a great telemetry for less than 4 $.
You just need a Frsky receiver with S port then the Max232 converter that can be bought from HK Frsky Ful 1 add a diode and a servo cable you are done.

BTW the LuaPlane.zip link in the first post is dead.

The APM forum has some quirks. I can’t even edit my first post anymore because it greys out on the author after a period. I had this happen on my mini Talon conversion thread as well. To top it off, the uploading feature now says my 2.1meg zip file is too large because the limit is 4meg. I hosted them on my Web site below.

Here are the two versions now. The LuaPlane.zip displays ground speed in kmh and the LuaPlaneMS.zip displays ground speed in m/s. Happy Thanksgiving!

LuaPlane.zip - 2.1meg
LuaPlaneMS.zip - 2.1meg

1 Like

Greg,
I have too the problem of “file to large” when I tried to upload files around 2 Mb.
Thanks again for sharing the updated files.

Hi Greg,

I have done some flights and the ms value displayed is wrong , about the half it should be .

drawText(getLastPos(), 25, round(data.spd*0.514), MIDSIZE)

Would it be possible that “data.spd” is already in ms ?

Yes, it is possible. I was basing it by the comment in the script below. I took “knotes per h” to mean “knots per hour”…which is really a “knot”.

data.spd = getValue(data.spdid) --knotes per h

and the existing conversions to mph and kmh match the formulas below.

if settings[‘imperial’] ~=0 then
drawText(getLastPos(), 25, round(data.spd*1.149), MIDSIZE)
drawText(getLastPos(), 29, “mph”, SMLSIZE)
else
drawText(getLastPos(), 25, round(data.spd*1.851), MIDSIZE)
drawText(getLastPos(), 29, “kmh”, SMLSIZE)
end

1 knot (kt) = 1.8520 kilometers per hour (kph).
1 knot (kt) = 1.1508 miles per hour (mph).
1 knot (kt) = 0.5144 meters per second (m/s).

I did find some interesting (if not confusing) information here. It suggests below that each transmitter can be set up to change the configured units of GSpd.

GSpd : current ground speed, calculated by GPS.

Note - some discovered sensors require to be edited before continuing:
ASpd & GSpd- These sensors will be discovered with the unit of kts configured - even though the value it displays will actually be in m/s. Do not change the units config of these sensors - leave as they are discovered and the telemetry screen will display them correctly in the SpeedUnits value chosen.

Thanks for your reply Greg.
I will do some tests to find out the right conversion.

In fact for plane it would be more useful to have the Airspeed rather than the ground speed of the plane but I’m afraid that it is not possible with standard native Frsky telemetry.

Out of curiosity…what are you basing the erroneous value on? In other words, where are you getting the other m/s display from? Mission Planner?

Yes on Mission Planner, the value did not match with the value showed on Luaplane but the fact that the displayed speed is the ground speed and not the airspeed value might had confuse me.

BTW I have just order a couple of Teensy to have the Airspeed value.
Guess I will try to modify the Mavlink Frisky port with Arduplane Flight modes as in Luaplane.

I have done some test and yes , data.spd , is already in ms so there is no need to convert it.

The displayed value in LuaPlane match with the Ground Speed in Mission Planner HUD.

We’ll have to test the other values as it would seem that they are all off by the factor below. Since the script was originally written for copter, I wonder if the value of data.spd is different for plane or if the original script was wrong. Something seems odd.

1knot = 0.5144444m/s

I think that the value is not in Knots but in ms as in Mission Planner

In fact in the doc of Mavlink FrskySport it is written m/s , it is only said to use as unit kts , it do not say the value is in knots.
This has lead to a misunderstanding.

It seems like an error in the original LUA script and you have a good catch. It is difficult for me to test fly this time of year so perhaps others can verify the issue and fix.

I can create new versions that replace the conversions below:

1 knot (kt) = 1.8520 kilometers per hour (kph).
1 knot (kt) = 1.1508 miles per hour (mph).
1 knot (kt) = 0.5144 meters per second (m/s).

drawText(getLastPos(), 25, round(data.spd*1.149), MIDSIZE)
drawText(getLastPos(), 29, “mph”, SMLSIZE)

drawText(getLastPos(), 25, round(data.spd*1.851), MIDSIZE)
drawText(getLastPos(), 29, “kmh”, SMLSIZE)

drawText(getLastPos(), 25, round(data.spd*0.514), MIDSIZE)
drawText(getLastPos(), 29, “m/s”, SMLSIZE)

to these:

1 m/s = 3.600 kilometers per hour (kph).
1 m/s = 2.237 miles per hour (mph).
1 m/s = 1.000 meters per second (m/s).

drawText(getLastPos(), 25, round(data.spd*2.237), MIDSIZE)
drawText(getLastPos(), 29, “mph”, SMLSIZE)

drawText(getLastPos(), 25, round(data.spd*3.600), MIDSIZE)
drawText(getLastPos(), 29, “kmh”, SMLSIZE)

drawText(getLastPos(), 25, round(data.spd*1.000), MIDSIZE)
drawText(getLastPos(), 29, “m/s”, SMLSIZE)

I updated the two versions and based data.spd on m/s instead of knots. The LuaPlane.zip displays ground speed in kmh and the LuaPlaneMS.zip displays ground speed in m/s. I’ll try to test them sometime on my Pixracer Quad 250.

LuaPlane.zip - 2.1meg
LuaPlaneMS.zip - 2.1meg

Thanks Greg !

I’ll let you know if I will have some success with my version of Luaplane with Teensy and Mavlink Frsky Port to have the Airspeed showed in my Taranis :slight_smile: