GPS Widget voor FrSky Horus

Daar zijn op het Internet wel voorbeelden van te vinden. Misschien hulp vragen van iemand met een nautische achtergrond?

Heb al diverse voorbeelden gevonden (formules) alleen omzetten naar Lua, je kan niet echt lekker debuggen.

Ik heb 2 global variabelen aangemaakt.

TempLat en TempLon


Nu wil ik in de background functie bekijken of de waarde dit in deze variabelen anders is dan de actuele waarden uit thisWidget.gpsLat en thisWidget.gpsLong

Als dit anders is voer dan de berekening uit om de bearing uit te rekenen.. zodra dat gedaan is kopieer de actuele data in de Temp data.

https://bluemm.blogspot.com/2007/01/excel-formula-to-calculate-distance.html

=ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371

Deze formule probeer ik om te zetten.

Code:
if (thisWidget.gpsLat ~= TempLat) or (thisWidget.gpsLong ~= TempLon) then
 
  Head = math.acos(math.cos(math.rad(90-thisWidget.gpsLat)) * math.cos(math.rad(90-TempLat)) + math.sin(math.rad(90-thisWidget.gpsLat)) * math.sin(math.rad(90-TempLat)) * math.cos(math.rad(thisWidget.gpsLong-TempLon))) * 6371
 
  TempLat = thisWidget.gpsLat
  TempLon = thisWidget.gpsLong
 
  end
 
Nou volgens mij is dat redelijk goed te doen hoor. Bij het tekenen van het vliegtuig in het beeld doe ik omgekeerde. Ik heb een hoek en gebruik deze voor het omrekenen naar een verplaatsing op de x en y as.

Je hebt coordinaat A en B. Het verschil tussen deze twee coordinaten geeft je een verplaatsing over de X-as en een verplaatsing over de Y-as.
Dan volgt de formule asin((Ax-Bx)/(Ay-By))
 
Nou volgens mij is dat redelijk goed te doen hoor. Bij het tekenen van het vliegtuig in het beeld doe ik omgekeerde. Ik heb een hoek en gebruik deze voor het omrekenen naar een verplaatsing op de x en y as.

Je hebt coordinaat A en B. Het verschil tussen deze twee coordinaten geeft je een verplaatsing over de X-as en een verplaatsing over de Y-as.
Dan volgt de formule asin((Ax-Bx)/(Ay-By))
Hmmm nee zo eenvoudig is het toch niet want de afstandverhouding tussen Lat en Lon is niet gelijk.

Wat als je de laatste scherm positie pakt en de huidige. Die zijn wel gelijk aan elkaar.
 
Daarom is het beste om het uit te rekenen uit de coordinaten zelf. elke keer berekenen tov de vorige coordinaten.. wat ook rekening houdt met de kromming van de aarde.. (voor kleine kaartjes zoals deze niet zo super belangrijk is) maar toch :-)

Mijn wiskunde is niet echt helemaal je van het..maar formules zat te vinden, krijg ze alleen niet omgezet naar lua..

De coordinaten die in opentx gebruikt worden zijn decimale graden.. de formules zo te zien werken met radialen.
Ik ga er vanavond weer even voor zitten.. het moet gewoon lukken.
Als dit werkt, kan je er weer een check in maken, dat kijkt of de "Hdg" sensor aanwezig is.. en dan die pakt.. zo niet.. wordt het uitgerekend..

Hier nog wat voorbeelden..

https://www.movable-type.co.uk/scripts/latlong.html

alleen geen idee wat φ2 representeerd
 
Omrekenen van graden naar radialen wordt ook gedaan in mijn Lua script. Hiervoor gebruik je de functie math.rad(x in graden) omgekeerd math.deg(x in radialen)
 
alleen geen idee wat φ2 representeerd

1c8977bc7f8485346a4fffb966ce208c.jpg
 
Toch denk ik dat je prima de hoek vh vliegtuig kunt uitrekenen aan de hand van de verplaatsing op het scherm. Hierin zit eigenlijk de verhouding altijd verwerkt doordat je de coordinaten van de map ingeeft in het Lua script. Het werkt dus overal op de wereld waar je de kaart gebruikt en het zal niet 100% nauwkeurig zijn, maar dit is de weergave op het scherm ook niet omdat het maar 13pixels groot is.
 
Het lijkt er op dat het werkt..

Wel jammer. vroeger had je een gps simulator, ik moet echt buiten even gaan testen.

Code:
---- #########################################################################
---- #                                                                       #
---- # GPS Widget for FrSky Horus                                                  #
-----#                                                                       #
---- # License GPLv3: http://www.gnu.org/licenses/gpl-3.0.html               #
---- #                                                                       #
---- # This program is free software; you can redistribute it and/or modify  #
---- # it under the terms of the GNU General Public License version 3 as     #
---- # published by the Free Software Foundation.                            #
---- #                                                                       #
---- # Rev 0.1                                                                                         #
---- # Tonnie Oostbeek                                                                                  #
---- #                                                                       #
---- #########################################################################

    TempLat = 0
    TempLong = 0
    head = 0
   

