Smoothing AnalogX signals?
Smoothing AnalogX signals?
I have a pair of 0-5v brake press sensors and a 0-5v fuel level sensor connected to an AnalogX. plumbed into the RJ45 of my MK2. works fine but the dash gauges are "jumpy". for example the fuel level gauge will jump back and forth between 5-8 gallons (with car siting still in shop, no slosh involved). brake gauges do the same, kind of flutter around zero/neg zero. is this due to the 0-5v input fluctuations? is there a way to smooth it. thanks, Dave
Yes. There's no smoothing option for direct CAN inputs, but you could do it in Lua with a virtual channel, by first reading the channel data, applying a smoothing / averaging algortihm and then setting that to a virtual channel.
2.13.x firmware will be needed for reading the channel by name. Documentation here:
https://wiki.autosportlabs.com/RaceCapt ... r_name_.29
2.13.x firmware will be needed for reading the channel by name. Documentation here:
https://wiki.autosportlabs.com/RaceCapt ... r_name_.29
ok, so to account for "voltage slosh" I could use the lua example, tweeked below? i'm just not sure how to add the nil check.
--"Fuel" is the CAN channel connected to level sensor
--"vFuel" is the smoothed virtual channel viewed in dashboard
--Add Virtual Channels
v1 = addChannel("vFuel", 5, 0, 0, 22, "gall")
--change this to make a bigger averaging window
maxAvg = 600
--600 = 20 seconds averaging at 30Hz tick rate
--do not change
fuelAvg={}
fuel2Index = 1
function updateFuelAvg(value)
local i
if #fuelAvg == 0 then
--initialize averaging table
for i = 1, maxAvg do fuelAvg=0 end
end
fuelAvg[fuel2Index] = value
fuel2Index = fuel2Index + 1
if fuel2Index > maxAvg then fuel2Index = 1 end
local sum = 0
for i = 1, #fuelAvg do
sum = sum + fuelAvg
end
setChannel(v1, sum / maxAvg)
end
setTickRate(30)
function onTick()
updateFuelAvg(getChannel(Fuel))
end
--"Fuel" is the CAN channel connected to level sensor
--"vFuel" is the smoothed virtual channel viewed in dashboard
--Add Virtual Channels
v1 = addChannel("vFuel", 5, 0, 0, 22, "gall")
--change this to make a bigger averaging window
maxAvg = 600
--600 = 20 seconds averaging at 30Hz tick rate
--do not change
fuelAvg={}
fuel2Index = 1
function updateFuelAvg(value)
local i
if #fuelAvg == 0 then
--initialize averaging table
for i = 1, maxAvg do fuelAvg=0 end
end
fuelAvg[fuel2Index] = value
fuel2Index = fuel2Index + 1
if fuel2Index > maxAvg then fuel2Index = 1 end
local sum = 0
for i = 1, #fuelAvg do
sum = sum + fuelAvg
end
setChannel(v1, sum / maxAvg)
end
setTickRate(30)
function onTick()
updateFuelAvg(getChannel(Fuel))
end
Not able to tests on a RaceCapture right now, but I fixed a few things:
* Quotes around getting the Fuel channel, since it's specified a a string
* Guarding against nil values for getChannel
When you run it, enable the poll log feature so you can check for any script errors.
* Quotes around getting the Fuel channel, since it's specified a a string
* Guarding against nil values for getChannel
When you run it, enable the poll log feature so you can check for any script errors.
Code: Select all
-"Fuel" is the CAN channel connected to level sensor
--"vFuel" is the smoothed virtual channel viewed in dashboard
--Add Virtual Channels
v1 = addChannel("vFuel", 5, 0, 0, 22, "Gal")
--change this to make a bigger averaging window
maxAvg = 600
--600 = 20 seconds averaging at 30Hz tick rate
--do not change
fuelAvg={}
fuel2Index = 1
function updateFuelAvg(value)
if value == nil then return end
local i
if #fuelAvg == 0 then
--initialize averaging table
for i = 1, maxAvg do fuelAvg[i]=0 end
end
fuelAvg[fuel2Index] = value
fuel2Index = fuel2Index + 1
if fuel2Index > maxAvg then fuel2Index = 1 end
local sum = 0
for i = 1, #fuelAvg do
sum = sum + fuelAvg[i]
end
setChannel(v1, sum / maxAvg)
end
setTickRate(30)
function onTick()
updateFuelAvg(getChannel("Fuel"))
end
that worked well. next question. i want to add the two brake press signals that also come via AnalogX. can these be combined into the one "smoothing" script?
v1 = addChannel("vFuel", 5, 0, 0, 22, "gall")
v2 = addChannel("vFbrake", 5, 0, 0, 1600, "psi")
v3 = addChannel("vRbrake", 5, 0, 0, 1600, "psi")
--can we set multiple channels?
end
setChannel(v1, sum / maxAvg)
setChannel(v2, sum / maxAvg)
setChannel(v3, sum / maxAvg)
end
--then update each?
setTickRate(30)
function onTick()
updateFuelAvg(getChannel("Fuel"))
updateFuelAvg(getChannel("F_brake"))
updateFuelAvg(getChannel("R_brake"))
end
v1 = addChannel("vFuel", 5, 0, 0, 22, "gall")
v2 = addChannel("vFbrake", 5, 0, 0, 1600, "psi")
v3 = addChannel("vRbrake", 5, 0, 0, 1600, "psi")
--can we set multiple channels?
end
setChannel(v1, sum / maxAvg)
setChannel(v2, sum / maxAvg)
setChannel(v3, sum / maxAvg)
end
--then update each?
setTickRate(30)
function onTick()
updateFuelAvg(getChannel("Fuel"))
updateFuelAvg(getChannel("F_brake"))
updateFuelAvg(getChannel("R_brake"))
end