simulation in labview - overview

Post on 03-Jan-2017

279 Views

Category:

Documents

17 Downloads

Preview:

Click to see full reader

TRANSCRIPT

SimulationinLabVIEW

Hans-PetterHalvorsen,M.Sc.

http://home.hit.no/~hansha/?page=labview

withSelf-pacedStep-by-StepExercises

LabVIEWInstallation

Downloadthesoftwarehere:

http://home.hit.no/~hansha/?page=labviewThesearethemainmodulesweuseinthedifferentcoursesatTelemark UniversityCollege:

• LabVIEW (LabVIEW ProfessionalDevelopmentSystem32-Bit:English)

• NI-DAQmx(HardwareDriverforNIUSB-6008,NITC-01,etc.)• LabVIEW ControlDesignandSimulationModule• LabVIEWMathScript RTModuleNote!Thesepackagesareseparate downloads!

Note!YougettheSerialNumber fromyourTeacher,butthesoftwarecanbeused for30daysbeforeyouneed toenteravalidSerialNumber.

AllLabVIEWSoftwarecanbedownloadedhere:www.ni.com/download

LabVIEWTraining

• LabVIEWTrainingforStudents(NationalInstruments):

http://ni.com/students/learnlabview

• LabVIEWCourse:http://home.hit.no/~hansha/?training=labview

Hereyouwillfind lotsofVideos,TutorialsandExercises

Itisrecommendedthatyouwatchsomeofthevideosbeforeyoureadfurter

LearningbyDoing!

Contents• IntroductiontoLabVIEW• Installation• BlockDiagramSimulationbasedondifferentialEquations– SimulationLoop

• PIDControlwithbuilt-inPIDblocks/functions• CreatingandusingSimulationSubsystems• SimulationsusingaWhileLoopwithSubsystemsinside• Discrete Simulation– FormulaNode

• MathScript

NationalInstrumentsisthevendorofLabVIEW

NationalInstrumentscreatesbothHardware andSoftware

Hardware

cRIO

ZigBee

VisionSystem

Arduino

USB-6008

Wi-FiDAQ

TC-01

NOxSensor

Pt-100

AirHeater

WaterTank

DAQmxistheHardwareDriverneeded inorder tousehardwaredevices likeNIUSB-6008,NITC-01,etc.insideLabVIEW.Themoduleisavailableasapaletteonyourblockdiagram.

LabVIEWThisisthecoreLabVIEWinstallationthatinstallstheLabVIEWProgrammingEnvironment.

Thismoduleisatext-based toolthatisverysimilartoMATLAB.Thesyntaxissimilarto MATLAB,youcancreateandrunso-calledmfiles,etc.ThemoduleisavailablefromtheToolsmenuinsideLabVIEW.

LabVIEWMathScriptRTModule

LabVIEWControlDesignandSimulationModuleThismoduleisusedforcreatingControlandSimulationapplicationswithLabVIEW.HereyouwillfindPIDcontrollers,etc.Themoduleisavailableasapaletteonyourblockdiagram.

NI-DAQmx

http://www.ni.com/pdf/manuals/376039a.pdf

Students:TrysomeoftheseShortcutsandTools

ControlandSimulationinLabVIEWControlDesign&SimulationPaletteinLabVIEW

SimulationPaletteinLabVIEW

PIDPaletteinLabVIEW

ControlDesignPaletteinLabVIEW

Students:Checkthatyouhaveallthesepalettes.Openthedifferentsubpalettes,etc.

SimulationLoop

LabVIEWControlandSimulationExample

Wearegoingtolearntocreatesuchasystem(andmuchmore)!

ExampleofSimulation (andcontrol)ofadynamicsystembasedontheblocksintheSimulationPalette

ModellingofDynamicSystems

Hans-PetterHalvorsen,M.Sc.

DynamicSystemsExamplesWaterTank:

MathematicalModels(differentialequations):

AirHeater:

Alt1(Integrator):

Alt2(Timeconstant/1.order):

Alt3(Nonlinear):h– Levelinthetank

T– Temperatureinthetube

Thesearesmall-scaleprocesseswehaveatHiT

DynamicSystemsExamples2Tank:MathematicalModels(differentialequations):

4Tank:

Thesearesmall-scaleprocesseswehaveatHiT

Integratorsymbol

Dynamicsystemrepresentedasadifferentialequation

DynamicSystems

Dynamicsystemrepresentedasablockdiagram

Whenwehavetheblockdiagramforthesystem,wecaneasilyimplement itinLabVIEW

Note Wecan“easily”createablockdiagramfromthedifferentialequation(s)

�̇� = −𝑎𝑥 + 𝑏𝑢

BlockDiagramExamples

Students:Findtheblockdiagramsfor thedifferentialequationsabove(pen&paper)

Example1:

Example2:

BlockDiagrams- Solutions

or:

Example1:

Example2:

BlockDiagramExamples

Students:Findtheblockdiagramfor thedifferentialequationabove(pen&paper)

HigherorderdifferentialequationsMass-Spring-DamperExample:

BlockDiagram- SolutionsHigherorderdifferentialequationsMass-Spring-DamperExample:

SimulationTools• MATLAB– Text-basedProgrammingTool– www.mathworks.com

• Simulink– Blockdiagram-basedSimulation,IntegratedwithMATLAB

• LabVIEW• MathScript– UsesMATLABsyntax,IntegratedwithLabVIEW

• Modelica– https://www.modelica.org

• HYSYS– http://www.aspentech.com/products/aspen-hysys.aspx

• ...

SimulationinLabVIEW

Hans-PetterHalvorsen,M.Sc.

SimulationinLabVIEWSimulationPaletteinLabVIEW SimulationLoop:SimilartoaWhileLoop,butcusomized forused

togetherwiththeSimulationBlocksavailableinLabVIEW

DifferentSimulationBlocksbyCategory• Continuous Systems• DiscreteSystems• NonlinearSystems• etc.

http://home.hit.no/%7Efinnh/videos/sim_module/sim_palette_overview/sim_palette_overview.html

SimulationPaletteOverviewVideo(15minutes)

Students:YoushouldwatchthisVideobeforeyougofurther!

SimulationExample

Students: ImplementandSimulatethissysteminLabVIEW

Integratorsymbol

Dynamicsystemrepresentedasadifferentialequation

�̇� = −𝑎𝑥 + 𝑏𝑢

SimulationExample- ConfigurationIntheexamplethefollowing simulationparameterscouldbeused(right-clickontheSimulationLoopborderandselect“ConfigureSimulationparameters…”):

SimulationExample- Solutions

StepResponseWeseetheStepResponseisasexpected!

Correctresults? – Checkstaticresponse:

Trywithdifferentvaluesforu

�̇� = −𝑎𝑥 + 𝑏𝑢

PIDControlinLabVIEW

Hans-PetterHalvorsen,M.Sc.

ControlSystems

PID Process

Sensor

r e u y

-

Kp Ti Td

v

ExampleofIndustrialControllers

Students:Whatisr,e,u,v,y,Kp,Ti,Td?

TypicalBlockDiagram:

DeltaVPIDController

ControlSystem

PID Process

Sensor

r e u y-

Kp Ti Td

v

r– ReferenceValue,SP(Setpoint),SV(SetValue)y– MeasurementValue(MV),ProcessValue(PV)e– Errorbetweenthereferencevalueandthemeasurementvalue(e=r– y)v– Disturbance,makesitmorecomplicatedtocontroltheprocessKp,Ti,Td– PIDparameters

PIDAlgorithm:

ControlSystemimplementationinLabVIEW

PID Process

Sensor

r e u y-

Kp Ti Td

vControlSystemimplementationwith“Pen&Paper”

Thetransition from“paper”toLabVIEWiseasy,becausetheimplementation isverysimilartothe“paper”version

Herewehaveusedthe“SimulationLoop”

PID Process

Sensor

r e u y-

Controller

Kp Ti Td

v

ControlSystemimplementationinLabVIEW

ControlSystemimplementationwith“Pen&Paper”

Allthisisnormallyincluded inthecontroller

Thetransition from“paper”toLabVIEWiseasy,becausetheimplementation isverysimilartothe“paper”version

HerewehaveusedanordinaryWhileLoop(whichisrecommended!)

PIDControlinLabVIEWPIDPaletteinLabVIEW(PIDToolkit)

Note!Thefunctions“PID.vi”and“PIDAdvanced.vi”requires thatTi andTdareinminutes,whileit’snormal tousesecondsastheunitfortheseparameters.Youcanusethefollowingpieceofcodeinordertotransformthem:ThismeansweentervaluesforTi andTdinsecons ontheFrontPanelandthevaluesareconvertedtominutes inthecode.

Alternative1: Alternative2:

Thisalternativeusesseconds!

LabVIEWPIDExample

Students:Replaceuinthepreviousexamplewiththebuilt-inPIDController (useAlternative2)

�̇� = −𝑎𝑥 + 𝑏𝑢

PIDExample- Solutions

FrontPanel:

Students:Findproper𝐾*,𝑇, ,𝑇- Parametersforthissystem.Use“TrialandError”oroneofthemethodsexplainedintheTextBook

�̇� = −𝑎𝑥 + 𝑏𝑢

PIDExample- Solutions

BlockDiagram:

Right-click(Configuration) onthePIDblocktoselectKp,Ti,TdasInputs(->Terminals)

�̇� = −𝑎𝑥 + 𝑏𝑢

NextStep:Continuous Simulation

Students:ChangeyourSimulationSettingsandRunyourSimulationwiththesechanges

AddaStopButtonanda“HaltSimulation”block

Right-clickontheSimulationLoopborderandselect“ConfigureSimulationParameters…”

Simulation in“RealTime”Inf=Infinite

PIDExample– Continuous Simulation- Solution

TheSimulationnowrunsuntilyoupresstheStopbutton

Students:ExtendtheexamplewithanewChartoftheControlSignal(u)andinclude thereferencesignal(r)intheexistingChart,soyoucaneasilyseethechangesinrandhowthesystemhandleit.

SimulationSubsystems

Hans-PetterHalvorsen,M.Sc.

CreateaSubsystemofthispart(yourprocessmodel)

SimulationSubsystemAWaytostructureyourcode,similartoSubVIs

Students:ChangeyourcodeabovewhereyoucreateaSimulationSubSystemforyourProcess

File->New…

Thisistherecommendedwaytodo it!– Youcaneasly reuseyourSubsystemsindifferentVIsandyourcodebecomesmorestructured!

SelectFile->New...,Thenchoose“SimulationSubsystem”.Copy(ormove) theblockscontainingyourprocessintotheNewVI(SimulationSubsystem)

SimulationSubsystem- Solutions

File->New…

SimulationSubsystem2(PIDController)

CreateaSubsystemofthispart(thePIDcontroller)

Students:ChangeyourcodeabovewhereyoucreateaSimulationSubSystemforthePIDControlleraswell.

SimulationSubsystem– Solutions2

Nowyourcodehasbecomereallysimpletounderstand!

Note!Youmayselectdifferenticonstyle

SimulationSubSystems

SimulationsusingaWhileLoopNote!TheSimulationLoophassomedrawbacks/ismorecomplicatedtousethananordinaryWhileLoop.IfweuseSimulationSubsystems,wecanusetheminsideaWhileLoopinstead!-whichbecomesveryhandy!

Soforrealapplicationsthatinvolvesmorethanjustsimulations(suchasDAQ,FileLogging,PIDcontroloftherealprocess,etc.),IrecommendtouseaWhileLoopinsteadofaSimulationLoop.

SimulationSubsystems

Students:AddyourControllerandProcessSubsystemsinsideaWhileloopasshownabove.Simulatethesystem.Doyougetthesameresults?

DataloggingwithLabVIEW

Hans-PetterHalvorsen,M.Sc.

SaveDatatoFile(Datalogging)

Right-click-Properties

RecommendedSettings

DataloggingExample

Students:(1) LogDatafromyoursystem,i.e.,theControlSignal(u)andtheoutputoftheprocess(y)toa“MeasurementFile”.(2) ThenPlottheDatafromtheFileinExcel.

DataloggingExample– BlockDiagram

DiscreteSystems

Hans-PetterHalvorsen,M.Sc.

ContinuousSignal

DiscretSignal Acomputercanonlydealwithdiscretesignals

k=0,1,2,3,4,....

Ts=SamplingTime

Note!Differentbooksusedifferentnotations WhenTs->0,wehaveacontinuoussignal,

butinacomputerthatisnotpossible.

DiscretizationExample

Inorder tosimulatethissysteminLabVIEWusing theFormulaNodeweneedtofind thediscrete differentialequation.

Giventhefollowingdifferentialequation:

Wecanusee.g.,theEulerApproximation:Ts – SamplingTime

Thenweget:

Thisgivesthefollowingdiscretedifferentialequation:

�̇� = −𝑎𝑥 + 𝑏𝑢

FormulaNode/MathScript

Hans-PetterHalvorsen,M.Sc.

FormulaNode&MathScriptNode

MathScriptNode:CreateanduseMathScript/MATLABcodewithinLabVIEW

FormulaNode:CreateanduseCcodewithinLabVIEW

Example:

Veryuseful formathematicalexpressionsandsimulations!

Right-clickon theborder toAdd InputorAddOutput

FormulaNode/MathScriptNode

Students:CreatethisExampleboth inFormulaNodeandinMathScriptNode

Students:TrythisFormulaaswell(both inFormulaNodeandinMathScriptNode):

SimulateDiscrete SystemsusingtheFormulaNodeinLabVIEW

Example

Inorder tosimulatethissysteminLabVIEWusing theFormulaNodeweneedtofind thediscrete differentialequation.

Giventhefollowingdifferentialequation:

WecanusetheEulerApproximation: Ts– SamplingTime

Thenweget:

Thisgivesthefollowingdiscretedifferentialequation:

Students:SimulateandPlotthediscretesystemaboveusingaFormulaNodeandaForLoopinLabVIEW Ts=0.1s

�̇� = −𝑎𝑥 + 𝑏𝑢

FormulaNodeinLabVIEW- Solutions

Asexpected,wegetthesameresultsasinthepreviousexampleusingablockdiagramsimulation

Students: Improveyour solutionbycreatingaSubVI ofyourmodel

xk1=(1-a*Ts)*xk + Ts*b*uk;

Discretemodel:

FormulaNodeinLabVIEW– Solutions2

SubVI

MainVI

AdvantagesusingSubVI:• OurMainprogramhasbecomesimplerandeasierto

understandandmaintain• Wecanreuseourmodel inotherapplications• Ifweneedtodochangesinthemodel,weonlydoitonceandin

oneplace!

MathScriptLabVIEWMathScriptRTModule

Add-onModule forLabVIEWwherewecandotext-basedprogrammingandsimulations– verypowerful!

MathScriptSimulationExample

% Simulation of discrete modelclear, clc

% Model Parametersa = 0.25;b = 2;

% Simulation ParametersTs = 0.1; %sTstop = 20; %suk = 1; % Step Responsex(1) = 0;

% Simulationfor k=1:(Tstop/Ts)

x(k+1) = (1-a*Ts).*x(k) + Ts*b*uk;end

% Plot the Simulation Resultsk=0:Ts:Tstop;plot(k,x)grid on

Students:CreateandtesttheMathScriptcode.YoushouldgetthesameresultsasintheLabVIEWExamples

CreatethefollowingcodeintheMathScript“ScriptEditor”

�̇� = −𝑎𝑥 + 𝑏𝑢

MathScriptNodeStudents:TrythesameexampleinsideLabVIEWusingtheMathScriptNode

Justcopyandpastethecodefromthepreviousexample

Hans-PetterHalvorsen,M.Sc.

DoyouneedmorePractice?- SelectaChallenge

Students:SimulatethissystemusingLabVIEW.Plottheposition, speedandtheaccelleration.Testwithdifferentvaluesonm,kandd.

Mass-Spring-DamperSystem

http://www.techteach.no/simview/mass_spring_damper/index.php

AsketchoftheAirHeaterSystem:

AirHeaterOverview

TemperatureMeasurement

AirIn

ControlSignal

Heater

AirOut

TT

AirtubeAirflow

TC

RealAirHeater

InthisassignmentwearegoingtosimulateandcontrolamathematicalmodelofanAirHeatersystem.

Amathematicalmodelofthesystemcouldbe:

Usethefollowing valuesinthesimulations:

Where:

AirHeaterSimulation

Note!YoufindanexampleofhowtodoitinLabVIEWonthenextslides– buttrytosolveitbyyourself first!

ImplementtheHeatermodel inaSimulationSubSystem,asshownbelow:

SeenextslideforFrontPanelexample

AirHeaterSimulationExample

FrontPanelExample:

AirHeaterSimulation

FindProperPI(D)Parameters

AirHeaterSimulationwithMathScript % Simulation of discrete model

clear, clc

% Model Parametersa = 0.25;b = 2;

% Simulation ParametersTs = 0.1; %sTstop = 20; %suk = 1;x(1) = 0;

% Simulationfor k=1:(Tstop/Ts)

x(k+1) = (1-a*Ts).*x(k) + Ts*b*uk;end

% Plot the Simulation Resultsk=0:Ts:Tstop;plot (k, x)grid on

AreyouabletosimulatetheAirHeatermodelusingMathScriptor/andMathScriptNode?

MathScriptSimulationExample

Hans-PetterHalvorsen,M.Sc.

UniversityCollegeofSoutheastNorwaywww.usn.no

E-mail:hans.p.halvorsen@hit.noBlog:http://home.hit.no/~hansha/

top related