Test Export-Function Model Simulation Using Schedule Editor - MATLAB & Simulink (original) (raw)

Main Content

Use the Schedule Editor to schedule the function-call components for simulation. This strategy is useful when you want to set the order of execution for function-call components and view data dependencies between components.

  1. Create a Simulink® model.
  2. Add a Model block that references the export-function model.
  3. Specify function-call events using the Schedule Editor.
  4. Specify data inputs.
  5. Run a simulation.

Create Test Model (Harness) for Simulation

A Simulink test model is used only for simulation. After simulation testing, generate code from the export-function model, then manually integrate exported function code with an externally coded scheduler. Referencing an export-function model from a Model block allows the addition of function-call events and logging of data signals for testing without changing the model itself.

  1. Create a Simulink model.
  2. On the Modeling tab and from the Setup section, select Model Settings .
  3. In the left pane of the Configuration Parameters dialog box, selectSolver. In the right pane, select the Solver details arrow to display additional parameters. Select the parameters Treat each discrete rate as a separate task and Automatically handle rate transition for data transfer.
  4. Add a Model block to your model.
  5. On the Modeling tab, in the Design gallery, select Property Inspector .
  6. In the Model name box, enter the name of an export-function model. For example, use the export-function model created in Create Export-Function Model.
  7. Select the Schedule rates parameter. From theSchedule rates list, select Schedule Editor.
  8. Add and connect Outport blocks to theoutput_100ms and output_10ms ports of theModel block.
  9. Add a Sine Wave block to provide data input. SetAmplitude to 2 and Sample time to 0.01. Connect the block to theinput_10ms input port on the Model block.
    Model block that references export-function model with inputs and outputs connected

Create Function-Call Events Using the Schedule Editor

Use the Schedule Editor to provide function-call events by defining time-vectors that indicate when events occur for root-level function-call Inport blocks.

  1. Open the Schedule Editor. On the Modeling tab, in theDesign section, select Schedule Editor . The Schedule Editor partitions the function-callInport blocks and names the partitions using the block names.
  2. Select the Model.function_call_2 partition. In the Hit Times box, enter a matrix with values that begin at 0 and periodically increase by 0.01 to 10. You can also test asynchronous behavior by entering a matrix with random values that are multiples of 0.01.
  3. Select the Model.function_call_1 partition. In the Hit Times box, enter a matrix with values that begin at 0 and increase by 0.1 to 10.

Prepare Export-Function Model for Simulation

Before you test the export-function model, configure model settings and specify signals to log.

  1. On the Modeling tab, click Model Settings .
  2. Verify the settings for these configuration parameters on theSolver pane:
    • Type is set toFixed-step.
    • Solver is set to discrete (no continuous states) or auto (Automatic solver selected).
    • Fixed-step size (fundamental sample time) is set toauto.
  3. Set up logging for signals. Right-click a signal you want to log. Then, selectLog selected signal. In this example, the export-function model output signals are logged because they connect to Outport blocks.

Test Export-Function Model Using Schedule Editor

To test and observe the export-function model behavior before generating code, simulate the completed test model.

Optionally, open and simulate the completed test model named ex_export_function_test_model_with_schedule_editor.

To view the simulation results, open the Simulation Data Inspector. On the Simulation tab, click Data Inspector.

After you test your model, you can generate code for the functions. See Generate Code for Export-Function Model.

See Also

Function-Call Subsystem

Topics