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
Check my script please
[lua] Gracefully stopping Lua Task
[lua] Destroying Lua State
[lua] Initializing Lua state
[lua] memory usage: 16KB
[lua] Starting Lua Task
[lua] Loading script. Length: 1238
[lua] Startup script error: ([string "function checkAutoLogging() ..."]:36.0: '<eof>' expected near 'end')
[lua] Failure: Failed to load script
Any help?
[lua] Destroying Lua State
[lua] Initializing Lua state
[lua] memory usage: 16KB
[lua] Starting Lua Task
[lua] Loading script. Length: 1238
[lua] Startup script error: ([string "function checkAutoLogging() ..."]:36.0: '<eof>' expected near 'end')
[lua] Failure: Failed to load script
Any help?
I feel like I'm talking to myself, but- does this mean my script should run?
[lua] Gracefully stopping Lua Task
[lua] Destroying Lua State
[lua] Initializing Lua state
[lua] memory usage: 16KB
[lua] Starting Lua Task
[lua] Loading script. Length: 1035
timebase/logging/telemetry sample rate: 50/25/10
[lua] Successfully loaded script.
[lua] Gracefully stopping Lua Task
[lua] Destroying Lua State
[lua] Initializing Lua state
[lua] memory usage: 16KB
[lua] Starting Lua Task
[lua] Loading script. Length: 1035
timebase/logging/telemetry sample rate: 50/25/10
[lua] Successfully loaded script.
Yes, it seems to be running. Looks like you fixed the initial script by deleting some "end" statements.ross2004 wrote:I feel like I'm talking to myself, but- does this mean my script should run?
[lua] Gracefully stopping Lua Task
[lua] Destroying Lua State
[lua] Initializing Lua state
[lua] memory usage: 16KB
[lua] Starting Lua Task
[lua] Loading script. Length: 1035
timebase/logging/telemetry sample rate: 50/25/10
[lua] Successfully loaded script.
It's easier to check the script this way:
Code: Select all
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[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(fuel2Id, sum / maxAvg)
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
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
--Paulo