Share Data Among Multiple Instances of a Reusable Algorithm
This example shows how to use a Data Store Memory block to share data among multiple instances of an algorithm in a model.
In this example, multiple Model blocks reference a model that represents a fault handling algorithm. Each Model block is a standalone instance of the algorithm. Each instance calculates and stores its own copies of the signals that the model contains.
Because the model instances do not interact, this example uses a datastore to share data, in this case a fault indication, among all instances of the reusable control algorithm. Any model instance can set the fault, causing all the model instances to take action to clear it.
Open Model
The top model sldemo_shared_data
represents a closed-loop feedback system. The plant in this loop is represented by a state-space model that has three states. Each state is represented by a signal. The output signals from the plant are inputs to the Model blocks containing the controller algorithm. In this model, the plant output signals have a one-to-one mapping to the Model block input ports.
The controller algorithm is represented by the model sldemo_shared_data_alg
, which is referenced by three Model blocks. The Data Store Memory block inside the sldemo_shared_data_alg
model stores the fault indication using a variable fault_ind
. To share the fault indication data among multiple model instances, in the Data Store Memory Block Parameters dialog box, select Signal Attributes > Share across model instances.
Since the datastore exists in sldemo_shared_data_alg
, the indication is local to the model. As a result, other models that refer to sldemo_shared_data_alg
cannot read from or write to the indication.
The Algorithm
subsystem uses a PID controller to generate a position command for an actuator.
The Fault Handling
subsystem sets and clears the fault indication. Each time an instance of the algorithm experiences a fault condition (the controller input exceeds 2.63), the subsystem increases the value of the datastore by 1. Each time an instance clears its fault condition (the controller input is less than 0.87), the subsystem decreases the value of the datastore by 1.
Simulate Model
Simulate the parent model sldemo_shared_data
. Use the Simulation Data Inspector to observe the position commands and the controlled signals. At t = 7.5 s, the Controller_instance2
signal experiences a disturbance.
The disturbance triggers a fault in the corresponding instance of the control algorithm. Due to the fault, all three position commands (the Position_instance
signals) lock at zero.
Later, when the fault condition clears, all of the position commands and controlled signals return to nominal values.
See Also
Data Store Memory | Data Store Read | Data Store Write