--[[ 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 target height saved in gvar 9 fm8 in script 8 8 pbest saved in gvar 7 fm8 scipt 6 8 TOT throws saved in gvar 4 and 5 script 3 and 4 --]] local altoffset = 0 local altoffset1 = 0 local oldalt = 0 local LIMIT = 30 local alt = 0 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 alt_id = getFieldInfo("altitude").id local vspeed_id = getFieldInfo("vertical-speed").id local sg_id = getFieldInfo("sg").id local pbest = model.getGlobalVariable(6, 8) local totlaunch = model.getGlobalVariable(3, 8)--single numbers for launches total local launch_k = model.getGlobalVariable(4, 8)-- 1000 numbers for launch total --local unit = "ft" --use this for feet local unit = "M" --use this for meters local units = 3.28 if unit == "M" then units = 1 end local function init() local limit = model.getGlobalVariable(8, 8) if limit > 0 then LIMIT = limit end end local function background() -- if alt is going down set alt offset1 to alt oldalt = alt alt = (getValue(alt_id) *units)-altoffset--get corrected altitude if oldalt > alt then altoffset1 = (getValue(alt_id) *units)--offset1 becomes the lowest reading of altitude, ready for when a launch is detected to replace offset end -- decide if launch has happened and increment launchNum if lastLaunchNum == launchNum then if getValue(alt_id) < 10 then if getValue(vspeed_id) > 5 then launchNum = launchNum + 1 altoffset = altoffset1--set alt offset to new setting only when a launch is detected lastTime = 0 totlaunch = totlaunch + 1 if totlaunch > 999 then launch_k = launch_k + 1 model.setGlobalVariable(4, 8, launch_k) totlaunch = 0 end model.setGlobalVariable(3, 8, totlaunch) end end -- if launch has happened look for drop/level in alt and average it elseif launchNum > lastLaunchNum then --alt = (getValue(alt_id) *units)-altoffset 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 --check pbest if alt > pbest then pbest = alt model.setGlobalVariable(6, 8, pbest) end -- vocal announcement playNumber( alt/units, 6, 0 ) end lastTime = alt end end -- draw result local function run() background() lcd.drawChannel(20, 4, alt_id, MIDSIZE+PREC1+LEFT) --lcd.drawChannel(90, 4, vspeed_id, MIDSIZE+PREC1+LEFT) lcd.drawNumber(86, 4, alt*10, MIDSIZE+PREC1+LEFT) lcd.drawLine(0, 20, 158, 20, SOLID, 0) lcd.drawPoint(0, 20) lcd.drawText(20, 26, "Throws:", 0) lcd.drawNumber(83, 26, launchNum, LEFT) lcd.drawText(20, 38, "Average:", 0) lcd.drawNumber(83, 38, average*10, PREC1+LEFT) --lcd.drawNumber(88, 38, average, 0) lcd.drawText( lcd.getLastPos(), 37, unit, 0 ) -- set LIMIT with throttle if switch G is down if getValue(sg_id) == 1024 then --LIMIT = math.floor( (getValue("thr") + 1024) / 29 * units ) LIMIT = math.floor( (getValue("thr") + 1224) / 33 * units ) model.setGlobalVariable(8, 8, LIMIT) numOverLimit = 0 end lcd.drawText(20, 50, "Over " .. tostring( LIMIT ) .. unit, 0) lcd.drawNumber(83, 50, numOverLimit, LEFT) lcd.drawLine( 159, 0, 159, 63, SOLID, 2 ) lcd.drawPoint( 159, 0 ) lcd.drawFilledRectangle( 121, 0, 98, 11, 0 ) lcd.drawText(178, 2, "Best", INVERS) lcd.drawText( 126, 1, "P.Best", SMLSIZE+INVERS) lcd.drawNumber(150, 12, pbest, SMLSIZE) lcd.drawNumber(180, 13, bestTime1,LEFT) lcd.drawText(lcd.getLastPos(), 12, unit, 0) lcd.drawNumber(180, 23, bestTime2, LEFT) lcd.drawText(lcd.getLastPos(), 22, unit, 0) lcd.drawNumber(180, 33, bestTime3, LEFT) lcd.drawText(lcd.getLastPos(), 32, unit, 0) lcd.drawFilledRectangle( 121, 43, 99, 11, 0 ) lcd.drawText(178, 45, "Last", INVERS) lcd.drawNumber(180, 56, lastTime, LEFT) lcd.drawText(lcd.getLastPos(), 56, unit, 0) lcd.drawText(133, 45, "Tot", SMLSIZE + INVERS) lcd.drawNumber( 158, 57, (totlaunch + (launch_k * 1000)), SMLSIZE) lcd.drawLine(120, -5, 120, 68, SOLID, 0) end return { init=init, background=background, run=run }