# A Framework for Communicating and Building a Digital Twin Model of the Electric Car
## 2 Digital Twin Components and Communication
### Establishing Communication  
Communication is based on the Modbus TCP/IP protocol. The protocol is used for industrial purposes, such as SCADA systems [56; 57]. The Modbus is a type of client-server architecture [58]. The PC is the client device that initiates communication and sends requests. The inverter is a server device that processes received requests and sends responses. Data are exchanged between them via a Modbus TCP/IP frame (Table 6). Thanks to the frame, the necessary functionality is ensured, and the parameters go directly to the appropriate registers in the inverter. The following FC operations (function codes) are available for the inverter device:  
* FC3--read holding registers. * FC16--write multiple registers. * FC23--read/write multiple registers. Using these functions, the AC motor can be started or stopped with the correct control word sent by the PC, or the actual values of the AC motor, such as speed, position, and current, can be read. Next, Table 7 presents the Modbus register mapping. This is how data are saved when exchanging process data words. The first available offset starts at reference number 4. The library supporting communication in LabVIEW software is Modbus Master from Plasmionique Inc. (Varennes, QC, Canada) [59]. LabVIEW uses the graphical environment presented in Figure 1(a) for programming. The code is similar to an electric diagram. More complex functions are presented in the form of blocks that organize and simplify the program structure. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Byte** & **Name** & **Notes** \\ \hline
0–1 & Transaction ID & \\
2–3 & Protocol ID & MABP—Modbus \\
4–5 & Length field & Application header \\
6 & Client ID & \\ \hline
7 & Function code & \\
8–n 1  & Data & PDU—protocol data unit \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Modbus TCP frame format. The entire frame is called an ADU (application data unit). LabVIEW is a software that contains all the tools needed to perform simulations [60; 61]. At the same time, the software is user-friendly and ensures quick implementation. The user interface consists of two windows: a block diagram and a front panel [62]. Figure 2b presents example Modbus frames. Frames are coded in the hexadecimal system. The last frame TX means transmitted data and RX means received data. The meanings of double words in the frame are as follows:  
* 16 AAhex--transaction identifier, value assigned by the client;
* 0000--protocol identifier must be zero;
* 000 Bhex = 11 dec--number of consecutive double words;
* FFhex--the server identifier means that the DFE11B is the end station;
* 10 hex = 16 dec--function code, FC16 is the operation record;
* 0004--address of the first register;
* 0002--number of required registers;
* 04--number of double words remaining;
* 0006 hex = 0110 bin--setting the value of control word 1, bit 1, and bit 2 to 1 causes the inverter to enter the read-ready state;
* 0032 hex = 50 dec--current controlled value, set value. All data included in the manufacturers' instructions and collected in Tables 4-7 are implemented in LabView. They are essential to avoid problems and errors during startup. The communication between the inverter and the PC via the Modbus protocol has been completed. setpoints accelerate the DC motor. The rotational speed vibrates, as shown in Figure 3b. The reason for this is that the drive inverter adjusts the AC motor current to achieve the set torque. At the same time, the rotational speed of the AC motor also changes. Moreover, the speed value stabilizes with a delay resulting from the existing moment of inertia. For setpoint 20, the final rotational speed is approximately 1760 rpm and is reached after 50 s.  
Based on historical data collected during races using telemetry sensors installed in cars [63], the Dunfold racetrack is divided into segments. A view of the Dunfold track is presented in Figure 4. The required range of rotational speed can be activated. According to historical data, the DC motor rotates at a speed from 1670 to 1815 rpm.