You are on page 1of 18

Page 1 of 18

Exercise1a:
1. BuildtheVIblockdiagram
OpenablankVIfromtheGettingStartedscreen.SaveitasExercise_1a.vi.
SwitchtotheblockdiagramoftheVI(<Ctrl+E>).
OpentheFunctionsPalettebyrightclickinganywhereintheblockdiagram.Dockthe
palettebyclickingtheiconatthetopleftcornerofthepalettewindow.
PlacetheCD Construct Transfer Function Model.viontheblock
diagram.Fromthefunctionspalette,navigatetoControlDesign&SimulationControl
DesignModelConstructionCDConstructTransferFunctionModel.vi,andplaceit
ontheblockdiagram.FromthedropdownmenuselectSingleInputSingleOutput
(Symbolic).
RightclicktheSymbolicNumeratorinputterminaloftheCD Construct
Transfer Function Model.vi,andselectCreateControlfromtheshortcut
menu.
RightclicktheSymbolicDenominatorinputterminaloftheCD Construct
Transfer Function Model.vi,andselectCreateControlfromtheshortcut
menu.
RightclicktheVariablesinputterminaloftheCD Construct Transfer
Function Model.vi,andselectCreateControlfromtheshortcutmenu.
Theblockdiagramshouldlooklikethis:


PlacetheCD Draw Transfer Function Equation.viontheblockdiagram.
Fromthefunctionspalette,navigatetoControlDesign&SimulationControlDesign
ModelConstructionCDDrawTransferFunctionEquation.vi,andplaceitontheblock
diagram.
WiretheTransferFunctionModeloutputterminaloftheCD Construct
Transfer Function Model.vitotheTransferFunctionModelinputterminalof
theCD Draw Transfer Function Equation.vi.
RightclicktheEquationoutputterminaloftheCD Draw Transfer Function
Equation.vi,andselectCreateIndicatorfromtheshortcutmenu.
Tripleclickthelabelofthepictureindicator,andrenameitPlant Equation.
Theblockdiagramshouldlooklikethis:

Page 2 of 18

SavetheVI(<Ctrl+S>).

2. RuntheVI
SwitchtothefrontpaneloftheVI(<Ctrl+E>).
RightclicktheValuenumericcontrolinsidetheVariablescontrolandselect
DisplayFormat,thenselectAutomaticFormatting.Thiswillallowthecontrolto
displaysmallnumbersproperly.
Onthefrontpanel,setthevaluesoftheSymbolic Numerator,Symbolic
Denominator,andVariablescontrolsaccordingtothefollowingtable:
SymbolicNumerator
K

SymbolicDenominator
K^2 J*Rm

Variables
Name Value
K 0.028
Rm 3.3
J 9.64E06

Note:Symbolicvariablesarecasesensitive,somakesuretouseconsistent
capitalization.

Setthefrontpanelcontrolvaluestodefault.SelectEditMakeCurrentValues
Default.
Thefrontpanelshouldlooklikethis:

Page 3 of 18

RuntheVI(<Ctrl+R>).ObservethetransferfunctiondrawninthePlant Equation
indicator.Thistransferfunctionwillbeusedinfutureexercises.
SavetheVI(<Ctrl+S>).

Page 4 of 18
Exercise1b:
1. BuildtheVIblockdiagram
OpenablankVIfromtheGettingStartedscreen.SaveitasExercise_1b.vi.
SwitchtotheblockdiagramoftheVI(<Ctrl+E>).
OpentheFunctionsPalettebyrightclickinganywhereintheblockdiagram.Dockthe
palettebyclickingtheiconatthetopleftcornerofthepalettewindow.
PlaceaMathScriptNodeontheblockdiagram.Fromthefunctionspalette,navigateto
ProgrammingStructuresMathScriptNode,anddrawarectangleontheblock
diagramtodefinethenode.
EnterthefollowingcodeinsidetheMathScriptNode:
%Motor Model
num = [K];
den = [J*Rm K^2];
plant = tf(num,den);
RightclickontheleftborderoftheMathScriptNodeandselectAddInput.EnterKas
theinput.RightclickontheinputterminaloftheKvariableandselectCreateControl
fromtheshortcutmenu.
RightclickontheleftborderoftheMathScriptNodeandselectAddInput.EnterRmas
theinput.RightclickontheinputterminaloftheRmvariableandselectCreate
Controlfromtheshortcutmenu.
RightclickontheleftborderoftheMathScriptNodeandselectAddInput.EnterJas
theinput.RightclickontheinputterminaloftheJvariableandselectCreateControl
fromtheshortcutmenu.
RightclickontherightborderoftheMathScriptNodeandselectAddOutput.Enter
plantastheoutput.Rightclickontheoutputterminaloftheplantvariableand
selectChooseDataTypeAddonsTFObject.
Theblockdiagramshouldlooklikethis:


