Check my script please
Posted: Tue Sep 26, 2017 4:39 pm
I'm brand new to RCP, and brand new to scripting, so please take it easy on me :D I'm trying to get my scripting in order for my ChumpCar build. I have four things I'm trying to accomplish: activating a warning light (ECT, oil temp, oil press, voltage), control my accusump, start logging at 10mph, and create a virtual channel for fuel level. I've attempted to copy and paste from the scripting examples and modify it to my needs. Thank you!
function checkAutoLogging()
if getGpsSpeed() > 10 then
startLogging()
else
stopLogging()
end
end
--The real analog channel should be named
--something other than FuelLevel
fuel2Id = addChannel("FuelLevel", 10, 0, 0,100,"%")
--change this to make a bigger averaging window
maxAvg = 300
--300 = 10 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(fuel2Id, sum / maxAvg)
end
end
function accusump()
rpmThreshold = 2500
lowOilPressure = 40
local accusump = 0
if getTimerRpm(0) > rpmThreshold and getAnalog(6) < lowOilPressure then
accusump = 1
end
setGpio(1, accusump)
end
end
function warningLight()
if getAnalog(4) > 215 or getAnalog(6) < 40 or getAnalog(8) < 13 or getAnalog(5) > 275 then
setGpio(0, 1)
else
setGpio(0, 0)
end
end
setTickRate(30)
function onTick()
checkAutoLogging()
updateFuelAvg(getAnalog(3))
accusump()
warningLight()
end
function checkAutoLogging()
if getGpsSpeed() > 10 then
startLogging()
else
stopLogging()
end
end
--The real analog channel should be named
--something other than FuelLevel
fuel2Id = addChannel("FuelLevel", 10, 0, 0,100,"%")
--change this to make a bigger averaging window
maxAvg = 300
--300 = 10 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(fuel2Id, sum / maxAvg)
end
end
function accusump()
rpmThreshold = 2500
lowOilPressure = 40
local accusump = 0
if getTimerRpm(0) > rpmThreshold and getAnalog(6) < lowOilPressure then
accusump = 1
end
setGpio(1, accusump)
end
end
function warningLight()
if getAnalog(4) > 215 or getAnalog(6) < 40 or getAnalog(8) < 13 or getAnalog(5) > 275 then
setGpio(0, 1)
else
setGpio(0, 0)
end
end
setTickRate(30)
function onTick()
checkAutoLogging()
updateFuelAvg(getAnalog(3))
accusump()
warningLight()
end