Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Algorithm for Pressure PID control:
- //initialize
- kP=0.1; kI=1; kD=0.01; cummulativeError = 0; lastError=0;
- //main body of code
- while (true) {
- read currentPressure
- error = setPressure - currentPressure;
- //proportional section (distance between curve and 0)
- pCorrection = kP * error
- //integral section (accumulation of error --- area under curve)
- cummulativeError += error
- iCorrection = kI * cummulativeError
- //derivative section (finds out rate of change of error --- slope of curve)
- slope = error - lastError
- dCorrection = kD * slope
- lastError = error
- //decision making time
- correction = pCorrection + iCorrection + dCorrection;
- if correction > 80 //limit max and min correction
- correction = 80
- display "limiting max correction to 80"
- elseif correction < -80 {
- correction = -80
- display "limiting min correction to -80"
- if error > 0.5 { //sets deadband and chooses solenoid for correction
- if time passed >= 30 ms //make sure at least 30ms has passed by before taking any action
- if correction > 0
- turn ON solenoid 1 for correction amount then turn it off
- elseif correction < 0
- turn ON solenoid 2 for correction amount then turn it off
- else
- display "deadband is active"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement