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.
Virtual Channel for Gear Calculator
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.
( 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.
- Attachments
-
- Gear Calc Script.txt
- (1.62 KiB) Downloaded 158 times
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.
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.
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.
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.
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!
http://autosportlabs.net/RaceCapturePro ... alculation
Let us know how it works out!