--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 ((1 stGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 1 end if ((2 ndGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 2 end if ((3 rdGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 3 end if ((4 thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 4 end if ((5 thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 5 end if ((6 thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 6 end else gearPos = 0 end setChannel(gearId, gearPos) --outputs to virtual channel end -- your code goes here