Im going insane. Help required geeting 2 scripts to work

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
Taner
Posts: 3
Joined: Tue Sep 26, 2017 11:35 am
Location: uk

Im going insane. Help required geeting 2 scripts to work

Post by Taner »

Hi All.

I have a script running currently that is very simple and turns my fans on and off sepeding on coolant temp.

What I want to do is run this script and Another which just filters my fuel level reading.

My problem is that when I try to run both scripts my fans stop working. its like the script is being ignored.


Here is the fan script and below that is what I was trying to run to allow both functions to work at the same time



function onTick()

if getAnalog(1) > 90
then
setGpio(0, 1)
else
setGpio(0, 0)
end
end





AND


function getCoolantTemp()
if getAnalog(1) > 90
then
setGpio(0, 1)
else
setGpio(0, 0)
end
end

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


setTickRate(30)
function onTick()
getcoolantTemp()
updateFuelAvg(getAnalog(0))
end





Any help would be greatly appreciated
Last edited by Taner on Tue Sep 26, 2017 5:56 pm, edited 1 time in total.

ross2004
Posts: 24
Joined: Mon Sep 18, 2017 3:58 pm
Location: Staunton, VA

Post by ross2004 »

I think your problem lies with two "function onTick()" commands. That's all I've got.

psfp
Posts: 49
Joined: Mon Aug 21, 2017 10:40 pm
Location: DF - Brazil

Post by psfp »

Is your fuel average function working? Where did you set the maxAvg value? And where did you initialize the fuel2Index variable?

Your idea is to smooth the fuel reading, is it right? You can try this setting as well:

viewtopic.php?p=25368&highlight=alpha#25368

Taner
Posts: 3
Joined: Tue Sep 26, 2017 11:35 am
Location: uk

Post by Taner »

Hi Ross

You may be right but I have no clue how else to write it.



PSFP. Yes the fuel averaging works a treat but if combined with my fan swithing script it seems to stop that working??

Just by creating the script it automatically creates Avg (filtered) channel for fuel.

gizmodo
Posts: 138
Joined: Mon Aug 05, 2013 10:22 pm

Post by gizmodo »

The problem is almost certainly two onTick functions. Get rid of the top onTick function

Code: Select all

function onTick&#40;&#41; 
    getcoolantTemp&#40;&#41; 
    updateFuelAvg&#40;getAnalog&#40;0&#41;&#41; 
end
The onTick method is what the Lua engine executes every N (the value of setTick) milliseconds. Defining it twice will cause problems. Copy and paste the entire script that isn't working, and only that script so we can actually see what you have.[/code]

wizrd54
Posts: 23
Joined: Sat Apr 15, 2017 6:56 pm

Post by wizrd54 »

gizmodo wrote:The problem is almost certainly two onTick functions. Get rid of the top onTick function

Code: Select all

function onTick&#40;&#41; 
    getcoolantTemp&#40;&#41; 
    updateFuelAvg&#40;getAnalog&#40;0&#41;&#41; 
end
The onTick method is what the Lua engine executes every N (the value of setTick) milliseconds. Defining it twice will cause problems. Copy and paste the entire script that isn't working, and only that script so we can actually see what you have.[/code]
I think this is the answer as well. You should define each function separately and call all of your functions in the single onTick function. I believe onTick is what executes all of your custom scripts.

Post Reply