Le forum français des radios OpenTX ou FrOS
Le forum français des radios OpenTX ou FrOS
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment : -20%
-20% Récupérateur à eau mural 300 ...
Voir le deal
79 €

Recherche utilisateur script LUA avec naza can bus+ teensy

Aller en bas

Recherche utilisateur script LUA avec naza can bus+ teensy Empty Recherche utilisateur script LUA avec naza can bus+ teensy

Message par Invité Mar 19 Déc 2017 - 18:30

Bonsoir,

Je recherche des utilisateurs de la télémétrie avec un contrôleur de vol naza+gps et le décodage via teensy.

J'ai réalisé le montage du post : https://frskytaranis.forumactif.org/t1779-naza-canbus-frsky-s-port

Je recois bien des données sur une radio taranis X9D opentx 2.1.9, j'ai modifié un script lua :
Code:

-- ######################################################
-- ## Script by Ollicious,  bowdown@gmx.net            ##
-- ## V 1.0, 2015/09/15                                ##
-- ## Dynamic design via initial values and functions  ##
-- ## Some of the Widgets and BMPs based on work by    ##
-- ## Sockeye                       ##
-- ######################################################

-- #################### Definitions #####################

------------------------------------------------------------
-- Widget definition:                                     --
-- The first line is commented and does the same as the   --
-- multiple lines below                                   --
-- Decide which format you prefer and then edit the array --
-- accordingly to how you want the widgets placed.        --
--                                                        --
-- Widgets in V1.0                                        --
-- Voltage: "battery", to be put in column alone          --
-- RSSI: "rssi", to be put in column alone                --
-- Consumption: "capacity", to be put in column alone     --
-- Flightmode: "fm"                                       --
-- GPS Status: "gps"                                      --
-- Timer: "timer"                                         --
-- Distance: "dist"                                       --
-- Height: "height"                                       --
-- Speed: "speed"                                         --
-- Speed: "heading"                                       --
-- Homepoint: "hp"                                        --
-- Logging: "logging"                                     --
--                                                        --
-- If you add own widgets, you need to add en entry to    --
-- function callWidget(name, xCoord, yCoord).             --
--                                                        --
------------------------------------------------------------
-- Examples:
-- Two single row columns, one three row columns, one single row column:
-- local widgetDefinition = {{"battery"},{"capacity"},{"dist", "height", "hp"},{"rssi"}}
-- Three Columns, single row:
-- local widgetDefinition = {{"battery"},{"capacity"},{"rssi"}}
-- Single Column, three rows:
-- local widgetDefinition = {{"fm", "gps","timer"}}
-- Single Column, single row:
-- local widgetDefinition = {{"battery"}}

local widgetDefinition = {{"battery"},{"fm", "gps","timer"},{"dist", "height", "speed"},{"hp","logging","heading"}}

-- local widgetDefinition = {}
-- widgetDefinition[1] = {"battery"}
-- widgetDefinition[2] = {"capacity"}
-- widgetDefinition[3] = {"rssi"}
-- widgetDefinition[4] = {"fm", "gps","timer"}
-- widgetDefinition[5] = {"dist", "height", "home"}

-- Edit to set the width of single widget columns
local xOffsetSingle = 35

-- Leave as is!
local displayWidth = 212
local displayHeight = 64
local xOffset
local xOffsetMulti
local numSingleCols
local numMultiCols

local myNumSat                                
local myQualSat                                
local gpsCurrentLocation
local gpsId
local gpsLatLon


-- ################### Functions ########################

--------------
-- Rounding --
--------------
local function rnd(v,d)
 if d then
 return math.floor((v*10^d)+0.5)/(10^d)
 else
 return math.floor(v+0.5)
 end
end

------------------
-- Telemetry ID --
------------------
local function getTelemetryId(name)
 field = getFieldInfo(name)
 if field then
  return field.id
 else
  return -1
 end
end
 
