Page 1 of 1

Linear graph script/behavior

Posted: Mon Sep 11, 2017 4:04 pm
by psfp
Hi guys,

I'm using a 1000 to 2000 rpm range to test my ShiftX2 in my garage, but when I reach the first threshold, the first 4 leds light up at the same time. I was expecting a smooth transition from the very first led.

See a video in the link below:

https://youtu.be/w1ct4EyeX4s

Here is my script:

Code: Select all

sxTx(40,{0,0,0,0,0,1})
sxTx(41,{0,0,128,0,0,255,0,0}) --green at 1000 RPM
sxTx(41,{1,0,192,0,255,255,0,0}) --yellow at 1500 RPM
sxTx(41,{2,0,0,1,255,0,0,10}) --flashing red at 2000 RPM

local function updateShiftX2()
    sxTx(42,{vRPM_L,vRPM_H})
end
No bitwise operation, as the RPM data is already separated in two bytes when I get it.

The formula to convert the raw value to RPM is RPM = raw * 125/16

I tried to use different values in the low range areas of linear graph configuration (CAN id + 40), but I had no luck.

Any ideas?

Posted: Tue Sep 12, 2017 12:14 pm
by TXBDan
Mine behaves the same and I also wonder why. That said I've never had a real/pro type shift light. Maybe that's how they work? I'd still like more information in the green zone though and I think having more leds sequence would be better.

Posted: Sun Sep 17, 2017 5:36 pm
by brentp
Hi , can you post your full script so we can check it out?

If you want the LED to show up at the first segment, try setting your first threshold at 0 RPM.

Posted: Wed Sep 20, 2017 10:54 pm
by psfp
Hi Brent,

I got it "fixed". Now the shift light represents the 4000 to 7000 range. The first LED turns on at 4000 rpm. Anything below 4000 rpm is ignored by the script.

Basically, the ShiftX2 is configured to work from 0 to 3000 rpm and my script converts the RPM value by subtracting 4000 from the real value. If RPM is below 4000, ShiftX2 receives 0 as value.

Here is my full script, before minifier and using a static oil pressure value as temporary solution, because I didn't have time to install the sensor. Sorry about the comments in portuguese.

Code: Select all

--======================================================Main data======================================================
--Inicializa CAN e define TickRate==

collectgarbage()

--println("start.."..collectgarbage("count")*1024)

initCAN(0, 500000)
initCAN(1, 500000)
setTickRate(50)
sleep(5000)

--==Declaracao de variaveis==

local vIPW, vRPM_H, vRPM_L, vRPM, vCoolant, vSSTTemp, vBoost = 0,0,0,0,0,0,0

--==Linha comentada traz todos os canais de RAX. Linha seguinte traz apenas os utilizados==
--local cSTFT, cLTFTcurrent, cLTFTidle, cLTFTcruise, cLoad, cAFR, cIPW, cAFRMAP, cLoadTiming, cTiming, cKnock, cRPM, cIDC, cBaro, cMAP, cBoost, cWGDC, cMAF, cInVVTtarget, cInVVTcurr, cExVVTtarget, cExVVTcurr, cTPS, cAPP, cIAT, cWGDCcorr, cSpeed, cBatteryECU, cCoolant, cMAT, cMAPcalc, cIMAPcalc, cMAFcalc, cChosenCalc, cSSTTemp

local cSTFT, cLTFTcurrent, cLTFTidle, cLTFTcruise, cLoad, cAFR, cIPW, cAFRMAP, cLoadTiming, cTiming, cKnock, cRPM, cIDC, cBaro, cMAP, cBoost, cWGDC, cMAF, cTPS, cAPP, cIAT, cWGDCcorr, cSpeed, cBatteryECU, cCoolant, cMAT, cMAPcalc, cIMAPcalc, cMAFcalc, cChosenCalc, cSSTTemp

--==Variaveis de canal auxiliar para acompanhamento de taxa de atualizacao==

--local counter = 0
--local cRefresh = addChannel("Refresh", 50,0)

