Hybrid Control and Switched Systems. Lecture #4 Simulation of hybrid systems

Similar documents
Hybrid Control and Switched Systems. Lecture #1 Hybrid systems are everywhere: Examples

Hybrid Control and Switched Systems. Lecture #8 Stability and convergence of hybrid systems (topological view)

Hybrid Control and Switched Systems. Lecture #9 Analysis tools for hybrid systems: Impact maps

Embedded Systems 5. Synchronous Composition. Lee/Seshia Section 6.2

Stochastic Hybrid Systems: Applications to Communication Networks

Course on Hybrid Systems

Embedded Systems 2. REVIEW: Actor models. A system is a function that accepts an input signal and yields an output signal.

Hybrid Systems - Lecture n. 3 Lyapunov stability

Hybrid systems and computer science a short tutorial

EE 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization Fall 2016

Simulation of Vehicle Drivetrain with Modelica

Hybrid Control and Switched Systems. Lecture #2 How to describe a hybrid system? Formal models for hybrid system

EECS 144/244: System Modeling, Analysis, and Optimization

Hybrid Systems Modeling, Analysis and Control

EE291E Lecture Notes 3 Autonomous Hybrid Automata

Controlo Switched Systems: Mixing Logic with Differential Equations. João P. Hespanha. University of California at Santa Barbara.

Synchronous languages and their extension to deal with discrete and continuous-time systems

Hybrid Systems Course Lyapunov stability

Modelica An Object-Oriented Language for Physical System Modeling

Using the Principles of Synchronous Languages in Discrete-event and Continuous-time Models

Symbolic Verification of Hybrid Systems: An Algebraic Approach

Hybrid Control and Switched Systems. Lecture #6 Reachability

Index Reduction and Discontinuity Handling using Substitute Equations

An introduction to Uppaal and Timed Automata MVP5 1

Analysis of a Boost Converter Circuit Using Linear Hybrid Automata

Cyber-Physical Systems Modeling and Simulation of Hybrid Systems

Hybrid Control and Switched Systems. Lecture #3 What can go wrong? Trajectories of hybrid systems

Switched Systems: Mixing Logic with Differential Equations

Discontinuous Systems

Using the Principles of Synchronous Languages in Discrete-event and Continuous-time Models

Stochastic Hybrid Systems: Modeling, analysis, and applications to networks and biology

Timed Automata VINO 2011

Stochastic Hybrid Systems: Applications to Communication Networks

An Introduction to Hybrid Systems Modeling

Specification and Validation of gproms Semantics

Index Theory and Structural Analysis for multi-mode DAE Systems

Hybrid Control and Switched Systems. Lecture #7 Stability and convergence of ODEs

Using Simulink to analyze 2 degrees of freedom system

A Stand Alone Quantized State System Solver for Continuous System Simulation

Physics 584 Computational Methods

HYBRID AND SWITCHED SYSTEMS ECE229 WINTER 2004

Towards a Mechanised Denotational Semantics for Modelica

YTÜ Mechanical Engineering Department

Verification of analog and mixed-signal circuits using hybrid systems techniques

Co-simulation of embedded systems: a PVS-Simulink integrated environment

0 t < 0 1 t 1. u(t) =

Multivariable Control Laboratory experiment 2 The Quadruple Tank 1

Operational Semantics of Hybrid Systems

Verification of Hybrid Systems with Ariadne

Multibody System Dynamics: MBDyn Hydraulics Modeling

Numerical Methods - Boundary Value Problems for ODEs

Interchange Semantics For Hybrid System Models

HRML: a hybrid relational modelling language. He Jifeng

Discrete Event Systems Exam

Modeling and Verifying a Temperature Control System using Continuous Action Systems

EE 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization Fall 2014

Proving Safety Properties of the Steam Boiler Controller. Abstract

HybridSAL Relational Abstracter

Hybrid Control and Switched Systems. Lecture #11 Stability of switched system: Arbitrary switching

Hybrid Systems. April 2012 Kazunori Ueda, Waseda University and NII (with thanks to my students) Computer Software, Vol.28, No.1 (2011), pp

Graphical User Interfaces for Emittance and Correlation Plot. Henrik Loos

Synchronous languages and their extension to deal with discrete and continuous-time systems