---------------
-- Get Value --
---------------
local function getValueOrDefault(value)
 local tmp = getValue(value)
 
 if tmp == nil then
 return 0
 end
 
 return tmp
end


-- #################### Widgets #########################

----------------------------------------
-- Battery;     SINGLE Row Col Widget --
----------------------------------------
local function batteryWidget(xCoord, yCoord)

   local myCurrent = getValueOrDefault("VFAS")                            
   local myMaxV = 16.6                                        -- Maximale Spannung des Akkus
   local myMinV = 14.6                                        -- Minimale Spannung des Akkus
   local myRangeV = myMaxV - myMinV                           -- Nutzspannung berechnen
   local myAvailV = myCurrent - myMinV                        -- Restliche Nutzspannung berechnen
   local myPercent = math.floor(myAvailV / myRangeV * 100)    -- Restliche Nutzspannung in Prozent
  
   if myAvailV < 0 then myAvailV = 0 end                      -- Fehlerhafte Werte abfangen
   if myPercent < 0 then myPercent = 0 end                    -- Fehlerhafte Werte abfangen
   if myPercent > 100 then myPercent = 100 end                -- Fehlerhafte Werte abfangen
  
   local myPxHeight = math.floor(myPercent * 0.37)            -- Benötigte Zeilenhöhe ermitteln
   local myPxY = 11 + 37 - myPxHeight

   lcd.drawPixmap(xCoord + 10, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/batteryh.bmp")           -- Leere Batterie anzeigen

 if myPercent > 0 then
     lcd.drawFilledRectangle(xCoord + 13, myPxY, xCoord + 19, myPxHeight, FILL_WHITE )
   end


   local i = 36
   while (i > 0) do
     lcd.drawLine(xCoord + 14, yCoord + 10 + i, xCoord + 20, yCoord + 10 + i, SOLID, GREY_DEFAULT)
     i= i-2
   end

   if (myCurrent > myMaxV) or (myCurrent < myMinV) then
 lcd.drawNumber(xCoord + 1,yCoord + 55, myPercent ,LEFT + BLINK+ SMLSIZE)
   else
 lcd.drawNumber(xCoord + 1,yCoord + 55, myPercent ,LEFT + SMLSIZE)
   end
   lcd.drawText(lcd.getLastPos(), yCoord + 55, "%", SMLSIZE)

end

----------------------------------------
-- RSSI;        SINGLE Row Col Widget --
----------------------------------------
local function rssiWidget(xCoord,yCoord)

  local percent = 0
  
  if getValueOrDefault("RSSI") > 38 then
   percent = ((math.log(getValueOrDefault(200)-28, 10)-1)/(math.log(72, 10)-1))*100
  else
   percent = 0
  end

  if percent > 90 then
   lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh10.bmp")
  elseif percent > 80 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh09.bmp")
  elseif percent > 70 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh08.bmp")
  elseif percent > 60 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh07.bmp")
  elseif percent > 50 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh06.bmp")
 elseif percent > 40 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh05.bmp")
  elseif percent > 30 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh04.bmp")
  elseif percent > 20 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh03.bmp")
  elseif percent > 10 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh02.bmp")
  elseif percent > 0 then
 lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh01.bmp")
  else
    lcd.drawPixmap(xCoord + 4, yCoord + 1, "/SCRIPTS/TELEMETRY/OLIMETRY/RSSIh00.bmp")
  end

  lcd.drawChannel(xCoord + 6, yCoord + 55, 200, LEFT + SMLSIZE)
  lcd.drawText(lcd.getLastPos(), yCoord + 55, "dB", SMLSIZE)
  
end  

------------------------------------------
-- Distance;       MULTI Row Col Widget --
------------------------------------------
local function distWidget(xCoord, yCoord)

   local dist = getValueOrDefault("Dist")
  
   if simModeOn == 1 then
      dist = tdist
   end
  
   lcd.drawPixmap(xCoord + 1, yCoord + 2, "/SCRIPTS/TELEMETRY/OLIMETRY/dist.bmp")
   lcd.drawNumber(xCoord + 18, yCoord + 7, dist, LEFT)
   lcd.drawText(lcd.getLastPos(), yCoord+ 7, "m", 0)
  
end
  
------------------------------------------
--  Height;        MULTI Row Col Widget --
------------------------------------------
local function heightWidget(xCoord, yCoord)

   local height = getValueOrDefault("Alt")
  
   if simModeOn == 1 then
      height = theight
   end
  
   lcd.drawPixmap(xCoord + 1, yCoord + 2, "/SCRIPTS/TELEMETRY/OLIMETRY/hgt.bmp")
   lcd.drawNumber(xCoord + 18, yCoord + 7, height, LEFT)                -- 213 Height
   lcd.drawText(lcd.getLastPos(), yCoord + 7, "m", 0)
end

------------------------------------------
--  Speed;        MULTI Row Col Widget --
------------------------------------------
local function speedWidget(xCoord, yCoord)

   local speed = getValueOrDefault("GAlt")
  
   lcd.drawText(xCoord + 1, yCoord + 2, "AMSL")
   lcd.drawNumber(xCoord + 18, yCoord + 12, speed , LEFT)
   lcd.drawText(lcd.getLastPos(), yCoord + 12, "m", 0)
end

------------------------------------------
--  Heading;       MULTI Row Col Widget --
------------------------------------------
local function headingWidget(xCoord, yCoord)

   local heading = getValueOrDefault("Hdg")
  
   lcd.drawPixmap(xCoord + 1, yCoord + 2, "/SCRIPTS/TELEMETRY/OLIMETRY/compass.bmp")
   lcd.drawNumber(xCoord + 18, yCoord + 7, heading, LEFT)
   lcd.drawText(lcd.getLastPos(), yCoord + 7, "dg", 0)
end

------------------------------------------
--  Logging;        MULTI Row Col Widget --
------------------------------------------
local function loggingWidget(xCoord, yCoord)

    if getValueOrDefault(92) < 0 then                                         -- Must be edited to match your switch!
      lcd.drawText(xCoord + 16, yCoord+ 3,"ON", MIDSIZE)
      lcd.drawPixmap(xCoord + 2, yCoord+ 5, "/SCRIPTS/TELEMETRY/OLIMETRY/save.bmp")
   else
      lcd.drawText(xCoord + 16,yCoord+ 3,"OFF", MIDSIZE)
      lcd.drawPixmap(xCoord + 2, yCoord+ 5, "/SCRIPTS/TELEMETRY/OLIMETRY/saveoff.bmp")

   end
end

------------------------------------------
-- Flight Modes;   MULTI Row Col Widget --
------------------------------------------
local function fmWidget(xCoord, yCoord)

  lcd.drawPixmap(xCoord + 1, yCoord + 2, "/SCRIPTS/TELEMETRY/OLIMETRY/fm.bmp")            -- Flugzeugbmp anzeigen
  
  if getValueOrDefault("RSSI") > 20 then                                -- Genug RSSI?
     --if getValueOrDefault(97) > 0 then                                -- ist RTH an? (Switch F)
        --lcd.drawText(66, 5, "RTH", BLINK+MIDSIZE)                     -- Zeige Return Home an
     --else                                                             -- ok kein RTH per Schalter
        if getValueOrDefault(98) < 0 then                               -- kein IOC an auf Schalter (Switch G)
           if getValueOrDefault(96) > 0 then                            -- Manual Mode auf Schalter (Switch E)
              lcd.drawText(xCoord + 1, yCoord + 7, "Man", 0)                       -- Zeige Manual an
           else                                                      
              if getValueOrDefault(96) == 0 then                        -- Atti Mode auf Schalter (Switch E)
                 lcd.drawText(xCoord + 18, yCoord + 7, "Atti", 0)                   -- Zeige Atti Mode an
              else                                                    
                 lcd.drawText(xCoord + 18, yCoord + 7, "GPS", 0)                    -- Zeige GPS Mode an
              end                                                      
           end
        else                                                            -- Schalter IOC ist an
           if getValueOrDefault(98) == 0 then                           -- HL? (Switch G)
              lcd.drawText(xCoord + 18, yCoord + 7, "CL", 0)                        -- Zeige CL an
           else                                                         -- CL? (Switch G)
              lcd.drawText(xCoord + 18, yCoord + 7, "HL", 0)                        -- Zeige HL an
           end                                                        
       end                                                            
     --end                                                            
  else                                                                  -- nicht genug RSSI also Failaife anzeigen
    lcd.drawText(xCoord + 18, yCoord + 7, "FAIL", BLINK+0)                          -- Zeige Failsafe an
  end  

end

------------------------------------------
-- Timer;          MULTI Row Col Widget --
------------------------------------------
local function timerWidget(xCoord, yCoord)

  lcd.drawPixmap(xCoord + 1, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/timer_1.bmp")
  lcd.drawTimer(xCoord + 18, yCoord + 8, getValueOrDefault(196), 0)
  
 end
 
 -----------------------------------------
 -- GPS;           MULTI Row Col Widget --
 -----------------------------------------
 local function gpsWidget(xCoord,yCoord)
 local mySat = getValueOrDefault("Tmp2")
 local fix = mySat % 10
 local sat = (mySat-fix)/10
    if simModeOn == 1 then
  myNumSat = tmyNumSat
      myQualSat = tmyQualSat  
    end

  
 if fix == 4 then
 lcd.drawText(xCoord + 1, yCoord + 1, "D", SMLSIZE )                -- kein Fix
 elseif fix == 3 then
 lcd.drawText(xCoord + 1, yCoord + 1, "3D", SMLSIZE )                -- 2D Fix
 elseif fix == 2 then
 lcd.drawText(xCoord + 1, yCoord + 1, "2D", SMLSIZE )                 -- 3D Fix
 elseif fix == 1 then
 lcd.drawText(xCoord + 1, yCoord + 1, "Fix", SMLSIZE + BLINK )                 -- Differenzial GPS (DGPS)
 end
 
 
 if sat >= 6 then
 lcd.drawPixmap(xCoord + 15, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/gps_6.bmp")               -- 6 oder mehr Sats
 elseif sat == 5 then
 lcd.drawPixmap(xCoord + 15, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/gps_5.bmp")               -- 5 Sats
 elseif sat == 4 then
 lcd.drawPixmap(xCoord + 15, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/gps_4.bmp")               -- 4 Sats
 elseif sat == 3 then
 lcd.drawPixmap(xCoord + 15, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/gps_3.bmp")               -- 3 Sats
 elseif sat == 2 then
 lcd.drawPixmap(xCoord + 15, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/gps_2.bmp")               -- 2 Sats
 elseif sat == 1 then
 lcd.drawPixmap(xCoord + 15, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/gps_1.bmp")               -- 1 Sat
 else
 lcd.drawPixmap(xCoord + 15, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/gps_0.bmp")                 -- kein Sat
 end
 
 
   lcd.drawNumber(xCoord + 30, yCoord + 1, sat,  SMLSIZE)                        -- Anzahl anzeigen
 end

 -----------------------------------------
 -- Home Point;    MULTI Row Col Widget --
 -----------------------------------------
 local function hpWidget(xCoord, yCoord)
   if gpsCurrentLocation == "not currently available" then
      lcd.drawPixmap(xCoord + 1, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/home1.bmp")
      lcd.drawText(xCoord + 19, yCoord + 5, "?", MIDSIZE + BLINK)
   elseif myNumSat > 5 then
      lcd.drawPixmap(xCoord + 1, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/home.bmp")
      lcd.drawPixmap(xCoord + 19, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/check.bmp")
   else
      lcd.drawPixmap(xCoord + 1, yCoord + 3, "/SCRIPTS/TELEMETRY/OLIMETRY/home.bmp")
      lcd.drawText(xCoord + 19, yCoord + 5, "X",  BLINK+ MIDSIZE)
   end
 end
 
-- ######################################################
 
-------------------------
-- Call defined Widget --
-------------------------
local function callWidget(name, xPos, yPos)
 if (xPos ~= nil and yPos ~= nil) then
 if (name == "battery") then
 batteryWidget(xPos, yPos)
 elseif (name == "dist") then
 distWidget(xPos, yPos)
 elseif (name == "height") then
 heightWidget(xPos, yPos)
 elseif (name == "fm") then
 fmWidget(xPos, yPos)
 elseif (name == "timer") then
 timerWidget(xPos, yPos)
 elseif (name == "gps") then
 gpsWidget(xPos, yPos)
 elseif (name == "rssi") then
 rssiWidget(xPos, yPos)
 elseif (name == "capacity") then
 capacityWidget(xPos, yPos)
 elseif (name == "hp") then
 hpWidget(xPos, yPos)
 elseif (name == "speed") then
 speedWidget(xPos, yPos)
 elseif (name == "logging") then
 loggingWidget(xPos, yPos)
 elseif (name == "heading") then
 headingWidget(xPos, yPos)
 else
 return
 end
 end
end

---------------------
--   Build Grid    --
---------------------
local function buildGrid(def)

 local tempSumX = -1
 local tempSumY = -1
 
 -- ## Cols
 for i=1, # def, 1
 do
 -- make single Columns narrower
 if (# def[i] == 1) then
 xOffset = xOffsetSingle
 else
 xOffset = xOffsetMulti
 end
 
 -- Vertical Lines
 lcd.drawLine(tempSumX, -1, tempSumX, displayHeight, SOLID, GREY_DEFAULT)

 -- ## Rows
 for j=1, # def[i], 1
 do
 -- Horizontal Lines
 lcd.drawLine(tempSumX, tempSumY, tempSumX + xOffset, tempSumY, SOLID, GREY_DEFAULT)
 
 -- Widget
 callWidget(def[i][j], tempSumX + 1, tempSumY + 1)
 
 tempSumY = tempSumY + math.floor(displayHeight / # def[i])
 end
 
 -- Reinit Values
 tempSumY = -1
 tempSumX = tempSumX + xOffset
 end
end

-- ################### Background #######################
local function background()

end

-- ###################### INIT ##########################
local function init()

 -- Calculate xOffset depending on how many single column widgets there are
 numSingleCols = 0
 numMultiCols = 0
 for i=1, # widgetDefinition, 1
 do
 if (# widgetDefinition[i] == 1) then
 numSingleCols = numSingleCols + 1
 else
 numMultiCols = numMultiCols + 1
 end
 end
 xOffsetMulti = (displayWidth - (numSingleCols * xOffsetSingle)) / numMultiCols
 
 -- Homepoint
 myNumSat =  getValueOrDefault("Sats")                                  
    myQualSat =  getValueOrDefault("Fix")                                  
  
 
 gpsId = getTelemetryId("GPS")
 gpsLatLon = getValue(gpsId)
 if (type(gpsLatLon) ~= "table") then
 gpsCurrentLocation = "not currently available"
 end
 
end

-- ####################### Run #########################
local function run(event)
 
 -- Clear necessary
 lcd.clear()
 
 -- Grid
 buildGrid(widgetDefinition)
end

return{init=init,run=run,background=background}

L'affichage de la tension batterie ok, altitude GPS ok, nombre sat et fix ok. Par contre le cap GPS pas bon et surtout impossible d'obtenir la distance entre le drone et le point de départ.

Je n'arrive pas à lire les données brutes latitude et longitude du GPS. Est ce que quelqu'un utilise un script lua qui fonctionne pour afficher les données GPS ?

Milles merci


Invité
Invité


Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum