Some E36 scripts
Posted: Mon May 08, 2017 1:57 am
Here are a couple scripts I wrote for my E36 M3. Having the speed sensor in the rear diff is handy. Change the constants to suit your diff ratio and tire size of course. Feel free to suggest how to improve them.
Code: Select all
setTickRate(10) --10Hz
--virtual channels
--addChannel("name",SR,prec,min,max,"unit")
speeddiff_id = addChannel("Speed_",10,0,0,160,"MPH")
gear_id = addChannel("Gear_",5,0,0,5,"gear")
--global constants
first = 4.20
second = 2.49
third = 1.66
fourth = 1.24
fifth = 1.00
final = 3.46
tirediameter = 24.7
--global variables
rpm = 0
rpm_diff = 0
speed = 0
function updateSpeedDiff()
rpm_diff = getTimerRpm(1)
speed = rpm_diff*tirediameter*0.002975
speed = speed + 0.5 -- round because 0 prec. truncates
setChannel(speeddiff_id, speed)
end
function updateGear()
rpm = getTimerRpm(0)
local gearErr = 0.15
local gear = 0
if speed > 2 then
ratio = rpm/(rpm_diff*final)
if ((first - ratio)^2) < (gearErr^2) then gear = 1 end
if ((second - ratio)^2) < (gearErr^2) then gear = 2 end
if ((third - ratio)^2) < (gearErr^2) then gear = 3 end
if ((fourth - ratio)^2) < (gearErr^2) then gear = 4 end
if ((fifth - ratio)^2) < (gearErr^2) then gear = 5 end
end
setChannel(gear_id, gear)
end
function onTick()
updateSpeedDiff()
updateGear()
end