Efficient Simulation of Hybrid Systems: A Hybrid Bond Graph Approach

540 IEEE TRANSACTIONS ON AUTOMATIC CONTROL, VOL. 43, NO. 4, APRIL Algorithmic Analysis of Nonlinear Hybrid Systems

TESTING is one of the most important parts of the

1 Introduction. 2 Process description

Hybrid Systems Techniques for Convergence of Solutions to Switching Systems

Is there Life after Zeno?

Plasma: A new SMC Checker. Axel Legay. In collaboration with L. Traonouez and S. Sedwards.

Formally Correct Monitors for Hybrid Automata. Verimag Research Report n o TR

7. Queueing Systems. 8. Petri nets vs. State Automata

Physical Modeling of Hybrid Systems with Rand Model Designer

Models for Efficient Timed Verification

Description of the ED library Basic Atoms

Networked Control System Protocols Modeling & Analysis using Stochastic Impulsive Systems

PC Control / Touch Control

Constructive Models of Discrete and Continuous Physical Phenomena

Differential Equations in the Unifying Theories of Programming

Verification of Nonlinear Hybrid Systems with Ariadne

Automation in Complex Systems MIE090

High Performance Computing

Logic Model Checking

ES205 Analysis and Design of Engineering Systems: Lab 1: An Introductory Tutorial: Getting Started with SIMULINK

YTÜ Mechanical Engineering Department

Introduction to Modelling and Simulation

IMPLEMENTATION OF CONTINUOUS-TIME DYNAMICS IN SCICOS. Masoud Najafi Azzedine Azil Ramine Nikoukhah

Lecture 14 - Using the MATLAB Control System Toolbox and Simulink Friday, February 8, 2013

Subject: Introduction to Process Control. Week 01, Lectures 01 02, Spring Content

Languages for Programming Hybrid Discrete/Continuous-Time Systems

Step Simulation Based Verification of Nonlinear Deterministic Hybrid System

Figure 1 A linear, time-invariant circuit. It s important to us that the circuit is both linear and time-invariant. To see why, let s us the notation

HYPENS Manual. Fausto Sessego, Alessandro Giua, Carla Seatzu. February 7, 2008

Model-Based Safety Assessment with AltaRica 3.0

Simulating Zeno Hybrid Systems Beyond Their Zeno Points

Modelling the Temperature Changes of a Hot Plate and Water in a Proportional, Integral, Derivative Control System

User s Manual of Flow* Version 2.0.0

CHAPTER 6 STATE SPACE: FREQUENCY RESPONSE, TIME DOMAIN

Operational Semantics of Hybrid Systems

Numerical Simulation of Dynamic Systems XXVI

Index. 1/f Noise Need for, 200 Simulating, 200 Using cascaded linear systems, 202

Transcription:

Hybrid Control and Switched Systems Lecture #4 Simulation of hybrid systems João P. Hespanha University of California at Santa Barbara Summary 1. Numerical simulation of hybrid automata simulations of ODEs zero-crossing detection 2. Simulators Simulink Stateflow SHIFT Modelica 1

Numerical simulation of ODEs Initial value problem (IVP) Definition: A signal x : [0,T] R n is a solution to the IVP if x(t) =x 0 + Z t 0 f x(τ) dτ t [0,T] Euler method (first order method): 1st partition interval into N subintervals of length h ú T/N 2nd assume derivative of x constant on each subinterval on each subinterval x is assumed linear x 0 x(t) 0 T t Numerical simulation of ODEs Initial value problem (IVP) Definition: A signal x : [0,T] R n is a solution to the IVP if x(t) =x 0 + Z t 0 f x(τ) dτ t [0,T] Runge-Kutta methods (m-order method): 1st partition interval into N subintervals of length h ú T/N 2nd assume derivative of x constant on each subinterval x 0 x(t) α i, δ i computed assuming a m- order polynomial approximation on each subinterval (truncated Taylor series) 0 T t 2

Numerical simulation of ODEs Initial value problem (IVP) Definition: A signal x : [0,T] R n is a solution to the IVP if x(t) =x 0 + Z t Variable-step methods (e.g., Euler): Pick tolerance ε and define t 0 ú 0 choose t k+1 sufficiently close to t k so that 0 f x(τ) dτ Z tk+1 t [0,T] x t k+1 = x(tk)+ f x(τ ))dτ t k x(t k)+(t k+1 t k)f x(t k) Simulation can be both fast and accurate: 1. when f is flat one can advance time fast, 2. when f is steep one advances time slowly (to retain accuracy) Example #1: Bouncing ball y g Free fall Collision c [0,1) energy absorbed at impact x 1 0 & x 2 < 0? t x 2 ú c x 2 linear/polynomial approximations are bad when transitions occur 3

Example #1: Bouncing ball x 1 0 & x 2 < 0? x 2 ú c x 2 t ball_nozerocross.mdl Example #1: Bouncing ball t before the transition the linear approximation seems very good so the integration algorithm is fooled into choosing a large integration step 4

Zero-crossing detection After a transition is detected, the integration algorithm goes back in time to determine where the transition occurred and starts a new integration step at that point. x 1 0 & x 2 < 0? x 2 ú c x 2 ball_withzerocross.mdl Zero-crossing detection After a transition is detected, the integration algorithm goes back in time to determine where the transition occurred and starts a new integration step at that point. t 5

Summary 1. Numerical simulation of hybrid automata simulations of ODEs zero-crossing detection 2. Simulators Simulink Stateflow SHIFT Modelica suitable for a small number of discrete modes difficult to recover hybrid automaton from Simulink file good for large numbers of discrete modes and complex transitions poor integration between continuous and discrete very good semantics (easily understandable) poor numerical algorithms very good numerical algorithms very convenient for large models with interconnected components difficult to recover hybrid automaton from simulink file MATLAB s Simulink 1. What you see: graphical user interface to build models of dynamical systems 2. What s behind: numerical solver of ODEs with zero-crossing detection A little history Commercial product developed by MathWorks (founded 1984, flag product is MATLAB/Simulink) MATLAB s Simulink was inspired by MATRIXx s SystemBuild (in 2001 MathWorks bought MATRIXx) 6

Simulation of ODEs simple_ode.mdl Simulation of ODEs simple_odex0.mdl 7

ODEs with resets (or impulse systems) Q R n f : R n R n ϕ R n ρ : R n R n set of discrete states continuous state-space vector field transition set reset map x ϕ? E.g., bouncing ball x ú ρ(q 1,x ) x 1 0 & x 2 < 0? x 2 ú c x 2 Q R n f : R n R n ϕ R n ρ : R n R n Simulation of ODEs with resets set of discrete states continuous state-space vector field transition set reset map x ϕ? x ú ρ(q 1,x ) integrator with reset (by default does zero-crossing detection on reset input) 8

Q R n f : R n R n ϕ R n ρ : R n R n Example #1: Bouncing ball set of discrete states continuous state-space vector field transition set reset map x 1 0 & x 2 < 0? x 2 ú c x 2 integrator with reset (by default does zero-crossing detection on reset input) Example #1: Bouncing ball ball_withzerocross.mdl 9

Q R n f : R n R n ϕ R n ρ : R n R n Simulation of ODEs with resets x 1 0 & x 2 < 0? set of discrete states continuous state-space vector field transition set reset map x 2 ú c x 2 x(t k ) x(t k-1 ) The reset pulse is not really instantaneous (may lead to problems for Zeno systems) Example #1: Bouncing ball fails to catch the rising edge of the reset trigger and the ball falls ball_withzerocross.mdl 10

Simulation of hybrid automaton (no resets) Q set of discrete states R n continuous state-space f : Q R n R n vector field ϕ : Q R n Q discrete transition ϕ(q 1,x ) = q 2? mode q 2 mode q 1 mode q 3 E.g., thermostat x mean temperature room ϕ(q 1,x ) = q 3? x 73? q = 1 q = 2 heater x 77? Simulation of hybrid automaton (no resets) Q set of discrete states R n continuous state-space f : Q R n R n vector field ϕ : Q R n Q discrete transition mode q 2 ϕ(q 1,x ) = q 2? mode q 1 Q R 11

Example #2: Thermostat x mean temperature room x 73? q = 1 q = 2 heater x 77? Example #2: Thermostat thermostat.mdl 12