PlacetheCD Draw Transfer Function Equation.viontheblockdiagram.
Fromthefunctionspalette,navigatetoControlDesign&SimulationControlDesign
ModelConstructionCDDrawTransferFunctionEquation.vi,andplaceitontheblock
diagram.
WiretheoutputterminaloftheplantvariabletoTransferFunctionModelinput
terminaloftheCD Draw Transfer Function Equation.vi.
RightclicktheEquationoutputterminaloftheCD Draw Transfer Function
Equation.vi,andselectCreateIndicatorfromtheshortcutmenu.

Page 5 of 18
Doubleclickthelabelofthepictureindicator,andrenameitPlant Equation.
Theblockdiagramshouldlooklikethis:


SavetheVI(<Ctrl+S>).

2. RuntheVI
SwitchtothefrontpaneloftheVI(<Ctrl+E>).
Setthevaluesofthefrontpanelcontrolsaccordingtothefollowingtable:
K 0.028
Rm 3.3
J 9.64E06

Setthefrontpanelcontrolvaluestodefault.SelectEditMakeCurrentValues
Default.
RuntheVI(<Ctrl+R>).ObservethetransferfunctiondrawninthePlant Equation
indicator.Thistransferfunctionwillbeusedinfutureexercises.
SavetheVI(<Ctrl+S>).

Page 6 of 18
Exercise2:
1. BuildtheVIblockdiagram
OpenablankVIfromtheGettingStartedscreen.SaveitasExercise_2.vi.
SwitchtotheblockdiagramoftheVI(<Ctrl+E>).
OpentheFunctionsPalettebyrightclickinganywhereintheblockdiagram.Dockthe
palettebyclickingtheiconatthetopleftcornerofthepalettewindow.
PlaceaWhileLoopontheblockdiagram.Fromthefunctionspalette,navigateto
ProgrammingStructuresWhileLoop.Drawarectangleontheblockdiagramto
definetheloop.
PlacetheCD Construct PID Model.viontheblockdiagram.Fromthe
functionspalette,navigatetoControlDesign&SimulationControlDesignModel
ConstructionCDConstructPIDModel.vi,andplaceitontheblockdiagram.Fromthe
dropdownmenuselectPIDParallel.
RightclickontheKcinputterminaloftheCD Construct PID Model.viand
selectCreateControlfromtheshortcutmenu.
RightclickontheKiinputterminaloftheCD Construct PID Model.viand
selectCreateControlfromtheshortcutmenu.
RightclickontheKdinputterminaloftheCD Construct PID Model.viand
selectCreateControlfromtheshortcutmenu.
RightclickontheHighFrequencyTimeConstant[s](Tf)inputterminaloftheCD
Construct PID Model.viandselectCreateConstantfromtheshortcutmenu.
PlacetheCD Series.viontheblockdiagram.Fromthefunctionspalette,navigate
toControlDesign&SimulationControlDesignModelInterconnectionCD
Series.vi,andplaceitontheblockdiagram.FromthedropdownmenuselectTransfer
FunctionandTransferFunction.
WiretheTransferFunctionModeloutputterminaloftheCD Construct PID
Model.vitotheModel1InputterminaloftheCD Series.vi.
PlacetheCD Feedback.viontheblockdiagram.Fromthefunctionspalette,
navigatetoControlDesign&SimulationControlDesignModelInterconnection
CDFeedback.vi,andplaceitontheblockdiagram.Fromthedropdownmenuselect
TransferFunctionandTransferFunction.
WiretheSeriesModeloutputterminaloftheCD Series.vitotheModel1input
terminaloftheCD Feedback.vi.
Theblockdiagramshouldlooklikethis:

Page 7 of 18


PlacetheCD Step Response.viontheblockdiagram.Fromthefunctionspalette,
navigatetoControlDesign&SimulationControlDesignTimeResponseCDStep
Response.vi,andplaceitontheblockdiagram.Fromthedropdownmenuselect
TransferFunction.
WiretheClosedLoopModeloutputterminaloftheCD Feedback.vitothe
TransferFunctionModelinputterminaloftheCD Step Response.vi.
RightclicktheStepResponseGraphoutputterminaloftheCD Step Response.vi
andselectCreateIndicatorfromtheshortcutmenu.
PlacetheCD Bode.viontheblockdiagram.Fromthefunctionspalette,navigateto
ControlDesign&SimulationControlDesignFrequencyResponseCDBode.vi,and
placeitontheblockdiagram.FromthedropdownmenuselectFrequencyRange
TransferFunction.
WiretheClosedLoopModeloutputterminaloftheCD Feedback.vitothe
TransferFunctionModelinputterminaloftheCD Bode.vi.
RightclicktheBodeMagnitudeoutputterminaloftheCD Bode.viandselectCreate
Indicatorfromtheshortcutmenu.
Theblockdiagramshouldlooklikethis:

Page 8 of 18
PlaceaMathScriptNodeontheblockdiagram.Fromthefunctionspalette,navigateto
ProgrammingStructuresMathScriptNode,anddrawarectangleontheblock
diagramtodefinethenode.
EnterthefollowingcodeinsidetheMathScriptNode:
%Motor plant
num = [K];
den = [J*Rm K^2];
plant = tf(num,den);
%integrator (position)
integrator = tf([1],[1 0]);
%place plant and integrator in series
sys = series(plant,integrator);
RightclickontheleftborderoftheMathScriptNodeandselectAddInput.EnterKas
theinput.RightclickontheinputterminaloftheKvariableandselectCreateControl
fromtheshortcutmenu.
RightclickontheleftborderoftheMathScriptNodeandselectAddInput.EnterRmas
theinput.RightclickontheinputterminaloftheRmvariableandselectCreate
Controlfromtheshortcutmenu.
RightclickontheleftborderoftheMathScriptNodeandselectAddInput.EnterJas
theinput.RightclickontheinputterminaloftheJvariableandselectCreateControl
fromtheshortcutmenu.
RightclickontherightborderoftheMathScriptNodeandselectAddOutput.Enter
sysastheoutput.Rightclickontheoutputterminalofthesysvariableandselect
ChooseDataTypeAddonsTFObject.
WirethesysoutputterminaloftheMathScriptNodetotheModel2inputterminalof
theCD Series.vi.
RightclickontherightborderoftheMathScriptNodeandselectAddOutput.Enter
plantastheoutput.Rightclickontheoutputterminaloftheplantvariableand
selectChooseDataTypeAddonsTFObject.
PlacetheCD Draw Transfer Function Equation.viontheblockdiagram.
Fromthefunctionspalette,navigatetoControlDesign&SimulationControlDesign
ModelConstructionCDDrawTransferFunctionEquation.vi,andplaceitontheblock
diagram.
WiretheplantoutputterminaloftheMathScriptNodetotheTransferFunctionModel
inputterminaloftheCD Draw Transfer Function.vi.
RightclicktheEquationoutputterminaloftheCD Draw Transfer Function
Equation.vi,andselectCreateIndicatorfromtheshortcutmenu.
Doubleclickthelabelofthepictureindicator,andrenameitPlant Equation.
CreateacontrolbuttonfortheStopfunctionoftheWhileLoop.
Theblockdiagramshouldlooklikethis:

Page 9 of 18


SavetheVI(<Ctrl+S>).

2. RuntheVI
SwitchtothefrontpaneloftheVI(<Ctrl+E>).
Setthefrontpanelcontrolsaccordingtothefollowingtable:
K 0.028
Rm 3.3
J 9.64E06
ProportionalGain(Kc) 1
IntegralGain(Ki) 0
DerivativeGain(Kd) 0.05

Setthefrontpanelcontrolvaluestodefault.SelectEditMakeCurrentValues
Default.
RuntheVI(<Ctrl+R>).ChangethevaluesofProportional Gain (Kc),
Integral Gain (Ki),andDerivative Gain (Kd),andobservehowthe
timeandfrequencyresponsechange.
SavetheVI.

Page 10 of 18
Exercise3:
OpenExercise_2.vi.SavetheVIasExercise_3.vi.
Gototheblockdiagram.RemovetheWhileLoop.Rightclicktheborderoftheloopand
selectRemoveWhileLoopsothatthecodeinsidetheloopisnotdeleted.
ChangethecontrolsconnectedtotheMathScriptNodeintoconstants.
o RightclicktheKcontrolandselectChangetoConstantfromtheshortcutmenu.
Setthevalueoftheconstantto0.028.
o RightclicktheRmcontrolandselectChangetoConstantfromtheshortcutmenu.
Setthevalueoftheconstantto3.3.
o RightclicktheJcontrolandselectChangetoConstantfromtheshortcutmenu.
Setthevalueoftheconstantto9.64E6.
RemoveeverythingfromtheblockdiagramexceptfortheMathScriptNode,theconstants
wiredtotheMathScriptNode,thePIDcontrols(ProportionalGain(Kc),IntegralGain(Ki),
andDerivativeGain(Kd)),andtheCD Draw Transfer Function Equation.vi.
Optional:RemovethesysoutputterminalfromtheMathScriptNode,thenremovelines5
10fromthecodeinsidetheMathScriptNode.(Thisportionofcodecreatesthesysmodel,
whichconsistsoftheplantmodelinserieswithanintegrator.Inthisexercise,the
integrationwillbeperformedinaSimulationLoop.)
Theblockdiagramshouldlooklikethis:



PlaceaSimulationLoopontheblockdiagram.Fromthefunctionspalette,navigateto
ControlDesign&SimulationSimulationSimulationLoop.Drawarectanglebelowthe
MathScriptNodeontheblockdiagramtodefinetheloop.
PlacetheProportional Gain (Kc),Integral Gain (Ki),andDerivative
Gain (Kd)controlsinsidetheSimulationLoop.
PlaceaStepSignalblockinsidetheSimulationLoop.Fromthefunctionspalette,navigateto
ControlDesign&SimulationSimulationSignalGenerationStepSignal,andplaceitin
theloop.DoubleclicktheStepSignalblocktoopentheconfigurationdialog.Setthevalue
ofsteptimeto0.01.ClickOK.
PlaceaSummationblockinsidetheSimulationLoop.Fromthefunctionspalette,navigate
toControlDesign&SimulationSimulationSignalArithmeticSummation,andplaceit
intheloop.LabeltheSummationblockSum1.

Page 11 of 18
PlacethreeGainblocksinsidetheSimulationLoop.Fromthefunctionspalette,navigateto
ControlDesign&SimulationSimulationSignalArithmeticGain,andplaceeachblock
intheloop.DothefollowingforeachGainblock:
o RightclicktheGainblockandselectVisibleItemsLabelfromtheshortcutmenu.
o RightclicktheGainblockandselectConfigurationfromtheshortcutmenu.Set
ParameterSourcetoTerminal.
MakethefollowingwiringconnectionsintheSimulationLoop:
o ConnecttheoutputterminaloftheStepSignalblocktotheOperand1terminalof
theSum1block.
o ConnecttheResultterminaloftheSum1blocktotheInputterminalofeachofthe
threeGainblocks.
o ConnecttheProportional Gain (Kc)controltothegainterminalofthe
Gainblock.
o ConnecttheIntegral Gain (Ki)controltothegainterminaloftheGain2
block.
o ConnecttheDerivative Gain (Kc)controltothegainterminaloftheGain3
block.
Theblockdiagramshouldlooklikethis:



PlacetwoIntegratorblocksinsidetheSimulationLoop.Fromthefunctionspalette,
navigatetoControlDesign&SimulationSimulationContinuousLinearSystems
Integrator,andplaceeachblockintheloop.LabelthetwoblocksIntegrator1and
Integrator2
PlaceaDerivativeblockinsidetheSimulationLoop.Fromthefunctionspalette,navigateto
ControlDesign&SimulationSimulationContinuousLinearSystemsDerivative,and
placeeachblockintheloop.

Page 12 of 18
PlaceanotherSummationblockinsidetheSimulationLoop.LabeltheSummationblock
Sum2.DoubleclicktheSum2blocktoopentheconfigurationdialog.Clicktheiconson
thediagramsothattheblockhasthreeAddinputterminals.ClickOK.
PlaceaTransferFunctionblockinsidetheSimulationLoop.Fromthefunctionspalette,
navigatetoControlDesign&SimulationSimulationContinuousLinearSystems
TransferFunction,andplaceitintheloop.DoubleclicktheTransferFunctionblocktoopen
theconfigurationdialog.SettheParametersourceoptiontoTerminal.ClickOK.
MakethefollowingwiringconnectionsintheSimulationLoop:
o ConnecttheoutputterminaloftheGain2blocktotheinputterminalofthe
Integrator1block.
o ConnecttheoutputterminaloftheGain3blocktotheinputterminalofthe
Derivativeblock.
o ConnecttheoutputterminalsoftheGain,Integrator1,andDerivativeblockstothe
Operand1,Operand2,andOperand3terminalsoftheSum2block.
o ConnecttheResultterminaloftheSum2blocktotheinputterminaloftheTransfer
Functionblock.
o ConnecttheplantoutputoftheMathScriptNodetotheTransferFunctionterminal
oftheTransferFunctionblock.
o Connecttheoutputy(k)terminaloftheTransferFunctionblocktotheinput
terminaloftheIntegrator2block.
o ConnecttheoutputterminaloftheIntegrator2blocktotheOperand2terminalof
theSum1block.Thiswillclosethefeedbackloop.
Theblockdiagramshouldlooklikethis:



PlaceaBuildArrayfunctioninsidetheSimulationLoop.Fromthefunctionspalette,
navigatetoProgrammingArrayBuildArray,andplaceitintheloop.ResizetheBuild
Arraynodesothatithastwoinputs.

Page 13 of 18
PlaceaSimTimeWaveformblockinsidetheSimulationLoop.Fromthefunctionspalette,
navigatetoControlDesign&SimulationSimulationGraphUtilitiesSimTime
Waveform,andplaceitintheloop.
MakethefollowingwiringconnectionsintheSimulationLoop:
o ConnecttheoutputterminaloftheIntegrator2blocktothefirstinputterminalof
theBuildArrayfunction.
o ConnecttheoutputterminaloftheStepSignalblocktothesecondinputterminalof
theBuildArrayfunction.
o ConnecttheappendedarrayterminaloftheBuildArrayfunctiontotheValue
terminaloftheSimTimeWaveformblock.
ConfigurethesimulationparametersoftheSimulationLoop:
o RightclicktheborderoftheSimulationLoop,andselectConfigureSimulation
Parameters.
o SetthevalueofFinalTime(s)to1.
o SetthevalueofODESolvertoRungeKutta4.
o SetthevalueofStepSize(s)to0.001.Thiswillsetthesimulationstepsizetoone
millisecond.
o ClicktheTimingParameterstab,andchecktheboxlabeledSynchronizeLoopto
TimingSource.
o SetthevalueofPeriodto1.Thiswillsetthelooptorunoncepermillisecond
(actualtime).
o ClickOK.
Theblockdiagramshouldlooklikethis:



Optional:ConfigurethedisplayoptionsfortheWaveformChart.
o SwitchtothefrontpaneloftheVI(<Ctrl+E>).
o RightclicktheWaveformChart,andselectProperties.
o IntheDisplayFormattab,selectFloatingPointforthevalueofType.ClickOK.

Page 14 of 18
o DoubleclicktherightmostnumericalvalueonthexaxisoftheWaveformChart,
andsetthevalueto1.
RuntheVI.ChangethevalueofthePIDGains,andthenruntheVIagain.

Page 15 of 18
Exercise2:
1. BuildtheVIblockdiagram
OpenExercise_3.vi.SavetheVIasExercise_4.vi.
PlaceaBooleanbuttononthefrontpanel.Fromthecontrolspalette,navigateto
ModernBooleanPushButton,andplaceitonthefrontpanel.Labelthebutton
AutoInput.
PlaceaDialonthefrontpanel.Fromthecontrolspalette,navigatetoModern
NumericDial,andplaceitonthefrontpanel.LabelthedialInputAngle(rad).
SettheminimumandmaximumvaluesofthescaleoftheInputAngle(rad)dialto
3.14and3.14,respectively.
MakeacopyoftheInputAngle(rad)dial(<Ctrl+Drag>).LabelthenewdialOutput
Angle(rad).
ChangetheOutputAngle(rad)dialfromacontroltoanindicator.Rightclickthedial
andselectChangetoIndicatorfromtheshortcutmenu.
PlaceaStopButtononthefrontpanel.Fromthecontrolspalette,navigatetoModern
BooleanStopButton,andplaceitonthefrontpanel.Thiswillallowyouto
terminatethesimulationatwill.
TakethefollowingstepstocustomizetheWaveformChartdisplayoptions:
o RightclickthechartandselectYScaleAutoscaleYfromtheshortcutmenu.
VerifythattheAutoscaleYoptionisnolongerchecked.
o SettheminimumandmaximumvaluesoftheYAxisto4and4,respectively.
o SetthemaximumvalueoftheXAxisto2.
SwitchtotheblockdiagramoftheVI(<Ctrl+E>).
RightclicktheborderoftheSimulationLoop,andselectConfigureSimulation
Parametersfromtheshortcutmenu.SetthevalueofFinaltime(s)toinf.Thiswill
settheSimulationLooptorununtilitismanuallyterminated.ClickOK.
MakesurethattheAutoInput,InputAngle(rad),OutputAngle(rad),andstop
controlterminalsareallinsidetheSimulationLoop.
RightclicktheStepSignalblock,andselectReplaceProgrammingComparison
Selectfromtheshortcutmenu.ThisreplacestheStepSignalblockwithaSelect
function.
PlaceaPulseSignalblockinsidetheSimulationLoop.Fromthefunctionspalette,
navigatetoControlDesign&SimulationSimulationSignalGenerationPulse
Signal,andplaceitintheloop.
DoubleclickthePulseSignalblocktoopentheconfigurationdialog.Setthevalueof
amplitudeto3.14.ClickOK.
PlaceaHaltSimulationblockinsidetheSimulationLoop.Fromthefunctionspalette,
navigatetoControlDesign&SimulationSimulationUtilitiesHaltSimulation,and
placeitintheloop.
MakethefollowingwiringconnectionsintheSimulationLoop:

Page 16 of 18
o WiretheoutputterminalofthePulseSignalblocktothet(topleft)terminalof
theSelectfunction.
o WiretheInputAngle(rad)controlterminaltothef(bottomleft)terminalof
theSelectfunction.
o WiretheAutoInputcontrolterminaltothes(centerleft)terminalofthe
Selectfunction.
o WiretheoutputterminaloftheIntegrator2blocktotheOutputAngle(rad)
indicatorterminal.
o WirethestopcontrolterminaltotheHalt?terminaloftheHaltSimulation
block.
InsertaSaturationblockatthePIDoutput.RightclickthewireconnectingtheResult
terminaloftheSum2blocktotheinputu(k)terminaloftheTransferFunctionblock.
SelectInsertAllPalettesControlDesign&SimulationSimulationNonlinear
Saturation.DoubleclicktheSaturationblocktoopentheconfigurationdialog.Setthe
valuesoflowerlimitandupperlimitto24and24,respectively(Thesevaluesrepresent
themaximumvoltageinputsoftheDCmotor).ClickOK.
Theblockdiagramshouldlooklikethis:



SavetheVI(<Ctrl+S>).

2. RuntheVI
SwitchtothefrontpaneloftheVI(<Ctrl+E>).
RuntheVI(<Ctrl+R>).ClicktheAutoInputbutton,andobservetheoutputsignal
followapulsesignal.
TurnofftheAutoInputbutton,andchangethevalueofInputAngle(rad).The
outputsignalshouldrespond.
ChangethevaluesofthePIDgains,andobservehowtheoutputsignalrespondstothe
inputwithdifferentgainvalues.

Page 17 of 18
PresstheStopbuttontoendthesimulation.

Page 18 of 18

You might also like