codesign tools for embedded control systems karl-erik Årzén, anton cervin, dan henriksson, martin...

62
Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker RUNES

Upload: ashley-sherman

Post on 27-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Codesign Tools for Embedded Control Systems

Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin,

Bo Lincoln, Johan Eker

RUNES

Page 2: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Outline

• Introduction• JitterBug – statistical analysis of

how timing affects control performance

• TrueTime – simulation-based analysis of how timing affects control performance

Page 3: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

What is Good Control Performance?• Application dependent• Time-domain criteria

– Rise time– Overshoot– Settling time

• Frequency-domain criteria– Cross-over frequency– Closed-loop bandwidth– Amplitude and phase margins

• Quadratic cost function– System excited by white noise– Statistical (average) measure

• ……

Page 4: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Control Performance

Scheduling &Network

Parameters(T,D,Prio,

Protocol,…)

Task TimingParameters

(latencies, jitter, …)

ControlPerformance

(variance, rise time, overshoot, ….)

Complex relationship Complex relationship

Page 5: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Control Performance in Reality

• Real applications consists of multiple cooperating control loops:– cascade controller– industrial robots– combustion engines– flight control systems

• Implemented as one or several tasks• The performance is related to the goal or mission rather

than to individual loops• How should we define control performance in this case?

Page 6: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Resource Constraints

• Product-level constraints ($$, size, connectability, …) generate platform-level resource constraints:– Computing speed– Memory and chip size– Communication bandwidth– Power consumption– …

• True in spite of the rapid development of computing hardware

Page 7: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Co-Design

• Increasingly important due to the resource constraints• Several levels:

– Mechatronics– Hardware-software– Functionality-dependability– Control and computing – ….

• Why control?– Important class of embedded systems– Unique possibilities to manage uncertainty

Page 8: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Not a New Topic

• In the 1960-70s constrained computer resources and temporal non-determinism were a general problem that was well-known among control engineers– E.g. effects of fixed point calculations on control performance

• During the last 20 years a lot of old knowledge has been forgotten

• Example: ”Rediscovered” PhD thesis– ”Random sampling and random delays in optimal control

systems”, Charles Davidson, KTH Stockholm, 1973

Page 9: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Co-Design Tools• Especially in embedded systems separation-of-

concern based approaches are not enough• New types of tools needed that take

implementation-level timing effects and constraints into account

• Analysis, simulation, synthesis

Page 10: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

The Control and Scheduling Co-Design Problem

“Given a set of plants to be controlled and an implementation platform with limited

computing and communication resources, design a set of controllers and schedule them such that the overall control performance is

optimized”

Page 11: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

DependenciesThe nature and degree of difficulty of the codesign

problem depend on:– The RTOS

• scheduling algorithms supported• I/O handling• execution time measurements, overrun handlers

– The scheduling algorithm• time or event-driven• priority or deadline-driven• schedulability and response time results available• which parameters can be changed on-line

Page 12: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Dependencies– The controller synthesis method

• design criteria• continuous-time or discrete-time design• robustness towards timing variations• active or passive compensation for timing variations

– Execution-time characteristics of controller code• predictable WCET• sample-to-sample variations• multiple operating modes with different timing profiles

Page 13: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Dependencies– Off-line or on-line optimization

• what information is available for off-line design?

• how accurate is it?

• what can be measured on –line?

• dynamic task allocation

• re-optimization at workload changes

• feedback from control performance to scheduling algorithm

– Network communication• network protocol

• guarantees on network latency

• probability of lost packets

• global notion of time

• time stamping

Page 14: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Co-Design Tool Origins

Co-Design Tools

Hybrid Systems Control

Multi-Model DesignEnvironments

Real-Time Scheduling &Computing

Networking

Page 15: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Multi-Model ToolsFocus:• modeling, simulation, and design of concurrent, real-time,

embedded systems. • assembly of concurrent components • well-defined models of computation that govern the interaction

between components • use of heterogeneous mixtures of models of computation

Examples:• Ptolemy II• Metropolis• MetaH

Page 16: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Ptolemy II• Berkeley / CHESS / Edgar Lee• Focus on complex embedded systems that mix widely different operations,

such as networking, signal processing, feedback control, mode changes, sequential decision making, and user interfaces

• Models of computations– Continuous Time– Discrete Events– Distributed Discrete Events– Communication Sequential Processes (CSP)– Discrete Time– Finite State Machine– Process Networks– Synchronous Data Flow & Dynamic Data Flow– Giotto– Synchronous/Reactive– Timed Multitasking– ….

• http://ptolemy.eecs.berkeley.edu/ptolemyII/• Status: Public domain, Version 5.0 Beta released in May 2005

Page 17: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Metropolis

• Gigascale Systems Research Center (GSRC) – Berkeley + Politechnico di Torino + Cadence – Alberto Sangiovanni-Vincentelli

• Design environment for heterogeneous systems• An infrastructure, a tool set, and design methodologies for various

application domains • Tools

– simulation– synthesis– analysis/verification

• Appears to be less homogeneous than Ptolemy II• http://www.gigascale.org/metropolis/• Status: Released in the open domain in September 2005

Page 18: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

MetaH

• Honeywell• Language and toolset for developing reliable, real-time

multiprocessor avionics system architectures• Describe the interfaces and properties of software and hardware

components and combine them into an overall integrated system. • Tools for analyzing real-time schedulability, reliability, and partition

integrity• Targeting to avionics real-time execution environments • http://www.htc.honeywell.com/metah/• Status unclear

Page 19: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Hybrid System Tools

• Continuous + discrete dynamics– differential equations– automata

• Continuous systems with– events– switches– modes

• Not well suited for modeling real-time computations

Page 20: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Hybrid System Tools• Simulation tools

– sometimes with automatic code generation

• Examples– Simulink + Stateflow– SCICOS

• public domain “Simulink”• connection to SynDEx CAD software for rapid prototyping of distributed r-t

embedded applications

– Modelica/Dymola– Sildex / RT-Builder

• based on the SIGNAL language• mathematical foundation

– HyVisual• based on Ptolemy II

Page 21: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Hybrid System Tools• Formal verification tools

– Charon (UPenn)• agents with modes with continuous and discrete behaviour

– CheckMate (CMU)• verification toolbox on top of Matlab• threshold event-driven hybrid systems

– Masaccio (Berkeley)• formal model for hybrid dynamical systems built from atomic discrete components

(difference equations) and atomic continuous components (differential equations) by parallel and serial composition

• hybrid automata– Shift (Berkeley)

• programming language for describing dynamic networks of hybrid automata • continuous-time phases separated by discrete-event transitions

– Hysdel (ETHZ)• describe discrete hybrid automata and generate piecewise affine systems (PWA)

– UPPAAL (Uppsala/Aalborg)• integrated tool environment for modeling, validation and verification of real-time

systems modeled as networks of timed automata, extended with data types (bounded integers, arrays, etc.).

– Others: LSTools, HDV, PHAVer, HyTech, d/dt, Requiem, Ellipsoidal toolbox, HSOLVER, ……

Page 22: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Hybrid System Tools

• Restrictions necessary in order to apply formal methods, e.g.– timed and hybrid automata – integrators (clocks) with

different speed– piecewise affine systems

• In addition to the tools mentioned here there are additional tools developed within the Petri Net community

Page 23: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Networking tools• Based on tools from the networking community

– analyze/simulate communication protocols– analyze/simulate ad hoc networks, e.g., sensor

networks

• Extended with support for computations and continuous dynamics

• Still focused on the networking aspects

Page 24: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Networking toolsExamples:• ns-2

– most widely used wired/wireless network simulator– movement models for mobile applications

• OMNeT• TOSSIM

– TinyOS sensor network simulator– TinyOS code + ZigBee networks

• NAB (Network in A Box)– large scale sensor networks

• Network/control cosimulation tool (Branicky)– based on ns-2– extended with continuous dynamics to model plants

• Ptolemy 2– extended to suppotr wireless sensor networks

• …..

Page 25: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Real-Time Scheduling

• Scheduling simulators and/or microprocessor simulators/emulators extended with networking and/or continuous dynamics

• Examples:– RTSIM (Pisa)

• extended with continuous dynamics (OCTAVE)

– SIMICS (Virtutech)• software emulation on various target models• extended with networking support

Page 26: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Control-Based Tools• Basis in continuous control & dynamics• Extended with support for computing and communication• Often based on Matlab-Simulink• Examples

– TrueTime (Lund)• Co-simulation of rt-kernels, networks and continuous plant dynamics in

Simulink– Jitterbug (Lund)

• Analysis of control performance subject to timing variations• Matlab

– AIDA Toolset (KTH)• Matlab/Simulink-based environment for model-based codesign and analysis

of real-time control systems• support for timing analysis

– XILO (KTH)• related to AIDA• also supports fault injection

Page 27: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Outline

• Introduction• JitterBug – statistical analysis of

how timing affects control performance

• TrueTime – simulation-based analysis of how timing affects control performance

Page 28: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug

• Matlab-based toolbox for analysis of real-time control performance

• Evaluate effects of latencies, jitter, lost samples, aborted computations, etc on control performance

• Analyze jitter-compensating controllers, aperiodic controllers, multi-rate controllers

• Calculation of a quadratic performance criterion function

• Packaging of existing theory for linear quadratic Gaussian systems and jump-linear systems

Developed by Bo Lincoln and Anton Cervin

