RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Linear graph script/behavior
Author Message
Reply with quote
Post Linear graph script/behavior 
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:

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?

View user's profile Send private message
Reply with quote
Post  
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.

View user's profile Send private message
Reply with quote
Post  
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.


_________________
Brent Picasso
Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
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:
--======================================================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 (vCoolant < 75 or vOilTemp < 75 or vSSTTemp < 75) then AlertL = 2 end
    if (vCoolant > 100 or vOilTemp > 100 or vSSTTemp > 120) then AlertL = 3 end
    if (vCoolant > 110 or vOilTemp > 110 or vSSTTemp > 130) then AlertL = 4 end

    --==Alerta Direita==

    vFuelPress, vFuelTemp, vOilPress = getAnalog(0),getAnalog(1),getAnalog(4)
    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 (vFuelTemp > 45 or vFuelPressDelta < 45) then AlertR = 2 end
    if (vFuelTemp > 50 or vFuelPressDelta < 40 or OilPressWarning) then AlertR = 3 end

    --==Retorno==
    return AlertL, AlertR

end

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



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

local function sxTx(offset, data)
    txCAN(1, 0xE3600 + offset, 1, data)
    --sleep(10)
end

--==Inicio Configuracao de start==

--==Configuracao do Shift Light==

--Configuracao considerando inicio em 4000 RPM
sxTx(40,{0,0,0,0,128,1}) -- Corte em 7000 RPM
sxTx(41,{0,0,0,0,0,255,0,0}) --verde em 4000 RPM
sxTx(41,{1,0,0,1,255,255,0,0}) --amarelo em 6000 RPM
sxTx(41,{2,0,128,1,255,0,0,10}) --vermelho piscante em 7000 RPM


--==Configuracao do alerta da esquerda==
sxTx(21,{1,0,2,0,0,0,255,0}) --azul
sxTx(21,{1,1,3,0,255,255,255,0}) --branco
sxTx(21,{1,2,4,0,255,0,0,10}) --vermelho piscante

--==Configuracao do alerta da direita==
sxTx(21,{0,0,2,0,255,255,255,0}) --branco
sxTx(21,{0,1,3,0,255,0,0,10}) --vermelho piscante

--==Fim Configuracao de start==

--==Inicio Configuracao de update==

local function updateShiftX2()

    local left, right
    left, right = UpdateAlerts()
    if vRPM_H < 2 then
      sxTx(42,{0,0})
    else
      sxTx(42,{vRPM_L,vRPM_H-2})
    end


    sxTx(22,{1,left,0})

    sxTx(22,{0,right,0})

end

--==Fim Configuracao de update==

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

--println("antes de onTick.."..collectgarbage("count")*1024)

--==Funcao onTick==

function onTick()

    if getGpio(0) == 0 then startLogging() else stopLogging() end
    local UpTime
    getSST()
    UpTime = getUptime()
    repeat
        getRAX()
        updateShiftX2() -- Funcao do ShiftX2

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

        --setChannel(cRefresh,counter)
        --counter = counter + 1
        --if counter == 2000 then
        --    counter = 0
        --end

        --==Continuacao de onTick()==

    until getUptime() > UpTime + 1000

    collectgarbage()
    --println("em onTick.."..collectgarbage("count")*1024)

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.

View user's profile Send private message
Reply with quote
Post  
Glad you got it working!


_________________
Brent Picasso
Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum