Created
August 2, 2015 14:39
-
-
Save xdandys/67612d119be6e0b4841e to your computer and use it in GitHub Desktop.
Telemetry Taranis script for usage with TauLabs and FrSky telemetry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright (c) 2015 dandys. | |
-- Copyright (c) 2014 Marco Ricci. | |
-- This program is free software: you can redistribute it and/or modify | |
-- it under the terms of the GNU General Public License as published by | |
-- the Free Software Foundation, either version 3 of the License, or | |
-- (at your option) any later version. | |
-- | |
-- This program is distributed in the hope that it will be useful, | |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
-- GNU General Public License for more details. | |
-- | |
-- A copy of the GNU General Public License is available at <http://www.gnu.org/licenses/>. | |
-- | |
-- Radar is based on Volke Wolkstein MavLink telemetry script | |
-- https://github.com/wolkstein/MavLink_FrSkySPort | |
local CONDENSED = 0x08 | |
-- Various local variables | |
local X1, Y1, X2, Y2, XH, YH | |
local delta, deltaX, deltaY | |
local getTelemetryValues | |
-- Draw a shape | |
-- ************ | |
local sinShape, cosShape | |
local function drawShape(col, row, shape, rotation) | |
sinShape = math.sin(rotation) | |
cosShape = math.cos(rotation) | |
for index, point in pairs(shape) do | |
lcd.drawLine( | |
col + math.floor(point[1] * cosShape - point[2] * sinShape + 0.5), | |
row + math.floor(point[1] * sinShape + point[2] * cosShape + 0.5), | |
col + math.floor(point[3] * cosShape - point[4] * sinShape + 0.5), | |
row + math.floor(point[3] * sinShape + point[4] * cosShape + 0.5), | |
SOLID, FORCE | |
) | |
end | |
end | |
-- Draw an ellipse | |
-- *************** | |
local function drawEllipse( col, row, width, height ) | |
X1 = col + width | |
Y1 = row | |
for i = 12, 360, 12 do | |
X2 = col + math.floor(width * math.cos(math.rad(i)) + 0.5) | |
Y2 = row + math.floor(height * math.sin(math.rad(i)) + 0.5) | |
lcd.drawLine( X1, Y1, X2, Y2, SOLID, 0 ) | |
X1 = X2 | |
Y1 = Y2 | |
end | |
end | |
-- Telemetry data | |
-- ************** | |
local yaw, pitch, roll = 0, 0, 0 | |
local altitude, speed, distance_3D = 0, 0, 0 | |
local heading, pilote_heading = 0, 0 | |
local latitude, longitude = 0, 0 | |
local pilot_latitude, pilot_longitude = 0, 0 | |
local vdop, hdop, sats, verticalSpeed, rssi, cellVoltage = 0, 0, 0, 0, 0, 0 | |
local modeString, gpsString = "", "" | |
local isArmed = True | |
-- GPS Calculation | |
-- *************** | |
-- Calculated data | |
local heading_from, heading_to, distance_2D = 0, 0, 0 | |
-- Working variables | |
local z1, z2 | |
local pilotLat, sin_pilotLat, cos_pilotLat | |
local currLat, sin_currLat, cos_currlat | |
local cos_currLon_pilotLon | |
local function gpsCalculation() | |
if pilot_latitude == 0 or pilot_longitude == 0 or latitude == 0 or longitude == 0 then | |
heading_from = 0 | |
heading_to = 0 | |
distance_2D = 0 | |
else | |
pilotLat = math.rad(pilot_latitude) | |
sin_pilotLat = math.sin(pilotLat) | |
cos_pilotLat = math.cos(pilotLat) | |
currLat = math.rad(latitude) | |
sin_currLat = math.sin(currLat) | |
cos_currlat = math.cos(currLat) | |
cos_currLon_pilotLon = math.cos(math.rad(longitude - pilot_longitude)) | |
-- Heading_from & heading_to calculation | |
z1 = math.sin(math.rad(longitude - pilot_longitude)) * cos_currlat | |
z2 = cos_pilotLat * sin_currLat - sin_pilotLat * cos_currlat * cos_currLon_pilotLon | |
heading_from = math.floor(math.deg(math.atan2(z1, z2)) + 0.5) % 360 | |
heading_to = (heading_from - 180) % 360 | |
-- Distance_2D calculation (Spherical Law of Cosines) | |
distance_2D = math.floor(6371009 * math.acos(sin_pilotLat * sin_currLat + cos_pilotLat * cos_currlat * cos_currLon_pilotLon)) | |
end | |
end | |
local colAH = 54 | |
local rowAH = 31 | |
local radAH = 22 | |
local pitchR = radAH / 25 | |
local attAH = FORCE + GREY(10) | |
local attBox = FORCE + GREY(5) | |
local colAlt = colAH + 31 | |
local colSpeed = colAH - 31 | |
local colHeading = colAH | |
local rowHeading = rowAH - radAH -- 9 | |
local rowDistance = rowAH + radAH + 3 | |
local homeShape = { | |
{ 0, -5, -4, 4}, | |
{-4, 4, 0, 2}, | |
{ 0, 2, 4, 4}, | |
{ 4, 4, 0, -5} | |
} | |
-- Draw artificial horizon | |
-- *********************** | |
local tanRoll, cosRoll, sinRoll | |
local dPitch_1, dPitch_2, mapRatio | |
local function drawHorizon() | |
dPitch_1 = pitch % 180 | |
if dPitch_1 > 90 then dPitch_1 = 180 - dPitch_1 end | |
cosRoll = math.cos(math.rad(roll == 90 and 89.99 or (roll == 270 and 269.99 or roll))) | |
if pitch > 270 then | |
dPitch_1 = -dPitch_1 * pitchR / cosRoll | |
dPitch_2 = radAH / cosRoll | |
elseif pitch > 180 then | |
dPitch_1 = dPitch_1 * pitchR / cosRoll | |
dPitch_2 = -radAH / cosRoll | |
elseif pitch > 90 then | |
dPitch_1 = -dPitch_1 * pitchR / cosRoll | |
dPitch_2 = -radAH / cosRoll | |
else | |
dPitch_1 = dPitch_1 * pitchR / cosRoll | |
dPitch_2 = radAH / cosRoll | |
end | |
tanRoll = -math.tan(math.rad(roll == 90 and 89.99 or (roll == 270 and 269.99 or roll))) | |
for i = -radAH, radAH, 1 do | |
YH = i * tanRoll | |
Y1 = math.floor(YH + dPitch_1 + 0.5) | |
if Y1 > radAH then | |
Y1 = radAH | |
elseif Y1 < -radAH then | |
Y1 = -radAH | |
end | |
Y2 = math.floor(YH + 1.5 * dPitch_2 + 0.5) | |
if Y2 > radAH then | |
Y2 = radAH | |
elseif Y2 < -radAH then | |
Y2 = -radAH | |
end | |
X1 = colAH + i | |
if Y1 < Y2 then | |
lcd.drawLine(X1, rowAH + Y1, X1, rowAH + Y2, SOLID, attAH) | |
elseif Y1 > Y2 then | |
lcd.drawLine(X1, rowAH + Y2, X1, rowAH + Y1, SOLID, attAH) | |
end | |
end | |
lcd.drawLine(colAH - radAH - 1, rowAH - radAH - 1, colAH - radAH - 1, rowAH + radAH + 1, SOLID, attBox) | |
lcd.drawLine(colAH + radAH + 1, rowAH - radAH - 1, colAH + radAH + 1, rowAH + radAH + 1, SOLID, attBox) | |
lcd.drawLine(colAH - radAH - 1, rowAH + radAH + 1, colAH + radAH + 1, rowAH + radAH + 1, SOLID, attBox) | |
end | |
-- Draw pitch line indication | |
-- ************************** | |
local function drawPitch() | |
sinRoll = math.sin(math.rad(-roll)) | |
cosRoll = math.cos(math.rad(-roll)) | |
delta = pitch % 15 | |
for i = delta - 30 , 30 + delta, 15 do | |
XH = pitch == i % 360 and 23 or 13 | |
YH = pitchR * i | |
X1 = -XH * cosRoll - YH * sinRoll | |
Y1 = -XH * sinRoll + YH * cosRoll | |
X2 = (XH - 2) * cosRoll - YH * sinRoll | |
Y2 = (XH - 2) * sinRoll + YH * cosRoll | |
if not ( -- test si l'on pas hors du cadre | |
(X1 < -radAH and X2 < -radAH) -- le trait est trop � gauche | |
or (X1 > radAH and X2 > radAH) -- le trait est trop � droite | |
or (Y1 < -radAH and Y2 < -radAH) -- le trait est trop � haut | |
or (Y1 > radAH and Y2 > radAH) -- le trait est trop � bas | |
) then -- ajuste X et Y pour ne pas sortir du cadre (c'est un peu le bordel, � am�liorer) | |
mapRatio = (Y2 - Y1) / (X2 - X1) | |
if X1 < -radAH then Y1 = (-radAH - X1) * mapRatio + Y1 X1 = -radAH end | |
if X2 < -radAH then Y2 = (-radAH - X1) * mapRatio + Y1 X2 = -radAH end | |
if X1 > radAH then Y1 = (radAH - X1) * mapRatio + Y1 X1 = radAH end | |
if X2 > radAH then Y2 = (radAH - X1) * mapRatio + Y1 X2 = radAH end | |
mapRatio = 1 / mapRatio | |
if Y1 < -radAH then X1 = (-radAH - Y1) * mapRatio + X1 Y1 = -radAH end | |
if Y2 < -radAH then X2 = (-radAH - Y1) * mapRatio + X1 Y2 = -radAH end | |
if Y1 > radAH then X1 = (radAH - Y1) * mapRatio + X1 Y1 = radAH end | |
if Y2 > radAH then X2 = (radAH - Y1) * mapRatio + X1 Y2 = radAH end | |
lcd.drawLine( | |
colAH + math.floor(X1 + 0.5), | |
rowAH + math.floor(Y1 + 0.5), | |
colAH + math.floor(X2 + 0.5), | |
rowAH + math.floor(Y2 + 0.5), | |
SOLID, FORCE | |
) | |
end | |
end | |
end | |
-- Draw heading indicator | |
-- ********************** | |
local parmHeading = { | |
{0, 2, "N"}, {30, 5}, {60, 5}, | |
{90, 2, "E"}, {120, 5}, {150, 5}, | |
{180, 2, "S"}, {210, 5}, {240, 5}, | |
{270, 2, "O"}, {300, 5}, {330, 5} | |
} | |
local wrkHeading = 0 | |
local function drawHeading() | |
lcd.drawLine(colHeading - 34, rowHeading, colHeading + 34, rowHeading, SOLID, FORCE) | |
for index, point in pairs(parmHeading) do | |
wrkHeading = point[1] - heading | |
if wrkHeading > 180 then wrkHeading = wrkHeading - 360 end | |
if wrkHeading < -180 then wrkHeading = wrkHeading + 360 end | |
delatX = math.floor(wrkHeading / 3.3 + 0.5) - 1 | |
if delatX >= -31 and delatX <= 31 then | |
if point[3] then | |
lcd.drawText(colHeading + delatX - 1, rowHeading - 8, point[3], SMLSIZE + BOLD) | |
end | |
if point[2] > 0 then | |
lcd.drawLine(colHeading + delatX, rowHeading - point[2], colHeading + delatX, rowHeading, SOLID, FORCE) | |
end | |
end | |
end | |
lcd.drawFilledRectangle(colHeading - 34, rowHeading - 9, 3, 10, ERASE) | |
lcd.drawFilledRectangle(colHeading + 32, rowHeading - 9, 3, 10, ERASE) | |
-- deltaX = (distance_3D < 10 and 6) or (distance_3D < 100 and 8 or (distance_3D < 1000 and 10 or 12)) | |
lcd.drawFilledRectangle(colHeading -8, 1, 16, 8, ERASE) | |
lcd.drawLine(colHeading -9, 0, colHeading - 9, 8, SOLID, FORCE) | |
lcd.drawLine(colHeading + 8, 0, colHeading + 8, 8, SOLID, FORCE) | |
lcd.drawNumber(colHeading - 7, 2, heading / 100, LEFT+SMLSIZE) | |
lcd.drawNumber(lcd.getLastPos(), 2, (heading / 10) % 10, LEFT+SMLSIZE) | |
lcd.drawNumber(lcd.getLastPos(), 2, heading % 10, LEFT+SMLSIZE) | |
end | |
local function drawDistance() | |
deltaX = (distance_2D < 10 and 6) or (distance_2D < 100 and 8 or (distance_2D < 1000 and 10 or 12)) | |
lcd.drawNumber(colAH + 3 - deltaX, rowAH + 10 , distance_2D, LEFT+SMLSIZE+INVERS) | |
lcd.drawText(lcd.getLastPos(), rowAH + 10, "m", SMLSIZE+INVERS) | |
drawShape(colAH, rowAH, homeShape, math.rad(heading_to - heading + 180)) | |
end | |
local function drawMode() | |
if not isArmed then | |
lcd.drawText(colAH - 22, rowAH - 20, "DISARMED", SMLSIZE+INVERS) | |
end | |
lcd.drawText(colAH - 22, rowAH + 25, modeString, SMLSIZE) | |
end | |
-- Vertical line parameters (to improve or even supress) | |
-- ***************************************************** | |
local parmLine = { | |
{rowAH - 36, 5, 30}, -- +30 | |
{rowAH - 30, 3}, -- +25 | |
{rowAH - 24, 5, 20}, -- +20 | |
{rowAH - 18, 3}, -- +15 | |
{rowAH - 12, 5, 10}, -- +10 | |
{rowAH - 6 , 3}, -- +5 | |
{rowAH, 5, 0}, -- 0 | |
{rowAH + 6, 3}, -- -5 | |
{rowAH + 12, 5, -10}, -- -10 | |
{rowAH + 18, 3}, -- -15 | |
{rowAH + 24, 5, -20}, -- -20 | |
{rowAH + 30, 3}, -- -25 | |
{rowAH + 36, 5, -30} -- -30 | |
} | |
-- Draw altitude indicator | |
-- *********************** | |
local function drawAltitude() | |
delta = altitude % 10 | |
deltaY = 1 + math.floor(1.2 * delta) | |
lcd.drawLine(colAlt, -1, colAlt, 64, SOLID, FORCE) | |
for index, line in pairs(parmLine) do | |
lcd.drawLine(colAlt - line[2] - 1, line[1] + deltaY, colAlt - 1, line[1] + deltaY, SOLID, FORCE) | |
if line[3] then | |
lcd.drawNumber(colAlt + 4, line[1] + deltaY - 3, altitude + line[3] - delta, LEFT+SMLSIZE) | |
end | |
end | |
lcd.drawFilledRectangle(colAlt - 5, 0, 5, 10, ERASE) | |
lcd.drawFilledRectangle(colAlt + 1, 0, 6 * 3, 9, ERASE) | |
lcd.drawNumber(colAlt + 4, 1 + rowAH - 3, altitude, LEFT+SMLSIZE+INVERS+CONDENSED) | |
lcd.drawText(colAlt + 5, 1, "m", SMLSIZE+FIXEDWIDTH) | |
end | |
-- Draw speed indicator | |
-- ******************** | |
local function drawSpeed() | |
delta = speed % 10 | |
deltaY = 1 + math.floor(1.2 * delta) | |
lcd.drawLine(colSpeed, -1, colSpeed, 64, SOLID, FORCE) | |
for index, line in pairs(parmLine) do | |
lcd.drawLine(colSpeed, line[1] + deltaY, colSpeed + line[2], line[1] + deltaY, SOLID, FORCE) | |
if line[3] then | |
lcd.drawNumber(colSpeed - 3, line[1] + deltaY - 3, speed + line[3] - delta, SMLSIZE) | |
end | |
end | |
lcd.drawFilledRectangle(colSpeed + 1, 0, 5, 10, ERASE) | |
lcd.drawFilledRectangle(colSpeed - 6 * 3, 0, 6 * 3, 9, ERASE) | |
lcd.drawNumber(colSpeed - 3, 1 + rowAH - 3, speed, SMLSIZE+INVERS) | |
lcd.drawText(colSpeed - 20, 1, "kmh", SMLSIZE+FIXEDWIDTH) | |
end | |
-- Draw radar area | |
-- *************** | |
local colRadar, rowRadar = 134, 27 | |
local radarShape1 = { | |
{-4, 5, 0, -4}, | |
{-3, 5, 0, -3}, | |
{3, 5, 0, -3}, | |
{4, 5, 0, -4} | |
} | |
local radarShape2 = { | |
{-3, 3, 0, -3}, | |
{-2, 3, 0, -2}, | |
{ 2, 3, 0, -2}, | |
{ 3, 3, 0, -3} | |
} | |
local wrkDistance, wrkShape, radTmp | |
local wrkCol, wrkRow, radarBlink | |
local radarArmed = 0 | |
local function drawRadar() | |
lcd.drawText(colRadar - 2,rowRadar - 4,"o",0) | |
-- lcd.drawRectangle(colRadar - 26, rowRadar - 26, 54, 54) | |
drawEllipse(colRadar, rowRadar, 24, 24) | |
for i=7, 24, 4 do | |
lcd.drawPoint(colRadar - i, rowRadar) | |
lcd.drawPoint(colRadar + i, rowRadar) | |
lcd.drawPoint(colRadar, rowRadar-i) | |
lcd.drawPoint(colRadar, rowRadar+i) | |
end | |
local distanceRange = 0 | |
local firstRange = 100 | |
for i=0,10,1 do | |
distanceRange = 2 ^ i * firstRange | |
wrkDistance = -distance_2D / distanceRange * 28 | |
if distance_2D < distanceRange then | |
if i > 0 then | |
drawEllipse(colRadar, rowRadar, 12, 12) | |
end | |
break | |
end | |
end | |
local orientationType = pilote_heading == 0 and "N" or "P" | |
lcd.drawText(colRadar - 2, rowRadar -27, orientationType, SMLSIZE) | |
radTmp = math.rad(pilote_heading - heading_from) | |
drawShape( | |
colRadar + wrkDistance * math.sin(radTmp), | |
rowRadar + wrkDistance * math.cos(radTmp), | |
radarShape2, | |
math.rad(heading - pilote_heading) | |
) | |
deltaX = (distanceRange < 10 and 6) or (distanceRange < 100 and 8 or (distanceRange < 1000 and 10 or 12)) | |
lcd.drawNumber(colRadar + 3 - deltaX, rowDistance , distanceRange, LEFT+SMLSIZE) | |
lcd.drawText(lcd.getLastPos(), rowDistance, "m", SMLSIZE) | |
lcd.drawText(colRadar - 24, rowRadar + 5, gpsString, SMLSIZE+INVERS) | |
end | |
-- Draw textual telemetry data | |
-- *************** | |
local textualRow = 164 | |
local function drawTextualTelemetry() | |
-- VDOP / HDOP | |
local y = 0 | |
lcd.drawText(textualRow, y, "HDP:", SMLSIZE) | |
lcd.drawNumber(lcd.getLastPos(), y, hdop, SMLSIZE+PREC2+LEFT) | |
y = y + 8 | |
lcd.drawText(textualRow, y, "VDP:", SMLSIZE) | |
lcd.drawNumber(lcd.getLastPos(), y, vdop, SMLSIZE+PREC2+LEFT) | |
y = y + 8 | |
lcd.drawText(textualRow, y, "SAT:", SMLSIZE) | |
lcd.drawNumber(lcd.getLastPos(), y, sats, SMLSIZE+LEFT) | |
y = y + 8 | |
lcd.drawNumber(textualRow + 3, y, cellVoltage, PREC2+LEFT+MIDSIZE) | |
lcd.drawText(lcd.getLastPos(), y, "V", MIDSIZE) | |
y = y + 13 | |
lcd.drawNumber(textualRow + 0, y, rssi, LEFT+MIDSIZE) | |
lcd.drawText(lcd.getLastPos(), y + 2, "RSSI", SMLSIZE) | |
y = y + 13 | |
local arrowSymbol = (verticalSpeed > 0 and "\192") or "\193" | |
lcd.drawText(textualRow - 5, y + 2, arrowSymbol, SMLSIZE) | |
lcd.drawNumber(lcd.getLastPos() + 3, y, math.abs(verticalSpeed), PREC2+LEFT+MIDSIZE) | |
lcd.drawText(lcd.getLastPos(), y + 2, "m/s", SMLSIZE) | |
end | |
-- Show message | |
-- ************* | |
local msgString = "" | |
local msgTime = 0 | |
local function showMessage(msg) | |
msgString = msg | |
msgTime = getTime() | |
end | |
local function showMessages() | |
if msgString ~= "" and ((getTime() - msgTime) < 100) then | |
lcd.drawFilledRectangle(20, 20, 180, 20, ERASE) | |
lcd.drawRectangle(20, 20, 180, 20, SOLID) | |
lcd.drawText(22, 25, msgString, SMLSIZE) | |
else | |
msgString = "" | |
end | |
end | |
-- Main function | |
-- ************* | |
local test = false -- test flag (true to simulate telemetry data) | |
local wrkPitch, wrkRoll = 0, 0 | |
local function getTelemetryValuesSmartPort() | |
altitude = getValue("Alt") | |
speed = 1.8 * getValue("GSpd") | |
heading = getValue("Hdg") | |
distance_3D = getValue("Dist") | |
roll = getValue("AccX") | |
pitch = (360 + getValue("AccY")) % 360 | |
local gprc = getValue("Gprc") | |
if gprc == 0 then gprc = getValue("T2") end | |
vdop = bit32.rshift(gprc, 8) / 100 | |
hdop = bit32.band(gprc, 0xff) / 100 | |
local gpss = getValue("Gpss") | |
if gpss == 0 then gpss = getValue("T1") end | |
sats = gpss % 100 | |
if gpss >= 100 and gpss < 200 then gpsString = "GPS disconn.!" | |
elseif gpss >= 200 and gpss < 300 then gpsString = "No fix!" | |
elseif gpss > 300 and gpss < 400 then gpsString = "2D fix!" | |
elseif gpss > 400 and gpss < 500 then gpsString = "No home set!" | |
elseif gpss > 500 and gpss < 600 then gpsString = "" | |
else gpsString = "???" end | |
cellVoltage = getValue("Cell") | |
rssi = getValue("RSSI") | |
verticalSpeed = getValue("VSpd") | |
local mode = getValue("MODE") | |
if mode == 0 then mode = getValue("RPM") end | |
if mode >= 100 and mode < 200 then isArmed = false else isArmed = true end | |
local modeNumber = mode % 100 | |
if (mode % 100) == 0 then modeString = "Manual" | |
elseif modeNumber == 1 then modeString = "Acro" | |
elseif modeNumber == 2 then modeString = "Leveling" | |
elseif modeNumber == 3 then modeString = "MWRate" | |
elseif modeNumber == 4 then modeString = "Horizon" | |
elseif modeNumber == 5 then modeString = "AxisLock" | |
elseif modeNumber == 6 then modeString = "VirtualBar" | |
elseif modeNumber == 7 then modeString = "Stab1" | |
elseif modeNumber == 8 then modeString = "Stab2" | |
elseif modeNumber == 9 then modeString = "Stab3" | |
elseif modeNumber == 10 then modeString = "Autotune" | |
elseif modeNumber == 11 then modeString = "AltHold" | |
elseif modeNumber == 12 then modeString = "PosHold" | |
elseif modeNumber == 13 then modeString = "RTH" | |
elseif modeNumber == 14 then modeString = "PathPlan" | |
elseif modeNumber == 15 then modeString = "Tablet" | |
else modeString = "???" | |
end | |
-- note: getting GPS coordinates currently requires a tiny patch to OpenTx firmware to work | |
local latlon = getValue("GPS") | |
if latlon < 0 then latlon = (2^32) + latlon end | |
local isLat = false | |
local latlonSig = 1 | |
if bit32.band(latlon, 2 ^ 31) ~= 0 then isLat = false else isLat = true end | |
if bit32.band(latlon, 2 ^ 30) ~= 0 then latlonSig = -1 else latlonSig = 1 end | |
latlonCoord = bit32.band(latlon, (2 ^ 30) - 1) / 6 / 100000 * latlonSig | |
if isLat then | |
latitude = latlonCoord | |
else | |
longitude = latlonCoord | |
end | |
if latitude ~=0 and pilot_latitude == 0 and gpss > 500 then | |
pilot_latitude = latitude | |
end | |
if longitude ~= 0 and pilot_longitude == 0 and gpss > 500 then | |
pilot_longitude = longitude | |
end | |
end | |
local function getTelemetryValuesTest() | |
altitude = altitude + 0.2 | |
speed = speed + 0.1 | |
pilot_latitude, pilot_longitude = 46.465091, 6.895155 | |
-- latitude, longitude = 46.461958, 6.890692 -- 488 m | |
-- latitude, longitude = 46.464234, 6.896357 -- 132 m | |
latitude, longitude = 46.465202, 6.895870 -- 56 m | |
heading = (heading + 1) % 360 | |
distance_3D = (distance_3D + 0.5) % 300 | |
wrkPitch = (wrkPitch + 0.1) % 120 | |
pitch = (wrkPitch > 60 and 120 - wrkPitch - 30 or wrkPitch - 30) % 360 | |
wrkRoll = (wrkRoll + 0.5) % 120 | |
roll = (wrkRoll > 60 and 120 - wrkRoll - 30 or wrkRoll - 30) % 360 | |
hdop = 2.03 | |
vdop = 1.97 | |
sats = 9 | |
verticalSpeed = 2.546 | |
cellVoltage = 3.74 | |
rssi = 61 | |
modeString = "Leveling" | |
gpsString = "2D fix!" | |
isArmed = false | |
end | |
local function run(event) | |
gpsCalculation() | |
if test then distance_2D = distance_3D end | |
lcd.clear() | |
drawAltitude() | |
drawSpeed() | |
drawHeading() | |
drawPitch() | |
drawDistance() | |
drawHorizon() | |
drawMode() | |
drawRadar() | |
drawTextualTelemetry() | |
if event == EVT_ENTER_BREAK then | |
if pilote_heading == 0 then | |
showMessage("Radar orientation switched to pilot") | |
pilote_heading = heading | |
else | |
showMessage("Radar orientation switched to North") | |
pilote_heading = 0 | |
end | |
end | |
showMessages() | |
end | |
local function background() | |
getTelemetryValues() | |
end | |
local function init() | |
if test then | |
getTelemetryValues = getTelemetryValuesTest | |
else | |
getTelemetryValues = getTelemetryValuesSmartPort | |
end | |
end | |
return {run=run, background=background, init=init} |
I then tried to make the script lighter by removing the lines of code related to drawPitch(), drawHorizon() and getTelemetryValuesTest()
It went from 19kb to 15kb, and "managed" to get the 1st error back :
attempt to compare table with number
So, still not working with me.
I am curious about this line in the code :
-- note: getting GPS coordinates currently requires a tiny patch to OpenTx firmware to work
Do you have any details about this ?
Thanks
Eventually, it works !
But had to remove the artificial horizon...
I put my derivative script in my gist : https://gist.github.com/Sovxx/63b331caff1575b706338957f16f0f67
Hope it could help some people to enjoy the script !
Thanks !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
The script looks really cool !
I managed to have it displayed (with empty data) on my Taranis Plus with OpenTX 2.1.6 firmware
but when the transmitter receives the actual GPS coordinates, I get the following error :
I have then uptaded the OpenTX firmware to v2.1.7 and, no matter telemetry is on or off, got instead :
PS : I am not using taulabs, I just have neo-6m GPS module connected to an arduino running this code
https://github.com/SamuelBrucksch/diy-frsky-gps
which receives the "GPS" field (and others) just fine.
Thanks