# Development of a Small CNC Machining Center for Physical Implementation and a Digital Twin
## 5 Developing a Digital Twin of the System  
### CAE Simulation  
The process of creating a digital twin for CNC equipment entailed the sequence of steps illustrated in Figure 14.  
The steps shown in Figure 13 are detailed below. **Realizing the 3D model of the CNC equipment as an assembly in Solidworks**  
The first step required making a 3D model of the CNC equipment in a CAD program. The Solidworks software (v. 2019) package was chosen for this task. Figure 14: Steps required to realize a digital twin of the CNC equipment. The use of the Solidworks software package to realize the 3D model as an assembly, later broken down into functional modules, was necessary because it was directly integrated with MATLAB and Simulink, allowing the automatic generation of a kinematic model in the latter by exporting the 3D assembly from Solidworks. **Separating the assembly into functional modules**  
The separation into subassemblies of the CNC equipment assembly was necessary in order to correctly identify its functional modules in the export process from Solidworks to MATLAB/Simulink. The identification of movable components (feed axes, main spindle unit) and fixed components (frame, fixtures) was performed by defining the corresponding constraints in Solidworks (v. 2019). Figure 15 shows the 3D model of the CNC equipment together with the functional modules. **Exporting the assembly module by module from Solidworks to MATLAB/Simulink**  
The Solidworks interface includes specific commands for managing the export of assemblies to MATLAB/Simulink. Figure 15: The 3D model of CNC equipment, divided into functional modules: (**a**) whole assembly; (**b**) frame; (**c**) X-axis; (**d**) Y-axis; (**e**) Z-axis. To export the 3D model from Solidworks, we went to the main menu Tools, submenu Simscape Multibody Link, submenu Export, and command Simscape Multibody. These commands generated a file with the.xml extension to be imported into the MATLAB workspace with the command:  
\[\text{smimport('filename')} \tag{24}\]  
The import generated a Simulink file (slx file) and a data file (m file). The slx file included all the necessary information for the kinematic simulation of the modeled CNC equipment using Simulink and its modules Simscape Multibody or Simscape Multibody First Generation (Simechanics), depending on the MATLAB version used. **Completing the Simulink diagram with kinematic joint actuation systems and reference input generation systems**  
At this stage the diagram could only simulate the motions executed by the CNC equipment, but only in an uncontrolled way. By supplementing the diagram with kinematic joint actuation systems and reference frame generation systems, the diagram in Figure 15 was obtained, which allowed the simulation of the system behavior both kinematically and dynamically. Kinematic simulation, in this case, means the possibility to generate the kinematic reference quantities, either in a positioning or in a circular interpolation regime, and to study how they are processed in the system from input to output. The dynamic simulation allowed the evaluation of how motion control systems influenced the behavior of the CNC equipment and how the technological resisting forces acting at the level of the main spindle influenced the operation of the X- and Y-axes feed systems. Most of the component subsystems of the diagram in Figure 15 were already presented in the previous figures, as follows:  
* The axis drive system (X, Y, Z) was presented in Figure 2;
* The PID controller was presented in Figure 5a;
* The input variable generation system (X, Y) was presented in Figure 2 or Figure 10, depending on the operating mode (fast positioning or contouring).