## 3. Matherial and Methods
### Development of the System
#### 3.7.1 Physical System Development
```
Data:\(DI_{V_{S_{k}}},DO_{V_{S_{k}}},AI_{V_{S_{k}}},AO_{V_{S_{k}}}\) Result:\(D{I}_{V_{S_{k}}},DO_{V_{S_{k}}},AI_{V_{S_{k}}},AO_{V_{S_{k}}}\) if\((St_{V_{S_{k}}}\
eq St_{V_{S_{k-1}}})\) then (Digital Virtual System): \[DI_{V_{S_{k}}}=|DI_{V_{S_{k}}}-DI_{V_{S_{k-1}}}|\] (15) \[DI_{V_{S_{k}}}=D{I}_{V_{S_{k-1}}}+DI_{V_{S_{k}}}\] (16) \[D{d}_{V_{S_{k}}}=|DO_{V_{S_{k}}}-DO_{V_{S_{k-1}}}|\] (17) \[DI_{mPS_{k}}=DI_{mPS_{k-1}}+DI_{PS_{k}}\]0 (Analog Virtual System): \[DI_{mPS_{k}}=DI_{mPS_{k-1}}+DI_{PS_{k}}\]1 (19) \[DI_{mPS_{k}}=DI_{mPS_{k-1}}+DI_{PS_{k}}\]2 (20) end
```

**Algorithm 2**Development of the digital and analog virtual system:

#### 3.7.3 Digital Control Operation and Fault Diagnosis

To diagnose faults, the physical input and output memory vectors and the virtual input and output vectors are continuously compared (Figure 9c, but with a synchronization time, considering the change of state in both the physical automata and the virtual automata, and it is implemented Algorithm 3. ## 4 Results and Discussion

The presented approach of a cyber-physical system at a supervisory control level is intended for the monitoring and diagnosis of hardware and software failures in an automated storage and retrieval system, as shown in \[DI_{mPS_{k}}=DI_{mPS_{k-1}}+DI_{PS_{k}}\]3 The virtual system is implemented by a real-time numerical simulation to model the behavior of the physical system. Hybrid automata are used to design the control functions of the physical controller and to ease the implementation of the virtual controller. The sensors and actuators were defined as complex network nodes, and their asynchronous activation was defined as events affecting the weight links. The complex network and the hybrid automata for both the digital twin and the physical system were coordinated. Every time that the physical controller activates an actuator or reads a sensor, data vectors save the information and are compared with the corresponding data vectors in the virtual controller. To detect failures in the hardware components, adjacency matrices are compared, and to detect failure in the execution of the sequential logic, the current states are compared. The simulation and implementation of the system present a problem of synchronization between the physical and virtual systems. This problem was solved by considering a time of delay between the data transfer and the change in the physical state and virtual state. Figure 9 shows the execution of the physical system and the virtual system. It can be observed that the virtual and physical hybrid automata change at the same time with an specific time of synchronization. In Figure 10, input and output changes can also be observed, besides changes between 0 and 1. The system updates and saves the values from the activation and deactivation events, and the algorithms detect discrepancies of data values of the physical controller with respect to data values of the virtual system. In this way, it is possible to detect failures in sensors, actuators, and in the execution of the control logic. To corroborate the operation of the algorithm, the stored information presented in the Figure 9 was examined. In the case where there are no failures, the data vectors are identical, and in the case that the data are not equal, there are failures. Figure 11 shows the difference in the data vectors with red rectangles to indicate failures and the green rectangles to indicate that the elements are working correctly. Finally, Figure 12 shows an operator panel with indicators to display the elements that present a failure. In order to evaluate the efficiency of the system, four different cases (row represents the number of simulations) of failure diagnosis were evaluated in different stages of the process, and the tests were carried out both in the loading and unloading configuration

\[DI_{mPS_{k}}=DI_{mPS_{k-1}}+DI_{PS_{k}}\]4 Diagnosis of faults. \[DI_{mPS_{k}}=DI_{mPS_{k-1}}+DI_{PS_{k}}\]5 Development of the cyber–physical system. of the warehouse.