CDS 0: Lecture. System Modeling Richard M. Murray 4 Octoer 004 Goals: Define what a model is and its use in answering questions aout a system Introduce the concepts of state, dynamics, inputs and outputs Provide examples of common modeling techniques: differential equations, difference equations, finite state automata Reading: Åström and Murray, Analysis and Design of Feedack Systems, Ch Advanced: Lewis, A Mathematical Approach to Classical Control, Ch Week : Introduction Review from to Feedack last week and Control Actuate Sense Control = Sensing + Computation + Actuation Compute Feedack Principles Roustness to Uncertainty Design of Dynamics Many examples of feedack and control in natural & engineered systems: BIO BIO ESE ESE CS CDS
Model-Based Analysis of Feedack Systems Analysis and design ased on models A model provides a prediction of how the system will ehave Feedack can give counter-intuitive ehavior; models help sort out what is going on For control design, models don t have to e exact: feedack provides roustness Weather Forecasting Control-oriented models: inputs and outputs The model you use depends on the questions you want to answer A single system may have many models Time and spatial scale must e chosen to suit the questions you want to answer Formulate questions efore uilding a model Question : how much will it rain tomorrow? Question : will it rain in the next 5-0 days? Question 3: will we have a drought next summer? Different questions different models CDS 3 q k m m Example #: Spring Mass System Applications Flexile structures (many apps) Suspension systems (eg, Bo ) Molecular and quantum dynamics Questions we want to answer How much do masses move as a function of the forcing frequency? What happens if I change the values of the masses? Will Bo fly into the air if I take that hill at 5 mph? Modeling assumptions Mass, spring, and damper constants are fixed and known Springs satisfy Hooke s law Damper is (linear) viscous force, proportional to velocity CDS 4
q k Modeling a Spring Mass System m m Model: rigid ody physics (Ph ) Sum of forces = mass acceleration Hooke s law: F = k(x x rest ) Viscous friction: F = v mq&& = k( q q) kq mq&& = k( u q) k( q q) q& 3 Converting models to state space form Construct a vector of the variales that are required to specify the evolution of the system Write dynamics as a system of first order differential equations: dx n p = f( x, u) x, u dt q y = h( x) y q& q q& q d = k k ( q q) q q dt & m m q& k3 k ( u q) ( q q) q& m m m q y = q State space form CDS 5 Frequency Response for a Mass Spring System q k m m Steady state frequency response Force the system with a sinusoid Plot the steady state response, after transients have died out Plot relative magnitude and phase of output versus input (more later) Phase (deg) Magnitude (db) 0 0 0-0 -0-30 -40-50 -60 0-90 -80-70 Frequency Response Matla simulation (see handout) function dydt = f(t, y,...) u = 0.0035*cos(omega*t); dydt = [ y(3); y(4); -(k+k)/m*y() + k/m*y(); k/m*y() - (k+k3)/m*y() - /m*y(4) + k3/m*u ]; t,y] = ode45(dydt,tspan,y0,[], k, 0. 0 k, k3, m, m,, omega); Frequency (rad/sec) CDS 6-360 3
Modeling Terminology State captures effects of the past independent physical quantities that determines future evolution (asent external excitation) q m m Inputs descrie external excitation Inputs are extrinsic to the system dynamics (externally specified) Dynamics descries state evolution update rule for system state function of current state and any external inputs Outputs descrie measured quantities Outputs are function of state and inputs not independent variales Outputs are often suset of state k Example: spring mass system State: position and velocities of each mass: q, q, q&, q& Input: position of spring at right end of chain: Dynamics: asic mechanics Output: measured positions of the masses: q, q CDS 7 Modeling Properties Choice of state is not unique There may e many choices of variales that can act as the state Trivial example: different choices of units (scaling factor) Less trivial example: sums and differences of the mass positions (HW.4) Choice of inputs and outputs depends on point of view Inputs: what factors are external to the model that you are uilding Inputs in one model might e outputs of another model (eg, the output of a cruise controller provides the input to the vehicle model) Outputs: what physical variales (often states) can you measure Choice of outputs depends on what you can sense and what parts of the component model interact with other component models Can also have different types of models Ordinary differential equations for rigid ody mechanics Finite state machines for manufacturing, Internet, information flow Partial differential equations for fluid flow, solid mechanics, etc CDS 8 4
Differential Equations Differential equations model continuous evolution of state variales Descrie the rate of change of the state variales dx Both state and time are continuous variales = f ( xu, ) dt y = h( x) Example: electrical power grid Swing equations && δ+ D & δ = ω0 P B δ δ + G δ δ && δ + D & δ = ω P B δ δ + G δ δ ( sin( ) cos( )) ( sin( ) cos( )) 0 State: Inputs: Outputs: Descrie how generator rotor angles (δ i ) interact through the transmission line (G, B) Staility of these equations determines how loads on the grid are accommodated rotor angles, velocities ( δ, & i δ i ) power loading on the grid (P i ) voltage levels and frequency (ased on rotor speed) CDS 9 Finite State Machines Finite state machines model discrete transitions etween finite # of states Represent each configuration of system as a state Model transition etween states using a graph Inputs force transition etween states Example: Traffic light logic Car arrives on E-W St Timer expires Timer expires Car arrives on N-S St State: Inputs: Outputs: current pattern of lights that are on + internal timers presence of car at intersections current pattern of lights that are on CDS 0 5
Difference Equations Difference eqs model discrete transitions etween continuous variales Discrete time description (clocked transitions) xk+ = f( xk, uk) New state is function of current state + inputs yk+ = h( xk+ ) State is represented as a continuous variale Example: CD read/write head controller (implemented on DSP) howstuffworks.com Controller operation (every /44,00 sec) Get analog signal from read head Determine the data (/0) plus estimate the location of the track center Update estimate of wole Compute where to position disk head for next read (limited y motor torque) State: Inputs: Outputs: estimated center, wole read head signal commanded motion Performance specification Keep disk head on track center Reject disturances due to disk shape, shaking and umps, etc CDS Example #: Predator Prey FOX http://www.math.duke.edu/education/ccp/ materials/diffeq/predprey/contents.html Questions we want to answer Given the current population of raits and foxes, what will it e next year? If we hunt down lots of foxes in a given year, what will the effect on the rait and fox population e? How do long term changes in the amount of rait food availale affect the populations? Modeling assumptions The predator species is totally dependent on the prey species as its only food supply. The prey species has an external food supply and no threat to its growth other than the specific predator. CDS 6
Example #: Predator Prey (/) Discrete Lotka-Volterra model State R k # of raits in period k F k # of foxes in period k Inputs (optional) u k amount of rait food Outputs: # of raits and foxes Dynamics: Lotka-Volterra eqs Rk+ = Rk + r( u) Rk afkrk F = F d F + af R k+ k f k k k Matla simulation (see handout) Discrete time model, simulated through repeated addition 350 300 50 00 50 00 50 0 850 870 890 90 930 Comparison with data Parameters/functions r (u) rait irth rate (per year) (depends on food supply) d f fox death rate (per year) a interaction term CDS 3 Summary: System Modeling Model = state, inputs, outputs, dynamics dx = dt y f ( xu, ) = h( x) x y = f( x, u ) k+ k k = h( x ) k+ k+ Principle: Choice of model depends on the questions you want to answer q k m m function dydt = f(t,y, k, k, k3, m, m,, omega) u = 0.0035*cos(omega*t); dydt = [ y(3); y(4); -(k+k)/m*y() + k/m*y(); k/m*y() - (k+k3)/m*y() - /m*y(4) + k3/m*u ]; CDS 4 7