local options = {
  { "TextColor", COLOR, Black },
  { "Imperial", BOOL, 0 },
  { "Map", VALUE, 1,1,10 },
}


-- in the create function you add all shared variables to the array containing the widget data ('thisWidget')
local function create(zone, options)
  local thisWidget  = { zone=zone, options=options}
 
  --create array containing all sensor ID's used for quicker retrieval
  local ID = {}
  ID.GPS = getFieldInfo("GPS") and getFieldInfo("GPS").id    or 0
  ID.Hdg = getFieldInfo("Hdg") and getFieldInfo("Hdg").id or 0
  ID.GSpd = getFieldInfo("GSpd") and getFieldInfo("GSpd").id or 0
  ID.GDis = getFieldInfo("GDis") and getFieldInfo("GDis").id or 0
  ID.GAlt = getFieldInfo("GAlt") and getFieldInfo("GAlt").id or 0
 
  --add ID to thisWidget
  thisWidget.ID = ID  

  --create array containing all map info per map size
  local map = {North={},South={},West={},East={},wx={},wy={},zx={},zy={}}

  -- Avenhorn ---
  -- coordinates for the small map.
  map.North.small = 52.633785
  map.South.small = 52.614104
  map.West.small = 4.930978
  map.East.small = 4.988488
  -- No Fly Zone screen coordinates for small map--
  map.wx.small = 0
  map.wy.small = 0
  map.zx.small = 0
  map.zy.small = 0

  -- coordinates for the medium map.
  map.North.medium = 52.641134
  map.South.medium = 52.611316
  map.West.medium = 4.916037
  map.East.medium = 5.002736
  -- No Fly Zone screen coordinates for medium map--
  map.wx.medium = 0
  map.wy.medium = 0
  map.zx.medium = 0
  map.zy.medium = 0

  --coordinates for the largest map.
  map.North.large = 52.651519
  map.South.large = 52.606515
  map.West.large = 4.893172
  map.East.large = 5.023711
  -- No Fly Zone screen coordinates for large map--
  map.wx.large = 0
  map.wy.large = 0
  map.zx.large = 0
  map.zy.large = 0

  --add one bitmap per map size and set current map size
  map.bmp={}
  map.bmp.small = Bitmap.open("/Widgets/Mapnew/map2a.png")
  map.bmp.medium = Bitmap.open("/Widgets/Mapnew/map2b.png")
  map.bmp.large = Bitmap.open("/Widgets/Mapnew/map2c.png")


--[[  
  -- MVC Pegasus ---
  -- coordinates for the small map.
  map.North.small = 52.734818
  map.South.small = 52.731422
  map.West.small = 5.273051
  map.East.small = 5.283480
  -- No Fly Zone screen coordinates for small map--
  map.wx.small = 0
  map.wy.small = 183
  map.zx.small = 261
  map.zy.small = 271

  -- coordinates for the medium map.
  map.North.medium = 52.736097
  map.South.medium = 52.730953
  map.West.medium = 5.270331
  map.East.medium = 5.286034
  -- No Fly Zone screen coordinates for medium map--
  map.wx.medium = 0
  map.wy.medium = 153
  map.zx.medium = 323
  map.zy.medium = 271

  --coordinates for the largest map.
  map.North.large = 52.737878
  map.South.large = 52.730145
  map.West.large = 5.266206
  map.East.large = 5.289811
  -- No Fly Zone screen coordinates for large map--
  map.wx.large = 0
  map.wy.large = 121
  map.zx.large = 354
  map.zy.large = 271

       
  --add one bitmap per map size and set current map size
  map.bmp={}
  map.bmp.small = Bitmap.open("/Widgets/Mapnew/map1a.png")
  map.bmp.medium = Bitmap.open("/Widgets/Mapnew/map1b.png")
  map.bmp.large = Bitmap.open("/Widgets/Mapnew/map1c.png")
--]]


  --set current size
  map.current = "large"

  --add the map array to thisWidget
  thisWidget.map = map  
 
  --return the thisWidget array to the opentx API, containing all data to be shared across functions
  return thisWidget
 
end

local function background(thisWidget)

  ImperialSet = thisWidget.options.Imperial
 
  thisWidget.gpsLatLong = getValue(thisWidget.ID.GPS)
  if  (type(thisWidget.gpsLatLong) ~= "table") then
    thisWidget.ID.GPS = getFieldInfo("GPS") and getFieldInfo("GPS").id    or 0
    thisWidget.ID.Hdg = getFieldInfo("Hdg") and getFieldInfo("Hdg").id or 0
    thisWidget.ID.GSpd = getFieldInfo("GSpd") and getFieldInfo("GSpd").id or 0
    thisWidget.ID.GDis = getFieldInfo("GDis") and getFieldInfo("GDis").id or 0
    thisWidget.ID.GAlt = getFieldInfo("GAlt") and getFieldInfo("GAlt").id or 0
    model.setGlobalVariable(8,0,0)
    return
  end
 
  thisWidget.Distance= getValue(thisWidget.ID.GDis)
  thisWidget.headingDeg= getValue(thisWidget.ID.Hdg)
  thisWidget.Speed= getValue(thisWidget.ID.GSpd)
  thisWidget.Altitude = getValue(thisWidget.ID.GAlt)
  thisWidget.gpsLat = thisWidget.gpsLatLong.lat
  thisWidget.gpsLong = thisWidget.gpsLatLong.lon
 
-- Part for loading the correct zoomlevel of the map

-- coordinates for the smallest map. These can be found by placing the image back into Google Earth and looking at the overlay
-- parameters

  local North = thisWidget.map.North
  local South = thisWidget.map.South
  local East = thisWidget.map.East
  local West = thisWidget.map.West
   
  if thisWidget.gpsLat < North.small and thisWidget.gpsLat > South.small and thisWidget.gpsLong < East.small and thisWidget.gpsLong > West.small then  
    thisWidget.map.current = "small"
  elseif thisWidget.gpsLat < North.medium and thisWidget.gpsLat > South.medium and thisWidget.gpsLong < East.medium and thisWidget.gpsLong > West.medium then  
    thisWidget.map.current = "medium"
  else  
    thisWidget.map.current = "large"
  end

-- Part for setting the correct zoomlevel ends here.

-- Calculate Position in relation to map.

  North = North[thisWidget.map.current]
  South = South[thisWidget.map.current]
  East = East[thisWidget.map.current]
  West = West[thisWidget.map.current]
  local wx = thisWidget.map.wx[thisWidget.map.current]
  local wy = thisWidget.map.wy[thisWidget.map.current]
  local zx = thisWidget.map.zx[thisWidget.map.current]
  local zy = thisWidget.map.zy[thisWidget.map.current]


  thisWidget.x = math.floor(480*((thisWidget.gpsLong - West)/(East - West)))
  thisWidget.y = math.floor(272*((North - thisWidget.gpsLat)/(North - South)))

  thisWidget.x=math.max(10,thisWidget.x)
  thisWidget.x=math.min(thisWidget.x,470)

  thisWidget.y=math.max(10,thisWidget.y)
  thisWidget.y=math.min(thisWidget.y,262)

  if ((thisWidget.x - wx)*(zy-wy))-((thisWidget.y - wy)*(zx-wx)) < 0 then
    model.setGlobalVariable(8,0,0)
  else
    model.setGlobalVariable(8,0,1)
  end

end

function calc_bearing()

end

local function update(thisWidget, options)
  thisWidget.options = options
end

local function refresh(thisWidget)
 
  local x = 0
  local y = 0
 
 
  background(thisWidget)

    if (thisWidget.gpsLat == NIL) or (thisWidget.gpsLong == NIL) then
    else
        if (thisWidget.gpsLat ~= TempLat) or (thisWidget.gpsLong ~= TempLong) then
   
            --Head = math.acos(math.cos(math.rad(90-thisWidget.gpsLat)) * math.cos(math.rad(90-TempLat)) + math.sin(math.rad(90-thisWidget.gpsLat)) * math.sin(math.rad(90-TempLat)) * math.cos(math.rad(thisWidget.gpsLong-TempLon))) * 6371
   
            y = math.sin(thisWidget.gpsLat-TempLat) * math.cos(thisWidget.gpsLong)
            x = math.cos(TempLong) * math.sin(thisWidget.gpsLong) - math.sin(TempLong) * math.cos(thisWidget.gpsLong) * math.cos(thisWidget.gpsLat - TempLat)
            head = math.deg(math.atan2(y,x))

            if head < 0 then
                head = 360 + head
            end
           
            TempLat = thisWidget.gpsLat
            TempLong = thisWidget.gpsLong
   
        end
    end

  if  (type(thisWidget.gpsLatLong) ~= "table") then
    lcd.drawBitmap(thisWidget.map.bmp.large, thisWidget.zone.x -10, thisWidget.zone.y -10)
    lcd.setColor(CUSTOM_COLOR, lcd.RGB(255,0,0))
    lcd.drawText( 120, 130, "No GPS SIGNAL", DBLSIZE, CUSTOM_COLOR)
    return
  end

  local xvalues = { }
  local yvalues = { }
  --local headingDeg = thisWidget.headingDeg
  local headingDeg = head
  local x = thisWidget.x
  local y = thisWidget.y
--                     A
--                     |
--                     |
-- C   _________________|___________________  D
--                     |
--                     |
--                     |
--                     |
--                     |
--                     |
--                     |
--                E ---|--- F
--                     B


  xvalues.ax = x + (4 * math.sin(math.rad(headingDeg)))                             -- front of fuselage x position
  yvalues.ay = y - (4 * math.cos(math.rad(headingDeg)))                             -- front of fuselage y position
  xvalues.bx = x - (7 * math.sin(math.rad(headingDeg)))                             -- rear of fuselage x position
  yvalues.by = y + (7 * math.cos(math.rad(headingDeg)))                             -- rear of fuselage y position
  xvalues.cx = x + (10 * math.cos(math.rad(headingDeg)))                             -- left wingtip x position
  yvalues.cy = y + (10 * math.sin(math.rad(headingDeg)))                            -- left wingtip y position
  xvalues.dx = x - (10 * math.cos(math.rad(headingDeg)))                            -- right wingtip x position
  yvalues.dy = y - (10 * math.sin(math.rad(headingDeg)))                            -- right wingtip y position
  xvalues.ex = x - ((7 * math.sin(math.rad(headingDeg))) + (3 * math.cos(math.rad(headingDeg))))    -- left tailwing tip x position
  yvalues.ey = y + ((7 * math.cos(math.rad(headingDeg))) - (3 * math.sin(math.rad(headingDeg))))    -- left tailwing tip y position
  xvalues.fx = x - ((7 * math.sin(math.rad(headingDeg))) - (3 * math.cos(math.rad(headingDeg))))    -- right tailwing tip x position
  yvalues.fy = y + ((7 * math.cos(math.rad(headingDeg))) + (3 * math.sin(math.rad(headingDeg))))    -- right tailwing tip y position
 
 
--draw background
  lcd.drawBitmap(thisWidget.map.bmp[thisWidget.map.current], thisWidget.zone.x -10, thisWidget.zone.y -10)

--draw info

    if thisWidget.gpsLat > 0 then
        NS = "N"
    else
        NS = "S"
    end

    if thisWidget.gpsLong > 0 then
        EW = "E"
    else
        EW = "W"
    end
   
    if ImperialSet == 1 then
        FM = "ft"
        FMx = "miles"
        SPD = "mph"
    else
        FM = "m"
        FMx = "Kilometers"
        SPD = "km/h"
    end

  lcd.setColor(CUSTOM_COLOR, WHITE)
 
  lcd.drawText(10, 5, "Speed: "..math.floor(thisWidget.Speed)..SPD , CUSTOM_COLOR  + SHADOWED)  
  lcd.drawText(10, 25, "Altitude: "..math.floor(thisWidget.Altitude)..FM , CUSTOM_COLOR  + SHADOWED)  
  lcd.drawText(180, 5, "Distance: "..math.floor(thisWidget.Distance)..FM , CUSTOM_COLOR + SHADOWED)

  --lcd.drawText(460, 5, "Heading: "..math.floor(thisWidget.headingDeg).."deg" , CUSTOM_COLOR + RIGHT + SHADOWED)
  lcd.drawText(460, 5, "Heading: "..head.."deg" , CUSTOM_COLOR + RIGHT + SHADOWED)
 
  lcd.drawText(10, 247, "Lat: "..NS..math.abs(thisWidget.gpsLat).." / Lon: "..EW..math.abs(thisWidget.gpsLong), CUSTOM_COLOR + SMLSIZE +SHADOWED)
  lcd.drawText(460, 247, "X:"..thisWidget.x.." / Y:"..thisWidget.y , CUSTOM_COLOR + RIGHT + SMLSIZE + SHADOWED)
 
--draw plane
  lcd.setColor(CUSTOM_COLOR, lcd.RGB(255,255,255))
  lcd.drawLine(xvalues.ax, yvalues.ay, xvalues.bx, yvalues.by, SOLID, CUSTOM_COLOR)
  lcd.drawLine(xvalues.cx, yvalues.cy, xvalues.dx, yvalues.dy, SOLID, CUSTOM_COLOR)
  lcd.drawLine(xvalues.ex, yvalues.ey, xvalues.fx, yvalues.fy, SOLID, CUSTOM_COLOR)

--draw noflightzone
  lcd.setColor(CUSTOM_COLOR, lcd.RGB(255,0,0))
  lcd.drawLine(thisWidget.map.wx[thisWidget.map.current], thisWidget.map.wy[thisWidget.map.current], thisWidget.map.zx[thisWidget.map.current], thisWidget.map.zy[thisWidget.map.current], SOLID, CUSTOM_COLOR)

end
return { name="Map", options=options, create=create, update=update, background=background, refresh=refresh }
 
Laatst bewerkt:
Het lijkt er op dat het werkt..

Wel jammer. vroeger had je een gps simulator, ik moet echt buiten even gaan testen.

Code:
---- #########################################################################
---- #                                                                       #
---- # GPS Widget for FrSky Horus                                                  #
-----#                                                                       #
---- # License GPLv3: http://www.gnu.org/licenses/gpl-3.0.html               #
---- #                                                                       #
---- # This program is free software; you can redistribute it and/or modify  #
---- # it under the terms of the GNU General Public License version 3 as     #
---- # published by the Free Software Foundation.                            #
---- #                                                                       #
---- # Rev 0.1                                                                                         #
---- # Tonnie Oostbeek                                                                                  #
---- #                                                                       #
---- #########################################################################

    TempLat = 0
    TempLong = 0
    head = 0
   

