RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Check my script please
Author Message
Reply with quote
Post Check my script please 
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[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
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

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

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

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


Yes, it seems to be running. Looks like you fixed the initial script by deleting some "end" statements.

It's easier to check the script this way:
Code:
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


Double check if those analog channels are correct.


_________________
--Paulo
View user's profile Send private message
Reply with quote
Post  
Thank you- yes for some reason when I copy/pasted the script I lost the formatting.

View user's profile Send private message
Reply with quote
Post  
I would highly advise triggering the accusump off a dedicated pressure switch and not to rely on the RCP to control the trigger. Frankly, the RCP just isn't reliable enough to entrust with your engine.

View user's profile Send private message
Reply with quote
Post  
Well that's disappointing to hear. The pressure switch is there, I can always use it. My reasoning for having RCP control it was to keep it from discharging oil at idle when the pressure is low.

View user's profile Send private message
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