Professional Documents
Culture Documents
Simulation Interface Toolkit (SIT) Tutorial
Simulation Interface Toolkit (SIT) Tutorial
J. Mlcak
Last Update: 8/27/2006
Block Diagram
SIT Server
model
TCP/IP
Host Computer
Host Computer
MEEN 364
J. Mlcak
Last Update: 8/27/2006
2. SIT Example
In the following example, a signal is acquired, and the acquired signal is
amplified by a user-defined amount. Finally, the amplified signal is output from the data
acquisition terminal. The same procedure can be applied when Simulink is used to
sample or generate a signal. A schematic of the system setup is given in Figure 2.
LabVIEW
Host VI
Front Panel
Block Diagram
SIT Server
model
TCP/IP
Host Computer
TCP/IP
Host Computer
National
Instruments
ACH0
Function
Generator
Ch1
NI PXI-1031
DAC0
Oscilloscope
Ch2
MEEN 364
J. Mlcak
Last Update: 8/27/2006
MEEN 364
J. Mlcak
Last Update: 8/27/2006
(a)
(b)
(c)
Figure 4. a, b, and c. Simulation parameters.
In the Simulink diagram, select the drop down menu in the upper toolbar and
choose External as shown in Figure 5.
MEEN 364
J. Mlcak
Last Update: 8/27/2006
*NOTE: For best results, label all input blocks, output blocks, gains, constants, and
NI Sinks with a unique name that will allow you to determine what each block
contains. This will be important at a later step. Also, all constant and gain blocks
should contain a nominal value that will be close to the true value. If the true values
are not known, leave the constant or gain as the default value.
Save the Simulink model under a filename that does not contain spaces and
does not begin with a number. For future reference, the term filename will be used to
denote your Simulink filename. Before continuing, ask your lab Teaching Assistant
review your Simulink model.
Close any LabVIEW programs that may be open, and build (compile) the
Simulink model by selecting Tools >> Real-Time Workshop >> Build Model, or press
Ctrl+B. Building the Simulink model creates a dynamic link library (DLL) file. The
Simulation Interface Toolkit includes a plug-in for Real-Time Workshop that converts
the .mdl file into C code and then compiles the C code into a model DLL. The model
DLL contains all aspects of the Simulink model but no longer requires Simulink to run.
Allow the Simulink model to build. LabVIEW will open and close in the process.
The build is complete when the MATLAB command prompt displays:
### Successful completion of Real-Time Workshop build
procedure for model: filename.
*NOTE: Do not close MATLAB throughout the process detailed in this tutorial
because the SIT server only runs when MATLAB is running.
The next step involves creating a LabVIEW interface to run the Simulink
diagram. Open LabVIEW and create a New (blank) VI. The LabVIEW execution target
should be LabVIEW for Windows. On the Front panel, add a numeric or dial control for
every data value you wish to alter from Simulink. In this example, it is desired to change
the signal amplification value and see the effects. A numerical or graphical indicator for
every data value you wish to view must be added. There should be at least one numerical
or graphical indicator for each NI Sink block in Simulink. The front panel for this
example is shown in Figure 6. Be sure to label all items on the front panel with a unique
and descriptive label.
Once the Front panel is completed, select Tools >> SIT Connection Manager. A
dialog box will open. Select Load Model and verify that the Select Host dialog box has
a machine name as localhost on port 6011 and click OK. In the next dialog box, select
the Simulink model in your project folder as filename.mdl and click OK. Link the
LabVIEW controls to Simulink gain or constant values, and link LabVIEW indicators to
Simulink NI Sink block names. See Figure 7. For this example, click the LabVIEW
control for the knob on the left and expand the gain listing on the right. Click on gain
and then click Add to connections. Repeat this process for the indicator by connecting
MEEN 364
J. Mlcak
Last Update: 8/27/2006
the Waveform chart to the NI_SINK. Note that the icons beside the controls and
indicators differ. Icons of different types cannot be linked. Once all connections have
been made, select OK to create all connections and return to the Front panel. Pressing
OK causes LabVIEW to build a block diagram that makes all necessary connections
between the Front panel elements and the Simulink model DLL.
MEEN 364
J. Mlcak
Last Update: 8/27/2006
For this example, it is desired to log (save) the data in an array, or spreadsheet
form. This array can be opened in any spreadsheet program or MATLAB as long as it is
saved as a comma-delimited or tab-delimited file. Double click the Waveform Chart
indicator on the Front panel. This takes you to the Waveform Charts location in the
Block diagram. Right click on the Block diagram and select Functions >> File I/O >>
Write LVM and drag the Write LVM block to a location under the Waveform Chart
terminal in the Block diagram. A dialog box as shown in Figure 8 will appear. Select a
location and file name where the data will be logged and save it as a .txt file. Select
all options so that they match those shown in Figure 8. Click OK to close the Configure
Write LVM File dialog box. A Write LVM block must be added for each data set you
wish to log.
*NOTE: The filename in the Write LVM block must be changed each time you want
to save another data set.
MEEN 364
J. Mlcak
Last Update: 8/27/2006
MEEN 364
J. Mlcak
Last Update: 8/27/2006
MEEN 364
J. Mlcak
Last Update: 8/27/2006
The Front panel of the main VI is shown in Figure 12. Select the Run SIT
button on the Front panel to run the SIT/Simulink diagram in LabVIEW, and select the
Stop SIT button on the Front panel to stop the SIT/Simulink diagram in LabVIEW.
*NOTE: Do not use the stop button labeled Stop VI or the stop button on the top
toolbar. These stop buttons do not properly close the SIT/Simulink connection with
LabVIEW.
Run SIT
Stop SIT
Figure 12. LabVIEW Front panel after SIT connections are established
To convert the logged data to a variable in the MATLAB workspace, make sure
the .txt file is in the MATLAB working directory. At the MATLAB command prompt
or a M-file type:
load Trial_1.txt
where Trial_1.txt is the filename given in the Write LVM block. This will create an array
labeled Trial_1 in the MATLAB workspace. The first column of the array is time, and
the second column is the data set that was logged while running SIT.
The data can be opened in Excel by first opening Excel, then going to
File>>Open. Under the Files of Type drop-down menu, select Text Files. Then select
the .txt file containing the data you want. Click the next button twice, and then click
the finish button. The data can then be manipulated using Excel. Like MATLAB, the
first column is time, and the second column is the data set that was logged while running
SIT.
10
MEEN 364
J. Mlcak
Last Update: 8/27/2006
3. Summary
1. Create a folder for your lab projects.
2. Open MATLAB and change the working directory to your lab project folder.
3. Create Simulink Diagram:
a. Label all blocks with a unique and descriptive name.
b. Include an In block for each analog input data acquisition terminal.
c. Include an Out block for each analog output operation.
d. Insert an NI Sink where data values will be viewed in LabVIEW.
e. Give constants and gains nominal values if appropriate.
f. Include at least one In and Out block even if the blocks are not used.
If the In or Out block is not used, do not connect it to anything.
4. Set the sampling frequency, fixed calculation step size, and real-time workshop:
a. Go to Simulation>>Simulation Parameters>>Solver tab:
i. Set a Stop time (can leave at default of 10 seconds).
ii. Under Solver Options, select the type as Fixed-step with the ode5
(Dormand-Prince) solver.
iii. Under Fixed step size, type in the sampling time in seconds. For
example, if sampling at 100 Hz, type 0.01 seconds.
b. Select the Workspace I/O tab:
i. Uncheck all boxes in the Save to workspace area.
ii. Uncheck Limit data points to last dialog box in the Save options
area.
c. Select the Real-Time Workshop tab:
i. Select browse.
ii. Select nidll.tlc (LabVIEW DLL Target) >> OK.
d. Click Apply and OK to close the Simulation Parameters dialog box.
e. From the drop-down menu on the toolbar, select External.
f. Save the Simulink model. Recall that no spaces can appear in a Simulink
file name. The first character in the filename must not be a number.
g. Ask your lab Teaching Assistant to review your Simulink model before
continuing.
5. Close all LabVIEW programs that may be open, and build the Simulink model by
selecting Tools >> Real-Time Workshop >> Build Model, or press Ctrl+B.
6. Allow the Simulink model to build. LabVIEW will open and close in the process.
The build is complete when the MATLAB command prompt displays:
### Successful completion of Real-Time Workshop build
procedure for model: filename.
7. Do NOT close MATLAB.
8. Open LabVIEW and create a New (blank) VI.
9. Select the Front panel
a. Add a numerical or dial control for every data value you wish to change
(ex. gains and constants).
b. Add a numerical or graphical indicator for every data value you wish to
output from your simulink model. At least one indicator must be present
for each NI Sink used in the Simulink model.
11
MEEN 364
J. Mlcak
Last Update: 8/27/2006
c. Label each control and indicator with a unique and descriptive name.
10. Select Tools >> SIT Connection Manager:
a. Select Load Model and verify that the Select Host dialog box has a
machine name as localhost on port 6011. Click OK.
b. Select the Simulink model and click OK.
c. Link LabVIEW controls and indicators with Simulink blocks. Any block
that must be varied in Simulink must be paired with a control, and every
NI Sink in Simulink must be paired with a LabVIEW indicator.
i. Match a LabVIEW control with a Simulink gain or constant value
and click Add to Connections
ii. Match a LabVIEW indicator with NI Sinks from Simulink and
click Add to Connections
iii. Repeat for all desired connections between the LabVIEW and
Simulink models.
d. Click OK.
11. If acquired will not be saved (logged), skip this step. For each data point that will
be logged:
a. Double click the indicator on the front panel. This will take you to the
indicators location in the Block diagram.
b. Select Functions >> Output >> Write LVM and drag the Write LVM
block to a location under the indicators terminal block in the Block
diagram.
c. In the dialog box, select a file name where the data will be logged and
save it as a .txt file.
d. Select options as shown in Figure 8.
e. Click OK to close the dialog box.
f. Use the wiring tool to connect the Signals port of the Write LVM block to
the wire that enters the indicators terminal block.
g. Repeat steps a-f for all values that require logging.
12. Save the LabVIEW VI in the project folder. A unique file name such as
RUN_ME.vi will help separate this VI from the many others that were generated
in the build process.
13. In LabVIEW, go to File>>Open:
a. In your project folder, double-click the filename_nidll_rtw folder
b. Open the filename_daq_driver.vi
c. Under AI Channels type in the analog input channels that any cables are
connected to on the terminal block.
d. Under the AO Channels type in the analog output channels that any
cables are connected to on the terminal block.
e. Save the filename_daq_driver.vi and close it.
14. If the PXI box is not already on, turn it on and allow it to boot.
15. Run the VI created that has the user interface (RUN_ME.vi):
a. In the dialog box type the following:
i. Machine Name/IP: Type in the IP address listed on the PXI box
ii. Port: 6011
b. Check the RT Target? box
12
c.
d.
e.
f.
g.
h.
MEEN 364
J. Mlcak
Last Update: 8/27/2006
Under Path to Model VI, click the open folder icon and select
filename_main_daq.vi in the filename_nidll_rtw folder.
Under Path to Model DLL, click the open folder icon and select
filename.dll.
Click OK in the Select Host dialog box to run the VI.
Select the Run SIT button on the Front panel to run the SIT/Simulink
diagram in LabVIEW.
Select the Stop SIT button on the Front panel to stop the SIT/Simulink
diagram in LabVIEW.
Do NOT use the stop button that says Stop VI or the stop button on the
top toolbar because these do not properly close the SIT/Simulink
connection with LabVIEW.
13