3.2.1. Principle of the Least Squares Method
The core idea of the least squares method is to adjust parameters to minimize the sum of squared errors between actual data and fitted data, thereby achieving optimal parameter matching. Specifically, the advantage of the least squares method lies in its use of mathematical optimization techniques to convert the data fitting problem into an optimization problem focused on error minimization. The goal of this method is to find an optimal solution—namely, a parameter combination that minimizes the sum of squared residuals—so that the fitted curve or model aligns more closely with the actual data.
By simply solving for unknown data, the least squares method not only provides a powerful tool but also offers a reliable mathematical means for scientific research and solving practical problems. The schematic diagram of its principle is shown in
Figure 8 and
Figure 9:
The mathematical expression describing the relationship between the input and output of the least squares model is as follows:
In the equation, denotes the object to be estimated, y represents the output value, and x stands for the input value.
When a series of values of
x and
y are obtained at different times
, the relationship between these data can be expressed using the function of
, thereby deriving the following formula:
Rewrite Equation (21) into its matrix form, which is shown as follows:
where
A solution to this equation exists only when the rank of matrix X is n. Moreover, when n = m, the equation has a unique solution. Let
be the estimated value; substituting it into Equation (22) yields:
where the estimated value cannot perfectly fit the true value, so the measurement residual vector is defined as:
Since residuals can be both positive and negative, making them unsuitable as a direct evaluation criterion, the squared residual is chosen as the evaluation criterion, resulting in:
Substituting Equation (26) into Equation (27) and taking the derivative yields:
Solving Equation (29) gives the corresponding
that minimizes the residual. Its value is:
The solution to the least squares method is derived by minimizing the sum of squared residuals. A key characteristic of this estimation algorithm is that its implementation process first requires the collection of input and output data, followed by data processing based on the collected data. This process is performed offline, as the entire estimation—from data collection to processing—is completed within a single execution of the algorithm.
3.2.2. Principle of the Recursive Least Squares Method
The least squares method performs excellently in static and offline data processing, but it exhibits significant limitations when dealing with dynamic data sources. Each time new data is input, it is required to reconstruct a matrix for recalculation—this not only consumes substantial controller resources and memory but also creates difficulties for the application of the least squares method.
To overcome this challenge, the Recursive Least Squares (RLS) method is introduced. When new data is acquired, RLS uses this new data along with previously computed results to perform calculations, enabling online updates of parameters. The introduction of this method effectively addresses the problems of the least squares method in dynamic data processing and enhances its adaptability and real-time performance. Its expressions are as follows:
where
is the correction term. The core of the RLS method is to calculate the current parameter estimate
using the previous estimate
. Based on Equation (30), the parameter estimate
at time
k is given by:
In the equation , is the input vector at time k, and is the output vector at time k.
The matrix inversion lemma is expressed as follows:
Define the covariance matrix P(k) using the matrix inversion lemma, we can derive:
Substituting
P(k) into Equation (32) yields:
Define the gain matrix
K(k), whose value is:
Through the above derivation, the formulas for the recursive least squares method are:
In the equations, when determining the initial values, we generally set , .
3.2.3. Principle of the FFRLS
When changes in the system input or output exceed the adaptive range of the algorithm, the problem of cumulative errors arises, leading to the phenomenon of data saturation—which in turn results in inaccurate estimated parameters or algorithm failure.
Assume there exists a natural number
a,
b, such that the following equation holds:
From Equation (38), we can derive:
Taking the reciprocal of both sides of the above equation gives:
From Equation (53), it can be derived that as k approaches infinity, the covariance matrix P(k) also approaches 0. The effect of new input data on updating the identification value gradually diminishes, weakening the correction effect on the result; over time, the update rate of the identification value slows down progressively.
The parameter identification algorithm is considered to have temporal data symmetry. If its evaluation function is the weight assigned to the measurement data, such that the influence of any data point k at time L on the parameter estimation value θ is only a function of the time difference (L − k), rather than the absolute time. When the weight of historical data is too large or the weight of new data is overly emphasized, this symmetry is disrupted.
The traditional recursive least squares method uses fixed-step data, and its evaluation function is . This seemingly assigns equal weights to all data, but in time-varying systems, it leads to “data saturation”, that is, new data is overwhelmed by historical data, causing the algorithm to lose its update capability and disrupting the dynamic symmetrical matching between the algorithm’s estimated values and the true parameter state of the system.
To address the above issue and overcome the disadvantage of data saturation, the least squares method is optimized by introducing a forgetting factor
to “forget” historical data. Additionally, an evaluation function is defined as follows:
In the equation, the value of generally ranges from 0 to 1. Weight is an exponential function of the time difference (L − k). This function describes a scaling of temporal symmetry, and its time constant is determined by the forgetting factor . By adjusting , a dynamic balance of the weights for new and old data can be achieved, enabling the algorithm logic to form a symmetrical match with the changing patterns of the motor’s operating state.
Equation (41) indicates that the weighting coefficients of the collected data information are related to the change in time. These weighting coefficients are ordered in chronological sequence: the weight of the most recently acquired data information is 1,
Based on the above derivation process of the recursive least squares algorithm, the parameter identification formulas for the recursive least squares algorithm with a forgetting factor (FF-RLS) can be derived as follows:
In the equation, regarding the method for determining the initial values and , generally, and are adopted. For the forgetting factor , its value is generally not less than 0.9; for linear relationship identification, the forgetting factor is usually selected within the range of 0.9 to 1. When the forgetting factor = 1, the FFRLS is equivalent to the ordinary recursive least squares method.
3.2.4. Simulation Analysis
The mechanical equation of a PMSM is as follows:
In the equation, denotes the electromagnetic torque, J denotes the moment of inertia of the servo system, B denotes the viscous friction coefficient, denotes the rotor mechanical angular velocity, and denotes the load torque.
To discretize the above equation, the derivative term is replaced by the backward difference method.
At time step
k + 1:
where
is the sampling period. Considering that within a short sampling interval, the load torque remains unchanged
, it can thus be neglected. Meanwhile, the viscous friction coefficient
B has a small value; within a short time interval, the product of the velocity change and the viscous friction coefficient can be regarded as a small quantity
and thus can also be neglected.
Subtracting Equation (44) from Equation (45) yields:
Rewriting the above equation into the standard form of the least squares method gives:
To simplify the calculation, based on the above equation, we obtain:
Substituting Equation (48) into Equation (42) yields:
According to Equation (62), a MATLAB/Simulink model is constructed, and its parameters are shown in
Table 1.
In this simulation, the core formula is . If the speed variation is zero, the denominator of the formula approaches zero, which easily leads to abnormal identification values; if the torque variation is zero, the numerator becomes zero, resulting in incorrect results. Moreover, the identification accuracy is strongly correlated with the input excitation. To address this, the input speed in the simulation is set as a triangular wave with an amplitude of 60 rad/s and a period of 0.12 s. Its linear variation characteristic can stably provide non-zero speed change rates and torque variations, avoiding issues such as sinusoidal wave identification interruption and square wave current impact. The selection of parameters balances the motor’s rated operating conditions and data acquisition efficiency.
In the algorithm update process, it is necessary to first determine whether the speed and torque variations are greater than the threshold. If the condition is satisfied, the algorithm is updated; otherwise, it remains unchanged. This step is designed to filter out the Gaussian white noise of the sensor. The threshold needs dynamic adjustment: a baseline value is initially set according to the noise level, then optimized based on the simulation results, and adapted to different operating conditions. This lays a foundation for the reliable operation of the subsequent FFRLS. The speed feedback waveform, feedback torque waveform,
waveform, and
waveform are shown in
Figure 10.
Among them, the absolute value processing is performed on the torque variation and the moment variation. It can be seen from the above figure that the torque variation thresholds are set as . Since the actual friction model has large mutations at low speeds, the moment of inertia identification is not performed under low-speed conditions either.
When using the FFRLS algorithm to identify the moment of inertia of the servo system, since the input values of the identification algorithm are the speed variation and the current variation, it is necessary to select an appropriate calculation period. After determining the calculation period, an appropriate forgetting factor should be determined through experimental debugging. For the current laboratory servo motor platform, the interrupt calculation period is designed as 10 kHz in the controller. In this simulation, the time period used for parameter identification should be larger than the interrupt calculation period, so it is set to 1 ms.
When selecting the forgetting factor, a small value is usually not chosen. In this simulation, the method of controlling variables is adopted, and the forgetting factor is set to 0.98, 0.96, 0.94, and 0.92, respectively, to perform online identification of the moment of inertia of the servo system. The identification results are shown in
Figure 11.
It can be seen from
Figure 11 that the selected value of the forgetting factor
is closely related to the convergence time, oscillation amplitude, and accuracy. Specifically, the smaller the value of
, the faster the convergence speed and the higher the accuracy; however, there is also a risk of oscillation in the convergence curve. In contrast, the larger the value of
, the smoother the convergence curve, but its convergence speed and identification accuracy are unsatisfactory. Therefore, for this simulation, selecting the forgetting factor
= 0.92 is quite appropriate. The convergence time and corresponding accuracy for different forgetting factors are shown in
Table 2:
Analysis of
Table 2 reveals the following: When
= 0.98, the identification accuracy is +17.5%, which is relatively poor and cannot be applied to the control of the speed loop. When
= 0.92, the identification accuracy is +5%, representing a 12.5% improvement compared to when
= 0.98; the convergence time is 0.39 s, which is 0.23 s shorter than that when
= 0.98. Therefore, different identification effects are produced when different forgetting factors are selected.
In many practical applications, the operating scenarios of PMSM are far from being limited to bearing the moment of inertia of the no-load motor itself. Generally speaking, such system application scenarios may involve multiple power levels, and the motor may need to operate under various load conditions. These loads can vary according to task requirements and may be dynamically changing. Therefore, for such systems, the accurate identification of multiple times the moment of inertia has become a basic and critical requirement. Furthermore, identifications are performed twice, five times, and ten times the moment of inertia, respectively, and the identification results are shown in
Figure 12:
It can be seen from
Figure 12 that under the condition of twice the inertia, the identification speed is the fastest and the identification accuracy is also the highest. When gradually increasing to ten times the inertia, the identification speed and accuracy decrease relatively, but the identification curve is smoother. This is because the response speed of the speed loop decreases under high load conditions. The convergence time and corresponding accuracy for different inertia values are shown in
Table 3:
Analysis of
Table 3 reveals that as the load inertia increases, the identification accuracy decreases while the identification convergence time increases. This highlights the importance of accurately identifying the load’s moment of inertia under high-multiple load conditions. Accurate inertia identification is not only crucial for improving system control precision but also a necessary prerequisite for ensuring dynamic response and stable system operation.
By employing the recursive least squares method with a forgetting factor for online identification of the moment of inertia, an effective symmetric relationship of dynamic approximation between the identified value and the true value is achieved. This method continuously revises the identification results based on real-time operating data, enabling the estimated moment of inertia to adaptively symmetrically track changes in the true inertia. Consequently, high parameter symmetry is maintained under time-varying operating conditions. The realization of this symmetry not only significantly enhances identification accuracy and the adaptability of system control but also lays a critical foundation for high-precision servo control and stability assurance.
3.2.5. Experimental Verification and Analysis
For the identification of moment of inertia using FFRLS, the following steps are implemented: first, delay correction is performed on the q-axis current signal and rotational speed signal collected by the AD converter to ensure synchronization between the identification program and data acquisition; then, the input signals are judged to screen out valid data that meets the identification conditions; subsequently, least squares fitting is conducted on the valid data; finally, the identified moment of inertia value is output through iterative loop calculations.
This experiment is built on a servo motor controller based on the STM32F446 processor, and the corresponding algorithm development has been completed. The experimental control platform is shown in
Figure 13a, which mainly consists of a host computer, a circuit board, an oscilloscope, and a DC power supply. The experimental motor setup is shown in
Figure 13b, which mainly includes an experimental motor, a load motor, and inertia disks. By replacing different inertia disks, experimental conditions with multiple times the base inertia can be created.
Since the input values of the FFRLS algorithm for identifying the moment of inertia are the speed variation and current variation, the convergence speed and identification accuracy of the algorithm are strongly related to the intensity of the speed excitation. Therefore, in this experiment, the speed reference is set as a triangular wave, and the forgetting factor FFRLS is used to identify the moment of inertia. Experiments under no-load conditions, double load inertia, fivefold load inertia, and tenfold load inertia are conducted, respectively, and the experimental results are shown in
Figure 14.
Based on the above experimental results, in order to intuitively present the identification accuracy and convergence time of the identification algorithm, the identification results under different inertia conditions are shown in
Table 4.
As shown in
Table 4, under the no-load condition, the identification accuracy is 5.2% and the convergence time is 0.41 s; under the tenfold inertia condition, the identification accuracy is 7.9% and the convergence time is 0.59 s. These results indicate that the algorithm can quickly and accurately capture the actual inertia of the system when there is no load disturbance, further verifying the rationality of the earlier simulation model and the adaptability to the actual system.
In conclusion, the FFRLS algorithm proposed in this paper meets the requirements of practical engineering applications in terms of both identification accuracy and convergence time for moment of inertia identification. It is conducive to quickly obtaining accurate system parameter estimation in real-time or rapidly dynamically changing system environments, thereby helping to improve the flexibility and reliability of the overall system control strategy.