model-based systems design with matlab/simulink

59
Model-Based Systems Design with MATLAB/SIMULINK Slobodan Lubura

Upload: dareh

Post on 24-Feb-2016

67 views

Category:

Documents


1 download

DESCRIPTION

Model-Based Systems Design with MATLAB/SIMULINK. Slobodan Lubura. What is Model-Based-System Design?. Model-Based-System Design use the models to describe the specifications, operation, performance of a component or a system of components - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Model-Based Systems Design with MATLAB/SIMULINK

Model-BasedSystems Design with MATLAB/SIMULINK

Slobodan Lubura

Page 2: Model-Based Systems Design with MATLAB/SIMULINK

What is Model-Based-System Design?

•Model-Based-System Design use the models to describe the specifications, operation, performance of a component or a system of components

•Instead of listing specification in a text document, a model is used that implements the specifications, operation, and performance of components

Page 3: Model-Based Systems Design with MATLAB/SIMULINK

What is Model-Based-System Design?

•Models can be shared with other engineers:•Engineers do not have to generate their own

models from text specifications.•Same model can be used by several

engineers at several different levels in the design process.

•Component models can be used in larger systems

•Models supplied by manufacturers accurately reflect the performance of their components

Page 4: Model-Based Systems Design with MATLAB/SIMULINK

What is Model-Based-System Design?•Model-Based-System Design allows us to

uses models throughout the entire design process:

•Simulation using Simulink (SIL)•Not real-time•Develop detailed plant model•Develop a controller

Page 5: Model-Based Systems Design with MATLAB/SIMULINK

What is Model-Based-System Design?•Real-Time Simulations:

oDetermine how the systems responds in real-time

oGood for human-system interactionoAdditional debugging

•Targeting:oImplement the controller in SIL and make a

Real-Time simulations on a hardware target platform (embedded controller)

oMost logic errors have been removedoErrors occur if model is inaccurate

Page 6: Model-Based Systems Design with MATLAB/SIMULINK

What is Model-Based-System Design?

•Hardware in the Loop (HIL) Simulations:oReal-timeoController implemented on our TargetoPlant implemented on a real-time system.

Page 7: Model-Based Systems Design with MATLAB/SIMULINK

What is Model-Based-System Design?

•Hardware in the Loop (HIL) Simulations:oSame physical interface as in actual systemo“Smoke-free" testing of the controlleroTests:

Controller logicController speed and processing powerPhysical interface.

Page 8: Model-Based Systems Design with MATLAB/SIMULINK

What is Model-Based-System Design?

•Controller deployment:oGiven accurate models and a consistent

interface, we can just plug in the controller to our plant

oIt should work perfectly the first time!! (Not)oIt should work reasonable well, but we will

notice that the plant model may have inaccuracies

oTypically we will need to modify the plant and controller to account for the differences.

Page 9: Model-Based Systems Design with MATLAB/SIMULINK

Example: Model-Based Design of a Motor-Generator System in MATLAB/SIMULINK

Page 10: Model-Based Systems Design with MATLAB/SIMULINK

Model-Based Design Solution

•Create Plant and Controller ModelsoMotor and Generator Modelso P and PI Controllers

•Simulate with Simulink•Real-Time Simulations with xPC

target•Implement Controller on Microchip

dsPIC Real-Time Target or ….•Test•Improve Model and Controller•Repeat

Page 11: Model-Based Systems Design with MATLAB/SIMULINK

Model-Based Design Solution

Simulation Fallacy!!!!•Simple system models are worthless•We must include:

All component nonlinearities and limitations

Every function the model will perform

•The first time we run a simulation of this type the following will occur:

It does not workIt has convergence errors, logic errors,

or improper component behaviorIt runs but the output is obviously wrong

Page 12: Model-Based Systems Design with MATLAB/SIMULINK

Modeling Building Philosophy

•Start with simple component models•Understand simple component

operation•Develop a simple controller•Anticipate expected system output•Verify that output matches

expectation

Page 13: Model-Based Systems Design with MATLAB/SIMULINK

Modeling Building Philosophy

•Add a single function to the model and:Understand the effect on the:

ComponentSystemController

Anticipate the expected system outputVerify that output matches expectation

•Repeat as needed…

Page 14: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink - High Level System

•Using the Simulink to build a model of the plant and controller:

o Plant : Motor, Generator, Shaft EncoderoController: P or PIoPlant Input : Light bulb loadoController Input : Generator speed

•First build a very simple plant•We are aiming for the following system:

Page 15: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink - High Level System

ActualRPM

1

Shaft Encoder

Encoder outputShaft input

Motor

Torque request Motor output 2

Initial Condition

Generator

Number of bulbsMechanical output

DrivelineEnvironment

Env

Number of bulbs2

Torquerequest

1

•Desired model of plant

Page 16: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink

•To build plant (and controller), we will use MBSD:

oStart with simple component modelsoAnticipate the appropriate system responsesoVerify the model works correctlyoMake ONE improvementoUnderstand effect on modeloMake ONE improvementoUnderstand effect on modeloRepeat

Page 17: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- plant model

•The first is created simple a model of ideal DC motor :

oVariable torque from 0 to max rated value

oNo rpm limitsoNo energy conversion inefficienciesoNo frictional lossesoTorque is independent of rpm

•This is a terribly inaccurate model, but it is an easy to understand first step

Page 18: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- motor model

•Use SimDriveline to deploy a simplify motor model

Motor output1

Torque Actuator

T

Motor torqueconstant

0.167

Motorcurrent

7.6

Inertia

Torquerequest

1

Page 19: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- improved motor model

•We will improve the motor model by making the motor torque a function of motor rpm

•Use a lookup table to implement the rpm dependence of the motor

•Obtain a lookup table from the manufacturer data

•Later on we will design an experiment andmeasure the actual torque curve of the motor

Page 20: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- improved motor model

Torque vs. RPM dependence of the motor

Motor output11

Torque Sensor

TB

F

Torque Actuator1

T

Shaft Encoder

Encoder output Shaft input

SaturationProduct

Motor torque

Lookup Table1

Inertia1 DrivelineEnvironment

Env

Torquerequest 2

1

Page 21: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- Generator Model

•Use SimDriveline to deploy a simplify generator model

Motor output 1

1

rad /RPM

60/(2*pi)

Torque Actuator1

T

Torque constant

-1

Saturation

Motion Sensor

v

Max RPM

3000

Inertia 1 DrivelineEnvironment

Env

Divide

Generator speed (RPM)

Signal goes from 0 to 1 as speed goes from 0 to 3000 RPM

Page 22: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- Generator Model

•Load torque changed linearly with speed

Page 23: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- improved generator model

•The max load was equivalent to all of the light bulbs being turned on

•The generator produces a voltage that is proportional to the generator speed.

•This voltage is applied to the light bulbs, and the bulbs draw current proportional to the voltage applied across them (Ohm’s Law)

•To supply the current, the generator produces a torque that opposes its direction of motion.

Page 24: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- improved generator model

Motor output11

rad/RPM1

24/3000

rad/RPM

60/(2*pi)

Torque Actuator1

T

Torque constant

-.167

Saturation1 RoundingFunction

floor

Motion Sensor

v

Inertia1 DrivelineEnvironment

Env

Divide1

Divide

Bulbresistance

12

Number of bulbs1

Generator voltage is 24V when the RPM is 3000

Generator current is the generatorvoltage divided by resistance of the bulbs in parallel

Page 25: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- encoder model

•The final step is to read the shaft speed through a shaft encoder

•We will use the SimDriveline Motion Sensor to convert the SimDriveline signal to a Simulink signal

Encoderoutput

1

Shaft input1

rad/RPM

60/(2*pi)

Motion Sensor

v

Encoder

Encoder outputShaft input

Page 26: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- whole plant

•Finaly we have a whole model of plant

ActualRPM

1

Shaft Encoder

Encoder outputShaft input

Motor

Torque request Motor output 2

Initial Condition

Generator

Number of bulbsMechanical output

DrivelineEnvironment

Env

Number of bulbs2

Torquerequest

1

Page 27: Model-Based Systems Design with MATLAB/SIMULINK

Plant model – transfer function

•For proper choice a plant controller the transfer function of plant must be known

•The first step is bias the plant to operate around the desired operating point

Plant

Torque request Encoder output

Scope 4Constant

0.5

Page 28: Model-Based Systems Design with MATLAB/SIMULINK

Plant model – transfer function

•With a constant torque input of 0.5 Nm the motor - generator system runs at about 600 rpm

0 0.5 1 1.5 2 2.5 30

100

200

300

400

500

600

700

RP

M

t

Page 29: Model-Based Systems Design with MATLAB/SIMULINK

Plant model – transfer function

•Now that we have our plant biased at 600 rpm, we will introduce a small-signal sine wave at the input and measure the magnitude of the output at various frequencies

Sine Wave

Scope 4

Plant

Torque request Encoder output

Constant 1

0.5

Page 30: Model-Based Systems Design with MATLAB/SIMULINK

Plant model – transfer function

•As results we see the following output waveform:

50 100 150 200500

520540

560580

600620640

660

Small signal sine wave around operating RPM

Page 31: Model-Based Systems Design with MATLAB/SIMULINK

Plant model – transfer function

•As results we have the Bode’s plot of transfer function:

10-1 100 101 102 103 10425

30

35

40

45

50

55

60

65 Motor Generator Magnitude Response

Ampl

itude

(dB)

Frequency (rad/sec)

Page 32: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink-controller

•We will start with simple P controler

•Now we have a top-level block diagram

Out11

SaturationError amplifier

P-Gain

Actual RPM2

Desired RPM1

Plant

In1 Actual RPM

Controller

Desired RPM

Actual RPM

Out1Constant

1800

Page 33: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink- Plant response for different controller Gain

0 0.5 1 1.50

100

200

300

400

500

600

700

0 0.5 1 1.50

100

200

300

400

500

600

700

0 0.5 1 1.50

100

200

300

400

500

600

700

0 0.05 0.1 0.15 0.2 0.25598

599

600

601

602

603

604

605

Gain=0.01 Gain=0.1

Gain=1 Gain=100

Page 34: Model-Based Systems Design with MATLAB/SIMULINK

Model Based System design

•This is why we do MBSD•Understand a complex system using

simple components•Understand effect of controller and

components / loads on system response•Identify model shortcomings for future

improvement

Page 35: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink - Improved Model - Friction

•The easiest way to add friction is to incorporate a Friction Clutch into the plant

ActualRPM

1

Shaft Encoder

Encoder outShaft input

Number of bulbs

0

Motor

Torque req Motor output

Max RPM1pressure

Initial ConditionHousing

Generator

Number of bulbs

Motor output

DrivelineEnvironment

Env

Desired RPM

2000

Controller

Desired RPM

Actual RPMOut1

ControllableFriction Clutch

PB F

Added friction

Page 36: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink - Improved Model - Friction

•The frictionless system hasn’t steady state error !!!!

0

200

400

600

800

1000

1200

1400

1600

1800

2000

2200

RPM

0 0.05 0.1 0.15 0.2 0.25 0.30

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

Nm

Page 37: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink - Improved Model - Friction

•If we introduce some friction in system then we have steady state error !!!!

0

200

400

600

800

1000

1200

1400

1600

1800

2000

2200

RPM

0 0.05 0.1 0.15 0.2 0.25 0.30.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

Nm

Page 38: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

•In vehicle design, a data point for verifying the accuracy of the mechanical model of the vehicle is a coast-down test

•Set the engine and motors to zero torque and set the vehicle initial speed and put it to coasts down to zero speed

•Tests and measures aerodynamic drag and vehicle frictional losses

Page 39: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

•Our goal is found the pressure value of the friction clutch to match the measured coast-down time to the simulated coast-down time

•Instead of searching for the clutch pressure manually, we will use the Simulink Response Optimization toolbox

•Suppose that we already have a set points from the measured rpm trace

Page 40: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

•Motor-Generator Coast Down characteristics

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.50

500

1000

1500

2000

2500

3000

RP

M

t

Page 41: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

•Inside the plant, we need to set the initial condition of speed

•We will add a new torque source that balances the torque due to friction

• While the forces are balanced, the motor – generator system will maintain the initial rpm, whatever it is

•When we want the system to coast-down we set the added torque source to zero

Page 42: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

ActualRPM

1

Torque Actuator1

T

Step

Signal Constraint

Shaft Encoder

Encoder outputShaft input

Product

Number of bulbs

0

Motor

Torque request Motor output 2

Max RPM1

pressure

Initial Condition1Housing

Generator1

Number of bulbs

Motor output 1

DrivelineEnvironment

Env

Controller

Desired RPM

Actual RPM

Out 1

ControllableFriction Clutch

PB F

Added compensation torque

Optimization

toolbox

Page 43: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

•Simulated Coast Down function for pressure=0.05

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.40

500

1000

1500

2000

2500

3000

3500

Page 44: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

•We will now use the MathWorks Simulink Response Optimization toolbox to determine the optimum value of the Pressure so that the response of our model matches the measured response

•Finally we have results for optimal value of pressure, pressure=1.1989

Page 45: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

•We will now use the MathWorks Simulink Response Optimization toolbox to determine the optimum value of the pressure so that the response of our model matches the measured response

•Finally we have results for optimal value of pressure, pressure=1.1989

Page 46: Model-Based Systems Design with MATLAB/SIMULINK

Plant Model – Coast Down test

Page 47: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink – Friction Model Notes

•The proposed friction model has a linear change from high rpm to zero. The actual response looks like an exponential decay – somewhat

•Our model of a constant frictional torque is probably too simple

•Friction is probably a function of rotational speed and have nonlinear characteristics???

Page 48: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink – Signal Filtering and scaling for dsPIC ECU

•We now need to clean up our model in terms of the signals being sent to the controller

•Tacho signal (0-10 V) is passed through a combination resistive divider and low pass filter to:

•Eliminate noise on the signal•Change range to 0-5 V R

RCV tacho V ADC

Page 49: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink – Signal Filtering and scaling for dsPIC ECU

•From circuit analysis we have:

2

1

, 1

12

1

ADC CC

tacho C

ADC

tacho

RV R Z sCR ZV R R Z R

sCR

V RsRCRV sCR RRsRC

This is Eq. of low-pass

filter

Page 50: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink – Signal Filtering

•Implementation low pass filter in SIMULINK:

Out 2

1

Low pass filter

10000

10 s + 20000Step Saturation 1

Scaling gain1

1 /5

Page 51: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink Improved Signals - Controller

•Next step is including low pass filter in P controller:

Out11

Transfer Fcn

10000

10s+20000Saturation 1

Saturation

Error amplifier 3

1/3000

Error amplifier 2

1/300

Error amplifier 1

1/5

P gain

50

Actual RPM2

Desired RPM1

Page 52: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink Improved Controller - PI

•PI Control:•One of our goals is to design a controller

for our system•Now that we have a good plant model, we

can use all of our knowledge of control systems to design controllers.

•We will improve existing controller adding an integrator to our system because:

• A proportional gain controller yields an error that is inversely proportional to the gain

• Too high of a proportional gain can make the system oscillate

Page 53: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink Improved Controller - PI

•Implemented PI Controller

Out11

Tacho signalconditioning

In1 Out1

SaturationP_ gain

200

I_ gain

1000

Error amplifier 3

1/3000

Discrete -TimeIntegrator

K Ts

z-1

Actual RPM12

Desired RPM1

Page 54: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink Improved Controller - PI

•System response for P controller no load bulbs

180018501900195020002050210021502200

RPM

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 100.20.40.60.81

1.21.41.61.8

2

Nm

Page 55: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink Improved Controller - PI

•System response for P controller max load bulbs

1800

18501900

195020002050210021502200

RPM

0 0.5 1 1.5 2 2.5 3 3.5 40.81

1.21.41.61.82

2.22.42.6

Nm

Page 56: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink Improved Controller - PI

•System response for PI contoller no load bulbs

1800

1850

1900

1950

2000

2050

2100

2150

2200

RPM

0 0.5 1 1.5 2 2.5 300.20.40.60.81

1.21.41.61.82

Nm

Page 57: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink Improved Controller - PI

•System response for PI controller max load bulbs

1800

1850

1900

1950

2000

2050

2100

2150

2200

RPM

0 0.5 1 1.5 2 2.5 30.81

1.21.41.61.82

2.22.42.6

Nm

Page 58: Model-Based Systems Design with MATLAB/SIMULINK

Model Building with Simulink conclusion

•MBSD is a powerful technique for complex system design

•MBSD can include a lot of different types of models in whole design

•MBSD is common part of rapid prototyping process with no waste of time.

•We can “Smoke-free" testing all the plant parts

Page 59: Model-Based Systems Design with MATLAB/SIMULINK

Thank you for attention