--==Criacao de canais RAX==

--==RAX A==

cSTFT = addChannel("STFT", 50,2)
cLTFTcurrent = addChannel("LTFTcurrent", 50,2)
cLTFTidle = addChannel("LTFTidle", 50,2)
cLTFTcruise = addChannel("LTFTcruise", 50,2)

--==RAX B==

cLoad = addChannel("Load", 50,2)
cAFR = addChannel("AFR", 50,2)
cIPW = addChannel("IPW", 50,1)
cAFRMAP = addChannel("AFRMAP", 50,2)

--==RAX C==

cLoadTiming = addChannel("LoadTiming", 50,2)
cTiming = addChannel("Timing", 50,0)
cKnock = addChannel("Knock", 50,0,0,20,"count")
cRPM = addChannel("RPM",50,0,0,8000,"RPM")
cIDC = addChannel("IDC", 50,1)

--==RAX D==

cBaro = addChannel("Baro", 50,2)
cMAP = addChannel("MAP", 50,2)
cBoost = addChannel("Boost", 50,2)
cWGDC = addChannel("WGDC", 50,1)
cMAF = addChannel("MAF", 50,2)

--==RAX E==

--cInVVTtarget = addChannel("InVVTtarget", 50,1)
--cInVVTcurr = addChannel("InVVTcurr", 50,1)
--cExVVTtarget = addChannel("ExVVTtarget", 50,1)
--cExVVTcurr = addChannel("ExVVTcurr", 50,1)

--==RAX F==

cTPS = addChannel("TPS", 50,1)
cAPP = addChannel("APP", 50,1)
cIAT = addChannel("IAT", 50,0)
cWGDCcorr = addChannel("WGDCcorr", 50,1)

--==RAX G==

cSpeed = addChannel("Speed", 50,0)
cBatteryECU = addChannel("BatteryECU", 50,2)
cCoolant = addChannel("Coolant", 50,0)
cMAT = addChannel("MAT", 50,0)

--==RAX H==

cMAPcalc = addChannel("MAPcalc", 50,2)
cIMAPcalc = addChannel("IMAPcalc", 50,2)
cMAFcalc = addChannel("MAFcalc", 50,2)
cChosenCalc = addChannel("ChosenCalc", 50,2)

--==Criacao de canais SST==

--println("after rax.."..collectgarbage("count")*1024)

cSSTTemp = addChannel("SSTTemp",1,0)

--==Funcao para fazer a chamada e receber os valores de RAX==

local function getRAXCAN(RAXaddress)
    local res, id, ext, data
    res = txCAN(0,2016,0,{5,35,128,81,RAXaddress,4,255,255},100)
    if res == 1 then
        id,ext,data = rxCAN(0,100)
    else
        data = nil
    end
    return data
end

--println("aftersst.."..collectgarbage("count")*1024)

--==Rotina para atualizar os canais RAX==

local function getRAX()

    local data,vMAP,vBaro

    --==RAX A==

    data = getRAXCAN(172)
    if data ~= nil then
        setChannel(cSTFT,(data[3]* 25/128)-25)
        setChannel(cLTFTcurrent,(data[4]* 25/128)-25)
        setChannel(cLTFTidle,(data[5]* 25/128)-25)
        setChannel(cLTFTcruise,(data[6]* 25/128)-25)
    end

    --==RAX B==

    data = getRAXCAN(168)
    if data ~= nil then
        setChannel(cLoad,data[3]*25/16)
        setChannel(cAFR,data[6]*0.0392+9.8)
        vIPW = data[4]/10
        setChannel(cIPW,vIPW)
        setChannel(cAFRMAP,(14.7*128)/data[5])
    end

    --==RAX C==

    data = getRAXCAN(176)
    if data ~= nil then
        --data[6] = data[6] + ((data[5]%8)*256) Esta linha traz a definicao antes da separacao em High e Low Byte para Shift Light
        vRPM_H = data[5]%8
        vRPM_L = data[6]
        data[5] = math.floor(data[5]/8) + ((data[4]%2)*32)
        data[4] = math.floor(data[4]/2)
        vRPM = ((vRPM_H*256)+vRPM_L)*125/16
        setChannel(cLoadTiming,data[3]* 25/16)
        setChannel(cTiming,data[4] - 20)
        setChannel(cKnock,data[5])
        setChannel(cRPM,vRPM)
        setChannel(cIDC,vIPW*vRPM/1200)
    end

    --==RAX D==

    data = getRAXCAN(180)
    if data ~= nil then
        data[3] = (data[3]*2) + math.floor(data[4]/128)
        if data[4] > 128 then
            data[4] = data[4] - 128
        end
        vMAP = data[3]* 0.096487
        vBaro = (data[4]+90)* 0.072519
        vBoost = vMAP - vBaro
        setChannel(cBaro,vBaro)
        setChannel(cMAP,vMAP)
        setChannel(cBoost,vBoost)
        setChannel(cWGDC,data[5]/2)
        setChannel(cMAF,data[6]*5/255)
    end

    --==RAX E==

    --    data = getRAXCAN(184)
    --    if data ~= nil then
    --        setChannel(cInVVTtarget,(data[3]-16)*5/32)
    --        setChannel(cInVVTcurr,(data[5]-16)*5/32)
    --        setChannel(cExVVTtarget,(16-data[4])*5/32)
    --        setChannel(cExVVTcurr,(16-data[6])*5/32)
    --    end

    --==RAX F==

    data = getRAXCAN(188)
    if data ~= nil then
        setChannel(cTPS,data[3]*100/255)
        setChannel(cAPP,(data[4]-32)*129/255)
        setChannel(cIAT,data[5]-40)
        setChannel(cWGDCcorr,(data[6]/2)-64)
    end

    --==RAX G==

    data = getRAXCAN(192)
    if data ~= nil then
        vCoolant = data[5]-40
        setChannel(cSpeed,data[3]*2)
        setChannel(cBatteryECU,data[4]*18.7/255)
        setChannel(cCoolant,vCoolant)
        setChannel(cMAT,data[6]-40)
    end

    --==RAX H==

    data = getRAXCAN(196)
    if data ~= nil then
        setChannel(cMAPcalc,data[3]*25/16)
        setChannel(cIMAPcalc,data[4]*25/16)
        setChannel(cMAFcalc,data[5]*25/16)
        setChannel(cChosenCalc,data[6]*25/16)
    end
end

--==Rotina para atualizar os canais SST==

local function getSST()
    local res, id, ext, data
    res = txCAN(0, 2017, 0, {2,33,51,255,255,4,255,255},100)
    if res == 1 then
        id,ext,data = rxCAN(0,100)
    else
        data = nil
    end
    if data ~= nil then
        vSSTTemp = data[4]-50
        setChannel(cSSTTemp,vSSTTemp)
    end
end

--==Rotina para atualizar os canais analogicos e demais valores para o ShiftX2==

local function UpdateAlerts()
    local AlertL, AlertR, vOilTemp, vFuelPress, vFuelTemp, vOilPress, vFuelPressDelta, OilPressWarning

    --==Alerta Esquerda==

    --vOilTemp = getAnalog(5)
    vOilTemp = 80

    AlertL = 1
    if &#40;vCoolant < 75 or vOilTemp < 75 or vSSTTemp < 75&#41; then AlertL = 2 end
    if &#40;vCoolant > 100 or vOilTemp > 100 or vSSTTemp > 120&#41; then AlertL = 3 end
    if &#40;vCoolant > 110 or vOilTemp > 110 or vSSTTemp > 130&#41; then AlertL = 4 end

    --==Alerta Direita==

    vFuelPress, vFuelTemp, vOilPress = getAnalog&#40;0&#41;,getAnalog&#40;1&#41;,getAnalog&#40;4&#41;
    vFuelPressDelta = vFuelPress - vBoost

    --==Explicacao da logica==
    --Oilpresswarning
    --se RPM >= 4000, Oilpress > 80
    --se RPM < 4000, Oilpress / RPM > 0.02

    OilPressWarning = false
    if vRPM >= 4000 and vOilPress < 80 then OilPressWarning = true end
    if vRPM < 4000 and vOilPress/vRPM < 0.02 then OilPressWarning = true end

    AlertR = 1
    if &#40;vFuelTemp > 45 or vFuelPressDelta < 45&#41; then AlertR = 2 end
    if &#40;vFuelTemp > 50 or vFuelPressDelta < 40 or OilPressWarning&#41; then AlertR = 3 end

    --==Retorno==
    return AlertL, AlertR

