Engee documentation
Notebook

Modelling of control logic with parallel states

To realise parallel operation, use parallel states in the finite automata library. For example, as part of the design of a complex system, you can use parallel states to model independent components or subsystems that are active at the same time.

State decomposition

The decomposition type of a diagram or state determines whether the diagram or state contains exclusionary or parallel states:

  • Exceptional states represent mutually exclusive modes of operation. No two exceptional states at the same hierarchical level can be active or executing at the same time. In transition diagrams, each exceptional state is represented by a solid rectangle.
  • Parallel states represent independent modes of operation. Two or more parallel states can be active at the same time, although they are executed sequentially. In state diagrams, each parallel state is represented by a dashed rectangle with a number indicating the order of execution.

You can combine excluded and concurrent states by specifying state decomposition at different levels of your state hierarchy. The default state decomposition type is Excluding (OR). To change the decomposition type to Parallel (AND), right-click the parent state and select Decomposition > Parallel (AND). To change the decomposition type back to Exclusive (OR), right-click the parent state and select Decomposition > Exclusive (OR).

Air temperature controller

This example uses parallel decomposition modelling to simulate a regulator that maintains the air temperature at 120 degrees in a real facility.

fan_1747037996176.png

At the top level, the air controller circuit has two mutually exclusive states, PowerOff and PowerOn. The circuit uses a mutually exclusive activation (OR) strategy because the controller cannot be on and off at the same time.

The controller controls two fans. The first fan turns on when the air temperature rises above 120 degrees. The second fan provides additional cooling when the air temperature rises above 150 degrees Celsius. In the schematic, these fans are represented as parallel sub-states FAN1 and FAN2 of the PowerOn top-level state. Since the fans operate as independent components that are switched on or off depending on the level of cooling required. PowerOn utilises a parallel activation (AND) circuit to ensure that both sub-states are active when the controller is switched on.

Except for thresholds, fans are modelled by states with an identical configuration of sub-states and transitions that reflect the two modes of fan operation: On and Off. Since neither fan can be On and Off at the same time, FAN1 and FAN2 are mutually exclusive (OR).

In PowerOn, a third parallel state called SpeedValue is an independent subsystem that counts the number of fans turned on at each time step. The boolean expression in(FAN1.On) has a value of 1 when the On state of FAN1 is active. Otherwise, in(FAN1.On) is 0. Similarly, the value in(FAN2.On) indicates whether FAN2 is on or off. The sum of these expressions indicates the number of fans turned on at each time step.

Execution order for parallel states

Although FAN1, FAN2 and SpeedValue are active simultaneously, these states are executed sequentially during the simulation. The numbers in the upper right corners of the states define the execution order. The rationale for this order of execution is as follows:

  • FAN1 is executed first because it turns on at a lower temperature than FAN2. It can switch on regardless of whether FAN2 is switched on or off.
  • FAN2 Runs second because it turns on at a higher temperature than FAN1. It can only turn on if FAN1 is already on.
  • SpeedValue is executed last so that the most current status of FAN1 and FAN2 can be observed.

By default, the order in which parallel states are executed is determined according to the order in which you add them to the diagram. To change the execution order of a parallel state, right-click on it and select a value from the Execution Order drop-down list.

Examine the model

This model contains a state diagram Air temperature controller and a subsystem called Physical Object.

fan_1747037852784.png

Depending on the air temperature at the physical plant, the diagram switches on the fans and outputs the number of running airflow fans in the subsystem. This value determines the cooling efficiency factor $k_{cool}$ according to these rules:

  • airflow = 0 - no fans are running. The air temperature does not decrease because $k_{Cool} = 0$.

  • airflow = 1 - one fan is running. The air temperature is reduced according to the cooling efficiency factor $k_{Cool} = 0.05$.

  • airflow = 2 - two fans are running. The air temperature is reduced according to the cooling efficiency factor $k_{Cool} = 0.1$.

The "Physical object" subsystem updates the air temperature $temp$ inside the object based on the equations

$$temp(0) = T_{initial}$$

$$temp'(t) = (T_{Ambient}-temp(t)) \cdot (k_{Heat}-k_{Cool}).$$

Where:

  • $T_{initial}$ is the initial temperature. The default value is 70°.

  • $T_{Ambient}$ is the ambient temperature. The default value is 160°.

  • $k_{Heat}$ is the heat transfer coefficient for the installation. The default value is 0.01.

  • $k_{Cool}$ - cooling activity coefficient corresponding to airflow.

The new temperature determines the degree of cooling at the next time step of the simulation.

Let's see how the air temperature controller works. Run the model using command control.

In [ ]:
modelName = "parallel_st_fan";
PID_model = modelName in [m.name for m in engee.get_all_models()] ? engee.open( modelName ) : engee.load( "$(@__DIR__)/$(modelName).engee");
In [ ]:
results = engee.run( modelName )
Out[0]:
SimulationResult(
    "Switch" => WorkspaceArray{Float64}("parallel_st_fan/Switch")
,
    "Tout" => WorkspaceArray{Float64}("parallel_st_fan/Tout")

)
In [ ]:
plot(
    plot(results["Tout"].time, results["Tout"].value, lab = "Tout"),
    plot(results["Switch"].time, results["Switch"].value, lab = "Switch", c="red"),
    layout = (2,1)
)
Out[0]:

Conclusion

We have considered modelling of control logic using parallel states of finite automata. This tool allows to realise variants of models in which several independent states of the system need to operate.