Test Export-Function Model Simulation Using Schedule Editor
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.
Create a Simulink® model.
Add a Model block that references the export-function model.
Specify function-call events using the Schedule Editor.
Specify data inputs.
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.
Create a Simulink model.
On the Modeling tab and from the Setup section, select Model Settings .
In the left pane of the Configuration Parameters dialog box, select Solver. 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.
Add a Model block to your model.
On the Modeling tab, in the Design gallery, select Property Inspector .
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.
Select the Schedule rates parameter. From the Schedule rates list, select
Schedule Editor
.Add and connect Outport blocks to the output_100ms and output_10ms ports of the Model block.
Add a Sine Wave block to provide data input. Set Amplitude to
2
and Sample time to0.01
. Connect the block to the input_10ms input port on the Model block.
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.
Open the Schedule Editor. On the Modeling tab, in the Design section, select Schedule Editor . The Schedule Editor partitions the function-call Inport blocks and names the partitions using the block names.
Select the
Model.function_call_2
partition. In the Hit Times box, enter a matrix with values that begin at0
and periodically increase by0.01
to10
. You can also test asynchronous behavior by entering a matrix with random values that are multiples of0.01
.Select the
Model.function_call_1
partition. In the Hit Times box, enter a matrix with values that begin at0
and increase by0.1
to10
.
Prepare Export-Function Model for Simulation
Before you test the export-function model, configure model settings and specify signals to log.
On the Modeling tab, click Model Settings .
Verify the settings for these configuration parameters on the Solver pane:
Type is set to
Fixed-step
.Solver is set to
discrete (no continuous states)
orauto (Automatic solver selected)
.Fixed-step size (fundamental sample time) is set to
auto
.
Set up logging for signals. Right-click a signal you want to log. Then, select Log 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
Related Topics
- Using the Schedule Editor
- Export-Function Models Overview
- Create Export-Function Model
- Test Export-Function Model Simulation Using Input Matrix
- Test Export-Function Model Simulation Using Function-Call Generators
- Test Export-Function Model Simulation Using Stateflow Chart
- Generate Code for Export-Function Model