04 août 2014

Au septième ciel ?

Pour les amateurs de Taranis et de planeurs lancés mains...

J'ai récupéré il y a quelques jours un script LUA écrit par un anglais nommé Nigel Sheffield.
J'ai fait un peu de nettoyage, ajouté l'annonce vocale de l'altitude atteinte au lancé (sur la Taranis, à condition d'avoir un vario/altimètre à bord, mais c'est abordable chez FrSky) et redessiné l'écran de télémétrie associé.

Pour ceux que ça intéresserait, voilà le machin à mettre sur la carte SD de la radio dans /SCRIPTS/xxxx/telemN.lua (où xxx est le nom du modèle sur la radio, qui ne peut pas contenir d'espace, c'est chiant ; et où N est l'indice du script, en démarrant de 1 contrairement à ce que disent certaines docs).
Mon firmware OpenTx est en 2.0.8 (la dernière version en date).

--[[
	telem lua for getting dlg launch height
	but ignoring launch switch and thermal climbs
	and then averaging by adding together and divide by number of launches.
	will use v.speed and alt to determine a launch

	NB: 206 = alt; 224 = vspeed
--]]

local LIMIT = 30

local launchNum = 0
local lastLaunchNum = 0
local average = 0
local altTotal = 0
local numOverLimit = 0
local bestTime1 = 0
local bestTime2 = 0
local bestTime3 = 0
local lastTime = 0


local function init()
	local limit = model.getGlobalVariable(8, 8)
	if limit > 0 then
		LIMIT = limit
	end
end


local function background()
	-- decide if launch has happened and increment launchNum
	if lastLaunchNum == launchNum then
		if getValue(206) < 10 then
			if getValue(224) > 5 then
				launchNum = launchNum + 1
				lastTime = 0
			end
		end

	-- if launch has happened look for drop/level in alt and average it
	elseif launchNum > lastLaunchNum then
		local alt = getValue(206)
		if lastTime > alt then
			altTotal = altTotal + alt
			average = altTotal / launchNum
			lastLaunchNum = launchNum

			-- save best launches
			if alt > bestTime3 then
				if alt > bestTime2 then
					bestTime3 = bestTime2
					if alt > bestTime1 then
						bestTime2 = bestTime1
						bestTime1 = alt
					else
						bestTime2 = alt
					end
				else
					bestTime3 = alt
				end
			end

			-- launches over LIMIT
			if alt >= LIMIT then
				numOverLimit = numOverLimit + 1
			end

			-- vocal announcement
			playNumber( alt, 6, 0 ) -- should be UNIT_DIST of TelemetryUnit (myeeprom.h) which is 5 ???
		end
		lastTime = alt
	end
end



-- draw result
local function run()
	background()

	lcd.drawChannel(20, 4, 206, MIDSIZE+PREC1+LEFT)
	lcd.drawChannel(100, 4, 224, MIDSIZE+PREC1+LEFT)
	lcd.drawText( lcd.getLastPos(), 4, "m/s", 0)

	lcd.drawLine(0, 20, 158, 20, SOLID, 0)
	lcd.drawPoint(0, 20)

	lcd.drawText(20, 26, "Throws:", 0)
	lcd.drawNumber(70, 26, launchNum, LEFT)

	lcd.drawText(20, 38, "Average:", 0)
	lcd.drawNumber(70, 38, average, LEFT)
	lcd.drawText( lcd.getLastPos(), 37, "m", 0 )

	-- set LIMIT with throttle if switch G is down
	if getValue(98) == 1024 then
		LIMIT = math.floor( (getValue(77) + 1024) / 29 )
		model.setGlobalVariable(8, 8, LIMIT)
		numOverLimit = 0
	end

	lcd.drawText(20, 50, "Over " .. tostring( LIMIT ) .. "m:", 0)
	lcd.drawNumber(70, 50, numOverLimit, LEFT)

	lcd.drawLine( 159, 0, 159, 63, SOLID, 2 )
	lcd.drawPoint( 159, 0 )

	lcd.drawFilledRectangle( 160, 0, 52, 11, 0 )
	lcd.drawText(178, 2, "Best", INVERS)
	lcd.drawNumber(180, 13, bestTime1, LEFT)
	lcd.drawText(lcd.getLastPos(), 12, "m", 0)
	lcd.drawNumber(180, 23, bestTime2, LEFT)
	lcd.drawText(lcd.getLastPos(), 22, "m", 0)
	lcd.drawNumber(180, 33, bestTime3, LEFT)
	lcd.drawText(lcd.getLastPos(), 32, "m", 0)

	lcd.drawFilledRectangle( 160, 43, 52, 11, 0 )
	lcd.drawText(178, 45, "Last", INVERS)
	lcd.drawNumber(180, 56, lastTime, LEFT)
	lcd.drawText(lcd.getLastPos(), 56, "m", 0)
end


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

Screenshot dans l'émulateur de "Companion"

Il y a un compteur de lancés qui dépassent une certaine limite. Dans cette version, on peut modifier la limite à l'aide du stick de gaz lorsque l'interrupteur G est en position basse. La valeur est mémorisée dans la variable globale 8 (flight mode 8).

J'imagine que ça peut être dur à lire, mais tout proprio de Taranis comprendra sans doute de quoi je parle ;-)

Désolé pour les autres, on reviendra à des trucs un peu moins techniques plus tard.

Aucun commentaire: