Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name E2 PID for 8 wheel suspension
- @inputs Input Input2 Input3 Input4 Input5 Input6 Input7 Input8 Setpoint Reset
- @outputs Integral LeftFront LeftRear LeftFrontRear LeftRearFront
- @outputs RightFront RightRear RightFrontRear RightRearFront
- @persist Error Measured_value Dt Derivative Previous_error Kp Ki Kd MaxOutput MaxInt IntLimiter
- @persist Output Output2 Output3 Output4 Output5 Output6 Output7 Output8
- @trigger
- @autoupdate
- ##this is a universal e2 pid for hydro suspension it can use up too 8 wheels
- ##if you find any flaws it may need seperate KP KI KD's
- ##if that is the case just add them and alter the code per wheel so it will look like
- ##KP2 KI2 KD2
- ##if your vehicle has less then 8 wheels just wire it respectivly
- ##anything labeled RearFront is just the wheel infront of your rear drive
- ##so if you have a 6 wheeler its rearfront then rearrear
- Dt=20
- interval(1000/Dt)
- if(Reset){
- Error = 0
- Previous_error = 0
- Derivative = 0
- Integral = 0
- }
- Intergral = 1
- Setpoint = 50
- Kp = 0.01
- Ki = 0.0005
- Kd = 1
- MaxOutput = 100
- MaxInt = 20000
- ##left front
- Error = Setpoint - Input
- Integral = clamp(Integral + Error*Dt,-MaxInt,MaxInt)
- Derivative = (Error - Previous_error)/Dt
- Output = clamp((Kp*Error + Ki*Integral + Kd*Derivative),-MaxOutput,MaxOutput)
- Previous_error = Error
- LeftFront = Setpoint + Output
- ## right front
- Error2 = Setpoint - Input2
- Integral2 = clamp(Integral2 + Error2*Dt,-MaxInt,MaxInt)
- Derivative2 = (Error2 - Previous_error2)/Dt
- Output2 = clamp((Kp*Error2 + Ki*Integral2 + Kd*Derivative2),-MaxOutput,MaxOutput)
- Previous_error2 = Error2
- RightFront = Setpoint + Output2
- #left front rear
- Error3 = Setpoint - Input3
- Integral3 = clamp(Integral3 + Error3*Dt,-MaxInt,MaxInt)
- Derivative3 = (Error3 - Previous_error3)/Dt
- Output3 = clamp((Kp*Error3 + Ki*Integral3 + Kd*Derivative3),-MaxOutput,MaxOutput)
- Previous_error3 = Error3
- LeftFrontRear = Setpoint + Output3
- #right front rear
- Error4 = Setpoint - Input4
- Integral4 = clamp(Integral4 + Error4*Dt,-MaxInt,MaxInt)
- Derivative4 = (Error4 - Previous_error4)/Dt
- Output4 = clamp((Kp*Error4 + Ki*Integral4 + Kd*Derivative4),-MaxOutput,MaxOutput)
- Previous_error4 = Error4
- RightFrontRear = Setpoint + Output4
- #left rear front
- Error5 = Setpoint - Input5
- Integral5 = clamp(Integral5 + Error5*Dt,-MaxInt,MaxInt)
- Derivative5 = (Error5 - Previous_error5)/Dt
- Output5 = clamp((Kp*Error5 + Ki*Integral5 + Kd*Derivative5),-MaxOutput,MaxOutput)
- Previous_error5 = Error5
- LeftRearFront = Setpoint + Output5
- #right rear front
- Error6 = Setpoint - Input6
- Integral6 = clamp(Integral6 + Error6*Dt,-MaxInt,MaxInt)
- Derivative6 = (Error6 - Previous_error6)/Dt
- Output6 = clamp((Kp*Error6 + Ki*Integral6 + Kd*Derivative6),-MaxOutput,MaxOutput)
- Previous_error6 = Error6
- RightRearFront = Setpoint + Output5
- #left rear
- Error7 = Setpoint - Input7
- Integral7 = clamp(Integral7 + Error7*Dt,-MaxInt,MaxInt)
- Derivative7 = (Error7 - Previous_error7)/Dt
- Output7 = clamp((Kp*Error7 + Ki*Integral7 + Kd*Derivative7),-MaxOutput,MaxOutput)
- Previous_error7 = Error7
- LeftRear = Setpoint + Output7
- #right rear
- Error8 = Setpoint - Input8
- Integral8 = clamp(Integral8 + Error8*Dt,-MaxInt,MaxInt)
- Derivative = (Error8 - Previous_error8)/Dt
- Output8 = clamp((Kp*Error8 + Ki*Integral8 + Kd*Derivative8),-MaxOutput,MaxOutput)
- Previous_error8 = Error8
- RightRear = Setpoint + Output8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement