Advertisement
Guest User

Untitled

a guest
Jun 29th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. Algorithm for Pressure PID control:
  2.  
  3.  
  4. //initialize
  5. kP=0.1; kI=1; kD=0.01; cummulativeError = 0; lastError=0;
  6.  
  7. //main body of code
  8. while (true) {
  9.     read currentPressure
  10.     error = setPressure - currentPressure;
  11.  
  12.     //proportional section (distance between curve and 0)
  13.     pCorrection = kP * error
  14.  
  15.     //integral section (accumulation of error --- area under curve)
  16.     cummulativeError += error
  17.     iCorrection = kI * cummulativeError
  18.  
  19.     //derivative section (finds out rate of change of error --- slope of curve)
  20.     slope = error - lastError
  21.     dCorrection = kD * slope
  22.     lastError = error
  23.  
  24.     //decision making time
  25.     correction = pCorrection + iCorrection + dCorrection;
  26.     if correction > 80 //limit max and min correction
  27.         correction = 80
  28.         display "limiting max correction to 80"
  29.     elseif correction < -80 {
  30.         correction = -80
  31.         display "limiting min correction to -80"
  32.  
  33.     if error > 0.5 { //sets deadband and chooses solenoid for correction
  34.         if time passed >= 30 ms //make sure at least 30ms has passed by before taking any action
  35.             if correction > 0
  36.                 turn ON solenoid 1 for correction amount then turn it off
  37.             elseif correction < 0
  38.                 turn ON solenoid 2 for correction amount then turn it off
  39.             else
  40.                 display "deadband is active"
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement