Analog and Digital Control Systems Robert Stengel Robotics and Intelligent Systems MAE 345, Princeton University, 2015 Frequency Response Transfer Functions Bode Plots Root Locus Proportional-Integral- Derivative (PID) Control Discrete-time Dynamic Models Copyright 2015 by Robert Stengel. All rights reserved. For educational use only. http://www.princeton.edu/~stengel/mae345.html 1 Analog vs. Digital Signals Signal: A physical indicator that conveys information, e.g., position, voltage, temperature, or pressure Analog signal: A signal that is continuous in time, with infinite precision and infinitesimal time spacing between indication points Discrete-time signal: A signal with infinite precision and discrete spacing between indication points Digital signal: A signal with finite precision and discrete spacing between indication points 2
Analog vs. Digital Systems System: Assemblage of parts with structure, connectivity, and behavior that responds to input signals and produces output signals Analog system: A system that operates continuously, with infinite precision and infinitesimal time spacing between signaling points Discrete-time system: A system that operates continuously, with infinite precision and discrete spacing between signaling points Digital system: A system that operates continuously, with finite precision and discrete spacing between signaling points 3 Frequency Response of a Continuous- Time Dynamic System Output Angle, deg Output Rate, deg/s Input Angle, deg < n = n > n : Input frequency, rad/s n : Natural frequency of the system, rad/s Hz : Hertz, frequency in cycles per sec = ( rad / s) Hz Sinusoidal command input (i.e., Desired rotational angle) Long-term output of the dynamic system: Sinusoid with same frequency as input Output/input amplitude ratio dependent on input frequency Output/input phase shift dependent on input frequency Bandwidth: Input frequency below which output amplitude and phase angle variations are negligibly small 2 4
Amplitude-Ratio and Phase-Angle Frequency Response of a 2 nd -Order System Output Angle, deg Straight-line asymptotes at high and low frequency Output Rate, deg/s Straight-line asymptotes at high and low frequency 20log AR and vs. log 5 Asymptotes of Frequency Response Amplitude Ratio 20 log 10 n has slope of 20n db/decade on Bode plot Natural Frequency 20log 10 H CLi (j ) = = 20log 10 AR i ( ) e j i ( ) = 20 log 10 AR i + log 10 e j i = 20log 10 AR i + j i 20log 10 e Logarithm of transfer function Amplitude ratio and phase angle are orthogonal Decibels (db): 20 log AR Decade: power of 10 6
Fourier Transform of a Scalar Variable [ ] = x( j ) = x(t)e jt F x(t) dt, = frequency, rad / s j i 1 x(t) x( j) = a() + jb() x(t) :real variable x( j ) :complex variable = a( ) + jb( ) j ( ) = A( )e A :amplitude :phase angle 7 Laplace Transforms of Scalar Variables Laplace transform of a scalar variable is a complex number s is the Laplace operator, a complex variable [ ] = x = x(t)e st dt L x(t), s = + j 0 x(t) :real variable x : complex variable = a( ) + jb( ) j ( ) = A( )e Multiplication by a constant L a x(t) Sum of Laplace transforms [ ] = x 1 + x 2 L x 1 (t) + x 2 (t) [ ] = a x 8
Laplace Transforms of Vectors and Matrices Laplace transform of a vector variable Laplace transform of a matrix variable L[ x(t) ] = x = x 1 x 2... L[ A(t) ] = A = a 11 a 12... a 21 a 22... Laplace transform of a derivative w.r.t. time L dx(t) dt = sx x(0) Laplace transform of an integral over time L x( )d ( = x s......... 9 Laplace Transforms of the System Equations Time-Domain System Equations x(t) = Fx(t) + Gu(t) y(t) = H x x(t) + H u u(t) Dynamic Equation Output Equation Laplace Transforms of System Equations sx x(0) = Fx + Gu y = H x x + H u u Dynamic Equation Output Equation 10
Example of System Transformation DC Motor Equations x 1 (t) x 2 (t) = 0 1 x 1 (t) 0 0 x 2 (t) + 0 u(t) 1/ J y 1 (t) y 2 (t) = 1 0 x 1 (t) 0 1 x 2 (t) + 0 x 1 (t) u(t) = 0 x 2 (t) Dynamic Equation Output Equation Laplace Transforms of Motor Equations sx 1 x 1 (0) sx 2 x 2 (0) = 0 1 x 1 0 0 x 2 + 0 u 1/ J y 1 y 2 = 1 0 x 1 0 1 x 2 + 0 x 1 u = 0 x 2 Dynamic Equation Output Equation 11 Laplace Transform of State Response to Initial Condition and Control Adj si F Rearrange sx Fx = x(0) + Gu [ si F]x = x(0) + Gu [ ] 1 [ x(0) + Gu ] x = si F [ si F] 1 = Matrix inverse si F Adj si F (n x n) : Adjoint matrix (n n) : Transpose of matrix of cofactors si F = det( si F) : Determinant ( 11) 12
Characteristic Polynomial of a Dynamic System Characteristic matrix ( si F) = ( s f 11 ) f 12... f 1n f 21 s f 22... f 2n............ f n1 f n2... s f nn (n x n) Characteristic polynomial si F = det( si F) = s n + a n1 s n1 +...+ a 1 s + a 0 13 Eigenvalues (or Roots) of the Dynamic System = s n + a n1 s n1 +...+ a 1 s + a 0 = 0 ( s 2 )... = s 1 Characteristic equation = 0 s n i are eigenvalues of F or roots of the characteristic polynomial, ( s) 14
2 x 2 Eigenvalue Example Characteristic matrix ( si F) = ( s f 11 ) f 12 f 21 s f 22 Determinant of characteristic matrix si F = ( s f 11 ) f 12 f 21 s f 22 ( s f 22 ) f 12 f 21 = s f 11 = s 2 ( f 11 + f 22 )s + f 11 f 22 f 12 f 21 15 Factors of the 2 nd - Degree Characteristic Equation = s 2 f 12 + f 21 s s + f 11 f 22 f 12 f 21 = 0 x x x = cos 1 = ( s 1 )( s 2 ) = 0 Solutions of the equation are eigenvalues of the system, either 2 real roots, or Complex-conjugate pair x s Plane 1 = 1 + j 1, 2 = 1 j 1 1 = 1, 2 = 2 ( s) = s 2 2 + 2 n s + n 16
Eigenvalues Determine the Stability of the LTI System Positive real part represents instability Envelope of time response converges or diverges x x x 1 (t) = e nt cos n 1 2 t + 1 ( ) x 1(0) s Plane Same criterion for real roots x(t) = e at x(0) 17 Numerator of the Matrix Inverse [ si F] 1 = Matrix Inverse si F Adj si F (n x n) Adjoint matrix is the transpose of the matrix of cofactors * Adj( si F) = C T (n x n) ( si F) = 2 x 2 example ( s f 11 ) f 12 f 21 s f 22 Adj( si F) = = ( s f 22 ) f 21 f 12 s f 11 ( s f 22 ) f 12 f 21 s f 11 T * Cofactors = signed minor determinants of the matrix 18
Analog Control 19 Transfer Function Matrix Laplace Transform of Output Vector from control input to system output (neglect initial condition, and H u = 0) y = H x x = H x H H x ( si F) 1 Gu H u Transfer Function Matrix ( si F) 1 G (r x m) 20
Open-Loop Dynamic Equation of Direct-Current Motor with Load Inertia, J x 1 (t) x 2 (t) = 0 1 0 0 x 1 (t) x 2 (t) + 0 1 / J u(t) Same as simplified pitching dynamics for quadcopter, with J = I yy 21 Open-Loop Transfer Function Matrix for DC Motor Transfer Function Matrix H OL = H x [ si F OL ] 1 G (r x m) where F OL = 0 1 0 0 H x = ; 1 0 0 1 [ si F OL ] = = I 2 ; G = s 1 0 s 0 1 J Matrix Inverse [ si F OL ] 1 = Adj si F OL = si F OL s 1 0 s 1 = = s 2 s 1 0 s 1 / s 1 / s 2 0 1 / s 22
Open-Loop Transfer Function Matrix for DC Motor = H OL = H x [ si F OL ] 1 Adj si F G = H OL x si F OL 1 0 0 1 1/ s 1/ s 2 0 1/ s 0 1/ J = 1 0 0 1 G Dimension = 2 x 1 1/ Js 2 1/ Js = 1 Js 2 1 Js = y 1 u y 2 u Angle = Double integral of input torque, u Angular rate = Integral of input torque, u 23 Closed-Loop System Closed-loop dynamic equation x 1 (t) x 2 (t) = 0 1 c 1 / J c 2 / J x 1 (t) x 2 (t) + 0 c 1 / J y C x(t) = F CL x(t) + Gu(t) 24
Closed-Loop Transfer Function Matrix H CL = H x [ si F CL ] 1 Adj si F G = H CL x si F CL 1 s + c 2 J c 1 J s = s 2 + c 2 J s + c ( 1 + ) * J, - 0 c 1 / J G Dimension = 2 x 1 Closed-loop transfer functions Scalar components differ only in numerators y 1 y C y 2 y C c 1 J ( c 1 J )s = s 2 + c 2 J s + c 1 * ( ) J +, = n 1 n 2 ( s) ( s) - s 25 Frequency Response Functions Substitute s = j in transfer functions Output Angle Commanded Angle = y 1( j ) y C ( j ) = c 1 J j = 2 n 2 2 + 2 n ( j ) + n 2 + ( c 2 J )( j ) + c 1 J a 1 ( ) + jb 1 ( ) AR 1 ( ) e j 1( ) Output Rate Commanded Angle = y 2( j ) y C ( j ) = j j 2 ( j ) = n 2 + 2 n j c 1 J 2 + ( c 2 J )( j ) + c 1 J + n 2 AR 2 ( ) e j 2 ( ) Natural Frequency: n = c 1 J Damping Ratio: = ( c 2 J ) 2 n = ( c 2 J ) 2 c 1 J 26
Bode Plot Depicts Frequency Response Hendrick Bode Frequency Response of DC Motor Angle Control F1 = [0 1;-1 0]; G1 = [0;1]; F1a = [0 1;-1-1.414]; F1b = [0 1;-1-2.828]; Hx = [1 0;0 1]; Sys1 Sys2 Sys3 = ss(f1,g1,hx,0); = ss(f1a,g1,hx,0); = ss(f1b,g1,hx,0); 20log AR and vs. log w = logspace(-2,2,1000); bode(sys1,sys2,sys3,w), grid 27 Root (Eigenvalue) Locus y 1 y C y 2 y C c 1 J ( c 1 J )s = s 2 + c 2 J s + c 1 * ( ) J +, = 2 - n - 2 n s s 2 2 + 2.- n s + - n = ( s 2 +1.414- n s +1) 1 s Variation of roots as scalar gain, k, goes from 0 to With nominal gains, c 1 and c 2, n = c 1 J = 1 rad / s, = c 2 J 2 n = 0.707 Root Locus of DC Motor Angle Control F = [0 1;-1-1.414]; G = [0;1]; Hx1 = [1 0]; Angle Output Hx2 = [0 1]; Angular Rate Output Sys1 Sys2 = ss(f,g,hx1,0); = ss(f,g,hx2,0); rlocus(sys1), grid figure rlocus(sys2), grid 28
Root (Eigenvalue) Locus Increase Angle Feedback Gain Increase Rate Feedback Gain Initial Root Initial Root Zero Initial Root Initial Root 29 Classical Control System Design Criteria Step Response Frequency Response Eigenvalue Location 30
Single-Axis Angular Control of Non-Spinning Spacecraft Pitching motion (about the y axis) is to be controlled (t) q(t) = 0 1 0 0 (t) q(t) + 0 1 / I yy M (t) y (t) q(t) = Pitch Angle Pitch Rate Identical to the DC Motor control problem 31 Proportional-Integral- Derivative (PID) Controller Control Error Control Command Control Law Transfer Function (w/common denominator) e = C e u = c P e + c I + c D se s u e = c Ps + c I + c D s 2 s Proportional term weights control error directly Integrator compensates for persistent (bias) disturbance Differentiator produces rate term for damping 32
Proportional-Integral- Derivative (PID) Controller Forward-Loop Angle Transfer Function g A = Actuator Gain e = c + c s + c I P D s2 s g A I yy s 2 33 Closed-Loop Spacecraft Control Transfer Function w/pid Control Closed-Loop Angle Transfer Function Ziegler-Nichols PID Tuning Method http://en.wikipedia.org/wiki/ziegler Nichols_method c I + c P s + c D s 2 c = e I yy s 3 1+ = e 1+ c + c s + c I P D s2 I yy s 3 = c D s 2 + c P s + c I I yy s 3 g A + c D s 2 + c P s + c I g A g A 34
Closed-Loop Frequency Response w/pid Control c = c I + c P s + c D s 2 c I + c P s + c D s 2 + I yy s 3 g A Let s = j. As 0 ( j) c ( j) c I = 1 c I As ( j ) c ( j ) c D 2 ji yy 3 g A = c D ji yy g A = jc D I yy g A AR c D I yy g A ; 90 deg Steady-state output = desired steady-state input High-frequency response rolls off and lags input 35 Digital Control Stengel, Optimal Control and Estimation, 1994, pp. 79-84, E-Reserve 36
From Continuous- to Discrete- Time Systems Continuous-time systems are described by differential equations, e.g., x(t) = Fx(t) + Gu(t) Discrete-time systems are described by difference equations, e.g., x(t k +1 ) = x(t k ) + u(t k ) Discrete-time systems that are meant to describe continuous-time systems are called sampled-data systems = fcn( F); = fcn( F,G) 37 Sampled-Data (Digital) Feedback Control Digital-to-Analog Conversion Analog-to-Digital Conversion 38
Integration of Linear, Time-Invariant (LTI) Systems x(t) = Fx(t) + Gu(t) t x(t) = x(0) + xd = x(0) + [ Fx + Gu]d 0 Homogeneous solution (no input), u = 0 x(t) = x(0) + [ Fx]d = e F(t0) x(0) = ( t,0)x(0) ( t,0) = e F(t0) = e Ft = State transition matrix from 0 to t t 0 t 0 39 Equivalence of 1 st -Order Continuousand Discrete-Time Systems Example demonstrates stability (green) and instability (red), defined by sign of a x(t) = ax(t), x(0) given t x(t) = x(0) + x(t)dt = e at x(0) 0 Choose small time interval, t Propagate state to time, t + nt 40
Equivalence of 1 st -Order Continuous- and Discrete-Time Systems x 0 = x(0) x 1 = x(t) = e at x 0 = (t)x 0 x 2 = x(2t) = e 2at x 0 = e at x 1 = (t)x 1... x k = x(kt) = e kat x 0 = e at x k1 = (t)x k1... x n = x(nt) = x(t) = e nat x 0 = (t)x n1 41 Initial Condition Response of Continuous-and Discrete-Time Models Identical response at the sampling instants t k+1 x(t k+1 ) = x(t k ) + Fx(t)dt = e F ( t k+1t )t k x(t k ) = (t)x(t k ) t k 42
Input Response of LTI System Inhomogeneous (forced) solution t ( x(t) = e Ft x(0) + e F(t ) Gu d = ( t 0)x(0) + t 0 0 t t ) 0 Gu( ) ( d 43 Sampled-Data System (Stepwise application of prior results) t k +1 t k Assume (t k t k+1 ) = t = constant = e F(t k+1 t k ) = e F(t ) = t Assume u = constant from t k to t k+1 x(t k+1 ) = (t)x(t k ) + t t t Evaluate the integral ) G ( d u k x(t k+1 ) = (t)x(t k ) + (t) I 1 (t) F 1 Gu t k ( (t)x(t k ) + )(t)u( t k ) 0 44
Digital Flight Control Historical notes: NASA Fly-By-Wire F-8C (Apollo GNC system, 1972) 1 st conventional aircraft with digital flight control NASA Dryden Research Center Princetons Variable-Response Research Aircraft (Z-80 microprocessor, 1978) 2 nd conventional aircraft with digital flight control Princeton University s Flight Research Laboratory http://www.princeton.edu/~stengel/frl.pdf 45 Next Time: Sensors and Actuators 46
SupplementaL Material 47 Eigenvalues, Damping Ratio, and Natural Frequency Eigenvalues, Damping Ratio, and Natural Frequency of Angle Control F1 = [0 1;-1 0]; G1 = [0;1]; F1a = [0 1;-1-1.414]; F1b = [0 1;-1-2.828]; Hx = [1 0;0 1]; Eigenvalues 0 + 1i 0-1i Damping Ratio, Natural Frequency 1, 2 n 0 1 Sys1 Sys2 Sys3 eig(f1) eig(f1a) eig(f1b) damp(sys1) damp(sys2) = ss(f1,g1,hx,0); = ss(f1a,g1,hx,0); = ss(f1b,g1,hx,0); -0.707 + 0.707i -0.707-0.707i -0.414-2.414 0.707 1 Overdamped 48
Bode Plots of Proportional, Integral, and Derivative Compensation H( j) =1 H( j) =10 H( j) =100 H( j) = 1 j H( j) = 10 j H( j) = j H( j) =10 j Amplitude ratio, AR(dB) = Slope of AR(dB) = Slope of AR(dB) = constant 20 db/decade +20 db/decade Phase Angle, ( deg) = 0 Phase Angle, = 90 deg Phase Angle, = +90 deg 49 Single-Input/Single-Output Sampled-Data Control Sampler is an analog-to-digital (A/D) converter Reconstructor is a digital-to-analog (D/A) converter Sampling of input and feedback signal could occur separately, before the summing junction Sampling may be periodic or aperiodic D/A Plant 50
Equilibrium Response of Linear Discrete-Time Model Dynamic model x k +1 = x k + u k + w k At equilibrium x k +1 = x k = x* = constant Equilibrium response ( I )x* = u*+w * 1 ( u*+w *) x* = I (.)* = constant 51 Factors That Complicate Precise Control 52
Error, Uncertainty, and Incompleteness May Have Significant Effects Scale factors and biases: y = kx + b Disturbances: Constant/variable forces Measurement error: Noise, bias Modeling error Parameters: e.g., Inertia Structure: e.g., Higher-order modes 53 Saturation (limiting) Displacement limit, maximum force or rate Threshold Dead zone, slop Preload Breakout force Friction Sliding surface resistance Rectifier Hard constraint, absolute value (double) Hysteresis Backlash, slop Higher-degree terms Cubic spring, separation Nonlinearity Complicates Response 54
Discrete-Time and Sampled-Data Models Linear, time-invariant, discrete-time model x k +1 = x k + u k + w k Discrete-time model is a sampled-data model if it represents a continuous-time system 55 Sampling Effect on Continuous Signal Two waves, different frequencies, indistinguishable in periodically sampled data Frequencies above the sampling frequency aliased to appear at lower frequency (frequency folding) Solutions: Either Sampling at higher rate or Analog low-pass filtering Folding Frequency Aliased Spectrum Actual Spectrum 56
Quantization and Delay Effects Continuous signal sampled with finite precision (quantized) Solution: More bits in A/D and D/A conversion Effective delay of sampled signal Described as phase shift or lag Solution: Higher sampling rate or Lead compensation Analog-to-Digital Converter r h illustrates zero-order hold effect 57 Time Delay Effect Control command delayed by sec Laplace transform of pure time delay L u( t ) = e s u( s) Delay introduces frequency-dependent phase lag with no change in amplitude AR e j = 1 = e j Phase lag reduces closed-loop stability 58
Effect of Closed-Loop Time Delay on Step Response With no delay n = 1 rad / s, = 0.707 With varying delays 59 Princetons Variable- Response Research Aircraft 60
Discrete-Time Frequency Response Can be Evaluated Using the z Transform x k+1 = x k + u k z transform is the Laplace transform of a periodic sequence System z transform is zx(z) x(0) = x(z) + u(z) which leads to [ ] x(z) = ( zi ) 1 x(0) + u(z) Further details are beyond the present scope 61 Second-Order Example: Airplane Roll Motion p ( ( = Roll rate, rad/s ( Roll angle, rad ( ) A = Aileron deflection, rad L p : roll damping coefficient L A : aileron control effect Rolling motion of an airplane, continuous-time p ( ( = L p 0 p ( ( 1 0 ( ( + L ) A 0 ( ) A ( Rolling motion of an airplane, discrete-time p k k ( ( = e L pt 0 ( e LpT )1) 1 L p ( ( ( ( p k)1 k)1 ( ( + ~ L T * A 0 ( * A k)1 ( T = sampling interval, s 62