Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. @name E2 PID for 8 wheel suspension
  2. @inputs Input Input2 Input3 Input4 Input5 Input6 Input7 Input8 Setpoint Reset
  3. @outputs Integral LeftFront LeftRear LeftFrontRear LeftRearFront
  4. @outputs RightFront RightRear RightFrontRear RightRearFront
  5. @persist Error Measured_value Dt Derivative Previous_error Kp Ki Kd MaxOutput MaxInt IntLimiter
  6. @persist Output Output2 Output3 Output4 Output5 Output6 Output7 Output8
  7. @trigger
  8. @autoupdate
  9.  
  10.  
  11. ##this is a universal e2 pid for hydro suspension it can use up too 8 wheels
  12. ##if you find any flaws it may need seperate KP KI KD's
  13. ##if that is the case just add them and alter the code per wheel so it will look like
  14. ##KP2 KI2 KD2
  15. ##if your vehicle has less then 8 wheels just wire it respectivly
  16. ##anything labeled RearFront is just the wheel infront of your rear drive
  17. ##so if you have a 6 wheeler its rearfront then rearrear
  18.  
  19. Dt=20
  20. interval(1000/Dt)
  21.  
  22.  
  23.  
  24. if(Reset){
  25. Error = 0
  26. Previous_error = 0
  27. Derivative = 0
  28. Integral = 0
  29.  
  30. }
  31. Intergral = 1
  32.  
  33. Setpoint = 50
  34.  
  35. Kp = 0.01
  36. Ki = 0.0005
  37. Kd = 1
  38.  
  39. MaxOutput = 100
  40. MaxInt = 20000
  41.  
  42. ##left front
  43.  
  44. Error = Setpoint - Input
  45. Integral = clamp(Integral + Error*Dt,-MaxInt,MaxInt)
  46. Derivative = (Error - Previous_error)/Dt
  47. Output = clamp((Kp*Error + Ki*Integral + Kd*Derivative),-MaxOutput,MaxOutput)
  48. Previous_error = Error
  49. LeftFront = Setpoint + Output
  50. ## right front
  51. Error2 = Setpoint - Input2
  52. Integral2 = clamp(Integral2 + Error2*Dt,-MaxInt,MaxInt)
  53. Derivative2 = (Error2 - Previous_error2)/Dt
  54. Output2 = clamp((Kp*Error2 + Ki*Integral2 + Kd*Derivative2),-MaxOutput,MaxOutput)
  55. Previous_error2 = Error2
  56. RightFront = Setpoint + Output2
  57. #left front rear
  58. Error3 = Setpoint - Input3
  59. Integral3 = clamp(Integral3 + Error3*Dt,-MaxInt,MaxInt)
  60. Derivative3 = (Error3 - Previous_error3)/Dt
  61. Output3 = clamp((Kp*Error3 + Ki*Integral3 + Kd*Derivative3),-MaxOutput,MaxOutput)
  62. Previous_error3 = Error3
  63. LeftFrontRear = Setpoint + Output3
  64. #right front rear
  65. Error4 = Setpoint - Input4
  66. Integral4 = clamp(Integral4 + Error4*Dt,-MaxInt,MaxInt)
  67. Derivative4 = (Error4 - Previous_error4)/Dt
  68. Output4 = clamp((Kp*Error4 + Ki*Integral4 + Kd*Derivative4),-MaxOutput,MaxOutput)
  69. Previous_error4 = Error4
  70. RightFrontRear = Setpoint + Output4
  71. #left rear front
  72. Error5 = Setpoint - Input5
  73. Integral5 = clamp(Integral5 + Error5*Dt,-MaxInt,MaxInt)
  74. Derivative5 = (Error5 - Previous_error5)/Dt
  75. Output5 = clamp((Kp*Error5 + Ki*Integral5 + Kd*Derivative5),-MaxOutput,MaxOutput)
  76. Previous_error5 = Error5
  77. LeftRearFront = Setpoint + Output5
  78. #right rear front
  79. Error6 = Setpoint - Input6
  80. Integral6 = clamp(Integral6 + Error6*Dt,-MaxInt,MaxInt)
  81. Derivative6 = (Error6 - Previous_error6)/Dt
  82. Output6 = clamp((Kp*Error6 + Ki*Integral6 + Kd*Derivative6),-MaxOutput,MaxOutput)
  83. Previous_error6 = Error6
  84. RightRearFront = Setpoint + Output5
  85. #left rear
  86. Error7 = Setpoint - Input7
  87. Integral7 = clamp(Integral7 + Error7*Dt,-MaxInt,MaxInt)
  88. Derivative7 = (Error7 - Previous_error7)/Dt
  89. Output7 = clamp((Kp*Error7 + Ki*Integral7 + Kd*Derivative7),-MaxOutput,MaxOutput)
  90. Previous_error7 = Error7
  91. LeftRear = Setpoint + Output7
  92. #right rear
  93. Error8 = Setpoint - Input8
  94. Integral8 = clamp(Integral8 + Error8*Dt,-MaxInt,MaxInt)
  95. Derivative = (Error8 - Previous_error8)/Dt
  96. Output8 = clamp((Kp*Error8 + Ki*Integral8 + Kd*Derivative8),-MaxOutput,MaxOutput)
  97. Previous_error8 = Error8
  98. RightRear = Setpoint + Output8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement