Share Data Store Between Instances of a Reusable Algorithm
To reuse an algorithm, instead of copying and pasting the blocks, you can encapsulate them in a separate model file. Then, you can refer to the model repeatedly with Model blocks. Each Model block is a standalone instance of the algorithm.
By default, each instance calculates and stores its own copy of the signals that the model contains. Therefore, the instances do not interact. However, you can use a data store to share a piece of data between the instances.
This example shows how to share a fault indication between all instances of a reusable control algorithm. Any instance can set the fault, causing all instances to take action to clear it.
Explore Example Models
Open the example model
The Controller subsystem refers to the controller algorithm model,
sldemo_shared_data_alg, multiple times through three Model blocks.
Open the algorithm model.
The Data Store Memory block
fault_ind represents a fault indication. The block parameter Signal Attributes > Share across model instances is selected, so all instances of
sldemo_shared_data_alg share the indication. Because the block exists in
sldemo_shared_data_alg, the indication is local to the model. Other models that refer to
sldemo_shared_data_alg cannot read or write to the indication.
The Algorithm subsystem uses a PID controller to generate a position command for an actuator (represented by a block in
The Fault Handling subsystem sets and clears the fault indication. Each time an instance of the algorithm experiences a fault condition (the controlled input exceeds 2.63), the subsystem increments the value of the data store by 1. Each time an instance clears its fault condition, the subsystem decrements the value by 1.
Simulate Example Models
Simulate the parent model,
Use the Simulation Data Inspector to observe the position commands and the controlled signals. In the Simulink Editor toolbar, click the highlighted button.
Partway through the simulation, the controlled signal
conc_mid experiences a disturbance.
Current plot held
The disturbance triggers a fault in the corresponding instance of the control algorithm. Due to the fault, all three position commands (the
vlv signals) lock at zero.
Later, when the fault condition clears, all of the position commands and controlled signals return to nominal values.