Thermal error compensation method for CNC machine tools based on deep convolution neural network

To avoid the resetting of temperature-sensitive points caused by seasonal and weather changes and the influence on the accuracy of the thermal error model, a thermal error prediction and compensation method for CNC machine tools without preselected temperature-sensitive points was proposed based on deep learning method. The original temperature data of the CNC machine tool were converted into thermal images and directly serve as the input of the deep learning network. To improve the prediction accuracy of the thermal error model, a thermal error model of CNC machine tool with 10 hidden layers was constructed by using the powerful image feature learning ability of deep convolution network. The nonlinear mapping relationship between temperature image and thermal error without pre-selection of temperature key points was established, and more relationships between thermal error and temperature feature of a machine tool were retained. STM32F4 microprocessor was used as thermal error compensation controller to develop software and hardware system. The application experiment of the thermal error compensation system is carried out on the CNC grinder, and the effectiveness of the thermal error compensation system is verified.


Introduction
Thermal error prediction and compensation of CNC machine tools is an important technology to improve the machining accuracy and reliability [1][2] . The key to effective compensation is accurate modeling of thermal error. The thermal error prediction model of machine tools, in recent years, has been divided into theoretical thermal error model and empirical thermal error model by scholars at home and abroad. For the theoretical thermal error model, Jorgensen et al. [3] solved the steady-state problem of a machine tool spindle system under different lubrication conditions using the lumped mass method; Kim et al. [4][5] used the mass concentration method to model the machine tool ball-screw system, and compared with the finite element model. For empirical thermal error model, Du et al. [6] used Deep Autoencoder to reconstruct features of temperature-sensitive points selected, then used genetic algorithm to optimize BP neural network parameters, established SAE-GA-BP thermal error model; Xie et al. [7] discovered the pseudo-hysteresis phenomenon of machine tools and established the thermal error pseudo-hysteresis prediction model based on optimized least squares support vector machine (LSSVM); Tan et al. [8] used binary whale optimization algorithm to optimize the hyperparameters of LSSVM. The loss function design considered the key points of maximizing forecast accuracy and minimizing optimal temperature. The experimental results show that the precision of the thermal error model was improved by about 62.8% and the number of temperature-sensitive points was reduced from 20 to 3. The above research has made satisfactory progress in the thermal performance of the machine tool, but the existing thermal error model is greatly affected by the temperature measurement points. The establishment and 2 accuracy of the model depend on the layout and optimal selection of the temperature-sensitive points of the machine tool.
Thermal error has the characteristics of time-varying, non-linearity, and coupling. The temperature field distribution mode and thermal error of machine tool will change with different working conditions [6] . Given the powerful data processing and feature self-learning capabilities of deep learning algorithms [9] , this paper proposes a numerical control machine tool thermal error modeling method based on data conversion and deep learning to solve the problems of temperature-sensitive point changes in traditional thermal error modeling methods. Exploring the introduction of the convolutional neural network (CNN)to establish the thermal error model of CNC machine tools, using the feature extraction ability of CNN and the idea of data-image conversion, CNN automatically extracts the features of the entire machine tool temperature data image and performs robust modeling of the CNC machine tool without the temperature measurement point is optimized to avoid the influence of the temperature measurement point on the accuracy of the machine tool. STM32F4 microprocessor is used to establish thermal error compensation controller, and STM32CubeIDE is used to realize the embedding of deep learning thermal error model and thermal error compensation. The application results showed that the CNN-based thermal error compensation method for CNC machine tools has high compensation accuracy and applicability.

Construction of thermal error model based on Deep Convolution Neural Networks (DCNNs)
In this paper, a deep learning thermal error model based on CNN is established, and its structure is shown in figure 1. The temperature characteristics of NC machine tools are preserved in this model, and features are extracted automatically by using CNN, thus improving the accuracy and robustness of the model. The input to the model is graphical temperature data. Instead of constructing convolution kernels, the high-level features of thermal errors of machine tools are automatically extracted from the coupled multidimensional data, and the proper convolution kernels are found automatically by training.

Temperature Data Sequence of Machine Tool
x m1 x 11 x 12 x 1L x 21 x 22 x 2L x m2 x mL ... ...  The deep learning thermal error model has consisted of 12 layers, including 10 hidden layers besides input layer and output layer, which are 4 convolutional layers, 3 pooling layers, 1 full connection layer, and 2 regression layers. The specific network structure is shown in table 1. Most  The function of the full connection layer is to display a multi-dimensional feature map into a singledimensional vector, which is passed down to the full connectivity layer network. To reduce the complex co-adaptability between neurons and the over-fitting of the model, Dropout regularization method is introduced in the full connectivity layer. Figure 3 shows the changes in the way neurons are connected after Dropout regularization. The neurons in the hidden layer are deleted randomly with a certain probability, which makes the full connection layer sparse, thus effectively reducing the synergy effect

Thermal Error Compensation Controller Based on Deep Learning
The hardware part of the embedded compensation controller includes MCU minimum system circuit module, human-machine interaction module, communication interface circuit module, and storage circuit module. The structural block diagram is shown in figure 4. STM32F407ZET6 is selected as the embedded microprocessor. To meet the basic requirement of neural network for processor power, the main frequency of CPU is 168MHZ and the architecture is Cortex-M4. With a 32-bit multiple AHB bus matrix and 192KB SRAM mounted externally, a large number of variables required for calculation can be stored. Flash is 128M NAND flash, which can store the whole network structure of the deep neural network. ADC/DAC has faster analog conversion speed and lower operating voltage, and has 3 serial communication interfaces and 1 USB interface. Since STM32F4 series supports the pre-training model in Keras and TensorFlow, the deep learning thermal error model based on CNN can be embedded in the embedded thermal error compensation device according to its modification. Arm processor programs mainly include interrupting programs, human-machine interaction programs, USART serial communication programs, EEPROM storage programs, etc. The program design follows the modular design idea and sets the interruption priority of each part to realize the operation control of the whole control system. After the system is powered up, the initialization of each module system is completed first, and then the deep learning thermal error model is read out from EEPROM. Then send the command to the temperature sensor to receive the temperature value. After judging the validity of the temperature value, the temperature value is sent to the thermal error model for calculation. After the prediction value is obtained, the validity of the error value is judged. If it is judged to be valid, the error value will be sent to the communication module to send a compensation starting signal and request the CNC system to read and write error compensation parameters. The upper computer also accepts error compensation value and temperature reading value information at the same time.
The pre-trained deep learning model is imported into IDE for analysis, and deep learning thermal error model which can run in embedded microprocessor can be generated by configuring relevant peripherals after analysis, thus realizing the transfer of deep learning thermal error model.
The upper computer software is designed with C# and MATLAB, including three main functions: thermal characteristic data observation, thermal error modeling and prediction, and thermal error compensation. The trained deep learning model is packed and called by MATLAB to realize the function of thermal error modeling module, the function of communication and compensation module with CNC machine tool is compiled by C#, the function of data observation and history recording is realized by MATLAB, and finally integrated into the thermal error compensation system of CNC machine tool. The observation part of thermal characteristic data can observe the historical data collected by thermal characteristic acquisition system of the CNC machine tool and observe the temperature data and thermal error data of machine tool at the same time. Thermal error modeling module can read historical data and carry out thermal error modeling prediction of various models. The evaluation index function of thermal error model can realize the applicability of thermal error model. Intuitive evaluation can further guide the implementation of thermal error compensation.

Compensation Application Experiment
The application experiment is carried out on the HBS2375 CNC grinder. The FAUNC CNC system used in the system has the function of origin offset. The instruction of origin offset is effected by setting the registry value to '1' in the parameter EMS (No.1203#0). Subsequently, the external mechanical origin offset is fed into the parameter (No. 1280) address with a binary two-byte offset of -32767~32767 set for each axis. Finally, the minimum mobile unit is set by parameters [1013#0,1013#1], and the system detection unit (minimum mobile unit/command multiplier) is obtained by setting command multiplier by parameter No.1820. Before compensation experiments, the machine tool is preheated for 40 minutes and then thermal error compensation experiments are carried out. Due to the high requirement of radial dimension accuracy for shaft parts, repeated installation during the experiment will affect the processing and measurement accuracy, so the lathe will only idle, close the coolant and the grinding wheel spindle will idle at 1500 r/min. During the compensation process, the thermal error value after compensation is checked every 30 minutes after shutdown. The radial thermal error compensation comparison diagram shown in figure 5 is obtained by measurement. Through idle compensation experiments, the radial thermal error of the spindle is reduced to 7μm, the maximum historical value of thermal error in this direction is 35μm, the error is compensated by nearly 80%, which validates the validity of the thermal error model in the thermal error compensation system.

Conclusion
Based on deep learning theory and CNN exploration, a thermal error prediction model without temperature-sensitive pre-selection is established, and a thermal error compensation controller is built by STM32F4 microprocessor, and thermal error compensation is realized by PMC and point offset function. Thermal error compensation experiments on CNC Grinders verify the effectiveness of the thermal error compensation system.