Embedded Systems MATLAB Tutorial

Transcription

Embedded SystemsMATLAB TutorialHans-Jörg PeterOctober 28th , 2008

Assignments and TutorialsAssignmentsHandout / return: Thursdays (before the lecture)Teams are allowed (at most 3 students / team)Box will be availableFirst assignmentHandout: Today afternoon, online availableReturn: By Monday, 8:00TutorialsMonday, 16:00 - 18:00, SR 015 / E1.3Wednesday, 14:00 - 16:00, SR 5 (215) / E2.4Friday, 10:00 - 12:00, SR 015 / E1.3

MATLAB - Matrix LaboratoryProduced by The MathworksUsed for simulation and numerical computationNo (Maple-like) symbolical solvingStandard tool for developing embedded systems

MATLAB StructureMATLAB core: IDE for the MATLAB languageSimulink: Graphical environment for continuous simulationStateflow: Statecharts for SimulinkMany other add-ons available.

Numerical ComputingSome problems cannot be solved preciselyApproximative numerical solutionsSimulation of the physical world

Starting MATLAB1http://sunray1.studcs.uni-sb.de2Log in3Click on MatLabalternatively:1Log onto a cip, bio, or sunray workstation2ssh -Y appsrv{1,2}.studcs.uni-sb.de3Execute /usr/local/matlab/bin/matlab

MATLAB IDE1231Current directory2Workspace3Command history4Command window4

The MATLAB LanguageSimplified C-like syntaxCase sensitiveInteractive shell: command windowUser defined functions: m-filesMany built-in commands:lookfor keyword help function sprintf ( format str , v1, v2, .)disp ( object )plot (Y)plot (X, Y).

VariablesEach numerical variable is a matrixScalars 1 1 matricesNo explicit declarations / dynamic typingPolymorphismRemoving variables:clear variable clear

Working with Matricesa 4b [4 8 15 ; 16 23 42 ; 1 2 3]c b’d 0:10e 0:0.01:2*pif ones(4)g eye(3)h b*bi b.*b

Script FilesSo called m-filesMust be located inthe current directory orthe global search pathCan be executed from the command windowCan also define functions

Control StructuresConditionalif cond statements [else statements ]endWhile loopwhile cond statements endFor loopfor v from :[ step :] to statements end

Example: Computing πMonte Carlo method for computing πpoints insidepoints total π4

Simulink

Harmonic Oscillatorm mass constantk spring constanty0 initial displacementy current displacementv ẏ current velocitymÿ ky 0 mv̇ ky 0

Harmonic Oscillator in Simulink

Damped Harmonic Oscillatorm mass constantR damper constantk spring constanty0 initial displacementy current displacementv ẏ current velocitymÿ R ẏ ky 0 mv̇ Rv ky 0

Damped Harmonic Oscillator in Simulink

Stateflow

Semantics: Statemate vs. StateflowStandard (Statemate)StateflowAny finite number ofactive events.At most one activeevent.Emitted events arecollected and thenpassed to the entire chart.Emitted events areimmediately passed tothe receiver.

Semantics: Statemate vs. Stateflow (2)Standard (Statemate)StateflowNon-determinism isallowed.Non-determinism is notallowed.Synchronous execution ofAND-states.Sequential execution ofAND-states.Variable changes at theend of the step.Immediate variablechanges.

Stateflow Development

MATLAB Tutorial Hans-Jorg Peter . MATLAB - Matrix Laboratory Produced by The Mathworks Used for simulation and numerical computation No (Maple-like) symbolical solving Standard tool for develop