end

--======================================================Main data======================================================



--=======================================================ShiftX2=======================================================

local function sxTx&#40;offset, data&#41;
    txCAN&#40;1, 0xE3600 + offset, 1, data&#41;
    --sleep&#40;10&#41;
end

--==Inicio Configuracao de start==

--==Configuracao do Shift Light==

--Configuracao considerando inicio em 4000 RPM
sxTx&#40;40,&#123;0,0,0,0,128,1&#125;&#41; -- Corte em 7000 RPM
sxTx&#40;41,&#123;0,0,0,0,0,255,0,0&#125;&#41; --verde em 4000 RPM
sxTx&#40;41,&#123;1,0,0,1,255,255,0,0&#125;&#41; --amarelo em 6000 RPM
sxTx&#40;41,&#123;2,0,128,1,255,0,0,10&#125;&#41; --vermelho piscante em 7000 RPM


--==Configuracao do alerta da esquerda==
sxTx&#40;21,&#123;1,0,2,0,0,0,255,0&#125;&#41; --azul
sxTx&#40;21,&#123;1,1,3,0,255,255,255,0&#125;&#41; --branco
sxTx&#40;21,&#123;1,2,4,0,255,0,0,10&#125;&#41; --vermelho piscante

--==Configuracao do alerta da direita==
sxTx&#40;21,&#123;0,0,2,0,255,255,255,0&#125;&#41; --branco
sxTx&#40;21,&#123;0,1,3,0,255,0,0,10&#125;&#41; --vermelho piscante

--==Fim Configuracao de start==

--==Inicio Configuracao de update==

local function updateShiftX2&#40;&#41;

    local left, right
    left, right = UpdateAlerts&#40;&#41;
    if vRPM_H < 2 then
      sxTx&#40;42,&#123;0,0&#125;&#41;
    else
      sxTx&#40;42,&#123;vRPM_L,vRPM_H-2&#125;&#41;
    end


    sxTx&#40;22,&#123;1,left,0&#125;&#41;

    sxTx&#40;22,&#123;0,right,0&#125;&#41;

end

--==Fim Configuracao de update==

--=======================================================ShiftX2=======================================================

--println&#40;"antes de onTick.."..collectgarbage&#40;"count"&#41;*1024&#41;

--==Funcao onTick==

function onTick&#40;&#41;

    if getGpio&#40;0&#41; == 0 then startLogging&#40;&#41; else stopLogging&#40;&#41; end
    local UpTime
    getSST&#40;&#41;
    UpTime = getUptime&#40;&#41;
    repeat
        getRAX&#40;&#41;
        updateShiftX2&#40;&#41; -- Funcao do ShiftX2

        --==Linhas abaixo para canal auxiliar para acompanhamento de taxa de atualizacao==

        --setChannel&#40;cRefresh,counter&#41;
        --counter = counter + 1
        --if counter == 2000 then
        --    counter = 0
        --end

        --==Continuacao de onTick&#40;&#41;==

    until getUptime&#40;&#41; > UpTime + 1000

    collectgarbage&#40;&#41;
    --println&#40;"em onTick.."..collectgarbage&#40;"count"&#41;*1024&#41;

end
I can't run all RAX logging values because of the memory limit, so I removed the MIVEC channels. It's currently very tight. Besides that, everything seems to be running fine.

Posted: Thu Nov 09, 2017 8:59 pm
by brentp
Glad you got it working!