Introduction

CNC machine tools with high-precision feed systems plays a crucial role in driving the advancement of advanced equipment in industries such as electric power, aerospace and high-speed railways1. Kim2 proposed a comprehensive design method for ball screw drive servo mechanisms, which improved design quality by mathematical modeling, nonlinear optimization, and multi-objective function optimization of dynamic performance. Lee3 established the control model of the machining center and the multi-body dynamic mechanical model of the transmission system based on Simulink and ABAQUS, for the analysis of cutting forces and surface quality in the milling process. Wang4 established a second-order mathematical model of ball screw considering viscous friction and transmission stiffness based on Matlab/Simulink. Wang5 built multi-domain models of CNC machine tools based on Modelica, providing a new approach to comprehensively improve the high-speed, high-precision, and intelligent development of CNC machine tools. The above studies show that the construction of high-precision feed systems through simulation techniques is effective, but the modeling process itself involves simplification, so it cannot fully reflect the physical properties of the objects in question, which often results in substantial discrepancies between simulation outputs and actual operational results, rendering them insufficient for practical applications. To address fixed characteristic errors of mechanism models, scholars have introduced DT simulation technology, which effectively merges mechanical expertise with big data analytics6. Tao7 introduced a comprehensive five-dimensional model of DT alongside its top ten applications, emphasizing the role of DT in forecasting failures and managing the health of complex electromechanical equipment. Sun8 developed a DT model specifically for cutting tools used in machining processes. Luo9 presented a framework for DT modeling and application tailored for CNC machine tools, successfully establishing a DT model to predict the lifetime and maintenance strategies of ball screws on CNC milling machines. Cai10 exemplified the construction of DT virtual machine tools within cyber-physical manufacturing through the development of a DT system for a three-axis vertical milling machine. Finally, Tong11 proposed a real-time data processing application and service based on intelligent CNC machine tool DT, enabling the evaluation and prediction of machine tools’ operational status.Huang12 proposed a DT simulation method for the CNC machine tool feed system based on the Long Short-Term Memory(LSTM) algorithm, which effectively compensated for processing errors. According to the literature above, it could be seen that the current DT simulation model based on traditional dual-loop PI control theory and LSTM algorithm had low accuracy and poor adaptability to complex operating conditions. Therefore, it is crucial to conduct research on efficient and reliable DT technology for machine tool feed control systems, to achieve adaptive dynamic updates of model parameters following changes in environmental conditions, and to further improve model simulation accuracy. In this study, a new method for DT modeling of the CNC machine tool feed system based on a mechanism-data hybrid drive was proposed to address the shortcomings of the traditional dual-loop PI control theory and the LSTM algorithm.

Methods

Digit twin model

The DT consisted of four main components: physical space, twin model space, data space, and data interaction space, as illustrated in Fig.  1. Initially, a physical space was established, comprising components such as feed systems, servo motors, sensor networks, and a DT space was formed by model-based mechanisms and data-driven models. Subsequently, the physical data collected from controllers, encoders, and linear encoders was processed through the data space and transmitted to the twin model space to predict the processing process of physical entities. Finally, the predicted data were transferred to the data interaction space for online monitoring and optimization control, ensuring the feed system to operate at its optimal state consistently. The process was depicted in Eq. (1).

$$\begin{aligned} F{S_{\textrm{DT}}} = (PFS{{, }}VFS,FSDTD,FSSS) \end{aligned}$$
(1)

In the equation: \(\textit{FS}_{DT}\) represented the DT framework of the feed system, PFS represented physical space, VFS represented digital model space, FSDTD represented data space, and FSSS represented data interaction space.

Construction of the mechanism control system model

The DT mechanism model was a highly interconnected, multi-parameter, nonlinear complex electromechanical integrated system that consists of control subsystems, electrical subsystems, and mechanical subsystems. This model serves as the foundation for visually mapping physical entities in a virtual space13. In this study, a method for obtaining mechanistic models using Matlab/ Simulink is proposed. Firstly, the internal components are modularized and decomposed according to the structural function of each subsystem. Secondly, the physical and energy flow relationships among modules were established through domain interface modules, enabling integration between the control, electrical, and mechanical subsystems. Finally, through the incorporation of pertinent parameters from the feeding system and the comparison of actual operational data with simulation results, the dynamic characteristics of the DT mechanism model were verified.

Construction of fuzzy PI control subsystem

The mechanism model of the control subsystem of the dual-axis feed system mainly includes the PI control module, coordinate transformation module and Space Vector Pulse Width Modulation(SVPWM) module.The PI control module is essential for the precise control of the mechanical subsystem14. However, the traditional PI control algorithm was based on an ideal model and lacks adaptability in nonlinear complex systems15. Hence, A fuzzy PI control system for dual-axis feed system was proposed to address the poor robustness of traditional PI control in dealing with nonlinear and complex systems16. Figure 2 illustrated the selection of input speed error \(E(\textit{t}\)) and its differential \(EC(\textit{t})\) as input signals for PI controller tuning using an online tuning method. Following the process of fuzzyfication, fuzzy reasoning, and defuzzification, the adjustment amounts \(\Delta\)Kp and \(\Delta\)Ki for parameters Kp and Ki were determined. These adjustments were subsequently utilized to update the parameters within the PI controller. The calculation of the relevant parameters was detailed in Eqs. (2) and (3).

$$\begin{aligned} E\left( t\right)= & {N^*} - N \end{aligned}$$
(2)
$$\begin{aligned} EC\left( t \right)= & E\left( t \right) - E\left( {t - 1} \right) \end{aligned}$$
(3)

In the equations: N*represented the instruction speed; N represented the system simulation speed. The fuzzy subsets of parameters E, EC, Kp, Ki and were {NB, NM, NS, ZO, PS, PM, PB}, with domains of {-10, 10}, {-10, 10}, {0.2, 0.8}, and {20, 60} respectively. The membership functions were represented as shown in Fig. 3. In terms of input-output membership functions, this study formulates control rules by leveraging expert knowledge and the specific traits of the controlled system, as illustrated in Table  1. Through the utilization of weighted average defuzzification, a blend of “exact” and “fuzzy” elements was attained to dynamically fine-tune the output variables Kp and Ki. The comparison between the fuzzy PI control system and the traditional PI control system was conducted at a constant speed of 1000 rpm, as illustrated in Fig. 4. The traditional PI control system achieved a tracking error of 0.064% at 0.0281 s, while the fuzzy PI control system achieved a tracking error of 0.060% at 0.0136 s. The fuzzy PI control system demonstrated improvement of 51.6% in tracking time efficiency and enhancement of 0.004% in accuracy compared to the traditional PI control system.

Construction of electrical subsystem

The mechanism model of the electrical sub-system of the dual-axis feed system depicted in Fig. 5 primarily consists of the power supply, inverter, signal model to current model conversion module, line voltage modulation module, and permanent magnet synchronous motor (PMSM) module. Key PMSM parameters, including rotational inertia (J) and load torque (\(T_l\)), were derived from experimental data. The voltage balance equation of the PMSM model in the d-q axis system was shown in Eq. (4).

$$\begin{aligned} {u_d}&= {R_s}{i_d} + \frac{{{\textrm{d}}{\varphi _d}}}{{{\textrm{d}}t}} - {\omega _e}{\varphi _q}\nonumber \\ {u_q}&= {R_s}{i_q} + \frac{{{\textrm{d}}{\varphi _q}}}{{{\textrm{d}}t}} - {\omega _e}{\varphi _d} \end{aligned}$$
(4)

The magnetic flux equation of permanent magnet was shown in Eq. (5).

$$\begin{aligned}&{\varphi _d} = {L_d}{i_d} + {\varphi _f}\nonumber \\&{\varphi _q} ={L_q}{i_q} \end{aligned}$$
(5)

In the equation: \(i_d\), \(i_q\), \(u_d\), \(u_q\), \(L_d\), \(L_q\), \(\varphi _d\), \(\varphi _q\) represented d-q axis current, voltage, inductance, magnetic flux respectively; \(R_s\) was the stator resistance of the motor, \(\omega _e\) was the angular velocity of the motor, and \(\omega _f\) was the permanent magnet flux. The torque equation of PMSM in the d-q coordinate system was shown in Eq. (6).

$$\begin{aligned} {T_e} = \frac{3}{2}p[{\varphi _f}{i_q} + ({L_d} - {L_q}){i_d}{i_q}] \end{aligned}$$
(6)

In the equation: \(T_e\) represented electromagnetic torque, and p represented the number of motor poles. The mechanical motion equations of PMSM are shown in Eqs. (7) and (8).

$$\begin{aligned} & {T_e} ={T_l} + J\frac{{{\textrm{d}}\omega }}{{{\textrm{d}}t}} + B\omega \end{aligned}$$
(7)
$$\begin{aligned} & \frac{{{\textrm{d}}\theta }}{{{\textrm{d}}t}} = \omega \end{aligned}$$
(8)

In the equations: B represented the damping coefficient, \(\omega\) represented the rotor mechanical angular velocity, and \(\theta\) represented the rotor mechanical angle. In the context of the SVPWM algorithm, which produced a saddle-shaped waveform as its output signal, and the conventional PMSM model being controlled by a sinusoidal signal. Therefore, the SVPWM algorithm cannot be introduced directly into the model, and the line voltage signal must be used to drive the model15. The internal coordinate transformation equation of the PMSM model at this stage was depicted in Eq. (9).

$$\begin{aligned} \left[ \begin{array}{l} {{\textrm{u}}_d}\\ {u_q} \end{array} \right] = \frac{1}{3}\left[ \begin{array}{l} \cos \theta \ \ \ \ \ \ \sqrt{3} \sin \theta \ \ \ \ \cos \theta \\ - \sin \theta \ \ \sqrt{3} \cos \theta \ \ - \sin \theta \end{array} \right] \left[ \begin{array}{l} u_a \\ u_b\\ u_c \end{array} \right] \end{aligned}$$
(9)

The corresponding current vector inverse transformation matrix was shown in Eq. (10).

$$\begin{aligned} \left[ \begin{array}{l} {{{\textit{i}}}_a}\\ {i_b}\\ {i_c} \end{array} \right] = \frac{1}{3}\left[ \begin{array}{l} \cos \theta - \sin \theta \\ \cos (\theta - 120^\circ ) \ \ \ - \sin (\theta - 120^\circ )\\ \cos (\theta + 120^\circ ) \ \ \ - \sin (\theta + 120^\circ ) \end{array} \right] \left[ \begin{array}{l} i_d\\ i_q \end{array} \right] \end{aligned}$$
(10)

Construction of the mechanical system

The mechanical transmission system demonstrates intricate dynamic characteristics, influenced by factors such as inertia, stiffness, damping, and friction. The equivalent dynamic model was illustrated in Fig. 6, where the angular displacement of the motor was denoted as \(\theta _m(t)\). The rotational inertia of the motor shaft and the lead screw were represented by \(J_m\) and \(J_s\), respectively. The rotational stiffness were denoted by \(K_a\) and \(K_s\) respectively, while the damping was represented by \(C_m\) and \(C_s\), respectively. Furthermore, the mass of the table was M, the stiffness coefficient of the worktable was \(K_g\), the movement damping was \(C_g\), and the angular displacement of the lead screw was denoted as \(\theta _s(t)\). This study converting the variables equivalent \(J_m\), \(J_s\), \(C_m\), \(C_s\), \(C_g\), \(K_a\), \(K_s\) and \(K_g\) to the motor, as illustrated in the calculation equation in Eq. (11).

$$\begin{aligned} J&= {J_m} + {J_s} + {{(\frac{L}{{2\pi }})}^2}M\nonumber \\ C&= {C_m} + {C_s} + {{(\frac{L}{{2\pi }})}^2}{C_g}\nonumber \\ K&= \frac{1}{{\frac{1}{{{K_a}}} + \frac{1}{{{K_s}}} + \frac{1}{{{{(\frac{L}{{2\pi }})}^2}{K_g}}}}} \end{aligned}$$
(11)

In the equations: L represented the lead of the screw. The balance equation of the mechanical transmission subsystem could be expressed equivalently as Eq. (12).

$$\begin{aligned} J{\ddot{\theta }_g}(t) + C{\dot{\theta }_g}(t) + K[{\theta _g}(t){\mathrm{- }}{\theta _m}(t)] = 0 \end{aligned}$$
(12)

By utilizing Solidworks for modeling essential components, including screws, couplings, and guide rails, the physical constraints and assembly relationships of the components were mapped using XML and STEP format files, followed by importing the files into MATLAB/Simulink to generate a virtual model of the mechanical subsystem of the feed system, as illustrated in Fig. 7. A sinusoidal signal was fed and the constructed mechanism model was compared to the mechanism model under traditional PI control, as shown in Fig. 8. In the traditional PI control system, a drift phenomenon was observed at 3.5 s, which fails to accurately map the input signal. In contrast, the fuzzy PI control system could dynamically adjust the PI parameters through the fuzzy system, achieving precise mapping of the input signal. This study confirmed the effectiveness and robustness of the proposed mechanism model construction method in this study.

Fig. 1
figure 1

DT model framework. CNC Computerized Numerical Control, CNN convolutional neural networks, LSTM long short-term memory.

Fig. 2
figure 2

Three-loop fuzzy PI control system. PositionAct: Actual displacement; PI:proportional integral; \(N_r\): actual speed of the motor; \(I_d\): d-axis current after the Park transformation; \(I_q\): q-axis current after the Park transformation; \(\omega _e\): actual angular velocity of the motor;\(U_d\): d-axis voltage after the Park transformation; \(U_q\): q-axis voltage after the Park transformation; pluse: Pulse modulated signal.

Fig. 3
figure 3

