View Single Post
Old 02-12-2018, 05:39 PM   #3
ermax
Senior Member
 
ermax's Avatar
 
Join Date: Sep 2017
Drives: 2022 BRZ Limited Silver
Location: Jacksonville, FL
Posts: 2,533
Thanks: 883
Thanked 2,048 Times in 1,190 Posts
Mentioned: 68 Post(s)
Tagged: 0 Thread(s)
This formula will determine the gear number. I didn't log the clutch. I will probably log the clutch going forward and add logic to my formula to return a 0 when the clutch is pressed. Also, the calculated gear ratio moves around a lot so I had to do gear ratio ranges to determine the gear number. This formula only works on the MT with the 4.1 final. Obviously you can change the final in this formula without too much trouble. If you have an auto then you would have to play around with the individual ratio ranges to make it work. But I suspect the auto already has a channel with the gear number without having to figure it out with math.



Code:
ratio = ($EngineSpeed*60)/($VehicleSpeed*0.621371*844*4.1)

if (ratio > 3.440 && ratio < 6) {
	return (1)
} else if (ratio > 1.8 && ratio < 2.35) {
	return (2)
} else if (ratio > 1.38 && ratio < 1.65) {
	return (3)
} else if (ratio > 1.1 && ratio < 1.280) {
	return (4)
} else if (ratio > .85 && ratio < 1.100) {
	return (5)
} else if (ratio > .70 && ratio < .79) {
	return (6)
} else {
	return(0)
}
844: The number of revolutions per mile on the OEM tires.
$VehicleSpeed*0.621371: Converts KPH to MPH
$EngineSpeed*60: Converts engine revs per min to revs per hour
ermax is offline   Reply With Quote