Schedule the Partitions
These two examples walk through the workflow of partitioning a model, scheduling the partitions and analyzing the simulations before and after editing the schedule of the partitions.
Schedule an Export-Function Model Using the Schedule Editor
This example shows how to view and edit the order of function-calls in an export-function model using the Schedule Editor. As in all export-function models, the desired functionality is modeled as function-call subsystems. These function-call subsystems define the partitions that are scheduled by the Schedule Editor.
With the Schedule Editor, you can easily view and edit the schedule of the function-calls. The behavior of the system depends on the order of these partitions. In this example, we change the order and observe its effects on the behavior of the system by simulating the model. To see the impact of editing the schedule on the simulation, we compare the model simulations before and after scheduling.
Create Partitions from Referenced Export-Function Model
To view and edit the schedule of the export-function model, reference the model.
open_system('ThrottlePositionControlTop.slx');
ThrottlePositionControl
is the referenced export-function model. By default, each function has an input port that can be used to trigger these functions. The Schedule Editor automatically handles these ports. To use the Schedule Editor, set the Schedule Rates With parameter to Schedule Editor.
set_param('ThrottlePositionControlTop/ThrottleControl','ScheduleRatesWith','Schedule Editor');
Establish a Simulation Baseline
To observe the impact of scheduling on the model behavior, establish a baseline by simulating the model before editing the schedule. Simulate the model.
sim('ThrottlePositionControlTop');
Open the Schedule Editor
To open the Schedule Editor, click Schedule Editor in the Design section of the Modeling tab. In the Schedule Editor, different components of the model are represented as partitions. Update the diagram to see the partitions. Partitions are the entry-points in the model. The Schedule Editor shows the order and data communications of these partitions. The arrows are data connections between the partitions that show the data flow. The dashed lines indicate that there is a delay because the source runs after the destination. The solid lines indicate that there is no delay as the source runs before the destination.
Edit Partition Schedule
The Order pane shows the order the partitions run in at a given time step. Assume that the order of the partitions is in an imperfect state. In this case, to remove the delay, you want to run the ThrottleControl.ActuatorRun5ms
partition after the ThrottleControl.ControllerRun5ms
partition.
Drag ThrottleControl.ActuatorRun5ms
after the ThrottleControl.ControllerRun5ms
in the Order pane. Observe that the delay between the ThrottleControl.ControllerRun5ms
and the ThrottleControl.ActuatorRun5ms
partitions changes to a dependency. Observe that now there is no delay between the executions of ThrottleControl.ControllerRun5ms
and ThrottleControl.ActuatorRun5ms
.
Schedule the Execution of Aperiodic Partitions
The export-function model contains an unconstrained partition, AccelerationPedalPositionSensor
. Suppose you want to schedule an unconstrained partition to simulate as if it were discrete. Schedule ThrottleControl.AppSnsrRun
partition to run at [0:0.02:100] to observe its behavior at different instances of time. Click the unconstrained partition and enter [(1:5000)*.02] for Trigger in the Property Inspector.
Compare the Runs in Simulation Data Inspector
Now, simulate the model with the changed schedule.
Open the Simulation Data Inspector. Select the two runs and compare. You can see how changing the schedule impacts the model behavior.
Copyright 2018-2022 The MathWorks, Inc.
Schedule a Rate-Based Model Using the Schedule Editor
This example shows how to partition a rate-based model using the Schedule Editor. Partitions are the components of the model that can execute independently. In this example, we convert the subsystems into partitions and view and edit their schedule.
With the Schedule Editor, you can easily view and edit the schedule of the partitions. The behavior of the system depends on the order of these partitions. In this example, we observe the effects of scheduling this model on the simulation. To see the impact of partitioning and scheduling the model, we compare the model simulations before and after creating partitions and scheduling them.
Open the Model and Establish a Simulation Baseline
Open the model of a Throttle Position Control system and simulate it to establish a baseline for comparison
open_system('ScheduleEditorWithSubsystemPartitions'); sim('ScheduleEditorWithSubsystemPartitions');
Open the Schedule Editor and Create Partitions
To open the Schedule Editor, click Schedule Editor in the Design section of the Modeling tab. Use Manage Partitions to create partitions from the subsystems in your model. Select all the subsystems in ThrottlePositionControl
, and click the Create Partitions icon on the top of the Manage Partitions panel. Specify the names for the partitions and their sample time. Update the diagram to see the partitions in the Schedule Editor.
The arrows are data connections between the partitions that show the data flow. The dashed lines always indicate that there is a delay as the source runs after the destination. The solid lines indicate that there is no delay as the source runs before the destination.
Edit Partition Schedule
The Order shows the order the partitions run at a given time step. Assume that the order of the partitions is in an imperfect state. In this case, you want to run the ActuatorRun5ms
partition before the ControllerRun5ms
partition. Drag ActuatorRun5ms
before the ControllerRun5ms
in the order. Observe that the dependency between the ControllerRun5ms
and the ActuatorRun5ms
partitions changes to a delay.
Compare Runs in Simulation Data Inspector
Now, simulate the model with the changed schedule.
Open the Simulation Data Inspector. Select the two runs and compare. You can see how changing the schedule impacts the model behavior.