Simulation of hybrid automaton Q set of discrete states R n continuous state-space f : Q R n R n vector field ϕ : Q R n Q discrete transition ρ : Q R n R n reset map x ú ρ(q 1,x ) mode q 2 ϕ(q 1,x ) = q 2? mode q 1 mode q 3 ϕ(q 1,x ) = q 3? x ú ρ(q 1,x ) Simulation of hybrid automaton Q set of discrete states R n continuous state-space f : Q R n R n vector field ϕ : Q R n Q discrete transition ρ : Q R n R n reset map x ú ρ(q 1,x ) mode q 2 ϕ(q 1,x ) = q 2? mode q 1 13

Example #5: Tank system pump pump-on inflow λ = 3 constant outflow μ = 1 y goal prevent the tank from emptying or filling up δ =.5 delay between command is sent to pump and the time it is executed y 1? pump off (q = 1) τ.5? wait to off (q = 4) τ ú 0 τ ú 0 wait to on (q = 2) τ.5? pump on (q = 3) y 2? Example #5: Tank system tank.mdl 14

Stateflow Q set of discrete states R n continuous state-space f : Q R n R n vector field ϕ : Q R n Q discrete transition mode q 2 ϕ(q 1,x ) = q 2? mode q 1 Simulink (continuous dynamics): generates continuous state Stateflow (discrete dyn.): generates discrete state & events (e.g., resets) signals & events Simulation of hybrid automaton Q set of discrete states R n continuous state-space f : Q R n R n vector field ϕ : Q R n Q discrete transition ρ : Q R n R n reset map x ú ρ(q 1,x ) mode q 2 ϕ(q 1,x ) = q 2? mode q 1 replaced by StateFlow chart 15

Simulation of hybrid automaton Q set of discrete states R n continuous state-space f : Q R n R n vector field ϕ : Q R n Q discrete transition ρ : Q R n R n reset map x ú ρ(q 1,x ) mode q 2 ϕ(q 1,x ) = q 2? mode q 1 pump off wait to off wait to on pump on Example #5: Tank system Stateflow does not automatically does zero crossing detection, which must be done manually tank_sf_withzerocross.mdl 16

Example #5: Tank system Stateflow does not automatically does zero crossing detection, which must be done manually tank_sf_nozerocross.mdl SHIFT (Hybrid System Tool Interchange Format) 1. Simulation Language for Hybrid Automaton 2. Developed at UC Berkeley under the PATH (Partners for Advance Transit and Highways) project to simulate Automated Highway Systems 3. PATH provides freeware to compile SHIFT into a C-based simulator ( http://path.berkeley.edu/shift/ ) Advantages: 1. Syntax matches very closely the hybrid automata formalism 2. Object-oriented and scalable (multiple copies of a automata can be created, connected, disconnected, and destroyed as the simulation runs) Problems: 1. Currently the simulation engine is poor (limited integration algorithms, no zero-crossing detection) 2. Still in the development stages 17