Page 29: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Cost Function Computation

Page 30: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Cost Function Computation

Page 31: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Cost Function Computation

Page 32: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Cost Function Computation

Page 33: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Cost Function Computation

Page 34: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Cost Function Computation

Page 35: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitter

• What if the delay L is random?– Impossible to obtain closed-form expression for J

• Alternatives:– Analysis with Jitterbug– Simulation with TrueTime

Page 36: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Analysis

• System described using a number of connected continuous-time and discrete-time transfer function blocks driven by white noise

Distributed Control Loop:

Plant SensorActuator

Controller

Page 37: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Analysis• The execution of the blocks is

described by a stochastic timing model expressed as an automaton

• Each state can trigger one or more discrete systems

• Time intervals are represented by discrete probability distributions

Page 38: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Model - Example

Page 39: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Example Script

% Corresponds to zero delay

Page 40: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug example script

Page 41: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Simple Example

• P(s) – Process (Inverted pendulum)• S(z) – Sampler (perfect sampling)• K(z) – Controller + actuator• Lio – input output latency

2

1 S(z)

K(z)

Timing model:

Lio

Page 42: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Demo

Page 43: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Results

Page 44: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

More complicated cases

Page 45: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Aperiodic Systems

• Jitterbug supports both periodic and aperiodic systems

• Periodic:– >calccost– Analytical solution, reasonably fast

• Aperiodic:– >calccostiter– Iterative computation with possibly very slow

convergence

Page 46: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Internal Workings (periodic case)

Page 47: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Computational complexity (periodic case)

Page 48: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Markov Models

1 2

[0 0.1 0.2 0.3 0.4]

1 2

1 1 1

0.4

0.3

0.2

0.1

Timing Nodes:

Markov Nodes:

Page 49: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Markov Models

1 2

Continuous Dynamics

Discrete Dynamics

Page 50: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Limitations• Only linear systems• Simplistic timing model

– Delays assumed to be independent from period to period– Delay characteristics may not change over time

• Only quadratic performance measures• Statistical analysis• Assumes that timing distributions are known• No GUI yet

Page 51: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Pros and cons

Pros:– Analytical performance computation– Fast to evaluate cost for a wide range of parameters– Guarantees stability (in mean-square sense) if cost is

finite

Cons:– Simplistic timing models– Only linear systems and quadratic costs– Requires knowledge about latency distributions

Page 52: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Limitations

Only linear systems:– Linear analysis and linear control is often good

enough– However, certain non-linear elements are crucial for

good control performance, e.g., anti-windup schemes in the case of actuator saturation

– Cannot be analyzed in Jitterbug

Page 53: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Limitations

Simplistic timing model:– Delays assumed to be independent from period to

period– Delay distributions may not change over time– Certain common controller implementation methods

Page 54: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Common Implementation Method

Cannot be analyzed

nextTime = getCurrentTime();while (true) { executeController(); nextTime = nextTime + samplingPeriod; delayUntil(nextTime);}

Page 55: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Limitations

Statistical analysis:– The calculated cost is an expected value– All results only hold in a mean-value sense

• Not suitable as a basis for formal verification

– Timing scenarios with probability zero are disregarded by the analysis

• E.g. switching-induced instability

Page 56: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Limitations

Latency distributions:– Assumed known– Where do we get them?– Existing scheduling theory can at best give worst-and

best-case values– Need for scheduling theory that provides more

statistical information– TrueTime can be used to generate the distributions

through simulation• But, then why not also use TrueTime to evaluate the cost

functions?

Page 57: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Textual Interface

… N = addtimingnode(N,1,Ptau,2); … N = adddiscsys(3,K,2,2);

2

1 S(z)

K(z)

Timing model:

Node Id

Block Id

Page 58: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug GUI• Under development

Matlab Text Console

Java GUI• System model• Timing model

JNI / C interface

Matlab Compute Engine

Page 59: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Jitterbug Availability

http://www.control.lth.se/user/lincoln/jitterbug/

Jitterbug 1.2 can be downloaded from

Page 60: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Outline

• Introduction• JitterBug – statistical analysis of

how timing affects control performance

• TrueTime – simulation-based analysis of how timing affects control performance

Page 61: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Separate PDF presentation

Page 62: Codesign Tools for Embedded Control Systems Karl-Erik Årzén, Anton Cervin, Dan Henriksson, Martin Ohlin, Bo Lincoln, Johan Eker

Future Development

• Port the network simulation parts to Modelica• Port TrueTime to Scicos/Scilab• Increase the possibility to use production C code directly in the

simulator

SimulinkControl Design

Code generation

Integration in ECU

SimulinkControl Design

Code generation

Integration in ECU

TrueTime ECUsimulation

TrueTime ECUsimulation

Manuelconversion