fork download
  1. --below values are constants for the vehicle
  2. local 1stGear = 2.66
  3. local 2ndGear = 1.78
  4. local 3rdGear = 1.3
  5. local 4thGear = 1.0
  6. local 5thGear = 0.74
  7. local 6thGear = 0.50
  8. local FinalDrive = 4.10
  9. --diameter in inches
  10. local TireDia = 25.1
  11. --allowable error of gear ratio to allow for measurement variation
  12. local gearErr = 0.1
  13. local rpmSpeedRatio = 0
  14. --initialized to 0 so if it doesn't work you know
  15. local gearPos = 0 --this is the gear channel variable
  16.  
  17. function onTick() --updates gear position every second by default
  18.  
  19. --assumes Pulse Input channel one is for the RPM signal and speed in MPH
  20. local speed = getGpsSpeed()
  21. local rpm = getTimerRpm(0)
  22.  
  23. --this part only works for firmware version 2.0 per the RCP page
  24. gearId = addChannel("Gear",5)
  25.  
  26. if speed > 10 then
  27. --makes sure your rolling so as not to divide by 0
  28.  
  29. rpmSpeedRatio = (rpm/speed)/(FinalDrive*1056/(TireDia*3.14159))
  30.  
  31. if ((1 stGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 1 end
  32. if ((2 ndGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 2 end
  33. if ((3 rdGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 3 end
  34. if ((4 thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 4 end
  35. if ((5 thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 5 end
  36. if ((6 thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 6 end
  37.  
  38. else gearPos = 0 end
  39.  
  40. setChannel(gearId, gearPos) --outputs to virtual channel
  41.  
  42. end
  43. -- your code goes here
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5
compilation info
luac: prog.lua:2: <name> expected near '1'
stdout
Standard output is empty