Tune Parameters

Tune Block Parameters and MATLAB Variables

In Simulink® normal mode, only the I/O drivers run in the kernel. Simulink itself manages the blocks and their parameters. This means that in normal mode, block parameters can be tuned just as in a non-real-time model.

Simulink external mode connects your Simulink model to your real-time application. The block diagram becomes a graphical user interface to the real-time application You can change parameter values while running the real-time application by changing the values in

  • Block parameters — Change block parameters by changing the values in the dialog boxes associated with the Simulink blocks. Once you change a value, and click OK, the new value is downloaded to the real-time application.

  • MATLAB® variables — Change MATLAB variables by entering the changes through the MATLAB command line, and then press Ctrl+D for the changes to be downloaded to your executable. An alternative method to download parameters is to click Simulation > Update Diagram in your Simulink window. Simply changing the value of the MATLAB variable at the MATLAB command line does not tell the Simulink software that the value has changed.

Simulink external mode also supports side-effect functions. For example, given an expression in a Gain block of 2*a+b, the expression is evaluated and the resulting value is exported to the real-time application during execution.

When a parameter in a Simulink model is changed, the communication module rtwinext.mex* transfers the data to the external real-time application and changes the model parameters. Only the parameters that do not result in model structure modification can be changed. If the structure is modified, you must recompile the model. Model structure changes are detected automatically using model checksum and reported to the MATLAB Command Window to avoid conflicts.

Change Model Parameters

After you start running your real-time application, you can open Simulink blocks, change parameter values, and observe the changes to the signals. In normal mode, Simulink transfers the new value to the real-time driver. In external mode, Simulink transfers the new value to the real-time application.

The following procedure uses the Simulink model rtwin_model as an example. It assumes you have created a real-time application and are executing it.

  1. From the Simulation menu, click Run.

    The real-time execution starts running and signal data is displayed in the Scope window.

  2. From the Simulink block diagram, double-click the Transfer Function block.

    The Block Parameters: Transfer Fcn dialog box opens.

  3. In the Denominator field, change 70 to 30. Click OK.

    The effect of changing a block parameter is shown in the Scope window.

Was this topic helpful?