Prediction of Spindle Thermal Deformation and Displacement Using Back Propagation Neural Network

Over the years, machine tool manufacturers have moved steadily towards the enhancement of machining accuracy to improve the quality of finished products. In this study, the thermal deformation of a machine spindle, which has a profound effect on machining accuracy, was investigated. The temperatures of the front and rear spindle bearings, and of the environment as well as the Z-axis displacement on a model MC4200BL CNC lathe (Hybrid Sphere) were measured under long-term operating conditions. Measurements were carried out at spindle speeds of 1000, 1500, 2000, 2500, and 3000 rpm, and the data were used to establish a model for the prediction of spindle displacement. A back propagation neural network (BPNN) was used to establish the model and explore adjustments of the training function, the data training ratio, and the number of neurons in the hidden layer. Results of the experiments showed that the coefficient of determination (R2) of the prediction model derived from the best parameters can be up to 0.9948. This was much better than the 0.8273 achieved by the partial least squares regression method.


Introduction
Over the years, machine tool manufacturers have moved steadily towards the enhancement of machining accuracy to improve the quality of finished products. Errors in accuracy, which can have a large impact on production, include those caused by geometry, by changes in temperature, and by the cutting force itself. (1,2) To enhance production capacity, machines must work faster, and when working time increases, so does the temperature. However, when processing time is increased, thermal error becomes more important and can seriously affect machining accuracy. According to Bryan, thermal error accounts for between 40 and 70% of the total machining error. (3,4) Thermal errors can arise from either an internal or external heat source. (5) Internal heat is mainly generated by moving parts of the machine, such as the motor and spindle bearings, as well as the cutting process itself. External heat comes from the operating environment. In a conventional spindle, the main heat source is the bearings. (6) To enhance machining accuracy, errors should be reduced and compensation for displacement applied. (7) Many studies related to this problem have been carried out. Zhu et al. (8) used multiple regression to construct a thermal error prediction model and succeeded in reducing the thermal displacement error of 20 µm down to 4 µm, a reduction of about 75%. Xiaohong et al. (9) used the rough set theory to analyze the relationship between temperature and error, and were able to reduce thermal errors to less than 5 µm using a back propagation neural network (BPNN) training model. Pahk and Lee (10) proposed a spindle temperature thermal error measurement system that used multiple linear regression, a neural network (NN), and the system identification method to establish a spindle-thermal error model. Lin and Chang (11) used complex multivariate regression analysis to predict spindle thermal displacement at any particular time. Li et al. (12) used the bat algorithm (BA) to optimize a traditional BPNN. It is always difficult to confirm the number of hidden layers in a traditional BPNN, and using the BA-back propagation (BP) solved this modeling problem. Ma et al. (13) used particle swarm optimization (PSO) and the genetic algorithm (GA) to improve the shortcomings of BPNN, and were able to improve processing accuracy from 67 to 78 and 89%, respectively. There are many types of artificial neural networks (ANNs), and the BPNN has the additional feature of nonlinear input-output mapping. (14,15) To solve the problem of inaccuracy caused by the thermal displacement of the spindle, it was necessary to establish a spindle thermal displacement model that could be used to predict these changes. Traditionally, regression analysis and the generalized least squares are used for this. Although these methods are relatively simple and easy to use, the prediction results are less than ideal. Thermal error is dynamic and nonlinear, and in this study, an appropriate ANN was therefore selected to suit the features of the data and establish a model for prediction. However, Li et al. (12) observed that traditional BPNN often has trouble confirming the number of neurons in the hidden layer. To attain the objective of this study, it was necessary to find the best BPNN parameter training function and ratio of data training, as well as overcome the problem of the number of hidden layer neurons. This allowed the prediction ability of the model to be enhanced, which reduced deviations in prediction, improved machining accuracy, and established an excellent model that was superior to partial least squares regression (PLSR).

