200 likes | 216 Views
Explore PID control, real-time Simulink execution, and automatic code generation for control systems. Understand principles and implementation of feedback control methods. Learn about circuit design, graphical programming, and real-time code generation.
E N D
Design Realization lecture 23 John Canny 11/13/03
Last time • Circuit design critique • Control principles • Simulation – Matlab/Simulink
This time • Finish circuit design critique • Graphical programming and real-time control (Simulink). • Automatic real-time code generation (Real-Time Workshop).
PD Control • In addition to position feedback, a multiple of the velocity (derivative) is fed back as well to stabilize the system:
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
Example2: Pendubot • A two-axis robot. The first (blue) link is driven, the second (red) link is passive. • The model includesgravity, and is quitenon-linear.
Example2: Pendubot • Use feedback and feedforward PID blocks to stabilize two oscillatory modes.
Implementing PID Controllers • Normally, the controller CPU is running at fixed discrete time steps. • Derivatives can be computed by differencing consecutive samples, integrals by summing samples since time zero. • 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 = 2fcwhere t is the discrete step time.
Transfer functions • The variable s represents frequency: • T(s) = 1/s is an integrator • T(s) = s is a derivative operator • T(s) = 1/(a + bs) is a low-pass filter with corner frequency a/b • T(s) = (c + ds) is a high-pass filter with corner frequency c/d • T(s) = (a + bs)/(c + ds) is a general gain block, DC gain = a/c, high frequency gain = b/d.
Real-time Simulink execution • Simulink does not have a real-time clock (at least under Windows), and runs in virtual time. • It can be driven in real-time if one of its blocks (especially input/output blocks) updates at regular real-time speed. • The remainder of the Simulink code must run fast enough to keep up.
Example: Real-time Theremin Model • 1-wire sensors control pitch and volume. • Real-time sound output via sound card.
Example: Real-time Simulink Model • The simsound block includes a separate thread which sends data to the sound card. • This thread signals the main program thread with a semaphore when it is ready to accept data, or when its buffer is full. • The buffer contains data with time stamps at the desired real-time update rate. • Simulink runs a little faster than the sound card update rate, and the sound thread interpolates from Simulink’s timestamps to real time.
Example: Real-time Simulink Model • The AtoD block also includes a separate thread to acquire A-to-D input data. • This thread runs as fast as it can to provide the most up-to-date sensor data to the running simulation.
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.
Summary • Feedback control methods: PD and PID. • Feedforward control. • Real-time use of Simulink. • Code generation with Real-Time Workshop.