--[[ PowerPanel telemetry script by dean church 2014Aug02 Shamelessly plagiarized from Fig Newton groton bobf nigelsheffield Thanks to all ! for electric powered planes SF-up, Throttle active in Ch1 mirrored as 0 to 100 in ch16 This lua script will get the throttle value and monitor the Current Sensor and Sport Voltage sensor for: Throttle output and its average Motor battery and its average current and its average min volts and its average wats = Pwr SwH-down provides some statistics of interest to me about the flight minimum cell voltage max current max watts Consumption in maHr per minute total time n seconds and number of samples. And total consumption in maHr It assumes a 2200 maHr and watches for 70% used.. 214 cell-min 215 cell-sum 216 vfas 217 currentent 218 consumption 219 power 244 cell-min-min 245 cell-sum-min 246 vfas-min 247 currentent-max 248 power-max Line Attributes FORCE = 0x02 ERASE = 0x04 ROUND = 0x08 --]] local Title = "PwrPnl_t7" local BatCapmaHr = 2200 -- Unicorn flies on 2200 mahr local BatCells = 3 -- Unicorn flies on 3s bat local BatPercent = 0.7 -- only discharge battery by 70% -- local CurThr=0 local CurVolt=0 local CurAmp=0 local CurPwr=0 local CurmaHr=0 local AvgThr=0 local AvgAmp=0 local AvgPwr=0 local AvgmaHr=0 local maHrPerMinute = 0 local TotThr=0 local TotAmp=0 local TotPwr=0 local TotmaHr=0 local MinVolt=0 local MaxAmp=0 local MaxPwr=0 -- Dynamic telemetry data local ch16 = 163 local Vfas = 216 local Curr = 217 local Powr = 219 local maHr = 218 local cellSumMin = 245 local cellMinMin = 244 local vfasMin = 246 local currententMax = 247 local powerMax = 248 -- Switches local Swa = 92 local Swb = 93 local Swc = 94 local Swd = 95 local Swe = 96 local Swf = 97 local Swg = 98 local Swh = 99 local i local x, y local timerNow = 0 local TotSamples = 0 --[[ ********* Background ********* --]] local function background() -- Check and see if the timer2 is zeroed. If it is, let's zero the average. -- I use this so that I can re-do the average between flights (where I zero out timer2). local timer = 0 timer = model.getTimer(0) if timer.value == 0 then timer = model.getTimer(1) -- Current values CurThr = 0 CurVolt=0 CurAmp=0 CurPwr=0 CurmaHr=0 -- Averages values AvgThr=0 AvgAmp=0 AvgPwr=0 maHrPerMinute=0 -- Total values TotThr=0 TotAmp=0 TotPwr=0 TotmaHr=0 -- Summary values MinVolt=0 MaxAmp=0 MaxPwr=0 -- TotSamples=0 else -- SF(down) is throttle lock. SF(up) arms the throttle. -- Don't start averaging until the throttle is moved up and the SF(UP) switch is flipped if getValue (ch16)/10.24 > -99 then if getValue(Swf) == -1024 then CurThr = getValue(ch16)/10.24 else CurThr = 0 end timer = model.getTimer(0) timerNow = timer.value TotThr = TotThr+CurThr AvgThr = TotThr/TotSamples CurAmp = getValue(Curr) TotAmp = TotAmp+CurAmp AvgAmp = TotAmp/TotSamples CurPwr = getValue(Powr) TotmaHr = getValue(maHr) TotPwr = TotPwr+CurPwr AvgPwr = TotPwr/TotSamples TotSamples=TotSamples+1 end end end --[[ ********* Run ********* --]] local function run(event) background() lcd.clear() -- Let's draw us some values. -- title x = 78 y = 2 --[[ ***** ReName PwrPnl___ to PwrPnl_tx to reflect which telemx this is ***** --]] lcd.drawText(x, y, Title, SMLSIZE+INVERS ) --Both Timers in Center x = 83 -- y = 11 timer = model.getTimer(1) if timer.value > 0 then lcd.drawRectangle(x, y, 34, 14 ) lcd.drawTimer(x+2, y+1, timer.value, MIDSIZE) else lcd.drawTimer(x+2, y+1, timer.value, MIDSIZE+INVERS+BLINK) end y = 26 local timer = model.getTimer(0) lcd.drawRectangle(x, y, 34, 14) lcd.drawTimer(x+2, y+1, timer.value, MIDSIZE) --[[ Current figures If SwH up Instantaneous and Average, If SwH down Maximum, Minimum data and Average --]] if getValue(Swh) == -1024 then x = 2 y = 2 CurVolt = getValue(Vfas) lcd.drawText(x, y, "Thr____", MIDSIZE) lcd.drawNumber(x+64, y, CurThr, MIDSIZE) y = 14 lcd.drawText(x, y, "Amps___", MIDSIZE) lcd.drawNumber(x+64, y, CurAmp, MIDSIZE) y = 26 lcd.drawText(x, y, "Volt___", MIDSIZE) lcd.drawNumber(x+64, y, CurVolt*10, MIDSIZE+PREC1) y = 37 lcd.drawText(x, y, "Pwr____", MIDSIZE) lcd.drawNumber(x+64, y, CurPwr, MIDSIZE) else -- Max Current Minimum Volts Max Pwr x = 2 y = 2 lcd.drawText(x, y+3, "maHr_________", SMLSIZE) lcd.drawText(x+22, y+3, "/Min", SMLSIZE+INVERS) maHrPerMinute = TotmaHr / (timerNow/60) lcd.drawNumber(x+72, y, maHrPerMinute, MIDSIZE) y = 14 MaxAmp = getValue(currententMax) lcd.drawText(x, y+3, "Max", SMLSIZE+INVERS) lcd.drawText(x+18, y, "Amps__", MIDSIZE) lcd.drawNumber(x+72, y, MaxAmp, MIDSIZE) y = 26 MinVolt = getValue(cellMinMin) MinVolt = getValue(vfasMin) lcd.drawText(x, y, "Cell__", MIDSIZE) lcd.drawText(x+32, y+3, "Min", SMLSIZE+INVERS) lcd.drawNumber(x+72, y, MinVolt*10, MIDSIZE+PREC2) y = 37 MaxPwr = getValue(powerMax) lcd.drawText(x, y+3, "Max", SMLSIZE+INVERS) lcd.drawText(x+18, y,"Pwr___", MIDSIZE) lcd.drawNumber(x+72, y, MaxPwr, MIDSIZE) x = 210 y = 56 lcd.drawNumber(x, y, TotSamples, SMLSIZE) lcd.drawNumber(x-40, y, timerNow, SMLSIZE) x = 78 y = 42 lcd.drawText(x, y, Title, SMLSIZE+INVERS ) if getValue(Swd) == 1024 then playFile("sounds/en/~CntDoIt.wav") elseif getValue(Swd) == 0 then playFile("sounds/en/&MsnImps.wav") else playFile("sounds/en/~gun.wav") end end x = 30 y = 50 lcd.drawText(x, y, "maHr_______", MIDSIZE) lcd.drawText(x+34, y+4, "Tot", SMLSIZE+INVERS) if TotmaHr > (BatCapmaHr*BatPercent) then lcd.drawNumber(x+108, y, TotmaHr, DBLSIZE+INVERS+BLINK) playFile("sounds/en/~TymWhlG") -- time to get those wheels on the ground else lcd.drawNumber(x+108, y, TotmaHr, DBLSIZE) end x = 130 y = 2 lcd.drawText(x, y+3, "Avg", SMLSIZE+INVERS) lcd.drawText(x+14, y, "Thr____", MIDSIZE) lcd.drawNumber(x+80, y, AvgThr, MIDSIZE) y = 14 lcd.drawText(x, y+3, "Avg", SMLSIZE+INVERS) lcd.drawText(x+16, y, "Amps___", MIDSIZE) lcd.drawNumber(x+80, y, AvgAmp, MIDSIZE) y = 26 MinVolt = getValue(cellSumMin) MinVolt = getValue(vfasMin) lcd.drawText(x, y, "Volts___", MIDSIZE) lcd.drawText(x+40, y+3, "Min", SMLSIZE+INVERS) lcd.drawNumber(x+80, y, MinVolt*10, MIDSIZE+PREC1) y = 37 lcd.drawText(x, y+3, "Avg", SMLSIZE+INVERS) lcd.drawText(x+16, y,"Pwr____", MIDSIZE) lcd.drawNumber(x+80, y, AvgPwr, MIDSIZE) end return { background=background, run=run }