Experimental equipment and architecture
In this study, we adopted the ball-type CNC lathe (model MC4200BL) from Mike Machine Industry Co., Ltd., together with the SYNTEC21-TA-type controller of Syntec Technology Co., Ltd., and the Posa spindle (model TAC-10-CY), which is a belt-type spindle. Temperature sensors are mainly divided into contact and noncontact types. The noncontact type requires much equipment to go with, such as the assist optical system, and the equipment cost is much higher than that of the contact type. In addition, for the machine tool, the noncontact type is more difficult to install. Therefore, contact temperature sensors are buried in the front and rear bearings of the spindle. In this study, we adopted the DS18B20 temperature sensor; it can measure temperature in the range from −55 to 125 ℃ and has a resolution of 0.5 ℃, and the sampling frequency is 5 Hz. Its special feature is to convert the measured temperature data into digital format, and the accuracy will not be affected during the receiving process. Moreover, the microcontrol board Arduino Uno equipped with a USB serial port was used as the data capture module. As for the laser displacement meter, we used KEYENCE's IL-S025 and IL-1000 to measure the displacement through noncontact measurement. The IL-S025 has a measurement range of 20 to 30 mm and a resolution of 1 µm, and the sampling frequency is 5 Hz. Finally, the NI-6341 capture card was used to capture signals.
The experimental flow chart of the study is shown in Fig. 1. The machine spindle speeds used in the experiments were 1000, 1500, 2000, 2500, and 3000 rpm. The spindle was run at each temperature for a measured time. The sensors used to measure the temperature were embedded in the front and rear bearing housings on the spindle assembly of a model MC4200BL CNC lathe (Hybrid Sphere). Measurements were made at 5 s intervals and the displacement of the Z-axis was measured at the same time using a laser displacement meter. To establish the BPNN model, the training function and the proportion of training data were adjusted, and the coefficient of determination (R 2 ) based on the number of hidden layer neurons was found. The root mean square error (RMSE), ratio of performance to deviation (RPD), mean square error (MSE), and mean absolute error (MAE) were all used to determine the degree of prediction and to explore the parameters needed to establish the best model compared with PLSR.

BPNN
The BPNN, a classic ANN, is a combination of multilayer perceptron (MLP) and error back propagation (EBP). The BPNN is a supervised learning network; this means that it requires a set of training materials that includes input features and target results. The main feature of the BPNN is the updating of the weight between points by calculating the error to enhance the prediction ability of the model. The advantages of the BPNN are that it can perform nonlinear input and output mapping and also use the gradient descent method (16) to reduce errors and give better results. Figure 2 is the basic architecture of the BPNN. The input layer is orange, the hidden layer is blue, and the output is yellow. The blue arrow represents the weight of the input layer connecting the hidden layer, the yellow arrow represents the weight of the hidden layer connecting the output layer, and the BPNN flow chart is shown in Fig. 3.

BPNN theory
The sigmoid function was used to calculate the equation of the hidden layer output value, as shown in Eqs. (1) and (2). (17) In these equations, h k is the input value of the kth hidden unit, net k is the weighted product sum of the input values, x i is the input value of the ith input unit, and w ik is the connected weight value between the ith input unit and the kth hidden unit. By using the sum of the squared errors of all the output nodes of the network as the objective function, the error calculation equation is as shown in Eq. (3). (18) In this equation, E is the error, y (i) is the actual value, and ŷ (i) is the predicted value.

Training function
In this study, we used three training functions, as follows: 1. Trainlm: The updated weight and bias values were optimized according to Levenberg-Marquardt. (19) The BPNN model achieves the fastest convergence, but it requires a lot of random access memory (RAM).
2. Trainbr: This minimizes the linear combination of square error and weight according to the Bayesian Regulation, (20) and confers the generated network with good generalized quality. It takes slightly longer than the other methods, but is suitable for more complicated data.
3. Trainscg: According to the scaled conjugate gradient method, (21) it reduces the time taken to search the network when adjusting the direction; it consumes fewer resources and is suitable for use with less RAM.

PLSR
PLSR is a regression modeling method suitable for multi-dependent and multi-independent variables. In the modeling process, the principal component analysis (PCA) (22) is extracted as much as possible from the independent and dependent variables, and the correlation between the extracted principal components is then maximized. Simply put, PLSR is a combination of three methods: PCA, canonical correlation analysis (CCA), and multiple linear regression. (23) The main components are extracted from the input and output actual values; the equations are as follows. (14) X = Uα T + X 0 (4) In these equations, X is the independent variable matrix, and Y is the dependent variable matrix. Moreover, U and K are the principal component matrices of X and Y, α T and γ T are the load vector matrixes of X and Y, and X 0 and Y 0 are the residual matrices of X and Y, respectively. The regression equation of PLSR is (24) In this equation, β is the regression coefficient, ε is the error, x i is the ith independent variable, and y is the dependent variable.

Model verification coefficient
To verify the prediction ability of the model, the R 2 , RMSE, RPD, MSE, and MAE were used. The R 2 values lies between 0 < R 2 < 1, but the model has a better prediction ability when the R 2 value is close to 1. The formula is as shown in Eq. (7) below. ( In Eq. (7), SS res is the residual sum of squares, SS tot is the total sum of squares, f i is the ith predictive value, y i is the ith actual value, and ȳ is the average value. RMSE, MSE, and MAE were used to calculate the errors; the smaller the error, the better the prediction ability. The following three equations [Eqs.
In these equations, f i is the ith predictive value and y i is the ith actual value. When RPD < 1.4, the prediction ability of the model will be poor, when 1.4 < RPD < 2, the prediction ability will be fair, and when RPD > 2, the prediction ability will be excellent. The RPD equations are as shown in Eqs. (11) and (12). (27) In the equations, SD is the standard deviation, y i is the ith actual value, and ȳ is the average value.
The several verification coefficients shown above can be used to compare the prediction ability of the model with respect to the number of neurons in the hidden layer, the training function, and the data training ratio to find the best parameters.

BPNN parameter adjustment and PLSR model
In this study, the training temperature and displacement data after adjustments of the training function, the data training ratio, the number of hidden layer neuron interval, and the number of hidden layer neurons were used for comparison with five indicators, namely, R 2 , RMSE, RPD, MSE, and MAE, and as references for the enhancement of the prediction ability of the model.

Comparison of training function
As mentioned in the first chapter, the BPNN has a disadvantage in that it is difficult to confirm the number of neurons in the hidden layer. Therefore, in this study, the BPNN parameters were adjusted to find the best parameters. With the other parameters fixed, the training results were taken as the average of 10  According to the results shown in Figs. 4(a)-4(e), the values of R 2 and RPD using Trainlm at each speed were higher than those using Trainbr and Trainscg, and the values of RMSE, MSE, and MAE were lower than those using Trainbr and Trainscg. It is clear that Trainlm had the highest prediction effect. The analysis shows that the prediction abilities of these training functions, for spindle thermal displacement prediction, ranked from high to low are Trainlm, Trainbr, and Trainscg.

Data training ratio
The results shown in Sect   and MAE are lower than 70%. The verification coefficients show that 80% has the highest prediction effect. The analysis showed that the data training ratio of the BPNN was predictive of the spindle thermal displacement.

Hidden layer neuron number intervals
The results described in Sect. 3.1.1 showed that Trainlm had the best prediction ability, and in Sect. 3.1.2, it can be seen that the best BPNN prediction was at a training data ratio of 80%. Under these circumstances, the number of hidden layer neurons increased by 5 each time, training for each hidden layer was performed 10 times, and the average was used. The results are shown in Figs. 6(a)-6(e).
According to the results shown in Figs lower than those in the other hidden layers. The verification coefficients show that the highest prediction rate is coincident with the number of hidden neuron intervals of around 40. Further analysis confirmed that for this displacement model, the hidden layer interval of 40 gives the best prediction rate.

Selection of the number of hidden layer neurons
All the results in Sects. 3.1.1 to 3.1.3 show that for Trainlm, the data training ratio of BPNN is 80%, and the number of hidden layer neurons that gives the best prediction is 40. The number of neurons in the hidden layers from 35 to 50 is increased by one each time. Training was performed 10 times and an average was taken; the comparison results are shown in Figs. 7(a)-7(e).

Prediction of displacement
Training was carried out using the experimental results described in Sects. 3.1.1 to 3.1.4, at the spindle rotation speeds of 1000, 1500, 2000, 2500, and 3000 rpm, and the results are shown in Figs. 8-12. Figure 8 shows the thermal displacement model at a spindle rotation speed of 1000 rpm, where R 2 was 0.9947, RMSE was 0.000199, RPD was 13.74, MSE was 3.95 × 10 −8 , and MAE was 0.000157. The orange line is the actual displacement value, whereas the blue line is the predicted displacement value. Figure 9 shows the thermal displacement model at a spindle speed of 1500 rpm, where R 2 was 0.9948, RMSE was 0.000284, RPD was 13.84, MSE was 8.09 × 10 −8 , and MAE was 0.000227.   Figure 10 shows the thermal displacement model at a spindle rotation speed of 2000 rpm, where R 2 was 0.9936, RMSE was 0.000418, RPD was 12.45, MSE was 1.75 × 10 −7 , and MAE was 0.00033. Figure 11 shows the thermal displacement model at a spindle speed of 2500 rpm, where R 2 was 0.9935, RMSE was 0.000556, RPD was 12.42, MSE was 3.21 × 10 −7 , and MAE was 0.000452. Figure 12 shows the thermal displacement model at a spindle speed of 3000 rpm, where R 2 was 0.9936, RMSE was 0.000562, RPD was 12.53, MSE was 3.15 × 10 −7 , and MAE was 0.000446.   To summarize the results shown in Figs. 8-12, in the model trained with the best parameter, the predicted value is very close to the actual value, the lowest R 2 value is 0.9935, and the highest is 0.9948, which is a very high prediction rate. The experiments clearly show that the BPNN established by the best parameter can effectively enhance the prediction ability of the model. Figure 13 shows the thermal displacement model predicted by PLSR at a spindle speed of 1000 rpm, where R 2 was 0.8273, RMSE was 0.0011, RPD was 2.27, MSE was 1.29 × 10 −6 , and MAE was 0.000807. It can be seen that the predicted displacement value was significantly different from the actual displacement value. At other speeds, PLSR showed even greater differences between the predicted and measured displacement values. The BPNN model R 2 established by the best parameters can be up to 0.9948, compared with the partial least squares regression where R 2 = 0.8273.

Conclusion
In this study, temperature sensors were used to measure thermal changes in front and rear spindle bearings of a model MC4200BL CNC lathe, as well as the temperature of the environment. A laser displacement meter was used to measure dimensional changes in the Z-axis at the same time. A BPNN was used and parameters including the training function, the data training ratio, and the number of neurons in hidden layers were adjusted to determine the accuracy of the prediction of judgment models with five different indicators, namely, R 2 , RMSE, RPD, MSE, and MAE. Comparisons revealed that the model showing the best prediction was generated using the Trainlm parameter Training Function. The data training ratio was 80% and the number of neurons in the hidden layer was 42. This parameter, generated from the experiment, was used to establish the model, and the results showed very good prediction, where R 2 was 0.9948, RMSE was 0.000284, RPD was 13.84, MSE was 0.0000000809, and MAE was 0.000227; the predicted displacement values were very close to the actual values. A comparison of BPNNs established with the best parameters with the partial least squares regression model showed that the BPNN using the best parameters has a better prediction ability than PLSR regardless of R 2 or the maximum error. Moreover, the verification index of R 2 shows that of the BPNN to be 0.9948, which is much higher than the 0.8273 of the PLSR. These best BRNN parameters effectively enhance the robustness and predictive accuracy of the model.