local options = {
  { "TextColor", COLOR, Black },
  { "Imperial", BOOL, 0 },
  { "Map", VALUE, 1,1,10 },
}


-- in the create function you add all shared variables to the array containing the widget data ('thisWidget')
local function create(zone, options)
  local thisWidget  = { zone=zone, options=options}
 
  --create array containing all sensor ID's used for quicker retrieval
  local ID = {}
  ID.GPS = getFieldInfo("GPS") and getFieldInfo("GPS").id    or 0
  ID.Hdg = getFieldInfo("Hdg") and getFieldInfo("Hdg").id or 0
  ID.GSpd = getFieldInfo("GSpd") and getFieldInfo("GSpd").id or 0
  ID.GDis = getFieldInfo("GDis") and getFieldInfo("GDis").id or 0
  ID.GAlt = getFieldInfo("GAlt") and getFieldInfo("GAlt").id or 0
 
  --add ID to thisWidget
  thisWidget.ID = ID  

  --create array containing all map info per map size
  local map = {North={},South={},West={},East={},wx={},wy={},zx={},zy={}}

  -- Avenhorn ---
  -- coordinates for the small map.
  map.North.small = 52.633785
  map.South.small = 52.614104
  map.West.small = 4.930978
  map.East.small = 4.988488
  -- No Fly Zone screen coordinates for small map--
  map.wx.small = 0
  map.wy.small = 0
  map.zx.small = 0
  map.zy.small = 0

  -- coordinates for the medium map.
  map.North.medium = 52.641134
  map.South.medium = 52.611316
  map.West.medium = 4.916037
  map.East.medium = 5.002736
  -- No Fly Zone screen coordinates for medium map--
  map.wx.medium = 0
  map.wy.medium = 0
  map.zx.medium = 0
  map.zy.medium = 0

  --coordinates for the largest map.
  map.North.large = 52.651519
  map.South.large = 52.606515
  map.West.large = 4.893172
  map.East.large = 5.023711
  -- No Fly Zone screen coordinates for large map--
  map.wx.large = 0
  map.wy.large = 0
  map.zx.large = 0
  map.zy.large = 0

  --add one bitmap per map size and set current map size
  map.bmp={}
  map.bmp.small = Bitmap.open("/Widgets/Mapnew/map2a.png")
  map.bmp.medium = Bitmap.open("/Widgets/Mapnew/map2b.png")
  map.bmp.large = Bitmap.open("/Widgets/Mapnew/map2c.png")


--[[  
  -- MVC Pegasus ---
  -- coordinates for the small map.
  map.North.small = 52.734818
  map.South.small = 52.731422
  map.West.small = 5.273051
  map.East.small = 5.283480
  -- No Fly Zone screen coordinates for small map--
  map.wx.small = 0
  map.wy.small = 183
  map.zx.small = 261
  map.zy.small = 271

  -- coordinates for the medium map.
  map.North.medium = 52.736097
  map.South.medium = 52.730953
  map.West.medium = 5.270331
  map.East.medium = 5.286034
  -- No Fly Zone screen coordinates for medium map--
  map.wx.medium = 0
  map.wy.medium = 153
  map.zx.medium = 323
  map.zy.medium = 271

  --coordinates for the largest map.
  map.North.large = 52.737878
  map.South.large = 52.730145
  map.West.large = 5.266206
  map.East.large = 5.289811
  -- No Fly Zone screen coordinates for large map--
  map.wx.large = 0
  map.wy.large = 121
  map.zx.large = 354
  map.zy.large = 271

       
  --add one bitmap per map size and set current map size
  map.bmp={}
  map.bmp.small = Bitmap.open("/Widgets/Mapnew/map1a.png")
  map.bmp.medium = Bitmap.open("/Widgets/Mapnew/map1b.png")
  map.bmp.large = Bitmap.open("/Widgets/Mapnew/map1c.png")
--]]


  --set current size
  map.current = "large"

  --add the map array to thisWidget
  thisWidget.map = map  
 
  --return the thisWidget array to the opentx API, containing all data to be shared across functions
  return thisWidget
 
end

local function background(thisWidget)

  ImperialSet = thisWidget.options.Imperial
 
  thisWidget.gpsLatLong = getValue(thisWidget.ID.GPS)
  if  (type(thisWidget.gpsLatLong) ~= "table") then
    thisWidget.ID.GPS = getFieldInfo("GPS") and getFieldInfo("GPS").id    or 0
    thisWidget.ID.Hdg = getFieldInfo("Hdg") and getFieldInfo("Hdg").id or 0
    thisWidget.ID.GSpd = getFieldInfo("GSpd") and getFieldInfo("GSpd").id or 0
    thisWidget.ID.GDis = getFieldInfo("GDis") and getFieldInfo("GDis").id or 0
    thisWidget.ID.GAlt = getFieldInfo("GAlt") and getFieldInfo("GAlt").id or 0
    model.setGlobalVariable(8,0,0)
    return
  end
 
  thisWidget.Distance= getValue(thisWidget.ID.GDis)
  thisWidget.headingDeg= getValue(thisWidget.ID.Hdg)
  thisWidget.Speed= getValue(thisWidget.ID.GSpd)
  thisWidget.Altitude = getValue(thisWidget.ID.GAlt)
  thisWidget.gpsLat = thisWidget.gpsLatLong.lat
  thisWidget.gpsLong = thisWidget.gpsLatLong.lon
 
-- Part for loading the correct zoomlevel of the map

-- coordinates for the smallest map. These can be found by placing the image back into Google Earth and looking at the overlay
-- parameters

  local North = thisWidget.map.North
  local South = thisWidget.map.South
  local East = thisWidget.map.East
  local West = thisWidget.map.West
   
  if thisWidget.gpsLat < North.small and thisWidget.gpsLat > South.small and thisWidget.gpsLong < East.small and thisWidget.gpsLong > West.small then  
    thisWidget.map.current = "small"
  elseif thisWidget.gpsLat < North.medium and thisWidget.gpsLat > South.medium and thisWidget.gpsLong < East.medium and thisWidget.gpsLong > West.medium then  
    thisWidget.map.current = "medium"
  else  
    thisWidget.map.current = "large"
  end

-- Part for setting the correct zoomlevel ends here.

-- Calculate Position in relation to map.

  North = North[thisWidget.map.current]
  South = South[thisWidget.map.current]
  East = East[thisWidget.map.current]
  West = West[thisWidget.map.current]
  local wx = thisWidget.map.wx[thisWidget.map.current]
  local wy = thisWidget.map.wy[thisWidget.map.current]
  local zx = thisWidget.map.zx[thisWidget.map.current]
  local zy = thisWidget.map.zy[thisWidget.map.current]


  thisWidget.x = math.floor(480*((thisWidget.gpsLong - West)/(East - West)))
  thisWidget.y = math.floor(272*((North - thisWidget.gpsLat)/(North - South)))

  thisWidget.x=math.max(10,thisWidget.x)
  thisWidget.x=math.min(thisWidget.x,470)

  thisWidget.y=math.max(10,thisWidget.y)
  thisWidget.y=math.min(thisWidget.y,262)

  if ((thisWidget.x - wx)*(zy-wy))-((thisWidget.y - wy)*(zx-wx)) < 0 then
    model.setGlobalVariable(8,0,0)
  else
    model.setGlobalVariable(8,0,1)
  end

end

function calc_bearing()

end

local function update(thisWidget, options)
  thisWidget.options = options
end

local function refresh(thisWidget)
 
  local x = 0
  local y = 0
 
 
  background(thisWidget)

    if (thisWidget.gpsLat == NIL) or (thisWidget.gpsLong == NIL) then
    else
        if (thisWidget.gpsLat ~= TempLat) or (thisWidget.gpsLong ~= TempLong) then
   
            --Head = math.acos(math.cos(math.rad(90-thisWidget.gpsLat)) * math.cos(math.rad(90-TempLat)) + math.sin(math.rad(90-thisWidget.gpsLat)) * math.sin(math.rad(90-TempLat)) * math.cos(math.rad(thisWidget.gpsLong-TempLon))) * 6371
   
            y = math.sin(thisWidget.gpsLat-TempLat) * math.cos(thisWidget.gpsLong)
            x = math.cos(TempLong) * math.sin(thisWidget.gpsLong) - math.sin(TempLong) * math.cos(thisWidget.gpsLong) * math.cos(thisWidget.gpsLat - TempLat)
            head = math.deg(math.atan2(y,x))

            if head < 0 then
                head = 360 + head
            end
           
            TempLat = thisWidget.gpsLat
            TempLong = thisWidget.gpsLong
   
        end
    end

  if  (type(thisWidget.gpsLatLong) ~= "table") then
    lcd.drawBitmap(thisWidget.map.bmp.large, thisWidget.zone.x -10, thisWidget.zone.y -10)
    lcd.setColor(CUSTOM_COLOR, lcd.RGB(255,0,0))
    lcd.drawText( 120, 130, "No GPS SIGNAL", DBLSIZE, CUSTOM_COLOR)
    return
  end

  local xvalues = { }
  local yvalues = { }
  --local headingDeg = thisWidget.headingDeg
  local headingDeg = head
  local x = thisWidget.x
  local y = thisWidget.y
--                     A
--                     |
--                     |
-- C   _________________|___________________  D
--                     |
--                     |
--                     |
--                     |
--                     |
--                     |
--                     |
--                E ---|--- F
--                     B


  xvalues.ax = x + (4 * math.sin(math.rad(headingDeg)))                             -- front of fuselage x position
  yvalues.ay = y - (4 * math.cos(math.rad(headingDeg)))                             -- front of fuselage y position
  xvalues.bx = x - (7 * math.sin(math.rad(headingDeg)))                             -- rear of fuselage x position
  yvalues.by = y + (7 * math.cos(math.rad(headingDeg)))                             -- rear of fuselage y position
  xvalues.cx = x + (10 * math.cos(math.rad(headingDeg)))                             -- left wingtip x position
  yvalues.cy = y + (10 * math.sin(math.rad(headingDeg)))                            -- left wingtip y position
  xvalues.dx = x - (10 * math.cos(math.rad(headingDeg)))                            -- right wingtip x position
  yvalues.dy = y - (10 * math.sin(math.rad(headingDeg)))                            -- right wingtip y position
  xvalues.ex = x - ((7 * math.sin(math.rad(headingDeg))) + (3 * math.cos(math.rad(headingDeg))))    -- left tailwing tip x position
  yvalues.ey = y + ((7 * math.cos(math.rad(headingDeg))) - (3 * math.sin(math.rad(headingDeg))))    -- left tailwing tip y position
  xvalues.fx = x - ((7 * math.sin(math.rad(headingDeg))) - (3 * math.cos(math.rad(headingDeg))))    -- right tailwing tip x position
  yvalues.fy = y + ((7 * math.cos(math.rad(headingDeg))) + (3 * math.sin(math.rad(headingDeg))))    -- right tailwing tip y position
 
 
--draw background
  lcd.drawBitmap(thisWidget.map.bmp[thisWidget.map.current], thisWidget.zone.x -10, thisWidget.zone.y -10)

--draw info

    if thisWidget.gpsLat > 0 then
        NS = "N"
    else
        NS = "S"
    end

    if thisWidget.gpsLong > 0 then
        EW = "E"
    else
        EW = "W"
    end
   
    if ImperialSet == 1 then
        FM = "ft"
        FMx = "miles"
        SPD = "mph"
    else
        FM = "m"
        FMx = "Kilometers"
        SPD = "km/h"
    end

  lcd.setColor(CUSTOM_COLOR, WHITE)
 
  lcd.drawText(10, 5, "Speed: "..math.floor(thisWidget.Speed)..SPD , CUSTOM_COLOR  + SHADOWED)  
  lcd.drawText(10, 25, "Altitude: "..math.floor(thisWidget.Altitude)..FM , CUSTOM_COLOR  + SHADOWED)  
  lcd.drawText(180, 5, "Distance: "..math.floor(thisWidget.Distance)..FM , CUSTOM_COLOR + SHADOWED)

  --lcd.drawText(460, 5, "Heading: "..math.floor(thisWidget.headingDeg).."deg" , CUSTOM_COLOR + RIGHT + SHADOWED)
  lcd.drawText(460, 5, "Heading: "..head.."deg" , CUSTOM_COLOR + RIGHT + SHADOWED)
 
  lcd.drawText(10, 247, "Lat: "..NS..math.abs(thisWidget.gpsLat).." / Lon: "..EW..math.abs(thisWidget.gpsLong), CUSTOM_COLOR + SMLSIZE +SHADOWED)
  lcd.drawText(460, 247, "X:"..thisWidget.x.." / Y:"..thisWidget.y , CUSTOM_COLOR + RIGHT + SMLSIZE + SHADOWED)
 
--draw plane
  lcd.setColor(CUSTOM_COLOR, lcd.RGB(255,255,255))
  lcd.drawLine(xvalues.ax, yvalues.ay, xvalues.bx, yvalues.by, SOLID, CUSTOM_COLOR)
  lcd.drawLine(xvalues.cx, yvalues.cy, xvalues.dx, yvalues.dy, SOLID, CUSTOM_COLOR)
  lcd.drawLine(xvalues.ex, yvalues.ey, xvalues.fx, yvalues.fy, SOLID, CUSTOM_COLOR)

--draw noflightzone
  lcd.setColor(CUSTOM_COLOR, lcd.RGB(255,0,0))
  lcd.drawLine(thisWidget.map.wx[thisWidget.map.current], thisWidget.map.wy[thisWidget.map.current], thisWidget.map.zx[thisWidget.map.current], thisWidget.map.zy[thisWidget.map.current], SOLID, CUSTOM_COLOR)

end
return { name="Map", options=options, create=create, update=update, background=background, refresh=refresh }
Debuggen en gps simulator, beide beschikbaar in opentx companion. Met simulator zelfs persistent in je otx fole, dus alsof een echte radio.

Toch nog eens door mijn blog heenbladeren, en de Lua thread ook, beide op rcgroups.
 
Debuggen en gps simulator, beide beschikbaar in opentx companion. Met simulator zelfs persistent in je otx fole, dus alsof een echte radio.

Toch nog eens door mijn blog heenbladeren, en de Lua thread ook, beide op rcgroups.

Ik heb van de week al redelijk door jouw blogs heen gebladerd :-) zeker dingetjes gevonden die handig zijn.

