Main Content

Tune Functional Mock-Up Unit Parameters Using Simulink Real-Time

This example shows how to tune parameters in Functional Mock-up Units (FMUs) by using the Simulink® Real-Time™ Explorer.

This example uses the fmudemo_export_fuelsys_controller model that controls the fuel rate by using signals from the system sensors to determine the fuel rate that gives a stoichiometric mixture. It then uses sensor inputs and feedback signals to adjust the fuel rate to give a stoichiometric ratio. The model uses three subsystems to implement this strategy: one for control logic, one for airflow calculation, and one for fuel calculation. Under normal operation, the model estimates the airflow rate and multiplies the estimate by the reciprocal of the desired ratio to give the fuel rate. Feedback from the oxygen sensor provides a closed-loop adjustment of the rate estimation to maintain the ideal mixture ratio.

This example follows these steps to tune an FMU parameter.

  1. In a Simulink model, replace the constant value of a Constant block with a MATLAB variable.

  2. Export the model to a standalone FMU.

  3. Generate a Simulink Real-Time supported FMU.

  4. Use the Simulink Real-Time supported FMU to create a model and then deploy the model on a target computer.

  5. Tune the parameter.

Generate Simulink Real-Time Specific FMU

Open the fmudemo_export_fuelsys_controller model.

open_system("fmudemo_export_fuelsys_controller");

  • In the Modeling tab, in the Design section, click Model Explorer.

  • Create a variable with name Normal in the model workspace or base workspace.

  • Specify a value for Normal, and select Argument.

  • In the fuel_calc subsystem, open the feedforward_fuel_rate subsystem.

  • In the Block Parameters dialog box of the Constant block, specify the Constant value as Normal.

  • Click Apply and save the model.

  • From the Simulation tab, click the drop-down button for Save. In Export Model To section, click Standalone FMU.

  • In the FMU Export dialog box, click Refresh to view the parameters list and verify that the added parameter Normal is available.

  • Under Options for saving FMU, select Access source code from FMU.

  • Specify a location to save the FMU in Destination folder, and click Create to export to FMU.

You can find the fmudemo_export_fuelsys_controller.fmu file at the specified save location. Compile the generated FMU to generate Simulink Real-Time supported FMU file by using this command:

slrealtime.fmu.compileFMUSources("fmudemo_export_fuelsys_controller.fmu");

This generates a Simulink Real-Time supported FMU file with name fmudemo_export_fuelsys_controller_slrt_FMUv2.fmu.

Create Simulink Real-Time Model with Simulink Real-Time Supported FMU

Use the Simulink Real-Time supported FMU file to create a Simulink Real-Time model and tune the FMU parameters.

  1. Create a Simulink model.

  2. In the Configuration Parameters dialog box, in the Code Generation pane, under Target selection, set System target file to slrealtime.tlc.

  3. Add an FMU block.

  4. Open the Block Parameters dialog box and specify the exported FMU file fmudemo_export_fuelsys_controller_slrt_FMUv2.fmu for FMU name.

  5. Save the model.

  6. In the Apps tab, open the Simulink Real-Time app. In the Real-Time tab, select Run on Target > Build Application to generate an application MLDATX file for the model.

Tune FMU Parameters

Connect to a target computer, load the application, and tune the FMU parameters.

  1. In the Real-Time tab, select Prepare > SLRT Explorer to open the Simulink Real-Time Explorer app.

  2. Connect the target computer and load the application. For more information, see Connect, Load Application, and Start. After loading the application, check the Parameters tab to verify that the added FMU parameter is available.

  3. In the Simulink Real-Time Explorer app, click Start from the Run on Target section. The application starts running on the connected target.

  4. Select the FMU parameter value in the Parameters tab and change the value.

You can view the change in value on Simulation Data Inspector. For more information about tuning parameters, see Tune Parameters by Using Simulink® Real-Time™ Explorer.

See Also

|

Topics

External Websites