You use Simulink® external mode to connect your Simulink model to your real-time application. The model becomes a user interface to your real-time application. You set up the Simulink interface in external mode to establish a communication channel between your Simulink model and your real-time application.
In Simulink external mode, when you change parameters in the Simulink model, Simulink downloads those parameters to the real-time application while it is running. You can change parameters in your program without rebuilding the Simulink model to create a new real-time application.
Simulink Real-Time™ does not support parameters of multiword data types.
After you download your real-time
application to the
target computer, you can connect your
Simulink model to the real-time
application. This procedure uses the
xpcosc. You must have already built and downloaded
the real-time application for that
Connect to the target computer. On the Real-Time tab, toggle the Disconnected indicator to Connected.
Build and download the real-time application to the target computer. On the Real-Time tab, click Run on Target.
The real-time application begins running on the target computer, and the target computer displays the following message:
System: execution started (sample time: 0.000250)
From the Simulation block diagram, double-click the block labeled Gain1
In the Block Parameters: Gain1 parameter
dialog box, the Gain text box, enter
When you change a MATLAB® variable and click OK, the changed parameters in the model are downloaded to the real-time application.
To stop the simulation, on the Real-Time tab click Stop.
Disconnect to the target computer. On the Real-Time tab, toggle the Connected indicator to Disconnected.
The Simulink model is disconnected from the real-time application. If you then change a block parameter in the Simulink model, the real-time application does not change.
By using Batch Mode, you can tune multiple parameters and apply the tuning changes at
once, instead of tuning one parameter at a time. This example uses model
(matlab: open_system(docpath(fullfile(docroot, 'toolbox', 'rtw', 'targets', 'xpc', 'xpcdemos', 'xpcosc')))).
In the Simulink Editor, on the Real-Time tab, click Run on Target.
On the Real-Time tab, click Prepare > Batch Mode. The editor remains in batch mode until you click Batch Mode again.
To set parameter values, you can either set values by clicking on each block or by using the Model Data Editor.
On the Real-Time tab, click Prepare > Signal Table.
In the Model Data Editor, click the Parameters tab. Modify parameters values in the Model Data Editor.
On the Real-Time tab, Prepare > Update All Parameters.
To stop the simulation before it ends, on the Real-Time tab, click Stop.