Page 1 of 1

Script Check - Virtual channels with math

Posted: Thu Mar 29, 2018 4:32 pm
by PS14
Would someone check this script and let me know if it looks right. I am pulling two 1600psi brake pressure senders in via AnalogX and want to create a virtual channel (gauge) that shows the percentage of one against the total of the two (to show brake bias %). thanks, Dave

--Create Virtual Channels:
vfbrakeId = addChannel("vfbrake", 10, 0, 0, 1600, "psi")
vrbrakeId = addChannel("vrbrake", 10, 0, 0, 1600, "psi")
bbsId = addChannel("BrakeBias", 10, 0, 0, 100, "%")

function processCan()
id, ext, data = rxCAN(0)
if id == 935444 then
setChannel(vfbrakeId, data[7], 16, 40, -200)
setChannel(vrbrakeId, data[9], 16, 40, -200)
end

function setChannel()
local a1 = vfbrake()
local a2 = vrbrake()
setChannel(bbsId, (a2 / (a1 + a2)))
end

function onTick()
processCan()
setChannel()
end
end

Posted: Wed Apr 04, 2018 7:27 pm
by brentp
Hi, this looks like a duplicate of the conversation you have in the AnalogX section? if so we can continue it there.