Abstract
In this paper, an intelligent neural network-based controller is designed and implemented to control the speed of a permanent magnet synchronous motor (PMSM). First, the exact mathematical model of PMSM is presented, and then, by designing a controller, we apply the wind turbine emulation challenges. The designed controller for the first time is implemented on a Arm Cortex-M microcontroller and tested on a laboratory PMSM. Since online learning neural network on a chip requires a strong processor, high memory, and convergence guarantee, this article uses the offline method. In this method, first, for different work points, the neural network is trained by local controllers, and then, the trained network is implemented on the chip and used. Uncertainty in the parameters and the effect of load torque as challenges of control systems are applied in the proposed method, and a comparison with other methods is performed in the implementation results section.
1. Introduction
In recent decades, fuzzy logic has grown dramatically in many sciences. One of the reasons for the growth of fuzzy logic is that it does not require strong mathematics, and also, in applying fuzzy logic to different systems, a precise dynamic model of the system is not needed [1]. One of the most important reasons for the rapid growth of the use of fuzzy logic is the implementation of human thinking and reasoning as if-then rules. One application of fuzzy logic is fuzzy modeling. Fuzzy modeling involves obtaining “if-then” fuzzy rules from system input-output data, creating the basic model structure (structural identification), and model training (parametric identification) [1]. One way to obtain if-then rules and identify fuzzy model parameters is to combine fuzzy logic and neural networks. This combination can be used as an intelligent controller in various systems. In this paper, the purpose of neuro-fuzzy control is synchronous motor; so first, a brief review of recent work is presented. In [2], the permanent magnet synchronous motor dynamics is first identified by a neural network with postpropagation error training, and then, it is used to adjust the fuzzy control parameters. Using the simulation in this reference, the fuzzy neural network is compared with the PID controller, which shows that the fuzzy neural networks are able to track the reference model with acceptable accuracy as well as the metamutation problem of the PID controller. There is no neuro-fuzzy controller. In [3], TSK fuzzy control with reduction gradient training and error propagation method is used to control the six-phase permanent magnet synchronous motor.
Nowadays, combined fuzzy neural methods with sliding mode control [4, 5], inverse control [6], robust control [7], H∞ [8], adaptive estimator [9], etc. to control the speed and position of the permanent magnet synchronous motor are widely used. An adaptive neural network distributed control algorithm for a group of high-order non-linear agents with nonidentical unknown control directions under signed time-varying topologies is presented in [10]. An adaptive cooperative control problem with guaranteed convergence for a class of nonlinear multiagent systems with unknown control directions and time-varying topologies is presented in [11]. In [12], the problem of neural network-based adaptive dynamic surface control for permanent magnet synchronous motors is presented. A decoupling scheme for a bearingless permanent magnet synchronous motor to achieve fast-response is presented in [13].
However, implementing fuzzy neural control hardware with online training is very difficult. Although more than 20 years have passed since the hardware implementation of computational intelligence systems with online training [14], they are still used in the PID industry and fixed structure controllers because they include derivatives and it is an instantaneous update of the parameters, and despite the noise and disturbance in the physical systems, this work has not yet taken place and requires changes in the training system of neural networks and fuzzy neural networks as well as changes in the chips [15]. The combination training method of least-squares and decreasing gradient was introduced in [16]. This method has a high speed in network training and has the least hardware problems and noise cancellation in terms of implementation and has been widely used in recent years [17–22].
In the present paper, the combined least-squares method and descending gradient algorithm and the error propagation method are used to train the adaptive neuro-fuzzy inference system (ANFIS). In the hybrid method, the least-squares method is used to adjust the linear parameters of the output layer, and the descending gradient algorithm is used to adjust the nonlinear parameters of the input layer, including the parameters of the input membership functions. In this paper, a new method based on the fuzzy neural adaptive network is presented offline. In this method, first, the fuzzy neural adaptive network detects changes in motor dynamics at different operating points and with different load torques (with random variable parameters) and is trained by the combined training method of least-squares and decreasing gradients. The identification method is such that for each working point, any amount of turbulence and load torque, as well as random changes of parameters, a precise local controller such as PID, LQR, and LQG is locally designed, and then, the input and output of this controller set is applied to an adaptive fuzzy neural network with combined training and the network covers all controllers. In this case, the trained network has the ability to cope with various situations and the motor speed can be controlled with high accuracy. In the following, first, the dynamic equations of the permanent magnetic synchronous motor will be expressed, and then, the structure of the fuzzy neural adaptive network and its relations will be presented, and finally, the combination of controller and motor, and simulation results will be presented.
2. Dynamic Model of Permanent Magnet Synchronous Motor
The dynamic model of the permanent magnet synchronous motor can be shown as follows [23]:where Id and Ud are the currents and voltages of the Iq, Iq, and Uq are the currents and voltages of the q-axis, ωr is the rotor angular velocity, θr is the rotor angular position, L is inductance, R is the stator resistance, and φf is the magnetic flux of the motor. TL is the load torque, Bm is the coefficient of friction, and Jm is the inertia. The electric torque is obtained from the following equation:where P is the number of motor poles. According to (3), by keeping the current of the d-axis constant, the torque can be controlled with the current of the q-axis. In this regard, (3) can be written as follows:where Kt is a constant value, so by controlling the current iq, the torque can be controlled.
3. Fuzzy Neural Network
Despite the widespread growth of fuzzy logic, there is still no cinematic process for designing a fuzzy controller [1]. However, a neural network has the ability to see from the training environment (input-output pairs), to arrange its structure and adapt its interaction in some way. Therefore, this problem can be overcome by combining fuzzy logic and neural network. Fuzzy neural networks have the ability to train and extract fuzzy rules and adjust the parameters of membership functions. Figure 1 shows the structure of an adaptive fuzzy neural network with two inputs y and x and one output f.

For the structure of Figure 1, two fuzzy rules are defined:(1)If x is equal to A1 and y is equal to B1, then, f1 = p1.x + q1.y + r1(2)If x is equal to A2 and y is equal to B2, then, f2 = p2.x + q2.y + r2
In Figure 1, the first layer is the fuzzy layer and two membership functions are provided for each of the inputs. The numeric input in this layer is converted to a fuzzy number. For example, if the membership functions are Gaussian, the output of the first layer is calculated as follows:where is the membership function of the linguistic variable related to the ith input and the kth rule, is the center of the Gaussian function and is the deviation from the Gaussian function criterion. In the second layer, fuzzy rules are created. If the AND operator is used in the second layer node, the output of the second layer is as follows:
In the third layer, the normalization operation is performed, so that the output of each node from the second layer is divided by the sum of all the outputs of the second layer.
In the fourth layer, the output of the third layer is multiplied by a function that is a linear combination of inputs.
In a single fifth layer node, the output of all fourth layer nodes is added together.
To train the fuzzy neural network, a combination of the least-squares method is used to update the parameters of the fourth layer (pi, qi, ri), and the error propagation method is used to update the parameters of the Gaussian membership function (, ). In the least-squares method, it is assumed that the network output is obtained as follows [6]:where U = [u1,…,un] is the input vector of the network, f1,…,fn are the specific functions of the input vector, and θ1,…,θn are also output parameters that must be updated during network training. It is assumed that for input training, the input-output pair is considered as {(ui,yi), i = 1,…,m}. (10) can be written as follows:where A is a matrix m×n s as follows:
Also, θ is the vector parameters of the output as follows:
The output is a vector m×1 as follows:
Since there is always m > n as well as the modeling error e, (11) could be written as follows:
The goal of finding is to minimize the cost function.where ai is the ith row of the matrix A.
If the cost function is minimized, then, is obtained.
If the matrix is not singular, is obtained by solving the following equation.
In equations (10)–(18), if new data is applied to the network, all of the above calculations are repeated. For this reason, it is better to use the least-squares return algorithm. The recursive least-squares algorithm is presented as follows:where Pk is the error variance matrix and ak+1 is the coefficient vector. For example, to estimate the parameters of the output layer of the fuzzy neural network in Figure 1, the values of vectors A and θ are as follows:
This section defines the error propagation method with a descending gradient algorithm. It is assumed that the fuzzy neural network has L layers and the lth layer has N(l) neurons. The output of neuron i from layer l is denoted by the symbol xl.i, and the function of neuron i from layer l is denoted by the symbol fl.i.where α.β.γ.… are the parameters of the neurons that must be updated at each stage of training. The total number of data used to train a multiinput-multioutput network is assumed to be equal to P. Now if the pth input-output pair () is applied to the network, the sum of the error squares of all outputs related to this data is obtained as follows:where dk is the optimal kth output of the network and xL,k is the actual network output of the kth neuron. Also, N(L) is the number of the network outputs. In network training with P data, the goal is to minimize the error associated with all training data, i.e., . This requires minimizing the error of each training data. The basis of the descending gradient algorithm and the error propagation method is based on the derivative, so that in each step the error derivative is calculated to the unknown parameter to obtain the optimal value of the unknown parameter. This starts from the output layer, and the parameters are updated to reach the input layer. The error of the ith neuron is calculated from the output layer (L) as follows:
Similarly, for the ith neuron from the lth layer, the error is obtained as follows:
For example, if α is the nth parameter of the lth layer, the error is obtained as follows:
Therefore, the following equation is used to update the parameter during the training:where
To apply the error propagation method, first consider the fuzzy neural network of Figure 2 with two inputs Δe and e and the output , with the Gaussian membership function. In this network, the number of membership functions for the input e is equal to j and for the input Δe is equal to k. Network input parameters that are updated with network training include m1.j (Gaussian membership function center for input e), m2.k (Gaussian membership function center for Δe input), σ1.j (deviation from the Gaussian membership function criterion for input e), and σ2.k (deviation from the Gaussian membership function criterion for input Δe).

First, the cost function is defined as follows:where Wref is the reference speed and Wa is the actual motor speed. The fifth layer error is calculated as follows:
The fourth layer error is obtained as follows:
The third layer error is obtained as follows:
The second layer error is calculated for each of the inputs from the following equation:
In equations (33)–(38), the update of the parameters of the front part and the sequence of fuzzy rules are stated, which includes the update of the parameters of the center and the width of the Gaussian function for each of the inputs [2].
It should be noted that in the combined training method, first the parameters of the first part are considered with initial values and in a fixed form, and then, all the data are applied to the network. Finally, after calculating the parameters of the output layer, the data are applied to the network in a pattern-by-pattern manner and the nonlinear parameters of the fuzzy layer are calculated from the descending gradient algorithm by the error backpropagation method.
4. Use of Fuzzy Neural Network as Speed Controller of the PMSM
The structure of the drive used with the fuzzy neural controller to control the motor speed is shown in Figure 3. Fuzzy neural network is first trained offline by combining two methods of least-squares and descending gradient with the error propagation method and after training the network and placing it as a controller in the block diagram of Figure 3, the motor speed can be controlled. The input signals of the controller are e and Δe, and the output signal of the controller is .

In Figure 3, the control inputs are obtained from the following equations:
In Figure 3, the two PI controllers act as a flow control loop. If the id current is controlled by a zero reference current, the PMSM can be coupled and controlled by the iq current like a DC motor [24]. Figure 3 uses IGBT modules in the inverter.
5. Hardware Implementation
The structure of Figure 3 has been used to evaluate the proposed method. Figure 4 shows the Arm Cortex-M board, and also, the laboratory setup of the PMSM control system is shown in Figure 5.


Specifications of the 4-pole permanent magnet synchronous motor used are described in Table 1 [24].
In the used fuzzy neural network, five membership functions are designed for each input. The membership functions used are of the Gaussian type. In Figures 6 and 7, the membership functions of each of the inputs are shown.


In Figure 6, the input space e is divided into five parts: very small, small, medium, large, and very large. Also, in Figure 7, the input space c is divided into five parts: large negative, medium negative, small negative, negative, and zero. Table 2 shows 25 fuzzy rules. As mentioned earlier, the output of the first-order Sugeno neural-fuzzy network is a linear combination of inputs and is a nonfuzzy number. In Table 2, the linear parameters of the control signal Iq, i.e., p, q, and r are expressed for each rule, respectively.
Figure 8 shows the speed of a permanent magnet synchronous motor using a neural-fuzzy controller.

Figure 9 shows the performance of three types of controllers ANFIS, Fuzzy, and PID.

In Figure 10, in order to show the ability of the proposed structure to deal with uncertainty, the motor parameters R and L are halved.

Figures 11–13 show the motor torque (Te) for normal mode, halving the parameters and doubling the parameters, respectively.



Figure 14 shows the performance of the three controllers ANFIS, Fuzzy, and PID for reference speed as a “step.”

Figure 15 is a magnification of the transient part of Figure 14.

Figure 16 shows the q-axis current of all three ANFIS, Fuzzy. and PID controllers in the “step” reference input mode.

Figure 17 shows the d-axis current of all three controllers ANFIS, Fuzzy, and PID, in the “step” reference input mode. As can be seen, the current on the d-axis is in the mA range.

Figure 18 shows the PWM signal of all three ANFIS controllers, Fuzzy, and PID, in the “step” reference input mode.

In Figure 19, part of Figure 18 is magnified.

In the following, our proposed method is compared with the method of [15]. In Figure 20, the PMSM speed is compared exactly with the method of [15] with its frame.

In order to better compare our proposed method in this paper with the reference method [15], it is assumed that at the moment t = 125 s, it is applied to the motor once as Tl = 2 Nm, and then, at the moment t = 175 s, it is separated from the motor. Figure 21 shows the state of motor speed following the “step” reference speed (applied from zero to 500 rpm at t = 50 s) with the above load conditions.

In Figure 22, Figure 21 is zoomed at t = 125 s.

In Figure 23, Figure 21 is zoomed at t = 175 s.

As expected and shown in Figures 21 to 23, the response speed of our proposed method is much faster than the reference method [15]. In general, it can be stated that in Figure 6, the neural-fuzzy controller has been able to follow the reference speed well. It should be noted that in order to train the fuzzy neural network, the input-output information of Fuzzy and PID controllers has been used. So, to put it simply, the adaptive fuzzy neural network uses the Fuzzy and PID controllers in its heart. As can be seen, the performance of the proposed method in the adaptive fuzzy neural network is better than fuzzy alone. Figures 8 and 9 showed the proper performance of the proposed method by considering the uncertainty in the parameters of the permanent magnet synchronous motor. In Figure 10, a load torque of one Nm was applied at the moment t = 100 s, which again proved the proper performance of our proposed method. In Figures 11–13, the motor torque was depicted, and finally, in Figure 14, the performance of the controllers was measured by considering the reference speed as a “step.” The simulation results showed that the performance of the control system presented in this paper is very suitable with the reference results [15], especially in the case of load application and parameter changes. Also, in reference [15], 36 fuzzy rules were used, while in our method, a total of 25 rules were defined, and in each training, the number of rules used was less than 10 fuzzy rules.
6. Conclusion
In this paper, a new method for using adaptive fuzzy neural network with combined training method was introduced as a speed controller for permanent magnetic synchronous motor. In this method, the adaptive fuzzy neural network, by identifying and approximating a set of several local controllers, has the ability to control the permanent magnet synchronous motor in a wide operating range and despite the uncertainty and load torque. Each of these local controllers performs well for a particular operating point. The experimental results show that despite the high ability and acceptability of PID control in indeterminate systems, the proposed method performs better because the proposed fuzzy neural network covers not only fuzzy control but also a number of other local controllers. Then, the proposed method was compared with two controllers, Fuzzy and PID, and the results show better performance of the proposed method than the two controllers. In future work, a structure based on type-2 fuzzy systems can be proposed that covers a wider range of uncertainty.
Data Availability
The derived data, models, or codes supporting the findings of this study are available from the corresponding author upon reasonable request.
Conflicts of Interest
The authors declare that they have no conflicts of interest.