Engee documentation
Notebook

A system of redundant sensors

In this demo example, let's look at how to create a model of a duplicate sensor system using the Chart block of the finite state machine library.

Redundant sensors increase the reliability of the system due to redundancy: if one sensor fails, it is replaced by others, which is critical in aviation, industry and robotics. Modeling of such a system makes it possible to analyze fault tolerance, optimize data processing algorithms, and determine the minimum required number of sensors for stable operation. The use of redundant sensors reduces the risk of accidents and improves measurement accuracy in critical systems.

Description of the model

The model contains two Chart blocks that simulate sensor fault detection and the logic of generating output data from sensors. The input signals are: sensor data and fault signals.

sensors-07.07.25 20_39_02.png

Fault detection

The sensors are modeled using two parallel states in the Chart block.

Let's analyze the fault detection algorithm using the example of sensor No. 1. By default, the sensor is active. However, if the input signal is sensor1Failure If it is greater than 0, the sensor becomes inactive. Sensor No. 1 remains inactive for 5 simulation steps. But at each step, the input signal is tested. sensor1Failure. If the signal is still zero, the 5-step countdown will start again. During this time period, the output data is generated only from the data received from sensor No. 2, if it is active.

image.png

The logic of forming the actual output signal

The output signal is generated using a transition graph. And it is determined using the following logic.

The actual value of the output signal is obtained by averaging the two sensor signals in order to reduce measurement noise. If both sensors are active, the output is the average value of the sum of sensor1 and sensor2. If one of the sensors is not active, that is, data from it is not being sent, data from the second sensor is being sent to the output. If both sensors are inactive, the output will be 0.

image.png

Simulation of the model

Run the script with the system parameters definition.

In [ ]:
engee.script.run("/user/start/examples/state_machines/dual_sensors/_set_params.ngscript");
In [ ]:
function start_model_engee()
    try
        engee.close("dual_sensors", force=true) # закрытие модели 
        catch err # в случае, если нет модели, которую нужно закрыть и engee.close() не выполняется, то будет выполнена её загрузка после catch
            m = engee.load("$(@__DIR__)/dual_sensors.engee") # загрузка модели
        end;

    try
        engee.run(m) # запуск модели
        catch err # в случае, если модель не загружена и engee.run() не выполняется, то будут выполнены две нижние строки после catch
            m = engee.load("$(@__DIR__)/dual_sensors.engee") # загрузка модели
            engee.run(m) # запуск модели
        end
end
Out[0]:
start_model_engee (generic function with 1 method)

Download and run the model to get the modeling data from the variable simout.

In [ ]:
start_model_engee();
In [ ]:
result = collect( simout )
Out[0]:
5-element Vector{WorkspaceArray}:
 WorkspaceArray{Float64}("dual_sensors/s2_fail")
 WorkspaceArray{Float64}("dual_sensors/s1_fail")
 WorkspaceArray{Float64}("dual_sensors/sens1_data")
 WorkspaceArray{Float64}("dual_sensors/sens2_data")
 WorkspaceArray{Float64}("dual_sensors/out")

Plot the data graphs from sensor No. 1 and sensor No. 2.

In [ ]:
plot(
    plot(result[3].time, result[3].value, lab = "Данные с датчика №1"),
    plot(result[4].time, result[4].value, lab = "Данные с датчика №2", c = "red"),
    layout = (1,2)
)
Out[0]:

We will display signals about sensor failures.

In [ ]:
plot(result[2].time, [result[2].value result[1].value], lab = ["Сбой датчика №1" "Сбой датчика №2"])
Out[0]:

The resulting measurement signal of the two sensors.

In [ ]:
plot(result[5].time, result[5].value, lab = "Данные с датчиков")
Out[0]:

Conclusion

As a result, we got a graph of the measurement of a certain signal. Individual signals from the first and second sensors have missing values due to sensor failures. The resulting value of the measured signal has one zero value for about 7 seconds. This is due to the fact that both sensors were inactive at this point in time.

Blocks used in example