Modeling a Redundant Sensor Pair Using Atomic Subcharts

This model shows how to model a simple redundant sensor pair using Atomic Subcharts. This feature allows you to compose a large chart from other charts which reside in a different library file.

Main Chart

The main Stateflow chart RedundantSensors consists of two "linked atomic subcharts" called Sensor1 and Sensor2.

By default, Sensor1 is active. It reads input u1 and sets the output y. When it fails, we switch to Sensor2 which reads input u2 and sets the output y. When both of them fail, we fall into the Alarm state and produce a nominal zero output.

Sensor1 and Sensor2 are "linked atomic subcharts". These look and behave just like normal Stateflow states except that the contents of the linked atomic subchart reside in a chart in another library model. In this case, both of the linked atomic subcharts correspond to the library chart sf_atomic_sensor_lib/SingleSensor.

Library Chart

The SingleSensor chart models a single sensor which accepts a sensor input u and provides a filtered sensor output y. It contains logic to detect out-of-range errors. By default the sensor is assumed to be in the state OK. If the sensor reading goes out of range (which is modeled by the transition from OK to FailOnce) and stays faulty for 0.5 seconds, then we transition to Fail. In this case, the sensor outputs a constant 0. This allows the sensor to model faults but ignore very transient spikes in the sensor reading.

  • The transition from OK to FailOnce relies on two Stateflow chart parameters LOW and HIGH.

  • There is a top-level function called inFailed that is used to convey to the container chart whether the sensor is in a failed state.

Mapping Inputs, Outputs and Parameters

The main chart RedundantSensors has two inputs u1 and u2, while the library chart corresponding to the linked atomic subcharts has only a single input u. In this case, we want the linked subchart Sensor1 to access the chart input u1 and the linked subchart Sensor2 to access the chart input u2. In order to accomplish this, we need to specify a mapping for each instance of the linked atomic subchart. To edit the subchart mappings, right-click the atomic subchart and select Subchart Mappings from the context menu.

In this dialog box, you map symbols (inputs, outputs and parameters) from the main chart to symbols in the library chart. Similarly, parameters defined in the library chart can be given different values among the various instances of the subchart. For example, this table lists the mappings for Sensor1 and Sensor2.

Simulation Behavior

If you simulate the model, you will notice the following behavior:

  • Initially, both inputs to the main chart are zero. Hence the output produced is zero.

  • When the input u1 varies between -75 and 75, the output will track u1.

  • As soon as u1 is outside these bounds, the output begins to track u2.

  • When u2 falls outside the range between -100 and 100, the output begins to produce a nominal zero output.

You can open this model and start the simulation to see this behavior. To change the inputs to the chart, double click on the gain blocks and drag the sliders.

Related Topics