finicu212

BeamNG Throttle Modulation

Jun 7th, 2020
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. if starting:
  2. system.setThreadTiming(TimingTypes.HighresSystemTimer)
  3. system.threadExecutionInterval = 5
  4.  
  5. def calculate_rate(max, time):
  6. if time > 0:
  7. return max / (time / system.threadExecutionInterval)
  8. else:
  9. return max
  10.  
  11. int32_max = (2 ** 14) - 1
  12. int32_min = -int32_max
  13.  
  14. v = vJoy[0]
  15. v.x = (int32_min) * 8
  16.  
  17. # =============f
  18. # Axis inversion setting (mul): normal = 1; inverted = -1
  19. # =============
  20. global t_max, t_min, target_throttle, throttle, lowThrottle, inversion, increase_time, decrease_time
  21. inversion = 1
  22. lowThrottle = 25 # How much do you want the throttle to be pushed when holding both alt and W? (as a percentage of full throttle)
  23. increase_time = 150 # In milliseconds
  24. decrease_time = 30 # In milliseconds
  25.  
  26. # Init values, do not change
  27. t_max = int32_max * inversion
  28. t_min = int32_min * inversion
  29.  
  30. throttle = t_min
  31.  
  32. global increase_rate, decrease_rate
  33. # Set behaviour with the increase time,
  34. increase_rate = calculate_rate(t_max, increase_time)
  35. decrease_rate = calculate_rate(t_max, decrease_time)
  36.  
  37. # ============================
  38.  
  39. ALT = keyboard.getKeyDown(Key.LeftAlt)
  40. W = keyboard.getKeyDown(Key.W)
  41.  
  42. if W and ALT:
  43. target_throttle = t_max - t_max * 2 * (100 - lowThrottle) / 100
  44. elif W:
  45. target_throttle = t_max
  46. else:
  47. target_throttle = t_min
  48.  
  49. if throttle < (target_throttle - increase_rate):
  50. throttle += increase_rate
  51. elif throttle > (target_throttle + decrease_rate):
  52. throttle -= decrease_rate
  53. else:
  54. throttle = target_throttle
  55.  
  56. v.x = throttle
  57. #set axis x to ang
  58.  
  59. # PIE diagnostics
  60.  
  61. diagnostics.watch(v.x)
Advertisement
Add Comment
Please, Sign In to add comment