Advertisement
Guest User

LSplit

a guest
Aug 20th, 2013
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.13 KB | None | 0 0
  1. # LSlip:    It shows a smiley on yer screen!
  2. #           Also outputs the average longitudinal slip of the rear tyres to a comma separated list (OFF BY DEFAULT).
  3. # Date:     20-Aug-2013
  4. # Filename: LSplit.py
  5. # Folder: <AC_path>\apps\python\LSplit\
  6.  
  7. import ac
  8. import acsys
  9.  
  10. #                                               Smiley settings, you can change these.
  11. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # #
  12. #                                                                                                                                               #
  13. # SmileyShowTime        0 to 3  (float, seconds). Default: 0.5                                                                                  #
  14. #       Action needs to last this long in order to be shown. 0 (instant), 3 (likely to miss ":)" and ":D").                                     #
  15. #                                                                                                                                               #
  16. # SlipLimitLow          0 to ~4000  (Scalar). Default: 3000                                                                                     #
  17. #       Anything below this is ":|" (no slip). Too low and you never see it; too high and it's all you see.                                     #
  18. #                                                                                                                                               #
  19. # SlipLimitMid          ~2000 to ~6000  (Scalar). Default: 4000                                                                                 #
  20. #       Between Low and Mid is ":)". Reduce to see less ":)" and more ":D". Increase to see more ":)" and less ":D".                            #
  21. #                                                                                                                                               #
  22. # SlipLimitHigh         ~4000+ (Scalar). Over 32k may be out of bounds. Default: 5500                                                           #
  23. #       Between Mid and High is ":D". More than High is ":O". Reduce to see more ":O" and less ":D". Increase to see less ":O" and more ":D".   #
  24. #                                                                                                                                               #
  25. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # #
  26.  
  27. SmileyShowTime = 0.5   
  28. SlipLimitLow = 3000    
  29. SlipLimitMid = 4000
  30. SlipLimitHigh = 5500
  31.  
  32. #                                               Slip value output settings, you can change these.
  33. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # #
  34. #                                                                                                                                               #
  35. # OutputFile            String.                                                                                                                 #
  36. #       Full path and file name of output file.                                                                                                 #
  37. #                                                                                                                                               #
  38. # WriteToFile           0 or 1  (bool).                                                                                                         #
  39. #       0 = output to file is disabled. 1 = output to file is enabled. A 1:25 lap is around 35kB.                                               #
  40. #                                                                                                                                               #
  41. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # #
  42.  
  43. OutputFile = 'd:\out.txt'
  44. WriteToFile = 0
  45.  
  46. ### Code starts here, stay away! ###
  47. CurLap = 0
  48. SlipValues = ''
  49. IsFileReset = 0
  50. SmileyTimer = 0
  51. SmileyText = 0
  52.  
  53. def acMain(ac_version):
  54.     global SmileyText
  55.    
  56.     # Frame settings.
  57.     appWindow = ac.newApp('LSlip')
  58.     ac.setSize(appWindow, 120, 60)
  59.    
  60.     # Text settings.
  61.     SmileyText = ac.addLabel(appWindow, 'Value')
  62.     ac.setPosition(SmileyText, 10, 30)
  63.     ac.setFontAlignment(SmileyText, 'center')
  64.     ac.setSize(SmileyText, 100, 30)
  65.    
  66.     return 'LSlip'
  67.    
  68. def acUpdate(deltaT):
  69.     global SmileyText, CurLap, SlipValues, IsFileReset, SmileyTimer, SmileyShowTime, OutputFile, SlipLimitLow, SlipLimitMid, SlipLimitHigh
  70.    
  71.     # Smiley section.
  72.     FL, FR, RL, RR = ac.getCarState(0, acsys.CS.TyreSlip)
  73.     CurSlipValue = round( (RL+RR)/2 )
  74.    
  75.     if SmileyTimer > SmileyShowTime:
  76.         if SlipLimitLow < CurSlipValue < SlipLimitMid+1:
  77.             ac.setText(SmileyText, ':)')
  78.         elif SlipLimitMid < CurSlipValue < SlipLimitHigh:
  79.             ac.setText(SmileyText, ':D')
  80.         elif CurSlipValue >= SlipLimitHigh:
  81.             ac.setText(SmileyText, ':O')
  82.         else:
  83.             ac.setText(SmileyText, ':|')
  84.         SmileyTimer = 0
  85.     else:
  86.         SmileyTimer += deltaT
  87.  
  88.     # Slip value output section.
  89.     CurLapCount = ac.getCarState(0, acsys.CS.LapCount)
  90.    
  91.     if WriteToFile:
  92.         # Remove old output file at initial load.
  93.         if not IsFileReset:
  94.             open(OutputFile, 'w').close()
  95.             IsFileReset = 1
  96.                
  97.         # Write to file if lap has changed.
  98.         if CurLapCount > CurLap:
  99.             f = open(OutputFile, 'a')
  100.             f.write(SlipValues)
  101.             f.close()
  102.             SlipValues = ''     # remove written data from memory.
  103.             CurLap = CurLap + 1
  104.         else:
  105.             # Ignore small slip values, can be changed.
  106.             if CurSlipValue > 75:
  107.                 SlipValues += str(CurSlipValue) + ','
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement