26_SimulinkExample[1]

41
J.Y.Hun J.Y.Hun g g ELEC 7500/6 State Variable ELEC 7500/6 State Variable Analysis Analysis 1 Computer Aided Computer Aided Analysis & Design Analysis & Design Meeting #27 Meeting #27 December 3, 2002 December 3, 2002

Transcript of 26_SimulinkExample[1]

Page 1: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 11

Computer AidedComputer AidedAnalysis & DesignAnalysis & Design

Meeting #27Meeting #27

December 3, 2002December 3, 2002

Page 2: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 22

Download Notes From...Download Notes From...

• FTP siteFTP siteftp.eng.auburn.edu/pub/jhung/ELEC_7500ftp.eng.auburn.edu/pub/jhung/ELEC_7500

• Today’s filenameToday’s filename

26_SimulinkExample.ppt26_SimulinkExample.ppt

Page 3: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 33

The ProblemThe Problem

• Given a systemGiven a system

• System analysisSystem analysis

• Feedback system designFeedback system design

• Using a modern computer toolUsing a modern computer tool

00 , ,, xxuxfx tt

Page 4: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 44

Examples Presented (1)Examples Presented (1)

• Model constructionModel construction

• Finding a linear modelFinding a linear model

• Linear stability analysisLinear stability analysis

• Analysis of model propertiesAnalysis of model properties

Page 5: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 55

Examples Presented (2)Examples Presented (2)

• Feedback controller designFeedback controller design

• State estimator designState estimator design

• Computer simulationComputer simulation

Page 6: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 66

The PlantThe Plant

2nd order, nonlinear2nd order, nonlinear

1

1212

21

1

xy

uxxxx

xx

Page 7: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 77

Equilibrium PointsEquilibrium Points

Satisfy Satisfy ff((x,ux,u)=0…)=0…

uxxx

x

10

0

121

2

Page 8: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 88

Equilibrium PointsEquilibrium Points

Satisfy Satisfy ff((x,ux,u)=0…)=0…

xx1 1 = 1 = 1 OR OR u u = 0= 0

uxxx

x

10

0

121

2

Page 9: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 99

Simulink StartupSimulink Startup

At the Matlab promptAt the Matlab prompt

>>simulink>>simulink

Or from the File menuOr from the File menu

New New Model Model

Page 10: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1010

Simulink Block LibrarySimulink Block Library

Page 11: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1111

Creating a New ModelCreating a New Model

Page 12: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1212

Drag & drop blocksDrag & drop blocks

Page 13: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1313

Simulink model of the plantSimulink model of the plant

Page 14: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1414

Nonlinear function blockNonlinear function block

Page 15: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1515

Specifying inputs and outputsSpecifying inputs and outputs

• INportINport– SOURCES block librarySOURCES block library

• OUTportOUTport– SINKS block librarySINKS block library

Page 16: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1616

Finding a Linear Model (1)Finding a Linear Model (1)

GivenGiven ((nonlinearnonlinear))

xx00 and and uu00 chosen so that chosen so that ff((xx00,u,u00))==00..

ThenThen

((linearlinear))

dudd

B

fx

A

fxuuxxu

uuxxx

0

0

0

0

uxfx ,

Page 17: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1717

Finding a Linear Model (2)Finding a Linear Model (2)

GivenGiven ((nonlinearnonlinear))

ThenThen

((linearlinear))

dudd D

hx

C

hyuuxxu

uuxxx

0

0

0

0

uxhy ,

Page 18: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1818

Using Simulink & MatlabUsing Simulink & Matlab

The "linmod" commandThe "linmod" command

>>[A,B,C,D]=linmod('JYHexample',[1; 0],0)>>[A,B,C,D]=linmod('JYHexample',[1; 0],0)

• Simulink filenameSimulink filename• value of the statevalue of the state• value of the inputvalue of the input

Page 19: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 1919

"linmod" result"linmod" result

A=A=

00 1.00001.0000

00 1.00001.0000

B=B=

00

00

C=C=

1.00001.0000 00

D=D=

00

Page 20: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2020

Different result for A,BDifferent result for A,B

>>[A,B,C,D]=linmod('JYHexample',[0; 0],0)>>[A,B,C,D]=linmod('JYHexample',[0; 0],0)

Note: Linearized model is in Note: Linearized model is in controllable canonic form!controllable canonic form!

Page 21: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2121

Linear model stabilityLinear model stability

>>eig(A)>>eig(A)

ans=ans=

001.00001.0000

Page 22: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2222

Linear model controllabilityLinear model controllability

>>Qc=ctrb (A,B)>>Qc=ctrb (A,B)

Qc=Qc=00 00

00 00

Page 23: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2323

Linear model observabilityLinear model observability

>>Qo=obsv (A,C)>>Qo=obsv (A,C)

Qo=Qo=1.00001.0000 0 0

00 1.00001.0000

Page 24: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2424

Summary of example resultsSummary of example results

• UnstableUnstable

• UnControllableUnControllable– can’t place poles by state feedbackcan’t place poles by state feedback

• ObservableObservable– can place poles by output feedback + can place poles by output feedback +

observerobserver

Page 25: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2525

Pole Placement DesignPole Placement Design

>>p=[-1+1j -1-1j]>>p=[-1+1j -1-1j]

>>K= place(A,B,p)>>K= place(A,B,p) pp

K=K=2.00002.0000 3.00003.0000

Matlab recognizes i or jfor complex numbers

Page 26: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2626

Optimal (LQR) DesignOptimal (LQR) Design

>>Q=eye(2,2), R=1>>Q=eye(2,2), R=1

>>[K,P,E] = LQR(A,B,Q,R)>>[K,P,E] = LQR(A,B,Q,R)

K=K=1.00001.0000 3.00003.0000

Page 27: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2727

Controller in SimulinkController in Simulink

Page 28: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2828

Subsystem in ModelSubsystem in Model

Page 29: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 2929

Gain Block in ModelGain Block in Model

Page 30: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3030

Observer DesignObserver Design

>>po=[-3+3i -3-3i]>>po=[-3+3i -3-3i]

>>L = place(A',C',po)'>>L = place(A',C',po)'

L=L= 7.00007.0000

25.000025.0000

Recall DUAL relationshipbetween control and

estimation!

Page 31: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3131

Observer in SimulinkObserver in Simulink

Page 32: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3232

Simulink Observer NotesSimulink Observer Notes

• Observer inputs are Observer inputs are dduu and and ddyy

• B field has to account for 2 signalsB field has to account for 2 signals– plant input plant input dduu

– plant output plant output ddyy

• C field should bring out all states!C field should bring out all states!

Page 33: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3333

Observer Setup ExampleObserver Setup Example

Page 34: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3434

Simulation ParametersSimulation Parameters

Page 35: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3535

Some Simulation ParametersSome Simulation Parameters

Page 36: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3636

Other Simulation IssuesOther Simulation Issues

• Initial conditionsInitial conditions– check the integrator blockscheck the integrator blocks

• Numerical integration methodNumerical integration method– Runge-Kutta: good, general purposeRunge-Kutta: good, general purpose

– Gear: "stiff" problems, linearGear: "stiff" problems, linear

Page 37: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3737

Plotting DataPlotting Data

• Use Simulink "scope" blockUse Simulink "scope" block– plots results as simulation progressesplots results as simulation progresses

• Save data to workspace blocks and Save data to workspace blocks and use Matlab "plot" commanduse Matlab "plot" command

Page 38: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3838

Workspace BlockWorkspace Block

Page 39: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 3939

More tips…More tips…

• Position of signals on blocksPosition of signals on blocks– affects order in a vectoraffects order in a vector

– study the MUX block carefullystudy the MUX block carefully

• Structures vs. arraysStructures vs. arrays

Page 40: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 4040

final comment…final comment…

The example doesn’t “work”!The example doesn’t “work”!– Several model construction errorsSeveral model construction errors

• see “More tips…” slidesee “More tips…” slide

– Choice of equilibrium point is badChoice of equilibrium point is bad• xx11 = 1 is not good = 1 is not good

• try try xx = 0 (the origin) = 0 (the origin)

– K and L values are fabricated!K and L values are fabricated!

Page 41: 26_SimulinkExample[1]

J.Y.HungJ.Y.Hung ELEC 7500/6 State Variable AnalysisELEC 7500/6 State Variable Analysis 4141

HomeworkHomework

• Work on term project ...Work on term project ...

• Study Fall-2000 final exam…Study Fall-2000 final exam…7500_final_exam_f’00.pdf7500_final_exam_f’00.pdf

7500_final_exam_f’00.2.pdf7500_final_exam_f’00.2.pdf