Fuzzy control parameter membership function diagram. a Relevance Function of E (x axis: the fuzzy subsets of parameters E is {NB, NM, NS, ZO, PS, PM, PB}, with domains of {–10, 10}; y axis: degree of membership). b Relevance Function of EC (x axis: the fuzzy subsets of parameters EC is {NB, NM, NS, ZO, PS, PM, PB}, with domains of {–10, 10}; y axis: degree of membership). c Relevance Function of Kp (x axis: the fuzzy subsets of parameters Kp is {NB, NM, NS, ZO, PS, PM, PB}, with domains of {0.2, 0.8}; y axis: degree of membership). d Relevance Function of Ki (x axis: the fuzzy subsets of parameters Ki is {NB, NM, NS, ZO, PS, PM, PB}, with domains of {20, 60}; y axis: degree of membership). NB negative big, NM negative medium, NS negative small, ZO Zero, PS positive small, PM positive medium, PB positive big, E speed error, EC acceleration error.

Fig. 4
figure 4

Comparison of fuzzy PI control and traditional PI control effects at 1000 rpm (x axis: simulation time from 0 to 0.1 seconds; y axis: motor speed per minute.

Fig. 5
figure 5

Electrical subsystem mechanism model of feed system. A, B, C, a, b, c: three-phase voltage. Tl: load torque; J: rotational inertia; Te: electromagnetic torque; \(\theta\): rotor mechanical angle; iabc: inverse conversion current; Wm: mechanical angular velocity.

Fig. 6
figure 6

Simplified dynamic model of mechanical subsystem. Jm: rotational inertia of the motor shaft; Js: rotational inertia of the lead screw; Ka: rotational stiffness of the motor shaft; Ks: rotational stiffness of the lead screw; Cm: damping of the motor shaft; Cs: damping of the lead screw; Kg: stiffness coefficient of the worktable; Cg: moving damping of the worktable; \(\theta _m(t)\): angular displacement of the motor; \(\theta _g(t)\): angular displacement of the lead screw.

Fig. 7
figure 7

Virtual model of the mechanical subsystem of the feed system.

Construction diagram of data-driven model for numerical control machine tool based on WOA-CNN-LSTM-Attention

Although the digital twin mechanism model of the feed system can visualize the geometric features, spatial positions, and overall control methods of physical entities, mechanism based models have significant limitations. On the one hand, due to the difficulty in obtaining detailed parameters of the equipment, the overall modeling of the equipment is simplified; On the other hand, the impact of various working conditions and environmental factors on the results of the feed system is difficult to characterize using a mechanistic model, which inevitably leads to residuals between the predicted results of the mechanistic model and the actual results, greatly reducing the simulation accuracy of the digital twin model17. To improve the prediction reliability of DT models, this study proposed a data-driven prediction model based on the deep fusion of convolutional neural networks(CNN), attention mechanism(Attention), whale optimization algorithm(WOA) and LSTM, as shown in Fig. 9. Firstly, based on the characteristics that CNN excelled at extracting features from collected experimental data and LSTM could better learn from time series data, a CNN-LSTM prediction model is established. Secondly, the WOA was introduced to optimize the hidden layer neuron quantity, learning rate, and iteration times to obtain the optimal parameters. Finally, the deep learning algorithm attention mechanism was coupled to highlight the impact of features on input effects, further improving the model’s prediction accuracy and computer efficiency. The proposed model was validated through experiments on a real feed system, and the results demonstrate its superior prediction performance compared to traditional models. This research provided a new approach for enhancing the prediction reliability of DT models in complex mechanical systems. The CNN primarily consisted of a sequence of convolutional layers and pooling layers18. In this study, a max-pooling CNN was employed to integrate signal features including actual speed, actual acceleration, and actual workbench position, thereby maximizing the activation of data features. The mathematical formulations for convolutional layers and pooling layers were presented in Eqs. (13) and (14) correspondingly.

$$\begin{aligned} O(l)&= \sum \limits _{a = 0}^{L - 1} {X(l + a) \times W\left( a \right) } + b \end{aligned}$$
(13)
$$\begin{aligned} Y\left( i \right)&= {\max _{{\textrm{j}} \in R}}X\left( {i \times l' + j} \right) \end{aligned}$$
(14)

In the equations, O(l) represented the output of the convolutional layer; X(l) represented the value of the input sequence; W(a) represented the weight of the convolutional kernel; L represented the size of the convolutional kernel; l represented the time position; b represented the bias term. Y(i) represented the output of the pooling layer ; i represented the output position; R represented the set of position indexes in the pooling window; \(l'\) represented the pooling stride. The LSTM model outperforms the traditional Recurrent Neural Network (RNN) when it came to managing and forecasting time series data19. This was due to its superior ability to handle long-term dependencies and gradient problems. The internal computational process of LSTM was detailed in Equations (15) to (20).

$$\begin{aligned} {{\textrm{f}}_l}&= \sigma \left( {{{\mathop {\textrm{W}}\nolimits } _{{\textrm{xf}}}} \times {x_l} + {{\mathop {\textrm{W}}\nolimits } _{{\textrm{hf}}}} \times {h_{l - 1}} + {b_f}} \right) \end{aligned}$$
(15)
$$\begin{aligned} {{\mathrm{{\tilde{c}}}}_l}&= \tanh \left( {{{\mathop {\textrm{W}}\nolimits } _{{\textrm{xc}}}} \times {x_l} + {{\mathop {\textrm{W}}\nolimits } _{{\textrm{hc}}}} \times {h_{l - 1}} + {b_c}} \right) \end{aligned}$$
(16)
$$\begin{aligned} {i_l}&= \sigma \left( {{{\mathop {\textrm{W}}\nolimits } _{{\textrm{xi}}}} \times {x_l} + {{\mathop {\textrm{W}}\nolimits } _{{\textrm{hi}}}} \times {h_{l - 1}} + {b_i}} \right) \end{aligned}$$
(17)
$$\begin{aligned} {c_l}&= {f_l} \times {c_{l - 1}} + {i_l} \times {{\tilde{c}}_l} \end{aligned}$$
(18)
$$\begin{aligned} {o_l}&= \sigma \left( {{{\mathop {\textrm{W}}\nolimits } _{{\textrm{xo}}}} \times {x_l} + {{\mathop {\textrm{W}}\nolimits } _{{\textrm{ho}}}} \times {h_{l - 1}} + {b_o}} \right) \end{aligned}$$
(19)
$$\begin{aligned} {h_l}&= {o_l} \times \tanh \left( {{c_l}} \right) \end{aligned}$$
(20)

In the equations: \(f_l\), \(i_l\) and \(o_l\) respectively represented the forget gate, input gate, and output gate of the LSTM unit, controlling the discard, memory, and output of information within the control unit; \(c_l\) represented the carrier of the long-term memory; \(h_l\) represented the output of the short-term memory unit at time step l , also serving as the carrier of short-term memory; \([W_{xf} \ \ W_{hf}]\), \([W_{xi} \ \ W_{hi}]\), \([W_{xo} \ \ W_{ho}]\) and \([W_{xc} \ \ W_{hc}]\) respectively represented the weights of the forget gate, input gate, output gate, and candidate memory state; \(b_f\), \(b_i\), \(b_o\) and \(b_c\) respectively represented the bias terms of the forget gate, input gate, output gate, and candidate memory state. Inappropriate selection of the learning rate, number of neurons, and regularization coefficient of the CNN-LSTM model could result in increased modeling errors20. To address this issue, this study employed the WOA to fine-tune these three key parameters of the CNN-LSTM model and obtain the optimal values, thereby enhancing modeling accuracy. WOA, a novel swarm intelligence algorithm inspired by the predatory behavior of whales, utilized shrinking surrounds, random walks, and spiral ways for optimization. Compared with genetic algorithm and particle swarm optimization algorithm, WOA has fewer setting parameters, but stronger global and local optimization capabilities21. In order to verify the advantages of WOA over other intelligent optimization algorithms for LSTM algorithm, a set of wind speed change data within the same period in a certain region was used to optimize the learning rate, number of neurons, and regularization coefficient of LSTM algorithm using Genetic Algorithm(GA), Particle Swarm Optimization(PSO), Grey Wolf Optimizer(GWO), and WOA under the same constraints. The comparison of optimized LSTM algorithms is shown in the Fig. 10 , and the results show that WOA has the best performance with \(R^{2}=0.96959\), and PSO has the worst performance with \(R^{2}=0.89709\). The optimization process was mathematically represented in Equations (21) to (24).

$$\begin{aligned} Z\left( {n + 1} \right)= & \left\{ {\begin{array}{*{20}{c}} {{Z^*}\left( n \right) - A \times \left| {D \times {Z^*}\left( n \right) - Z\left( n \right) } \right| q < 0.5}\\ {\left| {{Z^*}\left( n \right) - Z\left( n \right) } \right| \times {e^\gamma } \times cos\left( {2\pi \gamma } \right) + {Z^*}\left( n \right) q \ge 0.5} \end{array}} \right. \end{aligned}$$
(21)
$$\begin{aligned} A= & 2 \times m \times r - m \end{aligned}$$
(22)
$$\begin{aligned} D= & 2 \times r \end{aligned}$$
(23)
$$\begin{aligned} m= & 2 - 2 \times \frac{n}{{{n_{\max }}}} \end{aligned}$$
(24)

In the equations: n represented the current iteration number; Z(n)represented the position vector; \(Z^*(n)\) represented the best position vector; A and D respectively represented control parameter vectors; \(\gamma\) is any number in interval \([-2\ \ -1]\); r represented any vector between 0 and 1; m represented the convergence factor; \(n_{max}\) represented the maximum number of iterations; q represented a random number in interval \([0\ \ 1]\), seeking the global optimal solution through random walking while \(|A|\ge 1\) and seeking the local optimal solution through contraction and surroundinghen while \(|A|<1\) . The training of this model should take into consideration the channel information, as neglecting it may lead to uneven resource distribution and a decrease in resolution effect22. To address this issue, this study incorporates an attention mechanism that assigns different weight coefficients to each temporal feature of the CNN-LSTM model according to its importance, which ensured that crucial features were preserved even with an increased sequence length, ultimately enhancing the resolution accuracy23. The implementation steps of the model developed in this research were illustrated in Fig. 11. The algorithm developed in this study, WOA-CNN-LSTM-Attention, was illustrated in Fig. 12. It demonstrated superior precision in early-stage tracking when compared to the LSTM algorithm, resulting in smoother and more accurate overall predictions. Table  2 presented a detailed performance comparison, showing that the WOA-CNN-LSTM-Attention algorithm outperforms the LSTM algorithm by reducing the Mean Absolute Error (MAE) by 3.10%, the Mean Absolute Percentage Error (MAPE) by 52.95%, and the Root Mean Square Error (RMSE) by 32.21%.

Fig. 8
figure 8

Comparison diagram of fuzzy PI control and traditional PI control. a Traditional PI control (x axis: simulation time from 0 to 5 seconds; y axis: displacement of the table of the feed system); b Fuzzy PI control (x axis: simulation time from 0 to 5 seconds; y axis: displacement of the table of the feed system.

Fig. 9
figure 9

Algorithm structure diagram. LSTM long short-term memory, WOA whale optimization algorithm, CNN convolutional neural networks.

Fig. 10
figure 10

Comparison of Algorithm Performance. LSTM long short-term memory, GA genetic algorithm, PSO: particle swarm optimization, GWO grey wolf optimizer, WOA whale optimization algorithm.

Fig. 11
figure 11

WOA-CNN-LSTM-Attention algorithm flowchar.

Fig. 12
figure 12

Comparison of algorithm prediction performance graph (x axis: algorithm’s sample size of 1800; y axis: accuracy of the algorithm’s prediction results).

Fig. 13
figure 13

Test results of online parameter identification for rotational inertia (x axis: simulation time from 0 to 0.01 seconds; y axis: moment of inertia).

Fig. 14
figure 14

Feed system experimental platform.

Fig. 15
figure 15

Schematic model simulation effect diagram. a Traditional PI control system (x axis: actual machine running time from 0 to 5 seconds; y axis: displacement error of the table of the feed system); b Fuzzy PI control system (x axis: actual machine running time from 0 to 5 seconds; y axis: displacement error of the table of the feed system).

Fig. 16
figure 16

Prediction Error (x axis: test set ample number; y axis: prediction error).

Online parameter identification of numerical control machine tool model based on recursive least squares method with forgetting factors

It is one of the key technologies of DT to obtain important parameter information in real time and align it with the response of the physical system to help the control algorithm adjust the motor control strategy in time24. With the increase of real-time information, the traditional recursive least squares algorithm is prone to data saturation25. Therefore, this paper proposes an online recognition strategy for DT model based on the recursive least squares method based on the forgetting factor, and uses the mechanical characteristic parameters of moment of inertia as the system identification parameters. According to the principle of least squares, the iteration equation of the recursive least squares method with forgetting factors could be derived, as shown in Equation (25).

$$\begin{aligned}&{\zeta \left( k \right) = \frac{{{\lambda ^{ - 1}}\psi \left( {k - 1} \right) \varphi \left( k \right) }}{{1 + {\lambda ^{ - 1}}{\varphi ^T}\left( k \right) \psi \left( {k - 1} \right) \varphi \left( k \right) }}}\nonumber \\&{\xi \left( k \right) = Q\left( k \right) - {{\mathop S\limits ^ \wedge }^T}\left( {k - 1} \right) u\left( k \right) }\nonumber \\&{\mathop S\limits ^ \wedge \left( k \right) = \mathop S\limits ^ \wedge \left( {k - 1} \right) + \zeta \left( k \right) \xi \left( k \right) }\nonumber \\&{\psi \left( k \right) = {\lambda ^{ - 1}}\psi \left( {k - 1} \right) - {\lambda ^{ - 1}}\zeta \left( k \right) {\varphi ^T}\left( k \right) \psi \left( {k - 1} \right) } \end{aligned}$$
(25)

In the equation, \(\varphi (k)\) represented the branch input vector; Q(k)represented the output vector; \(\xi (k)\) represented the error; \(\psi (k)\)represented the covariance matrix; \(\zeta (k)\) represented the gain matrix; \(\mathop S\limits ^ \wedge \left( k \right)\) represented the least squares estimate ; \(\lambda\) represented the forgetting factor, choosing a suitable forgetting factor in the interval \([0.9\ \ 1]\) based on convergence speed and disturbance resistance can avoid data saturation. In order to accurately identify the moment of inertia of the permanent magnet synchronous motor, it is necessary to derive the mechanical motion equation of the permanent magnet synchronous motor, which is shown in Eq. (7). To accurately determine the moment of inertia of a permanent magnet synchronous motor, it is necessary to derive the mechanical motion equation of the permanent magnet synchronous motor. The equations of mechanical motion (7) for a permanent magnet synchronous motor could be expressed as Eqs. (26) and (27).

$$\begin{aligned} & \frac{{\mathbf{{d}}\omega }}{{\mathbf{{d}}t}} = \frac{{\omega (t) - \omega (t - 1)}}{{\Delta t}} = \frac{{\omega (t) - \omega (t - 1)}}{T} \end{aligned}$$
(26)
$$\begin{aligned} & \omega (t) = (1 - \frac{{BT}}{J})\omega (t - 1) + \frac{T}{J}{T_e}(k - 1) - \frac{T}{J}{T_l}(k - 1) \end{aligned}$$
(27)

By combining Eq. (12), the physical interpretations of each matrix in actual identification systems could be observed in Eq. (28).

$$\begin{aligned}&{{S}{\mathrm{= }}{{\left[ {1{\mathrm{- }}\frac{{BT}}{J}{\textrm{,}}\frac{T}{J}{\textrm{,}}\frac{T}{J}{{\textrm{T}}_{\textrm{l}}} \mathbf{{(}}{\mathrm{k - }}1)} \right] }^\mathbf{{T}}}}\nonumber \\&{\varphi (t) = [\omega (t - 1)],{T_e}(k - 1), - 1{]^\mathbf{{T}}}}\nonumber \\&{Q(t) = \omega (t)} \end{aligned}$$
(28)

Based on Eqs. (27) and (28), the branch weight vector S(k) of the actual system could be recursively derived, leading to the determination of the system moment of inertia J. Subsequently, a closed-loop PMSM control system was established, utilizing the integrated PMSM module in Matlab/Simulink, to evaluate the algorithm’s identification tracking performance with the specified torque \(J=0.003kg\cdot m^2\), as depicted in Fig. 13. The recursive least squares method with forgetting factors proposed in this study achieves error-free tracking within 0.005 s, validating the algorithm’s precise identification capability.

Fig. 17
figure 17

Error compensation diagram (x axis: actual machine running time from 0 to 5 seconds; y axis: displacement of the table of the feed system).

Fig. 18
figure 18

Mechanism - Data model simulation diagram at 1500 rpm (x axis: actual machine running time from 0 to 5 seconds; y axis: displacement error of the table of the feed system).

Fig. 19
figure 19

Mechanism - Data model simulation diagram at 3000 rpm (x axis: actual machine running time from 0 to 5 seconds; y axis: displacement error of the table of the feed system).

Fig. 20
figure 20

Identification effect diagram (x axis: actual machine running time from 0 to 0.3 seconds; y axis: moment of inertia).

Results of experimental verification

As shown in Fig. 14, the X-axis motion of the dual axis feed system is controlled by a programmable multi axis controller produced by Beckhoff Automation GmbH in Germany, which can be integrated with other EtherCAT devices. HIWIN’s screw and slide table are selected as the components of the motion pair, and a 0.005mm precision grating ruler is used as the position feedback element, forming a fully closed-loop control system for real-time communication. Encapsulate the hybrid driven digital twin model constructed in this chapter, import it into the industrial automation software TwinCAT PLC, and reserve input and output interfaces. Use the TwinCAT NC module to issue motion control commands to the feed axis, the console moves 100 mm, the input slope displacement signal is 1500 mm/min, and the initial moment of inertia of the permanent magnet synchronous motor is 0.0027 kg\(\cdot\)m2. The parameters of the permanent magnet synchronous motor are shown in Table 3 . The simulation of the mechanism model for the traditional three-loop PI control system was illustrated in Fig. 15a, showing a maximum error of 0.0857 mm. In contrast, the mechanism model tracking test for the fuzzy PI control system presented in this study, as depicted in Fig. 15b, exhibited a maximum error of 0.0576 mm. This system had the capability to autonomously adjust its PI control parameters in response to environmental variations. Compared to the conventional dual-loop PI control system, the maximum error had been decreased by 32.79%, which indicating superior simulation accuracy. The error compensation of the results is carried out by using WOA-CNN-LSTM-Attention, and the network structure parameters are shown in Table  4. The collected experimental displacement, experimental speed, and experimental acceleration were taken as input parameters, and the error between the output displacement of the mechanism model and the experimental displacement was taken as the output value, and the training set accounts for 80% of the dataset and was normalized, the specific operation process is as follows. Firstly, the input 3D vector extracts the data signal features through the convolutional layer, the convolution kernel is 16, and then the convoluted vector is input to the pooling layer, because the poolsize is 1, so the shape of the output vector remains unchanged. The vector enters the LSTM layer for calculation, using the Adam gradient descent algorithm, the maximum number of iterations is 100, the initial learning rate is 0.01, and the learning rate decline factor is 0.5, the attention layer is used to capture the important features of LSTM training, and the lower limit of the learning rate after 700 training times is set to 0.001 to avoid the learning rate from being too small and entering the local convergence. The WOA is used to find the optimal solution of the learning rate, the number of neurons, the regularization coefficient and other parameters of the CNN-LSTM model to improve the accuracy and efficiency of the algorithm, and the constraints are shown in Eq. (29), the maximum number of iterations is set to 20 times, the population size is 8, and the optimal parameter values are 0.001, 50 and 0.0001, respectively. The prediction performance of the trained algorithm is shown in the Fig. 16, \(R^{2}=0.99927\).

$$\begin{aligned}&{0.001 \le \varepsilon \le 0.01}\nonumber \\&{50 \le {L_1} \le 100}\nonumber \\&{0.0001 \le {L_2} \le 0.1} \end{aligned}$$
(29)

Figure 17 shows that the maximum error after compensation is 0.0121 mm, which is 78.99% lower than the maximum error of 0.0576 mm before compensation and 85.88% lower than that of traditional modeling methods. The simulation effect after compensation is shown in Fig. 18. Performance verification was conducted at 3000 rpm, as shown in the Fig. 19, and the maximum error decreased from 0.0726mm to 0.034mm, a decrease of 53.17%, indicating good performance. The results show that the method proposed in this paper can effectively fit the actual working conditions, and further improve the simulation accuracy of the machine tool feed system. In order to verify the identification and tracking capabilities of the feedforward control system model in complex environments, the permanent magnet synchronous motor is loaded with a load at 3 s, and the moment of inertia after the load is about 0.0081 kg\(\cdot\)m2. As can be seen from Fig. 20, the system realizes the moment of inertia following at about 0.01 s, and keeps the input value up and down the stable float, and its root mean square error RMSE = 5.7735e-06. The results show that the system still has good identification and tracking ability in the complex dynamic working environment, realizes the real-time dynamic monitoring of the motor state, and provides a reliable basis for the important decision-making and maintenance strategy of the feed system.

Table 1 Output parameter fuzzy rule table. NB negative big, NM negative medium, NS negative small, ZO Zero, PS positive small, PM positive medium, PB positive big, E speed error, EC acceleration error, \(EC^1\): fuzzy rule table of Kp, \(EC^2\): fuzzy rule table of Ki.
Table 2 Comparison table of algorithm performance indicators. MAE mean absolute error, MAPE mean absolute percentage error, RMSE root mean square error, LSTM long short-term memory, WOA whale optimization algorithm, CNN convolutional neural networks.
Table 3 Motor parameter table. DC bus voltage: direct current bus voltage.
Table 4 Network structure parameter table.

Discussion

In the study, a novel modeling approach for the feed system of numerical control machine tools was proposed, utilizing fuzzy control theory and deep learning concepts. Experimental validation confirmed the effectiveness and advantages of this approach, providing a new perspective on DT modeling and model refinement. The detailed findings are outlined below. (1) This study introduced a modeling approach for the feed system of a CNC machine tool utilizing a fuzzy PI control system integrated with physical knowledge, which enables real-time adaptive parameter updates. By conducting comparative validation experiments, it was demonstrated that the maximum discrepancy between this approach and actual operational outcomes was 0.0576 mm, representing a 32.79% reduction compared to conventional modeling techniques. Moreover, to further enhance simulation precision, an error compensation technique leveraging big data and the WOA-CNN-LSTM-Attention algorithm was proposed, resulting in a high-fidelity DT model powered by a hybrid of mechanism and data-driven models. Compared to actual operational outcomes, the maximum deviation was 0.0121 mm, indicating a 78.99% reduction from the mechanism model. Thus, the issue of low simulation accuracy in simplified mechanism models is effectively addressed. (2) This study presented an online parameter identification approach for the feed system of a CNC machine tool using the recursive least squares method with forgetting factors, which enables online identification tracking of the moment of inertia. Experimental validation showed that this approach can achieve rapid zero-error tracking in simple operating conditions within 0.005 s; in more complex scenarios, the method can still accomplish identification tracking in approximately 0.01 s, with an RMSE of 5.7735e-06. The digital twin model constructed in this study only considers the real-time update of the moment of inertia parameters of the electrical system during operation, and lacks the update of the parameters of other modules of the digital twin, such as mechanical system and control system. In the future, the idea of transfer learning will be combined with digital twins, so that multiple parameters of the digital twin model can be migrated and adjusted with the change of actual working conditions. And in this study has a long calculation time and low efficiency due to many adaptive optimization processes. In the future, we will study the surrogate model and response surface to realize the reduction of the model order and improve the calculation efficiency of the model, so as to realize the wide application of digital twin technology in practical applications.