Method for interpolating PMSM track points by Bi-LSTM based on attention mechanism
By using the Bi-LSTM-Att method, combined with an attention mechanism and a fully connected layer, the problems of computational complexity and low accuracy in PMSM trajectory point interpolation of traditional methods are solved, and high-precision interpolation of PMSM rotor rotation angle and acceleration is achieved, which is suitable for high-precision automated production.
Patent Information
- Application Number
- CN202411172889.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-26
- Publication Date
- 2026-03-03
AI Technical Summary
Traditional mathematical interpolation methods and LSTM interpolation methods are computationally complex, have low accuracy, and cannot meet high-precision requirements in PMSM trajectory point interpolation, especially when the acceleration transition is smooth.
We employ a bidirectional long short-term memory neural network (Bi-LSTM-Att) method based on an attention mechanism. This method analyzes time series data from both forward and backward directions using a bidirectional LSTM and automatically identifies and assigns weights to feature points that facilitate smooth acceleration transitions using an attention mechanism. This is then combined with a fully connected layer for prediction.
It significantly improves the interpolation accuracy of the PMSM rotor rotation angle and acceleration, achieving smoother high-precision control and meeting the needs of modern high-precision automated production.
Smart Images

Figure CN121602879A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of trajectory point interpolation, specifically a method for interpolating PMSM trajectory points using Bi-LSTM based on an attention mechanism. Background Technology
[0002] Permanent magnet synchronous motors (PMSMs) offer advantages such as high power efficiency, good stability, and high-precision control, making them widely used in CNC machine tools, robot manufacturing, and other fields. CNC system commands are executed by the PMSM, which transmits position command values in a time-series format to the PMSM's controller. Since the CNC system's operating cycle is much longer than the PMSM's control cycle, high-precision interpolation is necessary on the position command sequence to ensure that the PMSM, when applied to high-precision automated production, exhibits fast response, high-precision control, and smooth speed changes.
[0003] Mathematical interpolation methods such as nearest-neighbor interpolation, cubic spline interpolation, and polynomial interpolation require technicians to master relevant mathematical knowledge, resulting in complex modeling processes. In terms of processing, they are generally based on iterative methods, making the interpolation calculation process cumbersome. Furthermore, under the influence of the complex nonlinear changes in the servo system, their fitting deviation is large, and their accuracy is greatly reduced, failing to meet the requirements of modern high-precision machining. Currently, deep learning methods are also widely used for time series interpolation. Long short-term memory (LSTM) neural networks, based on a large amount of sample data, learn the changing characteristics of time series through their unique gating mechanism and memory unit structure. When only the accuracy of the interpolated values is considered, the interpolation effect is relatively good. However, when considering the smooth transition of PMSM acceleration, the interpolated values of LSTM gradually tend to a constant, resulting in a flattening problem, which makes effective interpolation impossible. Summary of the Invention
[0004] To address the limitations of traditional mathematical interpolation methods and Long Short-Term Memory (LSTM) neural network interpolation methods, this invention proposes an interpolation method combining an attention mechanism and a bidirectional LSTM neural network. This invention presents an improved bidirectional LSTM (Bi-LSTM) interpolation method, termed the attention-based bidirectional LSTM-Att interpolation method. This method utilizes Bi-LSTM to simultaneously analyze sequence data from both forward and backward directions, helping the model understand the global trend of acceleration changes and avoid getting trapped in local optima. Simultaneously, the Att-based attention mechanism allows the model to automatically identify and allocate more weights to time points or features that facilitate smooth acceleration transitions.
[0005] The technical solution adopted by the present invention to achieve the above objectives is as follows:
[0006] A method for interpolating PMSM trajectory points using Bi-LSTM based on an attention mechanism includes the following steps:
[0007] 1) Acquire the time series of position commands given by the CNC system and the time series of rotor rotation speed s and rotor rotation angle ω of the PMSM under acceleration transition smoothing, and stitch them into a three-dimensional input vector according to the same time step, and normalize the data;
[0008] 2) Use bidirectional LSTM to process the position command time series to obtain the output vector R of the attention layer;
[0009] 3) Pass the vector R to the fully connected layer to obtain the final two prediction outputs, namely the rotor rotation speed and rotor rotation angle at the next time step t+1.
[0010] Step 2) includes the following steps:
[0011] 2.1) The forward LSTM and the backward LSTM read the position instruction sequence from left to right and from right to left, respectively, and at each time step t, the outputs of the forward LSTM and the backward LSTM are combined into h. t ;
[0012] 2.2) Query vector matrix q t Dot product h t Obtain the similarity score l at each time step t score (h t ,q t ):
[0013]
[0014] 2.3) Use the softmax function to normalize all similarity scores to obtain the weight coefficients w. t :
[0015]
[0016] 2.4) w t with h t The weighted summation yields the output vector R of the attention layer:
[0017]
[0018] The process also includes the following steps: automatically adjusting the learning rate using the Adam optimizer, training the Bi-LSTM-Att interpolation model using mini-batch training, automatically updating relevant parameters using the training set, verifying the model's performance after training using the validation set and adjusting relevant hyperparameters, and finally calculating evaluation metrics using the validation results.
[0019] The evaluation metrics include: mean absolute error, mean absolute error percentage, root mean square error, and coefficient of determination.
[0020] The process also includes the following steps: deploying the trained model into a simulation experiment, and evaluating the model's interpolation effect using the simulated waveform images of the PMSM rotor's rotation angle, rotational angular velocity, and rotational angular acceleration obtained from the experiment.
[0021] A system for interpolating PMSM trajectory points using a Bi-LSTM based on an attention mechanism includes:
[0022] The data preprocessing module is used to acquire the time series of position commands given by the CNC system and the time series of rotor rotation speed s and rotor rotation angle ω of the PMSM under acceleration transition smoothing. The data is then concatenated into a three-dimensional input vector according to the same time step and normalized.
[0023] The attention weighting module is used to process the position command time series using a bidirectional LSTM to obtain the output vector R of the attention layer;
[0024] The trajectory point interpolation module is used to pass the vector R to the fully connected layer to obtain the final two prediction outputs, namely the rotor rotation speed and rotor rotation angle at the next time step t+1.
[0025] An apparatus for interpolating PMSM trajectory points using a Bi-LSTM based attention mechanism includes a memory and a processor; the memory is used to store a computer program; the processor is used to implement the method for interpolating PMSM trajectory points using a Bi-LSTM based attention mechanism when the computer program is executed.
[0026] A computer-readable storage medium storing a computer program that, when executed by a processor, implements a method for interpolating PMSM trajectory points using a Bi-LSTM based on an attention mechanism.
[0027] The present invention has the following beneficial effects and advantages:
[0028] 1. This invention proposes an improved bidirectional long short-term memory neural network interpolation method, namely Bi-LSTM-Att, which significantly improves the interpolation accuracy of permanent magnet synchronous motor rotor rotation angle and rotor acceleration transition compared to Bi-LSTM, LSTM-Att, and LSTM. This innovative method brings significant improvements to existing PMSM rotor rotation angle interpolation technology, providing new possibilities for the smoother application of PMSM in high-precision automated production.
[0029] 2. This invention provides a comprehensive evaluation of the Bi-LSTM-Att interpolation method. The verification results are evaluated using four indicators, and the results show that this method has higher accuracy in predicting interpolation trajectory points for PMSM.
[0030] 3. The bidirectional long short-term memory neural network (Bi-LSTM-Att) interpolation method based on the attention mechanism of the present invention was applied to the rotation angle interpolation of the PMSM rotor. Simulation experiments verified that it can effectively improve the interpolation accuracy of the PMSM trajectory points and make the PMSM rotor acceleration transition smoothly. Attached Figure Description
[0031] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0032] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments.
[0033] This invention addresses the limitations of traditional mathematical interpolation methods and long short-term memory (LSTM) neural network models in interpolating PMSM trajectory points. It proposes a bidirectional LSTM-Att interpolation method based on an attention mechanism. Traditional mathematical interpolation methods require strong mathematical foundations from technicians and involve complex modeling processes, typically employing iterative methods, leading to cumbersome interpolation operations. Furthermore, when dealing with the complex nonlinear changes in servo systems, their fitting deviations are significant, resulting in greatly reduced accuracy and failing to meet the requirements of modern high-precision machining. Currently, deep learning methods are also widely used for time series interpolation. LSTM neural networks, based on large amounts of sample data, learn the changing characteristics of time series through their unique gating mechanism and memory unit structure. When only the accuracy of the interpolated values is considered, they perform well in interpolating PMSM trajectory points. However, when considering the smooth transition of PMSM acceleration, the LSTM interpolated values deviate significantly from the true values, gradually approaching a constant value, resulting in a flattening problem and rendering them ineffective for interpolation. To overcome the aforementioned problems, this invention proposes Bi-LSTM-Att, which analyzes the time command sequence given by the CNC system simultaneously in two directions. This helps the model predict the interpolation values of PMSM trajectory points from a global trend, avoiding getting trapped in local optima. Simultaneously, the attention mechanism (Att) can automatically identify and allocate more weights to time points or features that facilitate smooth acceleration transitions.
[0034] like Figure 1 As shown, the model structure includes a dataset acquisition module, a bidirectional LSTM module, and an attention mechanism module. The method of this invention includes the following steps:
[0035] S1. Acquire the time series of position commands with a period of 2ms given by the CNC system, as well as the time series of the rotor rotation speed s and rotor rotation angle ω of the PMSM under acceleration transition smoothing. Concatenate them into a three-dimensional input vector according to the same time step, and then normalize the data set.
[0036] S2, the forward LSTM and the backward LSTM read the position instruction sequence from left to right and from right to left, respectively, and at each time step t, the outputs of the forward LSTM and the backward LSTM are combined into h. t Then, the query vector matrix q t Dot product h t Obtain the similarity score l at each time step t score (h t ,q t The softmax function is used to normalize all similarity scores to obtain the weight coefficients w. t Finally, w t with h t The weighted summation yields the output vector R of the attention layer.
[0037] S3. Pass the attention-weighted summed vector R to the fully connected layer to generate the final two prediction outputs: the rotor rotation speed s and rotor rotation angle ω of the PMSM at the current time step t, and the prediction of s at the next time step t+1. ′ and ω ′ .
[0038] S4. All models are built using the deep learning framework PyTorch, with the Adam optimizer automatically adjusting the learning rate. Mini-batch training is used, with the training set used to train and automatically update relevant parameters. Then, the validation set is used to verify the effect of the model training and adjust the relevant hyperparameters. Finally, the validation results are used to calculate the evaluation metrics in the formula.
[0039] The dataset is divided into a training set and a validation set in a 4:1 ratio.
[0040] The evaluation metrics include mean absolute error (MAE), mean absolute error percentage (MAPE), root mean square error (RMSE), and coefficient of determination (R²). 2 Or R-Square).
[0041] The primary task of the attention mechanism is to assign weights to vectors. These weights are not pre-set but are optimized through continuous learning. Each encoding operation calculates a new weight, the value of which is determined by the input and the hidden state. The weights are then normalized and used to calculate a weighted average or weighted sum, obtaining a weighted representation of different elements in the input sequence.
[0042] The Long Short-Term Memory (LSTM) neural network controls the selective flow of information through input gates, output gates, and forget gates, solving the problems of gradient vanishing and gradient explosion, and is widely used in processing time series problems.
[0043] The aforementioned attention-based bidirectional long short-term memory neural network (Bi-LSTM-Att) interpolation method has been improved in three stages:
[0044] Stage 1: The Bi-LSTM-ATt module calculates the memory cells at each time step using a forward LSTM. Calculated using inverse LSTM The features from the two directions are concatenated, and the output layer of the Bi-LSTM at each time step is represented as h1, h2, ..., h t-1 ,h t The query vector matrix is represented as [q1, q2, ..., q t-1 ,q t ],h t Dot product q t Get similarity l score (h t ,q t );
[0045] The formula is expressed as follows:
[0046]
[0047] Stage 2: Normalize the similarity to obtain the weight coefficient w t ;
[0048]
[0049] Stage 3: W t Applied to each h t Then, the weighted sums are performed to obtain the output R of the attention layer;
[0050]
[0051] The attention mechanism focuses on the values of each element and their weights w. i The input sequence is weighted, and then the weighted sum of all elements is accumulated to obtain the attention value, which is used to represent the relevance of the input sequence to the query vector.
[0052]
[0053] Attention mechanisms enable neural network models to pay more attention to input features relevant to the target task. The implementation process can be represented as follows:
[0054]
[0055] In the formula, e t For attention energy, it can be determined based on the input features x. t The hidden state s of the previous time step t-1 And the attention weight a-1 from the previous time step is calculated to obtain w ij Indicates input feature x ij The attention weights are determined by their corresponding attention energy e. ij After normalization, X is obtained; ij This indicates that the input features, after being weighted by attention weights, can replace the original input x. ij As input to a neural network.
[0056] LSTM utilizes input gates, output gates, and forget gates to control the selective flow of information, thus solving the vanishing and exploding gradient problems. It is primarily used for processing time series data. The specific calculation formula for LSTM is as follows:
[0057]
[0058] In the formula, f t Let σ be the activation value of the forget gate, and W be the activation function. f This is the weight vector for the forget gate, * denotes convolution operation, h t-1 x is the output of the memory unit at time t-1. t b is the input to the memory unit at time t. f For the bias of the forget gate, i t W is the activation value of the input gate. i Let b be the weight vector of the input gate. i For the bias of the input gate input control, g t W represents the candidate states of a memory cell. c Let b be the weight vector of the candidate states of the input gate. c C is the bias of the candidate states of the input gate. t For the state of the memory unit at time t, o t W is the activation value of the output gate. o Let b be the weight vector of the output gate. o This is the bias of the output gate.
[0059] To improve the convergence speed of the loss function and prevent gradient explosion, the dataset needs to be standardized before training the model, ensuring that all data falls within the [0,1] interval. After obtaining the trajectory point values of the PMSM through interpolation, destandardization is then performed to restore the data to the actual standard range. The output of the Bi-LSTM-Att of this invention is the rotation angle s of the PMSM rotor. ′ and velocity ω′ .
[0060] The Bi-LSTM-Att interpolation model of this invention requires automatic optimization of the learned parameters, which are automatically updated using the Adam optimizer with an initial learning rate of 0.001. All models employ mini-batch training with a batch size of 100. The model uses the training set to learn and automatically update relevant parameters, then uses the validation set to verify the training effect and adjust relevant hyperparameters, and finally uses the validation results to calculate evaluation metrics.
[0061] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should be considered within the scope of protection of the present invention.
Claims
1. A method for interpolating PMSM trajectory points using Bi-LSTM based on an attention mechanism, characterized in that, Includes the following steps: 1) Acquire the time series of position commands given by the CNC system and the time series of rotor rotation speed s and rotor rotation angle ω of the PMSM under acceleration transition smoothing, and stitch them into a three-dimensional input vector according to the same time step, and normalize the data; 2) Use bidirectional LSTM to process the position command time series to obtain the output vector R of the attention layer; 3) Pass the vector R to the fully connected layer to obtain the final two prediction outputs, namely the rotor rotation speed and rotor rotation angle at the next time step t+1.
2. The method for interpolating PMSM trajectory points based on an attention mechanism according to claim 1, characterized in that, Step 2) includes the following steps: 2.1) The forward LSTM and the backward LSTM read the position instruction sequence from left to right and from right to left, respectively, and at each time step t, the outputs of the forward LSTM and the backward LSTM are combined into h. t ; 2.2) Query vector matrix q t Dot product h t Obtain the similarity score l at each time step t score (h t ,q t ): 2.3) Use the softmax function to normalize all similarity scores to obtain the weight coefficients w. t : 2.4) w t with h t The weighted summation yields the output vector R of the attention layer:
3. The method for interpolating PMSM trajectory points based on an attention mechanism according to claim 1, characterized in that, It also includes the following steps: The Adam optimizer is used to automatically adjust the learning rate. The Bi-LSTM-Att interpolation model is trained using mini-batch training. The training set is used to automatically update the relevant parameters. The validation set is used to verify the effect of the model training and adjust the relevant hyperparameters. Finally, the validation results are used to calculate the evaluation index.
4. The method for interpolating PMSM trajectory points based on an attention mechanism using Bi-LSTM according to claim 3, characterized in that, The evaluation metrics include: mean absolute error, mean absolute error percentage, root mean square error, and coefficient of determination.
5. The method for interpolating PMSM trajectory points based on an attention mechanism using Bi-LSTM according to claim 3, characterized in that, It also includes the following steps: The trained model is deployed into a simulation experiment. The interpolation effect of the model is evaluated by using the simulated waveform images of the PMSM rotor rotation angle, rotational angular velocity, and rotational angular acceleration obtained from the experiment.
6. A system for interpolating PMSM trajectory points using a Bi-LSTM based on an attention mechanism, characterized in that, include: The data preprocessing module is used to acquire the time series of position commands given by the CNC system and the time series of rotor rotation speed s and rotor rotation angle ω of the PMSM under acceleration transition smoothing. The data is then concatenated into a three-dimensional input vector according to the same time step and normalized. The attention weighting module is used to process the position command time series using a bidirectional LSTM to obtain the output vector R of the attention layer; The trajectory point interpolation module is used to pass the vector R to the fully connected layer to obtain the final two prediction outputs, namely the rotor rotation speed and rotor rotation angle at the next time step t+1.
7. A device for interpolating PMSM trajectory points using a Bi-LSTM based on an attention mechanism, characterized in that, It includes a memory and a processor; the memory is used to store a computer program; the processor is used to implement, when executing the computer program, a method for interpolating PMSM trajectory points based on an attention mechanism as described in any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, implements a method for interpolating PMSM trajectory points using a Bi-LSTM based on an attention mechanism as described in any one of claims 1-5.