1. Creating the DLL in The MathWorks, Inc. Simulink® Software Environment
To create the simulation DLL, you must first define the inputs and outputs of the model you developed using the Simulink software. Inputs to the model are defined with Inport blocks such as the “u” block in the f14 model. Outputs are defined with Outport blocks such as the “alpha (rad)” and “Nz Pilot (g)” blocks in the f14 model. These are the same blocks used in the Simulink environment to allow one diagram to be used as a “subsystem,” or sub-diagram, of another model you developed using the Simulink software. Therefore you do not need to rewrite the model to use it in a LabVIEW Real-Time application.
You need to set up the Simulation Parameters for the f14 model by selecting Simulation»Simulation parameters. In the Simulation Parameters:f14 dialog box, select the Solver tab. In the Solver options section, select Fixed-step option in the Type listbox. Simulations using Variable-step size instead of Fixed-step size solvers cannot be used with The MathWorks, Inc.' Real-Time Workshop® software.
You must also specify the model's step size. In the Solver tab, type 0.1 in the Fixed step size text box. When the LabVIEW application calls the generated DLL, a 0.1 step size will be used. The DLL uses all the simulation parameters except for Stop time, which is overwritten by the SMI Initialize Model VI.
You also need to configure the settings in the Real-Time Workshop tab in the Simulation Parameters:f14 dialog box. Select the Target configuration option in the Category listbox.
To display the list of all possible target configurations, click the Browse button in the Configuration section. Except for the LabVIEW DLL target (nidll.tlc), all of the target files listed are the default target configurations provided by the Real-Time Workshop software. The LabVIEW Simulation Model Integration Toolkit installs these files into the Real-Time Workshop software to provide the LabVIEW DLL target.
Select the LabVIEW DLL target and click the OK button. To start the DLL build process, click the Build button in the Simulation Parameters:f14 dialog box. The generated DLL, VIs, and other support files are all placed in a folder generated during the build process. For the f14 model, this folder is c:\matlabR12\work\f14_grt_rtw. The utility ftpToTarget.exe is also copied to this work folder. This utility can be used to download the DLL to a LabVIEW Real-Time target after the build process.
During the build process, The MATLAB workspace will show all the steps of the build process. The last line, Successful completion of the Real-Time Workshop build procedure for model: f14, indicates a successful build.
2. Calling the DLL in LabVIEW
The model_driver VI is located in the model work folder after the build procedure. This VI is a ready-to-run example built specifically for the generated model DLL. The example VI is a software-only simulation of the model. If you type 60 in the Stop time control and run the model, you get the same results as when you ran the f14 model in the Simulink software. The model_driver VI also includes a Parameters control. In this control you can set the values of any parameters to the values in the Simulink model. A ring control in the array, which is used to select the parameter, is automatically generated with all of the model parameter names during the build process. For example, the f14_driver VI includes all of the following f14 model parameter names:
MATLAB®, Simulink®, and Real-Time Workshop® are registered trademarks of The MathWorks, Inc.