Alleen wat ik met gps simulator bedoel is deze:

 
Ik heb van de week al redelijk door jouw blogs heen gebladerd :-) zeker dingetjes gevonden die handig zijn.

Alleen wat ik met gps simulator bedoel is deze:

Ok. Maar je kan toch nog steeds logfiles afspelen in de telemetrie simulator.

En gps coördinaten handmatig ingeven. Daarna sensor discoveren in radio sim en klaar?
 
Dat kan ook, maar moet je wel een log file hebben ;-) ik ga zo even een rondje rijden hier in de buurt.
ik heb ooit voor android een GPS simulator geschreven.. kijken of ik die via openxsensor aan de praat krijg.
 
En het werkt :-)

Er waren 2 problemen, de berekening was niet juist. ik moest de boel nog omzetten naar radialen in de berekening.
En het vliegtuigje sprong alle kanten op tijdens het bewegen.. dit kwam omdat ik eerst keek of Lattitude was veranderd OF Longtitude.
Hier werd het tuigje erg onrustig van..
Ik voer nu de berekening pas uit.. als beide zijn veranderd.. dit gaat nu veel rustiger.

Code:
    if (thisWidget.gpsLat == NIL) or (thisWidget.gpsLong == NIL) then
    else
        if (thisWidget.gpsLat ~= TempLat) and (thisWidget.gpsLong ~= TempLong) then

            y = math.sin(math.rad(thisWidget.gpsLong)-math.rad(TempLong)) * math.cos(math.rad(thisWidget.gpsLat))
            x = math.cos(math.rad(TempLat)) * math.sin(math.rad(thisWidget.gpsLat)) - math.sin(math.rad(TempLat)) * math.cos(math.rad(thisWidget.gpsLat)) * math.cos(math.rad(thisWidget.gpsLat) - math.rad(TempLat))
            
            head = math.deg(math.atan2(y,x))
            
            if head < 0 then
                head = 360 + head
            end
                
            TempLat = thisWidget.gpsLat
            TempLong = thisWidget.gpsLong
    
        end
    end
 
En het werkt :-)

Er waren 2 problemen, de berekening was niet juist. ik moest de boel nog omzetten naar radialen in de berekening.
En het vliegtuigje sprong alle kanten op tijdens het bewegen.. dit kwam omdat ik eerst keek of Lattitude was veranderd OF Longtitude.
Hier werd het tuigje erg onrustig van..
Ik voer nu de berekening pas uit.. als beide zijn veranderd.. dit gaat nu veel rustiger.

Code:
    if (thisWidget.gpsLat == NIL) or (thisWidget.gpsLong == NIL) then
    else
        if (thisWidget.gpsLat ~= TempLat) and (thisWidget.gpsLong ~= TempLong) then

            y = math.sin(math.rad(thisWidget.gpsLong)-math.rad(TempLong)) * math.cos(math.rad(thisWidget.gpsLat))
            x = math.cos(math.rad(TempLat)) * math.sin(math.rad(thisWidget.gpsLat)) - math.sin(math.rad(TempLat)) * math.cos(math.rad(thisWidget.gpsLat)) * math.cos(math.rad(thisWidget.gpsLat) - math.rad(TempLat))
            
            head = math.deg(math.atan2(y,x))
            
            if head < 0 then
                head = 360 + head
            end
                
            TempLat = thisWidget.gpsLat
            TempLong = thisWidget.gpsLong
    
        end
    end
Eigenlijk moet je een huidige en een nieuwe heading uitrekenen, en de huidige updaten als de nieuwe genoeg afwijkt.
 
Ik kan je niet helemaal volgen wat er dan anders zou zijn als nu? en wat is genoeg? stel dat de koers ineens maar 1 graad gaat afwijken.. wil ik dat wel weten.
Dat doet de gewone gps ook.
 
Dan zul je de koers wel als tekst aan moeten geven, want een verdraaiing van 1 graag zul je niet zien een het getekende vliegtuigje lijkt mij.
 
Vandaag gevlogen, ging perfect.. alleen de plaatjes waren erggg donker.. heb ze nu weer even door paint.net getrokken en de helderheid wat omhoog gezet.
Verder heb ik nog wat maximale waardes toegevoegd aan het scherm.

screenshot_x10_19-09-08_21-44-16.png


Ik zat nog te denken over het idee met meerdere maps.
Zoals je nu selecteerd uit je 3 verschillende zoom niveaus.. kan je natuurlijk ook je mappen kiezen..

Verder ga ik me nog even verdiepen in het omschakelen tussen GPS Altitude en Vario Altitude.

Ik was ook nog bezig geweest om het tuigje wat "dikker" te maken.. dus in plaats van 3x 1px lijntje.. 3x 3px lijntjes.. ik moet nu soms nog even zoeken op het scherm :p

@toostbeek, jij vertelde dat je nog je laatste versie online ging zetten? is daar veel aan veranderd?

Hieronder in iedergeval mijn laatste variant :)
 

Bijlagen

Back
Top