Page 1 of 1

Virtual Channel for Gear Calculator

Posted: Fri Aug 22, 2014 5:48 pm
by rob_h
Does anyone have the math behind determining which gear I'm in based on engine RPM and vehicle speed?

I have the final drive, tire diameter, and trans gear ratios so I know I have all the variables.

Posted: Sat Aug 23, 2014 12:33 am
by L Cubed
Here is the math your are looking for:

( RPM / GearRatio / FinalDrive ) * TireDiameter * pi / 1056 = Speed
Where Tire Diameter is in inches and speed is in MPH.

I wrote up some Lua Script code you can try if you want. It creates a virtual channel (which only works with Version 2 firmware as far as I know) called "Analog1" and will give you the active gear at 5 Hz sample rate. This is setup as a 5 speed so if you more or less just copy the a gear row and change it to 6th or delete the ones you don't need/use.

Posted: Tue Sep 02, 2014 6:38 pm
by brentp
This is great, thank you. We'll add this to the wiki!

Posted: Tue Sep 02, 2014 6:43 pm
by brentp
added here: http://autosportlabs.net/RaceCapturePro ... alculation

ping us if you want access to the wiki for more scripts; we have account creation currently locked down due to the spam bot hordes.

Posted: Tue Oct 20, 2015 3:44 am
by Ls_Rx7
Is anyone using this script or having any issues with it?

I tried using this script with 2.8.5 and 1.3.13 but am getting an error message. "lua: startup script error: ([string " ..."]:83.0: malformed number near '1stGear')"

Here is the script I am trying.

--below values are constants for the vehicle
local 1stGear = 2.66
local 2ndGear = 1.78
local 3rdGear = 1.3
local 4thGear = 1.0
local 5thGear = 0.74
local 6thGear = 0.50
local FinalDrive = 4.10
--diameter in inches
local TireDia = 25.1
--allowable error of gear ratio to allow for measurement variation
local gearErr = 0.1
local rpmSpeedRatio = 0
--initialized to 0 so if it doesn't work you know
local gearPos = 0 --this is the gear channel variable

function onTick() --updates gear position every second by default

--assumes Pulse Input channel one is for the RPM signal and speed in MPH
local speed = getGpsSpeed()
local rpm = getTimerRpm(0)

--this part only works for firmware version 2.0 per the RCP page
gearId = addChannel("Gear",5)

if speed > 10 then
--makes sure your rolling so as not to divide by 0

rpmSpeedRatio = (rpm/speed)/(FinalDrive*1056/(TireDia*3.14159))

if ((1stGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 1 end
if ((2ndGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 2 end
if ((3rdGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 3 end
if ((4thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 4 end
if ((5thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 5 end
if ((6thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 6 end

else gearPos = 0 end

setChannel(gearId, gearPos) --outputs to virtual channel

end


I also put the script in http://ideone.com/RvZmRF and received the error message

" Compilation error time: 0 memory: 0 signal:0 luac: prog.lua:2: <name> expected near '1' " on line 2 of the script.

Posted: Tue Oct 20, 2015 5:53 am
by brentp
Youre right, that script won't work out of the box; you cannot start a variable name with a number. try prefixing all of the variable names with an underscore to get around the issue perhaps?

Posted: Tue Oct 20, 2015 5:55 am
by brentp
We fixed the variable names in the script here; it still needs to be tested in an actual environment:

http://autosportlabs.net/RaceCapturePro ... alculation

Let us know how it works out!