## 4 Implementation and Validation DT in AS Ecosystem
Thus, the input for the block diagram of the cylinder is the airflow, and the output is the cylinder stroke, Figure 7. Equation (1) presents the relation between the volumetric flow rate (\(q(t)\)), piston surface (\(A\)), and the rod's velocity \(\dot{x}(t)\):  
\[q(t)=A\dot{x}(t), \tag{1}\]  
from where the cylinder position results from Equation (2):  
\[x(t)=\frac{1}{A}\int q(t)\,dt, \tag{2}\]  
Figure 6: The implementation of first prismatic cylinder (U/D) in AS for two approaches: (**a**) the screenshot from the 3D editor workshop where the constraints and the displacement were defined; and (**b**) the screenshot from the pneumatic workshop to customise parameters similar to a real cylinder. In AS, a servo pneumatic system was implemented for the physical behaviour of the U/D cylinder, with the main goal of accurately controlling the position of the cylinder's rod. The proportional valve is responsible for managing the airflow exhausted from the cylinder. It allows one to make precise adjustments to the cylinder's motion by varying the airflow according to the control signal from the feedback controller. The process begins when the controller receives a desired setpoint for the position of the cylinder's rod. The ultrasonic position sensor continuously measures the actual position of the rod and sends this information back to the controller. The controller calculates the error between the desired setpoint and the actual position, using this information to generate a control signal to adjust the proportional valve. As the proportional valve adjusts the airflow exhausted from the cylinder based on the control signal, the cylinder's rod moves towards the desired position. The position sensor keeps providing feedback to the controller, ensuring that the system maintains a closed-loop control configuration. This enables the servo pneumatic system to combine the benefits of a pneumatic, such as high force and robust components, with the precision and accuracy of a closed-loop control system. The hardware system utilised for conducting the HiL simulation consists of several components, presented in Figure 3. A host computer is included, which runs the DT of the 3 DoF robot in an AS environment which the real PLC conducts. The mechanism behind the communication between the mechatronic digital twin and the real PLC is an OPC server. OPC is a popular industrial communication protocol that permits data transmission and compatibility between automation devices and software programs. In this setup, the OPC server (KEPServerEX) links the digital twin and the real PLC in this configuration. Regardless of the implementation specifics or communication protocols the two components use, it offers a common interface that enables seamless communication. KEPServerEX facilitates M2M communications by enabling connections between data values from PLC and AS [39]. The choice of communication protocol is decisive to the successful operation of a DT. The chosen protocol must be well suited to the system's specific requirements, including the network infrastructure, PLC compatibility, real-time performance requirements, etc. Given its robustness and real-time performance, the OPC is an excellent choice for many DT applications, especially mechatronic applications. Employing an OPC server establishes a vital communication bridge between the digital twin of the mechatronic system and the real-world PLC. Firstly, the OPC server builds a connection with the PLC, enabling a two-way communication pathway. This pathway facilitates the transmission of various data types, encompassing status indicators, sensor-derived measurements, and control commands. The OPC server adeptly converts data originating from the PLC into a format compatible with and readily interpretable by the digital twin. This conversion mechanism accommodates the diversity of data formats and protocols potentially employed by different PLCs, thereby establishing a universal communication language. Subsequently, the OPC server orchestrates the data transfer to the digital twin.