31
Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing and new Frequencies: Anti- aliasing filters PID Control: Discretization, integrator windup Real time implementation

Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Embed Size (px)

Citation preview

Page 1: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Computer Control: An Overview Wittenmark, Åström, Årzén

• Computer controlled Systems

• The sampling process

• Approximation of continuous time controllers

• Aliasing and new Frequencies: Anti-aliasing filters

• PID Control: Discretization, integrator windup

• Real time implementation

Page 2: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Computer controlled systems

Quantization in timeand magnitude

Page 3: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

The sampling process

Periodic sampling

Sampling instants: times when the measured physical variables are converted into digital form

Sampling period: time between two sampling instants (denoted by h or T)

Page 4: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Sampling and Reconstruction

Sampler: A device that converts a continuous time signal into a sequence of numbers, e.g., A/D converter

A/D: 8-16 bits 2^8 to 2^16 levels of quantization, normally higher than the precision of physical sensor

Reconstructor: Converts numbers from the computer to analog signals

D/A converter combined with a hold circuit (Zero Order Hold)

Page 5: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Discretization of continuous controllers

k J

Disk drive system controller design:

Analysis done on board

Page 6: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Sampling continuous signals

Page 7: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Aliasing and new frequencies

Can information be lost by sampling a continuous time signal? sin(2 0.9t) & sin(2 0.1t)

Are sampled values obtained from a low frequency signal or a high frequency signal? It may be possible that some continuous signal CANNOT be recovered from the sampled signal

May have loss of information

Page 8: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

If a signal contains no frequencies above 0, then the continuous time signal can be uniquely reconstructed from a periodically sampled sequence provided the sampling frequency is higher than 20 (Nyquist rate)

Shannon’s Sampling Theorem (1949)

Can recover 0.1 Hz but not 0.9 Hz

Page 9: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Can recover 0.1 Hz but not 0.9 Hz

What should be the sampling frequency for recovering the 0.9 Hz sinusoidal?

Sampling Theory- Example

Page 10: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Aliasing & Anti-aliasing Filters

Aliasing (or frequency folding): High frequency signal interpreted as a low frequency signal when sampled at lower than the Nyquist rate (the 0.9=1-0.1 Hz signal)

w1-w1 wsws-w1 ws+w1

……

Page 11: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

… anti-aliasing filters

To prevent aliasing:

Remove all frequencies above the Nyquist frequency before sampling the signal.

Antialiasing filter (low pass analog filter)

High attenuation at and above Nyquist frequency

Bessel/Butterworth filters (order 2-6):

Page 12: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Example: Pre-filtering

Square wave + 0.9 Hz sine disturbance

Sampled at 1 Hz (alias freq 0.1 Hz)

Filtered bya 0.25HzLPF.

Sampledvalues

Page 13: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Summary

Information can be lost through sampling if the signal contains frequencies higher than the Nyquist frequency.

Sampling creates new frequencies (aliases).

Page 14: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

… summary

Aliasing makes it necessary to filter the signals before they are sampled.

Effect of the anti-aliasing filters must be considered when designing controllers. The dynamics can be neglected if the samplingperiod is sufficiently short.

Page 15: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Computer control (Wittenmark, Astrom, Arzen)

PID Control: Discretization, saturation and windup

Other practical issues

Page 16: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

PID Control

Most common controller:

e: error, K: gain, Ti: integration time, Td: derivative time

System error as K & 1/Ti , stability improves as Td , increasing 1/Ti reduces stability

Originally implemented using analog technology

Page 17: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

PID Control & DiscretizationModifications to PID:

Derivative term:

Derivative not acting on the command signal

N: gain athigh freq:3-20

Page 18: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Discretization of PID Controller

Proportional part needs no approximation:

Integral part: can be approximated as

Page 19: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

.. Discretization of PID: P+I+D

Derivative part: D(t)

use backward differences for approximation:

Page 20: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Integrator windupActuators can become saturated due

to large inputs Examples of saturated actuators: - throttle position in an automobile - amplifier output voltage - aircraft control surfaces

Page 21: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

A taste of the practical worldIf error is large, Integral Control can

saturate the actuator.

PID

error

Integrator output can become large (windup) with no effect on the output (due to saturation).

System y reference

+

-

u uc

Page 22: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

… integrator windupIntegrator output winds up until the sign of

e(t) changes and the integration turns the other way around Solution: Reset integrator when actuator is saturated

Using anti-windup

Without anti windup

y

uc

Desired output

Page 23: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

PID implementation

Signalsdouble uc; // set point

double y; // measured variable

double v; // control output

double u; //limited control output

Statesdouble I = 0; //Integral part

double D = 0; //Derivative part

double yold=0; //delayed measured variable

Parameters

double Kp, Ki, Kd;

double Ts; //Sampling time

double ul, uh; //output limits

Page 24: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

PID class

oo

PID

Signals signals;

States states;

Parameters par;

double calculateOutput(uc, y);

void updateState(double u);

Calculate, Perform integratoranti-windup

Page 25: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Main programmain( ) {double uc, y, u;PID pid = new PID( ); // Can pass parameters herelong time = getCurrentTimeMillis( ); // Get current

timewhile (true) {

y = readY( ); uc = readUc( );u = pid.calculateOutput(uc,y);writeU(u);pid.updateState(u);time = time + pid.par.Ts*1000; // Increment timewaitUntil(time); // Wait until "time“- RTOS call

}

Page 26: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

void updateState(double u)

void updateState(double u) {states.I = states.I + par.bi*(signals.uc

- signals.y) +par.ar*(u - signals.v);states.yold = signals.y;}

Page 27: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

calculateOutput( )double calculateOutput(double uc, double y) {….double P = par.K*(par.b*uc - y);states.D = par.ad*states.D - par.bd*(y - states.yold);signals.v = P + states.I + states.D;if (signals.v < par.ulow) {signals.u = par.ulow;} else {if (signals.v > par.uhigh) {signals.u = par.uhigh;} else {signals.u = signals.v;}}return signals.u;}

Page 28: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Summary of PID

PID is a useful controller.Things to consider:

Filtering of the derivative term Updating the integrator Anti windup compensation

Page 29: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

Some practical issues

Numerical accuracy is improved if more bits are used: float coeff; vs double coeff; (64 bits)

A/D and D/A Much less accuracy Typical resolutions: 8, 12, 16 bits Better to have a good resolution at the

A/D converter than D/AA control system is less crucial for a quantized

signal applied to the input of the plant.

Page 30: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

… practical issues

Nonlinearities such as quantization by A/D can result in oscillations Do simulations to find out if A/D, D/A resolutions can

improve performance

Selection of the sampling period A common rule: = 0.1 to 0.6, : desired BW of the closed-loop

system

Page 31: Computer Control: An Overview Wittenmark, Åström, Årzén Computer controlled Systems The sampling process Approximation of continuous time controllers Aliasing

… practical issues

Anti-aliasing filters Must provide attenuation at Nyquist

frequencyAnti-reset windup is important to

include in the controller.