[Solved] Help with Brake script on wiki

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
Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

[Solved] Help with Brake script on wiki

Post by Canyonfive »

Here is my script. Where did I go wrong or why did it stop on the MaxDecel?

MaxDecelG = 1.20
chBrake = addChannel("vBrake", 25, 0, 0, 100, ' ')

function updatevBrake()
BrakeG = getChannel(LongAccel)
BrakePos = (BrakeG/MaxDecelG)*100

if BrakePos < 10 then BrakePos = 0 end
BrakePos = math.abs(BrakePos)
if BrakePos > 99 then BrakePos = 100 end
setChannel(chBrake, BrakePos)
end

setTickRate(25)
function onTick()
updatevBrake()
end

Here is the error

[lua] Successfully loaded script.
[lua] Script error: [string "MaxDecelG = 1.20..."]:5.0: Expected number or string argument at position 1
[lua] Script error: [string "MaxDecelG = 1.20..."]:5.0: Expected number or string argument at position 1
[lua] Script error: [string "MaxDecelG = 1.20..."]:5.0: Expected number or string argument at position 1
[lua] Failure: Runtime Error
[lua] Gracefully stopping Lua Task
[lua] Destroying Lua State
[lua] Initializing Lua state
[lua] memory usage: 17KB
[lua] Starting Lua Task
[lua] Loading script. Length: 354
timebase/logging/telemetry sample rate: 100/100/50
[lua] Successfully loaded script.
[lua] Script error: [string "MaxDecelG = 1.20..."]:5.0: Expected number or string argument at position 1
[lua] Script error: [string "MaxDecelG = 1.20..."]:5.0: Expected number or string argument at position 1
[lua] Script error: [string "MaxDecelG = 1.20..."]:5.0: Expected number or string argument at position 1
[lua] Failure: Runtime Error
Last edited by Canyonfive on Fri Aug 07, 2020 8:15 pm, edited 1 time in total.

Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

Post by Canyonfive »

Thought it might be the uppercase in the variables but no it still fails

Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

Post by Canyonfive »

Even though I'm on the current firmware it looks like it worked with getImu instead of getChannel.


MaxDecelG = 1.20
chBrake = addChannel("vBrake", 25, 0, 0, 100, ' ')

function updatevBrake()
BrakeG = getImu(1)
BrakePos = (BrakeG/MaxDecelG)*100

if BrakePos < 10 then BrakePos = 0 end
BrakePos = math.abs(BrakePos)
if BrakePos > 99 then BrakePos = 100 end
setChannel(chBrake, BrakePos)
end

setTickRate(25)
function onTick()
updatevBrake()
end

Post Reply