U of U CS 5785 - Closed loop control and PID controllers

Unformatted text preview:

 TODO add: PID material from Pont slides Some inverted pendulum videos Model-based control and other more sophisticated controllers?controllers? More code speed issues – perf with and w/o FP on different processorsLast Time Estimating worst case execution time Holistic scheduling: real-time guarantees over a CAN busToday Feedback (closed loop) control and PID controllers Principles Implementation TuningControl Systems Definitions: Desired state variables: X*(t)• These are given to the system from outside• E.g. “room temperature should be 70°” Estimated state variables: X’(t)•E.g. “room temperature is currently 67°”•E.g. “room temperature is currently 67°”• Estimation uses standard data acquisition techniques– E.g. thermistor + ADC Actions: U(t)• System commands U(t) converted into driving forces using transducers• E.g. “turn off the furnace”More Control Terms Goal of a control system is to minimize error:  e(t) = | X*(t) – X’(t) | Evaluating a control system Steady-state controller error• Average e(t)Transient responseTransient response• How long the system takes to reach 99% of the desired final value after X*(t) is changed Stability• Does the system reach a steady state (smooth constant output) or does it oscillate?Early Feedback Control Centrifugal governor for a throttleSimple Closed Loop Example We’re designing a thermostat Goal is to heat room to a set temperature We can turn the furnace on and off When furnace is off, room cools down by itself Fancy control is not needed here!Rather we just need two temperature settingsRather we just need two temperature settings Tlow– temperature at which we turn on the furnace Thigh– temperature at which we turn off the furnace The difference between these provides hysteresis An on/off (“bang bang”) controller works well when the physical system is slow to respond What happens if control loop runs too fast or slow?Thermostat Codeint Thigh, Tlow;bool on = false;timer_interrupt_handler (void) {int T = read_adc();if (T < Tlow && !on) {turn_furnace_on();on = true;}if (T > Thigh && on) {turn_furnace_off();on = false;}}Another Simple Controller We’re controlling a robot arm attached to a stepper motor Need to get the arm to a certain position Position sensor tells us where the arm is Algorithm:if E > 1mm then decrement position by 1mmif E > 1mm then decrement position by 1mm if E < -1mm then increment position by 1mm Pretty tough to go wrong with a strategy like this But slow to converge What happens if control loop runs too fast or slow?PID Controllers Simple controllers like previous two examples work but in many real situations Respond slowly Have large errors Better answer: PID (Proportional Integral Derivative)PID equation:PID equation: KP, KI, and KDare design parameters Can be fixed at zero to simplify the controllerdttdEKdEKtEKtUtDIP)()()()(0∫++=ττPID Intuition KP– determines response to current error Too large → Oscillation Too small → Slow response Can’t eliminate steady-state error KI– determines response to cumulative errorCan eliminate steady-state error but often makes transient Can eliminate steady-state error but often makes transient response worse KD– determines response to rate of change of error Damps response when error is moving in the right direction Amplifies response when error is moving in the wrong direction Can be used to increase stability and improve transient responsePID Loop Skeleton Codedouble UpdatePID (SPid *pid, double error, double position) { …}}position = ReadPlantADC(); drive = UpdatePID (&plantPID, plantCommand - position,position);DrivePlantDAC (drive);Proportional Controldouble UpdatePID (SPid *pid, double error, double position) { double pTerm;double pTerm;pTerm = pid->pGain * error;return pTerm;}Example System 1Example System 2 Problem: Proportional control can’t always eliminate steady-state errorExample System 3 Problem: When there is too much actuator delay, proportional control cannot stabilize the systemIntegral Controldouble iTerm;pid->iState += error;if (pid->iState > pid->iMax) { pid->iState = pid->iMax;} else if (pid->iState < pid-> iMin) { } else if (pid->iState < pid-> iMin) { pid->iState = pid->iMin;}iTerm = pid->iGain * iState;  In practice, always used in conjunction with proportional controlExample 2 with PI Control Steady state error is eliminatedIntegrator Issues Sampling time becomes more important Sampling time shouldn’t vary more than 1%-5% On average, sampling should be periodic Integrator range is important “Integrator windup” occurs when the integrator value gets stuck too high or too lowstuck too high or too low Limiting the range makes this less of a problem Reasonable heuristic: Set integrator limits to drive limits Usually, if you can’t stabilize a system with proportional control, you can’t stabilize it with PI control eitherDifferential Controldouble dTerm;dTerm = pid->dGain * (position - pid->dState);pid->dState = position; Basically just computes the slope of the system state Attempts to predict system future based on recent past historyExample 3 with PD ControlDifferential Issues Derivative is very sensitive to noise In practice, might keep a buffer of several samples into the past in order to smooth out noise• This is just a low-pass filter• Decreases responsiveness – which is the point of differential control in the first placedifferential control in the first place Important for sampling period to be very even Do sampling in a high-priority interrupt or threadFull PID Source Codetypedef struct {double dState; // Last position inputdouble iState; // Integrator statedouble iMax, iMin; double iGain, // integral gainpGain, // proportional gaindGain; // derivative gain} SPid;double UpdatePID (SPid * pid, double error, double position) {double pTerm, dTerm, iTerm;pTerm = pid->pGain * error; pid->iState += error;if (pid->iState > pid->iMax) pid->iState = pid->iMax;else if (pid->iState < pid->iMin) pid->iState = pid->iMin;iTerm = pid->iGain * iState;dTerm = pid->dGain * (position - pid->dState);pid->dState = position;return pTerm + iTerm - dTerm;}Implementation Issues Example code uses floating point Convert to integer or


View Full Document

U of U CS 5785 - Closed loop control and PID controllers

Download Closed loop control and PID controllers
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Closed loop control and PID controllers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Closed loop control and PID controllers 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?