Design Realization lecture 22 John Canny 11/6/03 Last time Some physics: Bending and stretching Construction methods: Molding Welding Structural components Modular systems This time Circuit design critique Control principles Simulation – Matlab/Simulink Feedback Control Often we want to move a system in a particular way, by controlling a parameter such as: Position control Speed control Force control Feedback control uses sensor(s) to measure this parameter and make corrections. Feedback must be applied with care to avoid ever-increasing corrections (instability). Feedback Control Naively, we want to do something like this: - V+ Amplifier + Input (voltage representing desired angle) Motor Potentiometer on shaft (angle sensor) Feedback Control Any difference between input and measured shaft angle will be amplified, moving the motor. If the direction is correct, the motor will reduce the difference. With high gain, the error 0. - V+ Amplifier + Input Motor Potentiometer on shaft (angle sensor) Simulink Models Tools like Matlab/Simulink allow us to design and test controllers before building them. Here is the controller just shown in Simulink: Voltage angle Feedback Instability Problem: the amplifier has delay, the motor has inertia, keeps moving even after error 0. If gain is too high, it will overshoot, “ring” or possibly oscillate. PD Stabilizing Controller The simplest way to control feedback is with a “PD” (Proportional Derivative) controller. A multiple of the derivative of the output is subtracted from the amplifier input. PD Stabilization Why does derivative feedback stabilize the system? Derivative feedback simulates a damper. Motion in a fluid creates viscous drag (F -v). Viscous drag quickly robs the system of energy. PID Control Sometimes there is a residual error between desired and actual output (not for DC motors). Computing the integral of the difference signal will reduce it to zero in the steady state. PID Tracking Controller All three terms P,I,D are computed on the difference signal: PID controller Implementing PID Controllers Normally, the controller CPU is running at fixed discrete time steps. Derivates can be computed by differencing consecutive samples, integrals by summing samples. This approach introduces delays and can cause problems at high frequency. Make sure that amplifiers “roll off” at high frequency – use a low-pass amplifier. Discrete lowpass amplifier Input is (x1,…,xn), output is (y1,…,yn) yk = a yk-1 + (1-a)b xk a, b constants, a < 1. If x = 0, y non-zero, then the amplifier outputs a decreasing geometric sequence, which is a discrete approximation to exponential decay. It simulates a simple RC low-pass circuit. Discrete lowpass amplifier The amplifier’s DC Gain is b Corner frequency c = (- ln a)/t = 2fc where t is the discrete step time. Automatic code generation There is a companion to Matlab/Simulink called “real-time workshop” (RTW). RTW automatically generates C code to run a Simulink model. It can handle new user-defined blocks (e.g. for sensor input or motor output). This code can be compiled and run on the control processor. Automatic code generation RTW code generation includes scheduling and event-handling and allows blocks to run at different rates. It also allows complicated models that may not run correctly with a simple discrete-step approximation.