1 Introduction

Permanent magnet synchronous motors (PMSMs) have gained widespread application in industrial robots, CNC machine tools, aerospace, and other fields, owing to its high power density, fast response speed, ample output torque, efficiency, and small size [1,2,3,4]. Direct torque control (DTC) and field-oriented control (FOC) are the two main control methods for PMSMs. However, DTC has a significant torque ripple when a motor runs at low speeds. Hence, most PMSM control systems use FOC [5].

PID control is widely used in various industrial fields in closed-loop control systems due to its good stability, convenient parameter adjustment, and high reliability [6,7,8]. However, the traditional PID control parameters are fixed during system operation, the adaptability to changes in the working environmental is poor, and it cannot meet the higher speed regulation requirements of a motor under different conditions. In addition, the permanent magnet synchronous motor is a nonlinear, complex, time-varying control object. Therefore, many experts have improved conventional PID control in field-oriented control systems. Many studies have shown that fuzzy control allows for easier and more accurate parameter adjustment than conventional PID control. Fuzzy logic is an effective method for dealing with uncertainty in the control process, and it has recently become a critical controller design theory [9]. In [10], Lukichev et al. used fuzzy PI control and conventional PID control in the FOC of a PMSM, and concluded that the fuzzy PI control can significantly shorten the adjustment time of the system. In [11], Qu et al. proved that a fuzzy logic controller that optimizes membership functions can optimally determine the parameters of a PI controller. Wang et al. [12], El-Sousy et al. [13], and Yang et al. [14] used fuzzy PI control and neural network PI control, respectively. In terms of response speed and chattering reduction, fuzzy control is more advantageous.

However, fuzzy PI control also has its disadvantages. It relies too much on expert experience and cannot achieve the anti-interference capability under special conditions. Once the fuzzy controller is determined, the control rules and controller parameters are determined, which reduces the adaptive capability of the control system. In addition, the selection of the controller parameters is difficult and the calculation is large. The development of a multi-objective optimization algorithm provides an efficient method for fuzzy PI control optimization. Such algorithms include the neural network algorithm [15], genetic algorithm [16], particle swarm optimization [17], and so on. In [15], He et al. designed a genetic algorithm to control a remotely operated vehicle (ROV) with an adaptive neural network. This solves the problem of large-scale computation in fuzzy control. Castillo et al. [16] introduced the particle swarm optimization, annealing algorithm, and genetic algorithm to the design of an optimal type-2 fuzzy controller, which proves that using biomimetic optimization methods helps find appropriate parameter values and complex tasks for fuzzy systems.

Particle swarm optimization (PSO) is an efficient random optimization algorithm with global search. Because the PSO algorithm is simple and requires few parameters to be adjusted, it has been widely used in various optimization problems Mahfouf et al. [17] developed an adaptive weighted PSO to increase the searchability of the algorithm by adaptive inertia weight and acceleration factors. The authors of [18,19,20] designed an adaptive particle swarm optimization algorithm to optimize traditional fuzzy PI control parameters. In [19], Ren et al. proposed an modified particle swarm algorithm to improve the problems of the overshoot, oscillation, and un-synchronization of multiple motors. The algorithm is simple, has few adjustment parameters, possesses a rapid convergence speed, and can achieved good results in motor control. Jiang et al. [20] proposed to use a natural selection strategy to accelerate the convergence rate of particle swarm algorithms and to improve the ability to avoid local optima. Wen et al. [21] proposed a complementary multi-objective approach plan for particle swarm optimization and the genetic algorithm, which was applied to the optimal parameter optimization of a fuzzy logic controller. In this paper, the optimization problem of fuzzy controller parameters is studied by using the powerful optimization capability of PSO.

Considering the effects of various disturbances on the motors such as external loads, environmental changes, and parameter errors, the key contributions of this work are as follow.

  1. 1.

    A parameter adaptive particle swarm optimization fuzzy PI control strategy to overcome external disturbances is proposed.

  2. 2.

    The proportionality and quantization factors in the fuzzy PI control are optimized using particle swarm optimization algorithms.

Then a simulation analysis under the rated conditions is used to verify the design feasibility. Experimental results demonstrate that under this control strategy, the motor speed and rated current are always kept near the rated value. In addition, it has a faster response speed and a better anti-disturbance capability than the traditional PI control.

The remainder of this paper is organized as follows. In Sect. 2, a mathematical model of a PMSM is given. The design of a fuzzy PI controller based on the particle swarm optimization algorithm is given in Sect. 3. Section 4 shows the advantages of the fuzzy PI controller optimized by PSO through experimental results. Finally, Sect. 5 provides a conclusion to this study.

2 Mathematical model of a PMSM based on FOC

The core of field-oriented control [22, 23] is decoupling control. Its purpose is to change the controlled alternating current vector into a DC scalar. Through a coordinate transformation from three-phase static to two-phase rotation, a motor can be controlled in a synchronous coordinate system to obtain its ideal torque.

To model a PMSM, a mathematical model is typically developed using the two-phase rotating coordinate system d-q axis [24]. However, to ensure the accuracy of subsequent experimental results, certain assumptions are typically made during the modeling process [25].

These assumptions include ignoring the saturation of the motor core, not considering the eddy current or hysteresis losses in the motor, and assuming that the current in the motor is a symmetrical three-phase sine wave current. It is important to note that PMSMs are multi-variable and strongly coupled systems.

Based on the above assumptions, a mathematical model of a three-phase PMSM under the d-q coordinate system was established in [26].

Its voltage equation is as follows:

$$\left\{ {\begin{array}{*{20}c} {u_{d} = R_{s} i_{d} + \frac{{d\varphi_{d} }}{dt} - \omega_{e} \varphi_{q} } \\ {u_{q} = R_{s} i_{q} + \frac{{d\varphi_{q} }}{dt} + \omega_{e} \varphi_{d} } \\ \end{array} } \right.$$
(1)

The flux linkage equation is given as:

$$\left\{ \begin{gathered} \varphi_{d} = L_{d} i_{d} + \varphi_{f} \hfill \\ \varphi_{q} = L_{q} i_{q} \hfill \\ \end{gathered} \right.$$
(2)

For surface-mounted permanent magnet synchronous motors \(L_{d} = L_{q} = L\). Thus, the torque equation is:

$$T_{e} = \frac{3}{2}p_{n} \left[ {\varphi_{f} i_{q} + \left( {L_{d} - L_{q} } \right)i_{d} i_{q} } \right]$$
(3)

The mechanical equation of motion is given as:

$$J\frac{{d\omega_{m} }}{dt} = T_{e} - T_{L} - B\omega_{m}$$
(4)

According to the above equation, the state space equation is obtained as follows:

$$\left\{ \begin{gathered} \dot{i}_{q} \; = \;\frac{1}{{L_{q} }}\left( {u_{q} - R_{s} i_{q} + L_{d} i_{d} \omega_{e} - \psi_{f} \omega_{e} } \right) \hfill \\ \dot{i}_{d} \; = \;\frac{1}{{L_{d} }}\left( {u_{d} - R_{s} i_{d} + L_{d} i_{d} \omega_{e} } \right) \hfill \\ \dot{\omega }_{e} \; = \;\frac{1}{J}\left( {1.5p_{n}^{2} \left( {\psi_{f} i_{q} + \left( {L_{d} - L_{q} } \right)i_{d} i_{q} } \right) - p_{n} T_{L} - B\omega_{e} } \right) \hfill \\ \end{gathered} \right.$$
(5)

In the PMSM vector control system given in this paper, it is assumed that \(i_{d} = 0\). In addition, the state space equation Eq. (5) can be rewritten as:

$$\left\{ \begin{gathered} \dot{i}_{q} = \frac{1}{{L_{q} }}\left( {u_{q} - R_{s} i_{q} - \psi_{f} \omega_{e} } \right) \hfill \\ \dot{\omega }_{e} = \frac{1}{J}\left( {1.5p_{n}^{2} \psi_{f} i_{q} - n_{p} T_{L} - B\omega_{e} } \right) \hfill \\ \end{gathered} \right.$$
(6)

where \(u_{d}\), \(u_{q}\) is the voltage of the d-q axis of the two-phase rotating coordinate system; \(i_{d}\), \(i_{q}\) is the current of the d-q axis of the two-phase rotating coordinate system; \(L_{d}\), \(L_{q}\) is the inductance of the d-q axis; \(R_{s}\) is the phase resistance; \(P_{n}\) is the number of motor pole pairs; \(\varphi_{f}\) is the permanent magnet synchronous motor permanent magnet flux; \(\varphi_{d}\), \(\varphi_{q}\) is the component of the permanent magnet flux linkage of the permanent magnet synchronous motor on the d-q axis; \(\omega_{e}\) is the electrical angular velocity; \(\omega_{m}\) is the mechanical angular velocity; \(T_{e}\) is the electromagnetic torque; \(T_{L}\) is the load torque; and \(J\) is the moment of inertia.

3 Parameter optimization of a fuzzy PI controller based on PSO

3.1 PMSM fuzzy PI controller design

Fuzzy control is a method of controlling systems with nonlinear and time-varying characteristics by summarizing the knowledge and experience of experts into relatively complete language rules. Unlike other control methods, it does not require an accurate mathematical model of the system [27].

To study the vector control system of a PMSM, the structure and parameters of the fuzzy controller are designed. The error signal \(e\) and the error rate of the change \(ec\) of the controlled quantity are selected as input quantities, and two parameters \(K_{p}\), \(K_{i}\) of the PI are used as output variables. The academic field of the two input variables is [− 6, 6], and the theoretical domain of \(K_{p}\), \(K_{i}\) is [− 3, 3].

In fuzzy control, quantization and scaling factors are needed to change the actual deviation into the fuzzy domain. When the true value change range is [\(- x,x\)] and the fuzzy field is [\(- n,n\)], the quantization factor and proportion factor are chosen as follows:

$$K = \frac{x}{n}$$
(7)

In this paper, {NB NM NS Z VS MB VB} is selected as the fuzzy partition of the input and output [28].

The fuzzy control rule is to determine the fuzzy relationship between the PI parameters at different moments.

For the PI controller of the speed loop in the vector control of a PMSM, the general expression of the conventional PI controller is:

$$u(t) = K_{p} e(t) + K_{i} \int_{0}^{t} {e(\tau )} d\tau$$
(8)

Combining Eq. (8) and the experience summed up by predecessors, the fuzzy PI control rules are obtained as shown in Table 1 and Table 2:

Table 1 Fuzzy rule table for Kp parameter adjustment
Table 2 Fuzzy rule table for Ki parameter adjustment

3.2 PSO based fuzzy PI controller

In addition to the fuzzy rules in the fuzzy controller, the quantization and proportion factors settings also affect the control performance. However, the proportion factor and quantization factor are often determined by manual experience, which has a certain blindness. In this paper, the particle swarm algorithm is used to optimize both the quantization factor (\(K_{e}\), \(K_{ec}\)) and the scale factor (\(K_{up}\), \(K_{ui}\)), which can enhance the adaptability of the controller and improve the control accuracy by establishing a fitness function. Aiming at the problem where the particle swarm optimization algorithm can easily fall into a optimal local solution, a piecewise time-varying optimization method is adopted for the learning factor.

The fundamental concept of particle swarm optimization (PSO) is to obtain the optimal solution algorithm through cooperation and information exchange among the individuals in a group [29]. This is achieved by representing each bird in a space as a massless particle, where each particle represents a feasible solution and has its position, velocity, and fitness information. In each iteration, the particle adjusts its speed and direction based on its position, as well as the individual and group extrema. Throughout the iterations, the particle updates its position and velocity according to certain rules:

$$V_{id}^{k + 1} = \omega V_{id}^{k} + c_{1} r_{1} \left( {P_{id}^{k} - X_{id}^{k} } \right) + c_{2} r_{2} \left( {P_{gd}^{k} - X_{gd}^{k} } \right)$$
(9)
$$X_{id}^{k + 1} = X_{id}^{k} + V_{id}^{k + 1}$$
(10)

where \(\omega\) is the inertia weight, and adjusting its size can change the search range and search speed; \(c_{1}\), \(c_{2}\) are the learning factors, and both of them are non-negative; and \(r_{1}\) and \(r_{2}\) are independent random numbers between [0, 1]. The inertia weight and learning factor change with time as follows:

$$\omega \left( k \right) = \omega_{\max } - \left( {\omega_{\max } - \omega_{\min } } \right)\frac{k}{{k_{\max } }}$$
(11)
$$c_{1} (k) = (c_{1\max } - c_{1\min } )\frac{k}{{k_{\max } }} + c_{1\min }$$
(12)
$$c_{2} (k) = (c_{2\max } - c_{2\min } )\frac{k}{{k_{\max } }} + c_{2\min }$$
(13)

where \(\omega (k)\) is the inertia weight of the \(k - th\) iteration. \(\omega_{\max }\) and \(\omega_{\min }\) are the maximum and minimum weights, respectively. \(k_{\max }\) is the maximum number of iterations. \(c_{1} (k)\) and \(c_{2} (k)\) are the values of the learning factor after iterations. \(c_{1\max }\), \(c_{1\min }\), \(c_{2\max }\), \(c_{2\min }\) are the initial and final values of the learning factor sum.

The particle swarm algorithm continuously optimizes the four parameters based on the above formula. The optimization process ends when the maximum number of iterations is reached. The individual position at that time represents the optimal value of the parameters. The specific implementation steps are outlined as follows [30].

  1. 1)

    Assign values to particles. Set the initial population number and the number of iterations.

  2. 2)

    Establish the fitness function. All of the particles in the population are evaluated, particle fitness values are calculated, and the current particle fitness values are compared with the optimal fitness values of the historical population. In addition, the full particle fitness of the current population is compared with the optimal fitness values of the historical population. In this paper, select the ITAE criterion [29]. The ITAE criterion is as Eq. (14):

    $$J = \int_{0}^{T} {t\left| {e(t)} \right|} dt_{{}}$$
    (14)

where \(T\) is the simulation time, \(e(t)\) is the speed error of the PMSM rotor, and the system optimized by the ITAE criterion has the characteristics of high speed, good stability, and a slight overshoot.

  1. 1)

    Find the particle with the minor fitness function through continuous iterations, which is the fuzzy control factor with the best position in the search space.

4 Experiments and analysis

To verify the effectiveness and feasibility of the proposed algorithm, the control system scheme shown in Fig. 1 is used to build a simulation model based on MATLAB/Simulink. In addition, a physical system is built with a development kit of TI Incorporated (TMS320F28035) as the control chip. It will be verified experimentally with fuzzy control.

Fig. 1
figure 1

PMSM vector control structure diagram

The motors used in the following experiments are all three-phase surface-mount PMSMs. The parameters are shown in Table 3.

Table 3 Permanent magnet synchronous motor parameters

The control program for PMSMs was written on a computer and then burned into the control unit, as shown in Fig. 2. The PMSM test platform, as shown in Fig. 3, operates based on the PMSM control platform mentioned above. It includes 4 PMSMs used as detection motors and another 4 PMSMs capable of outputting a specified constant torque as the load torque. Additionally, the platform is equipped with sensors such as torque sensors, ammeters, and voltmeters. In this experiment, PMSM 1 was controlled using a fuzzy PI controller, while PMSM 2 was controlled using a PSO fuzzy PI controller.

Fig. 2
figure 2

PMSM control platform

Fig. 3
figure 3

PMSM test platform

Algorithm parameter settings: the population number is 50, the dimension of each particle is D = 4, the maximum number of iterations is 40,\(c_{1} = c_{2} = 1.7\), \(\omega = 0.6\), the particle velocity range is [100, − 100], and the initial PI control parameters are \(K_{p} = 0.14\) and \(K_{i} = 7\).

The parameters obtained through the optimization method proposed in this paper are compared with those calculated based on Eq. (7), and presented in Table 4.

Table 4 Parameter comparison

Figure 4 depicts speed curves of the motor with no-load, starting with a fuzzy PI control strategy, and a fuzzy PI control strategy optimized by PSO. From this figure, it can be observed that the speed response rise time is 0.01368 s under the fuzzy PI control, while the speed response rise time is reduced to 0.01160 s after optimizing the fuzzy PI control with PSO. Additionally, the overshoot reaches the ideal effect, and the response speed is faster than the traditional PI control. Moreover, it is not very different from the fuzzy PI control in achieving the expected rate.

Fig. 4
figure 4

No load start speed

Figure 5 shows motor speed curves when the motor speed is suddenly increased to 800 r/min after running the motor at 600 r/min for 0.1 s. From Fig. 5, after giving the motor an acceleration command, the motor acceleration time under the traditional fuzzy PI control takes 0.01147 s, while the motor acceleration time of the optimized fuzzy PI control with PSO is only 0.00501 s. Compared with the traditional fuzzy PI control, the performance is improved by about 56%.

Fig. 5
figure 5

Motor acceleration curve

Figure 6 shows motor speed curves after running the motor at 800 r/min for 0.1 s, and then suddenly decelerating the motor speed to 600 r/min. From Fig. 6, it can be seen that after giving the motor a deceleration command, the motor with the optimized fuzzy PI control decelerates to 600 r/min in 0.0628 s. In contrast, the motor with the conventional fuzzy PI control decelerates to 600 r/min in 0.1037 s. Compared with the traditional fuzzy PI control, the control performance of the optimized fuzzy PI control is improved by about 39.4%. Comparing Figs. 5 and 6, the PSO-optimized fuzzy control can be seen to be more responsive to speed changes.

Fig. 6
figure 6

Motor deceleration curve

Figure 7 shows motor speed curves when the motor is run steadily at 800 r/min for 0.2 s, and a load of 10 Nm is suddenly added at 0.2 s. The figure shows that the speed fluctuations of both the motor controlled by the fuzzy PI and the motor controlled by the PSO optimization is about 17 r/min when the load is suddenly added. Still, when the load is removed, the motor controlled by the fuzzy strategy with PSO optimization reaches stability after 0.00371 s. The motor with the traditional fuzzy PI control reaches stability after 0.1275 s. Figure 8 shows current curves of the motor with sudden load changes under the two control strategies.

Fig. 7
figure 7

Speed curve of a motor with a sudden load change

Fig. 8
figure 8

\(i_{q}\) current curves

To avoid the contingency of an experiment, the initial setting parameters were changed and the feasibility of the algorithm was verified.

Algorithm parameter settings: the population number is 100, the dimension of each particle is D = 4, the maximum number of iterations is 50,\(c_{1} = c_{2} = 1.7\), \(\omega = 0.6\), the particle velocity range is [100, − 100], and the initial PI control parameters are \(K_{p} = 0.18\) and \(K_{i} = 10\).

As can be seen in Figs. 9 and 10, after changing the initial parameters, the motor controlled by the traditional fuzzy PI reaches the specified speed at 0.02631 s and remains stable, while the motor controlled by the PSO-optimized fuzzy PI control strategy reaches the specified speed at 0.0136 s in the start-up stage and remains stable. In addition, the PSO-optimized fuzzy PI control improves the rotational speed response by 48% compared with the traditional fuzzy PI control. When the speed changes suddenly, the motor with the traditional fuzzy PI control reaches the specified speed at 0.00949 s, while the motor with the PSO-optimized fuzzy PI control reaches the specified speed at 0.00516 s, which is a control performance improvement of 45.6%.

Fig. 9
figure 9

No load start speed

Fig. 10
figure 10

Motor acceleration curve

Figure 11 displays speed curves of the motor running steadily at 800 r/min for 0.2 s, followed by the sudden addition of a 10 Nm load at 0.2 s. This figure indicates that when there is a sudden change in the external load, the motor speed fluctuates by 32 r/min under the fuzzy PI control strategy optimized by PSO and gradually stabilizes after 0.03156 s. However, under the traditional fuzzy PI control strategy, the motor speed fluctuation range is 97 r/min, and it gradually becomes stable after 0.0415 s. It can be seen from this figure that the ability of the PSO-optimized fuzzy PI control strategy to maintain speed stability is 67% higher than that of the traditional fuzzy PI control. Figure 12 shows current curves of the motor with sudden load changes under the two control strategies.

Fig. 11
figure 11

Speed curve of a motor with a sudden load change

Fig. 12
figure 12

\(i_{q}\) current curves

In summary, the two groups of experiments conducted under the condition of different initial PI parameters can demonstrate that the fuzzy PI control optimized by PSO is superior to the traditional fuzzy PI control in improving the response speed and maintaining motor speed stability.

5 Conclusion

This paper proposed a PMSM controller based on PSO and fuzzy PI control theory. To address the shortcomings where fuzzy PI control rules are difficult to set when relying on manual design, the optimal control effect is achieved by adaptively optimizing the proportion and quantization factors. Simulation software was used to build a PMSM mathematical model under the d-q coordinate axis, and an experimental platform was established to compare the performance of the system under the traditional fuzzy PI control and the proposed fuzzy PI control based on PSO. Speed and torque response curves were used to analyze and compare the performance indicators of the two control methods. Compared with the traditional fuzzy PI control, under the fuzzy PI control based on PSO optimization, the pulsation of the system torque is slight, the speed has an excellent dynamic response, the overshoot converges to none, and when the load suddenly changes, the ability to resist external interference is superior.