A SHIFT program type AutomataType { // declaration of automata types } input state output export discrete transition setup // declaration of input signals // declaration of internal states // declaration of output signals // declaration of events for synchronization // declaration of discrete modes // & corresponding continuous dynamics // definition of transition rules // initializations global setup // declaration of global Automata // creation and initialization of global Automata Example #2: Thermostat x mean temperature room x 73? q = 1 q = 2 heater x 77? thermostat.hs type ThermostatType { state continuous number x := 50; discrete first declared is the initial mode heater_off { x = -x + 50; }, heater_on { x = -x + 100; }; transition heater_off -> heater_on {} when { x<= 73}, heater_on -> heater_off {} when { x>= 77}; } global ThermostatType thermostat; setup define { thermostat := create(thermostattype, x:= 60); } declaration of the ThermostatType type declaration of a variable called thermostat of type ThermostatType creation (and initialization) of the hybrid automaton 18

Example #7: Server system with control incoming rate r q max q Additive increase/multiplicative decrease control (AIMD): while q < q max increase r linearly when q reaches q max instantaneously multiply r by m (0,1) queue dynamics q q max? server B rate of service (bandwidth) controller q(t) r ú mr t Example #7: Server system with control q max incoming rate r server B rate of service (bandwidth) q queue dynamics variable r controller q q max? queue-full event queue-full r > 1 queue-full r ú m r synchronized transitions (all guards must hold for transition to occur) 19

Example #7: Server system with control controller r > 1 queue-full r ú m r.hs type CongestionControllerType { output continuous number r := 0; state number m := 0.5; // multiplicative decrease (parameter) export queue_full; discrete additive_increase { r = 1; } } transition additive_increase -> additive_increase { queue_full } when { r > 1 } do { r := m * r; } synchronization event jump condition reset Example #7: Server system with control queue dynamics r > B? empty q q max, r > B? normal queue-full full q 0, r < B? type QueueType { input continuous number r := 0; state continuous number q := 0; state CongestionControllerType controller; r < B? // controller to synchronize with.hs state number B := 1; state number qmax := 10; // Bandwidth (parameter) // Maximum queue size (parameter) discrete empty_queue { q = 0; } full_queue { q = 0; } normal { q = r - B; } } transition empty_queue -> normal {} when { r > B }, full_queue -> normal {} when { r < B }; normal -> empty_queue {} when { q <= 0 and r <= B ) do { q = 0; }, normal -> full_queue { controller:queue_full } when { q >= Qmax and r>b ) do { q = qmax; }, 20

Example #7: Server system with control queue dynamics variable r event queue_full controller.hs global QueueType queue; global CongestionControllerType contr; setup define { contr := create(congestioncontrollertype); queue := create(queuetype, controller := contr); } connect { r(queue) <- r(contr); } declaration of global variables creation (and initialization) of the hybrid automata inputs output connections Example #10: Server with multiple controllers incoming rates r 1 q max r 2 controller 1 queue_full controller 2 q r 1 r2 server queue dynamics B rate of service (bandwidth) 21

Example #10: Server with multiple controllers controller 1 controller 2 queue_full type QueueType { input continuous number r1 := 0; input continuous number r2 := 0; state continuous number r := 0; state continuous number q := 0; state set(congestioncontrollertype) controllers; r 1 queue dynamics r2 state number B := 1; state number qmax := 10; discrete empty_queue { q = 0; r = r1 + r2; } full_queue { q = 0; r = r1 + r2; } normal { q = r - B; r = r1 + r2; } // Bandwidth (parameter) // Maximum queue size (parameter) 2.hs } transition empty_queue -> normal {} when { r > B }, full_queue -> normal {} when { r < B }; normal -> empty_queue {} when { q <= 0 and r <= B ) do { q = 0; }, normal -> full_queue { controllers:queue_full(all) } when { q >= Qmax and r>b ) do { q = qmax; }, Example #10: Server with multiple controllers controller 1 r 1 queue_full controller 2 r2 global QueueType queue; global CongestionControllerType contr1; global CongestionControllerType contr2; setup define { contr1 := create(congestioncontrollertype, r := 1.5); contr2 := create(congestioncontrollertype, r := 2.0); queue := create(queuetype, controllers := {contr1,contr2} ); } connect { } r1(queue) <- r(contr1); r2(queue) <- r(contr2); queue dynamics declaration of global variables 2.hs creation (and initialization) of the hybrid automata inputs output connections 22

Modelica 1. Object-oriented language for modeling physical systems 2. Developed and promoted by the Modelica Association (international non-profit, non-governmental organization based in Sweden) http://www.modelica.org/ 3. Dynasim AB sells Dymola, currently the best Modelica simulator (interfaces with MATLAB and Simulink) Advantages: 1. Object-oriented and scalable 2. Large number of component libraries available (electric circuits, mechanical system, thermo-hydraulics, power systems, robotics, petri-nets, etc.) 3. Numerically stable simulation engine (allows differential algebraic equations, automatic zero-crossing detection) 4. Heavily used in industry, especially in Europe 5. UCSB has a site license! Problems: 1. Not as widely known as MATLAB/Simulink Modelica object model ModelName // declarations of public variables (inputs and outputs) that // can be accessed using ModelName.Variable name TypeName VariableName; protected // declarations of internal (hidden) variables (state) TypeName VariableName; equation // algebraic and differential equations Expression = Expression; end ModelName 23

Modelica 101 Predefined types Real x, // x is a real number y (start = 1.1, unit = inches ) height ; // y is a height, initialized with 1.1 inches Integer n; // n is an integer Boolean p; // p can be either true or false Type modifiers parameter Real B; // B does not change during the simulation but // can be initialized with different values constant Real PI; // PI is a fixed constant discrete Real q; // q is a piecewise constant variable (discrete state) flow Real r; // r is a flow variable // (connection of flows follow conservation law, // by convention positive means flow enters component) Modelica 101 Predefined functions/variables for use in equation der(x) // derivative of Real signal x pre(x) // left-limit of discrete signal x edge(x) // true when discrete variable x is discontinuous time // simulation time Commands for use in equation x = y // equate two variable x + z = y // (should be interpreted as equation and not assignment) reinit(x, 2.1); // reset variable x to to 2.1 connect(x,y); // connects variables: connect(x,z); // x = y = z (or x + y + z = 0 in case of flows) when p then // execute command when p becomes true command; end when; 24

Example #2: Thermostat x mean temperature room x 73? q = false q = true heater model thermostat Real x Boolean q(start = false) x 77? "Average temperature"; "Heater state"; parameter Real xon = 73 "Turn-on temperature"; parameter Real xoff = 77 "Turn-off temperature"; equation q = if not pre(q) and x <= xon then true // turn on else if pre(q) and x >= xoff then false // turn off else pre(q); // no change der(x) = if q then 100-x else 50-x; end thermostat; thermostat.mo Example #2: Thermostat To get started: setenv PATH /usr/local/dymola/bin:$path dymola5 thermostat.mo [documentation online & refs 15,16] 25

Example #7: Server system with control incoming rate r queue dynamics q q max? q max server B rate of service (bandwidth) q variable r controller queue-full event queue-full queue-full? r ú m r NOT synchronized transitions Example #7: Server system with control controller queue-full r ú m r model Controller Real r(start=0) discrete Boolean queue_full parameter Real a=.1 parameter Real m=.5 "out-flow"; "Queue full"; "Additive constant"; "Multiplicative constant"; equation der(r) = a; when pre(queue_full) then reinit(r, r*m); end when; end Controller.mo 26

Example #7: Server system with control queue dynamics r > B? empty q q max, r > B? normal queue-full full model Queue Real r "In-flow"; q 0, r < B? discrete Boolean queue_full(start=false) "Queue full"; parameter Real B=1 "Bandwidth"; parameter Real Qmax=1 "Max queue size"; r < B? protected discrete Integer status(start=0) "Queue status"; // 0 empty, 1 normal, 2 full Real q(start=0) "Queue size"; equation status = if pre(status) == 0 and r > B then 1 // no longer empty else if pre(status) == 2 and r < B then 1 // no longer full else if pre(status) == 1 and q <= 0 and r < B then 0 // became empty else if pre(status) == 1 and q >= Qmax and r > B then 2 // became full else pre(status); // no change queue_full = pre(status) == 1 and status == 2; der(q) = if status == 1 then r - B else 0; end Queue.mo Example #7: Server system with control queue dynamics r queue_full controller model System Queue queue; Controller contr; equation queue.r = contr.r; queue.queue_full = contr.queue_full; end System.mo 27

Example #7: Server system with control.mo Example #10: Server with multiple controllers incoming rates r 1 q max r 2 controller 1 queue_full controller 2 q r 1 r2 server queue dynamics B rate of service (bandwidth) 2.mo 28

Example #10: Server with multiple controllers controller 1 queue_full controller 2 r 1 r2 model System Queue queue; Controller contr1; Controller contr2; queue dynamics equation queue.r = contr1.r + contr2.r; queue.queue_full = contr1.queue_full; queue.queue_full = contr2.queue_full; end System 2.mo Example #10: Server with multiple controllers 2.mo 2.mo 29

Example #10: Server with multiple controllers see 3.mo for the use of the connect command 3.mo Interfacing Dymola & MATLAB/Simulink Sharing data Each time you simulate a Dymola model, a file xxxx.mat is created with all the data. You can get this data into MATLAB with load xxxx.mat Using Dymola models in Simulink Add dymola to the MATLAB path: path('/usr/local/dymola/mfiles',path) path('/usr/local/dymola/mfiles/traj',path) The Simulink block /usr/local/dymola/mfiles/dymolablockmaster.mdl can be used to insert a Dymola system into a Simulink diagram Not sure if its working? 30

Next class Properties of hybrid systems Safety (reachability) Liveness Asymptotic properties (stability) 31