Control Task Timing and Quality of Control Anton Cervin Department - - PowerPoint PPT Presentation

control task timing and quality of control
SMART_READER_LITE
LIVE PREVIEW

Control Task Timing and Quality of Control Anton Cervin Department - - PowerPoint PPT Presentation

Control Task Timing and Quality of Control Anton Cervin Department of Automatic Control Lund University Sweden Joint work with Bo Lincoln, Dan Henriksson, Martin Andersson and Karl-Erik rzn Anton Cervin Control Task Timing and Quality of


slide-1
SLIDE 1

Control Task Timing and Quality of Control

Anton Cervin

Department of Automatic Control Lund University Sweden Joint work with Bo Lincoln, Dan Henriksson, Martin Andersson and Karl-Erik Årzén

Anton Cervin Control Task Timing and Quality of Control

slide-2
SLIDE 2

Outline

1

Introduction

2

Inverted pendulum example

3

Controller timing

4

Analysis of quality of control

The Jitter Margin Jitterbug TrueTime

5

Conclusion

Anton Cervin Control Task Timing and Quality of Control

slide-3
SLIDE 3
  • 1. Introduction

Anton Cervin Control Task Timing and Quality of Control

slide-4
SLIDE 4

Classical Control Systems

Controller Process Control Reference Output Feedback Process: Continuous-time dynamics (differential equations) Controller: Continuous-time dynamics

Anton Cervin Control Task Timing and Quality of Control

slide-5
SLIDE 5

Computer-Controlled Systems

A/D Controller D/A Process Computer Task i+1 Task i−1 Process: Continuous-time dynamics Controller: A task executing in an operating system

Anton Cervin Control Task Timing and Quality of Control

slide-6
SLIDE 6

A Typical Control Task

t = current_time(); while (1) { read_input(); compute_control(); write_output(); t = t + T; wait_until(t); }

Anton Cervin Control Task Timing and Quality of Control

slide-7
SLIDE 7

Control Performance

The performance of a control task depends on the task timing Some rules of thumb: The shorter the period, the better the control performance

A suitable task period T is given by 0.2/ω b < T < 0.6/ω b where ω b is the bandwidth of the closed-loop system (fast system high bandwidth)

The larger the delays and jitter, the worse the performance

Delays and jitter smaller than 10% of the period can usually be ignored

Anton Cervin Control Task Timing and Quality of Control

slide-8
SLIDE 8

Some Interesting Design Trade-Offs

Trade-off between resource usage and control performance Trade-off between delay and jitter

Jitter can be reduced at the expense of more delay But, a long, constant delay is often worse than a short, time-varying delay

Trade-off between different control tasks

How to optimize the global performance?

Anton Cervin Control Task Timing and Quality of Control

slide-9
SLIDE 9
  • 2. Inverted Pendulum Example

Anton Cervin Control Task Timing and Quality of Control

slide-10
SLIDE 10

Inverted Pendulum Example

Suppose you want to control three inverted pendulums using

  • ne CPU:

y1 y1 y2 y2 y3 y3 u1 u1 u2 u2 u3 u3 CPU RTOS

Anton Cervin Control Task Timing and Quality of Control

slide-11
SLIDE 11

Design

Discrete-time LQG controllers Sampling intervals: (T1, T2, T3) = (10, 14.5, 17.5) ms (short pendulum short sampling period) Assumed execution time: Ci = 3.5 ms Schedulable under both rate-monotonic and earliest-deadline-first scheduling (assuming Di = Ti)

U = Ci

Ti = 0.79

Anton Cervin Control Task Timing and Quality of Control

slide-12
SLIDE 12

TrueTime Simulations

1

Ideal simulation (no scheduling, only fixed delay of 3.5 ms)

2

Rate-monotonic scheduling

3

Earliest-deadline-first scheduling

Anton Cervin Control Task Timing and Quality of Control

slide-13
SLIDE 13
  • 3. Controller Timing Analysis

Anton Cervin Control Task Timing and Quality of Control

slide-14
SLIDE 14

Ideal Controller Timing

Process u t

( ) )

uk y t

(

u t

( )

yk Sampler Hold Computer uk yk t t t y t

( )

t D-A A-D

Periodic sampling, no delays, no jitter

Anton Cervin Control Task Timing and Quality of Control

slide-15
SLIDE 15

Real Controller Timing – Single Task

(k − 1)T kT (k + 1)T Lk−1

io

Lk

io

Lk+1

io

t

I I I O O O

T – nominal sampling period Lk

io – input-output latency in period k

varying execution time, hardware interrupts

Anton Cervin Control Task Timing and Quality of Control

slide-16
SLIDE 16

Real Controller Timing – Multiple Tasks

(k − 1)T kT (k + 1)T Lk−1

io

Lk

io

Lk−1

s

Lk

s

t

I I I O O

Lk

s – sampling latency in period k

preemption from other tasks

Lk

io – input-output latency in period k

preemption from other tasks and varying execution times

Anton Cervin Control Task Timing and Quality of Control

slide-17
SLIDE 17

Definition of Jitters

tk−1 tk tk+1 Lk−1

io

Lk

io

Lk−1

s

Lk

s

t

I I I O O

Sampling jitter: Js

def

= max

k

Lk

s − min k

Lk

s

Input-output jitter: Jio

def

= max

k

Lk

io − min k

Lk

io

Js and Jio can be found using scheduling theory

Anton Cervin Control Task Timing and Quality of Control

slide-18
SLIDE 18

Computing the Jitters

Response-time analysis for fixed-priority scheduling: worst-case analysis [Joseph & Pandya, 1986]: Ri = Ci +

  • j∈hp(i)

Ri Tj

  • Cj

best-case analysis [Redell & Sanfridson, 2002]: Rb

i = Cb i +

  • j∈hp(i)
  • Rb

i − Tj

Tj

  • Cb

j

(Response-time analysis under EDF is more complicated)

Anton Cervin Control Task Timing and Quality of Control

slide-19
SLIDE 19

Computing the Jitters

Sampling jitter of task i: Replace task τ i by short “sampling task” ˜ τ i with ˜ Ci 0 min

k

Lk

s i = 0

max

k

Lk

s i = ˜

Ri Jsi = ˜ Ri − 0 = ˜ Ri Input-output jitter of task i: min

k

Lk

ioi = Rb i

max

k

Lk

ioi = Ri

Jioi = Ri − Rb

i

Anton Cervin Control Task Timing and Quality of Control

slide-20
SLIDE 20
  • 4. Analysis of Quality of Control

Anton Cervin Control Task Timing and Quality of Control

slide-21
SLIDE 21

Analysis of Quality of Control

Constant delay and no jitter – easy

the delay decreases the phase margin still a linear, time-invariant system standard linear control theory can be used

Time-varying delays (jitter) – more difficult

worst-case stability analysis – the Jitter Margin stochastic performance analysis – Jitterbug detailed co-simulation – TrueTime

Anton Cervin Control Task Timing and Quality of Control

slide-22
SLIDE 22

The Jitter Margin

Anton Cervin Control Task Timing and Quality of Control

slide-23
SLIDE 23

The Jitter Margin

Generalizes the classical delay margin to systems with jitter Assumptions: Periodic sampling (Js = 0)

hardware- or interrupt-driven sampling plant is sampled when the task is released

Time-varying input-output delay Lio = L + Jio

L – minimum delay Jio – input-output jitter

Input Output

t T Jio L

Anton Cervin Control Task Timing and Quality of Control

slide-24
SLIDE 24

Jitter Margin

Definition: The jitter margin Jm(L) is the largest input-output jitter Jio that guarantees stability of the closed-loop system, given a minimum delay of L. Numerically computed example (Pendulum controller 3):

5 10 15 1 2 3 4 5 6 7 8 9 Constant delay L Jitter margin Jm Lm

Anton Cervin Control Task Timing and Quality of Control

slide-25
SLIDE 25

Computing the Jitter Margin

Simplified continuous-time version: Continuous-time plant P(s), including constant delay L Continuous-time controller K(s) Time-varying control delay in the interval [0, Jio] Theorem [Kao & Lincoln, 2004]: Closed loop stable if

  • P(iω)K(iω)

1 + P(iω)K(iω)

  • <

1 Jioω , ∀ω ∈ [0,∞]

Anton Cervin Control Task Timing and Quality of Control

slide-26
SLIDE 26

Example

Bode Magnitude Diagram Frequency (rad/sec) Magnitude (abs) 10 10

1

10

2

10

−2

10

−1

10 10

1

10

2

1 Jioω

  • PK

1+PK

  • Anton Cervin

Control Task Timing and Quality of Control

slide-27
SLIDE 27

The Pendulum Example – RM

Rate-monotonic scheduling Measure/calculate L and Jio for each task Compute the jitter margin Jm(L) for each task Jio < Jm(L) Stable Task L Jio Jm(L) Stable 1 3.5 4.4 Yes 2 3.5 3.5 6.4 Yes 3 3.5 10.5 8.1 Cannot say

Anton Cervin Control Task Timing and Quality of Control

slide-28
SLIDE 28

The Pendulum Example – EDF

Earliest-deadline-first scheduling Slightly larger jitter for Task 2 Smaller jitter for Task 3 Task L Jio Jm(L) Stable 1 3.5 4.4 Yes 2 3.5 4.0 6.4 Yes 3 3.5 7.0 8.1 Yes (In general, EDF distributes the jitter more evenly than RM)

Anton Cervin Control Task Timing and Quality of Control

slide-29
SLIDE 29

Summary of the Jitter Margin

Pros: Only assumes knowledge of minimum and maximum delays Gives hard (worst-case) stability guarantees Can be used to assign meaningful task deadlines

Assign D < Jm(L) to guarantee stability

Cons: Can be conservative Does not handle sampling jitter Says little about performance

Anton Cervin Control Task Timing and Quality of Control

slide-30
SLIDE 30

Jitterbug

Anton Cervin Control Task Timing and Quality of Control

slide-31
SLIDE 31

Jitterbug

Is a MATLAB toolbox Performs stochastic analysis of control performance Assumes known latency probability distributions Assumes white noise disturbances in the control loop Measures the performance by a quadratic cost function V = lim

t→∞

1 t t xT(τ)Qx(τ) dτ

x – full state vector Q – weighting matrix

Anton Cervin Control Task Timing and Quality of Control

slide-32
SLIDE 32

Jitterbug Model – Example

S(z) S(z) K(z) K(z) P(s) y u v 1 2 3 Ls Lio Signal model: Timing model:

P(s) – process S(z) – sampler, K(z) – controller/actuator Ls, Lio – latency probability distributions

Anton Cervin Control Task Timing and Quality of Control

slide-33
SLIDE 33

Jitterbug Example Script

Ls = ... ; Lio = ... ; N = initjitterbug(dt,h); N = addtimingnode(N,1,Ls,2); N = addtimingnode(N,2,Lio,3); N = addtimingnode(N,3); N = addcontsys(N,1,P,3,Q,R1,R2); N = adddiscsys(N,2,S,1,2); N = adddiscsys(N,3,K,2,3); N = calcdynamics(N); V = calccost(N)

Anton Cervin Control Task Timing and Quality of Control

slide-34
SLIDE 34

Latency Probability Distributions

How to obtain the latency distributions? Simulations (e.g. TrueTime) Statistical scheduling theory

more research needed

Anton Cervin Control Task Timing and Quality of Control

slide-35
SLIDE 35

Example of Latency Distribution

Pendulum controller 3 under EDF scheduling:

0.005 0.01 0.015 1 2 3 4 5 6 7 Lio

Anton Cervin Control Task Timing and Quality of Control

slide-36
SLIDE 36

Jitterbug Example 1

Pendulum controller 3: Ideal case (no jitter): V = 1.00 EDF scheduling: V = 3.29 RM scheduling: V = ∞

Anton Cervin Control Task Timing and Quality of Control

slide-37
SLIDE 37

Jitterbug Example 2

Pendulum controller 3: Cost vs I-O delay and uniform I-O jitter

0.005 0.01 0.01 0.02 1 1.5 2 2.5 3 Average input−output latency Input−output jitter Cost

Anton Cervin Control Task Timing and Quality of Control

slide-38
SLIDE 38

Summary of Jitterbug

Pros: Computes the performance analytically Can evaluate the quality of control for a wide range of timing parameters (period, delay, jitter, lost samples, . . . ) Cons: Uses a simplistic timing model

cannot handle dependencies between periods

Handles only linear systems and quadratic cost functions Hard to obtain the latency distributions

Anton Cervin Control Task Timing and Quality of Control

slide-39
SLIDE 39

TrueTime

Anton Cervin Control Task Timing and Quality of Control

slide-40
SLIDE 40

TrueTime

New MATLAB/Simulink blocks:

Anton Cervin Control Task Timing and Quality of Control

slide-41
SLIDE 41

Features

Computer block: Simulates a full real-time kernel with A/D-D/A interface and network interface User-defined tasks (controllers) are defined as C or Matlab functions or as block diagrams Arbitrary scheduling policy Simulation of hardware interrupts, context switches Network block: Simulates wired and wireless local area networks Offers a variety of predefined network protocols

Anton Cervin Control Task Timing and Quality of Control

slide-42
SLIDE 42

Simulation of Code Execution

1 2 3

Simulated Execution Time Execution of User Code

Simulation on segment level rather than instruction level Each code segment can have a different execution time (may be constant, data-dependent, or random)

Anton Cervin Control Task Timing and Quality of Control

slide-43
SLIDE 43

Example of User-Defined Task

Controller written in Matlab code:

function [exectime, data] = myregul(seg, data) switch seg, case 1, data.y = ttAnalogIn(1); data.u = calculateOutput(data.y); exectime = 0.003; case 2, ttAnalogOut(1,data.u); updateState(data.y); exectime = 0.004; case 3, exectime = -1; end

Anton Cervin Control Task Timing and Quality of Control

slide-44
SLIDE 44

Initialization

The kernel and the tasks are initialized in a script:

nbrInputs = 3; nbrOutputs = 3; ttInitKernel(nbrInputs, nbrOutputs, ’prioFP’); periods = [0.010 0.0145 0.0175]; code = ’myregul’; for k = 1:3 data.ctrl = designctrl(k, delay(k), hdesign(k)); data.x = zeros(3,1); period = periods(k); prio = k; taskname = [’Task ’ num2str(k)]; release = 0; % Release thread at time 0 ttCreatePeriodicTask(taskname,release,period,prio,code,data); end

Anton Cervin Control Task Timing and Quality of Control

slide-45
SLIDE 45

Wireless Embedded Control Systems

The new TrueTime Wireless Network block facilitates the simulation of cooperating mobile robots

Anton Cervin Control Task Timing and Quality of Control

slide-46
SLIDE 46

TrueTime Summary

Pros: Does co-simulation of plant dynamics, environment, code execution, CPU scheduling, network scheduling, batteries Handles any systems than can be modeled in Simulink Can evaluate the impact on control performance of different scheduling policies, control strategies, . . . Cons: Potentially very time-consuming No hard results

Anton Cervin Control Task Timing and Quality of Control

slide-47
SLIDE 47
  • 5. Conclusion

Anton Cervin Control Task Timing and Quality of Control

slide-48
SLIDE 48

Conclusion

Control tasks are an interesting class of real-time tasks

more soft than hard in nature the quality of control depends on the resource allocation

Very complex relationship between task parameters (Ti, Ci, . . . ), controller timing parameters (Ls, Lio, . . . ), and control performance Some tools that can help:

The Jitter Margin Jitterbug (www.control.lth.se/user/lincoln/jitterbug) TrueTime (www.control.lth.se/user/dan/truetime)

Anton Cervin Control Task Timing and Quality of Control