Field Programmable Gate Array Based Torque Predictive Control for Permanent Magnet Servo Motors

With the increasing demand for legged robots, the importance of the joint drive is increasing. The dynamic performance of the inner-most torque/current control loop conditions the capabilities of the whole joint system. In this paper, a direct torque control based on a prediction model is proposed. The motor torque is estimated by considering calculation and measurement delay; error estimation and torque tracking error are observed and compensated. The control algorithm was implemented on a Field Programmable Gate Array (FPGA) board to apply the capabilities of concurrency calculation of the FPGA. The effectiveness of the proposed control algorithm was experimentally verified. Compared with the commonly used Field Oriented Control (FOC) current controller, the presented controller can not only improve the dynamic performance of the motor but also reduce the average switching times of the inverter.


Introduction
The legged robot is an important branch of the service robot, configured to mimic the movement of living things in nature. In addition, as a kind of mobile robot, the legged robot can be used for dangerous or difficult tasks which are not suitable for humans, such as planetary exploration, disaster recovery operations, anti-terrorism, etc. [1]. Consequently, the issues of legged robots, including mechanical structure, stability analysis, control and drive algorithms have become an important research direction in the field of robotics in recent years [2]. With the increasing requirement for dynamic performance, the joint drive of the legged robot becomes more and more important. The highly customized robot joints consist normally of retarders and permanent magnet servo motors (PMSM), whose power density is much higher than that of induction motors. Traditionally, the joints are controlled by the cascade control structure with position, speed and current/torque control loops. With the increasing demand for environmental adaptability, impedance control can also be seen nowadays. Independently of which control strategy is applied, the dynamic performance of the innermost current or torque control loop conditions the capabilities of the whole joint system [3].
The solution for driving a PMSM can be mainly divided into two categories, the current control and the torque control. The space vector pulse width modulation (SVPWM) is commonly used for the current control, where the reference voltage is synthesized by two neighboring candidate voltage vectors and a zero vector (see Figure 1) with a certain duty cycle calculated by the modulator. The motor current, as well as the torque generated by the SVPWM, is smooth, but the switching frequency for the inverters is constant, normally with a high value (16)(17)(18)(19)(20)(21)(22)(23)(24)(25)(26)(27)(28)(29)(30)(31)(32), even if the current reference is zero. It consequently results in high energy consumption and a low lifetime for the inverters [4]. Different from the current consequently results in high energy consumption and a low lifetime for the inverters [4]. Different from the current control, the direct torque control (DTC) estimates the flux linkage from the conducted voltage and chooses a certain candidate voltage through a lookup table for the desired torque change. Compared with the current control, the motor controlled by the DTC has a better tracking performance, but the torque ripple is also larger. Therefore, DTC is normally considered to be unsuitable for the precise servo system. During the past decades, the finite-control model predictive torque control (FCS-MPTC) method has been regarded as an alternative method to DTC [5,6], which has been widely used in the electrical field [7,8]. FCS-MPTC utilizes the inherent discrete characteristics of modulatorless power inverters to solve optimization problems [5]. It inherits the fast response features of DTC while achieving other control goals, such as low switching frequency, energy consumption and current protection by multi-step prediction and cost function construction. Due to the limitations of fixed amplitude and phase angle of the candidate voltage, the torque ripple will be large when the control frequency is low [7].
In order to reduce torque ripple, many solutions have been proposed. Some scholars have found that two vectors can be used together in a single control cycle, usually to add the zero vector after the early optimization of the voltage vector [9][10][11]. To further predict the optimal situation, the duty cycle corresponding to each alternative vector can be calculated separately [12,13]. In addition, some scholars put forward the strategy of changing the switching point [14,15]. It is also effective to introduce virtual vectors to increase the number of alternative vectors [16][17][18][19], which could improve the accuracy of electromagnetic torque and stator flux. Using more complex electrical topologies and inverters to generate more alternative vectors is another option [20][21][22][23].
In essence, whether considering the duty ratio method or the virtual voltage vector expansion method, its core is still to reduce torque ripple by increasing the amount of calculation. Therefore, with the premise of keeping the switching frequency relatively low, a better control effect could be achieved by high-frequency calculation and reasonable cost function construction [24]. In this paper, a novel predictive torque control method to drive the PMSMs is proposed. Its principle is introduced in Section 2. A Field Programmable Gate Array (FPGA) is applied to implement the control algorithm, which is introduced in Section 3. With the capability of parallel computing of the FPGA, the prediction and control period can be reduced to 10 −5~1 0 −6 s, and achieve a better control performance. In Section 4, the effectiveness of the presented method is experimentally verified and analyzed. Section 5 concludes with comments.

Principle of Predictive Torque Tracking Control
The proposed control structure is depicted in Figure 2, which combines current and torque prediction, tracking error accumulation, model error estimation and compensation. In the following text, the proposed model predictive direct torque control will be During the past decades, the finite-control model predictive torque control (FCS-MPTC) method has been regarded as an alternative method to DTC [5,6], which has been widely used in the electrical field [7,8]. FCS-MPTC utilizes the inherent discrete characteristics of modulatorless power inverters to solve optimization problems [5]. It inherits the fast response features of DTC while achieving other control goals, such as low switching frequency, energy consumption and current protection by multi-step prediction and cost function construction. Due to the limitations of fixed amplitude and phase angle of the candidate voltage, the torque ripple will be large when the control frequency is low [7].
In order to reduce torque ripple, many solutions have been proposed. Some scholars have found that two vectors can be used together in a single control cycle, usually to add the zero vector after the early optimization of the voltage vector [9][10][11]. To further predict the optimal situation, the duty cycle corresponding to each alternative vector can be calculated separately [12,13]. In addition, some scholars put forward the strategy of changing the switching point [14,15]. It is also effective to introduce virtual vectors to increase the number of alternative vectors [16][17][18][19], which could improve the accuracy of electromagnetic torque and stator flux. Using more complex electrical topologies and inverters to generate more alternative vectors is another option [20][21][22][23].
In essence, whether considering the duty ratio method or the virtual voltage vector expansion method, its core is still to reduce torque ripple by increasing the amount of calculation. Therefore, with the premise of keeping the switching frequency relatively low, a better control effect could be achieved by high-frequency calculation and reasonable cost function construction [24]. In this paper, a novel predictive torque control method to drive the PMSMs is proposed. Its principle is introduced in Section 2. A Field Programmable Gate Array (FPGA) is applied to implement the control algorithm, which is introduced in Section 3. With the capability of parallel computing of the FPGA, the prediction and control period can be reduced to 10 −5~1 0 −6 s, and achieve a better control performance. In Section 4, the effectiveness of the presented method is experimentally verified and analyzed. Section 5 concludes with comments.

Principle of Predictive Torque Tracking Control
The proposed control structure is depicted in Figure 2, which combines current and torque prediction, tracking error accumulation, model error estimation and compensation. In the following text, the proposed model predictive direct torque control will be abbreviated as MPDTC. In this paper, the value with star denotes the reference value and the value with hut denotes the predictive value.

Prediction of the Motor Torque
For a 3-phase PMSM, the voltage equilibrium equation of a PMSM is always described in the dq-coordinate frame, which rotates with the rotor.
where ω e is the electric rotational speed, Modern servo drivers are discrete controlled, so Equation (2) should be discretized by solving the equation with the current sampling period T s .
Since the magnitude order of T s is less than 10 −5 s, the terms with more than one order of T s can be ignored. With the first-order Taylor expansion of e A c T s , the discrete state equation can be approximated as follows.
To simplify the derivation in the following sections, Equation (4) will be reformed by introducing a new voltage vector V.
On the other hand, the motor flux linkage in the dq-coordinate frame can be summarized as Therefore, the torque generated by a 3-phase motor can be formulated as the function of the current, where P is the pole pair.

Choice of the Voltage Vector Considering One Step Delay
With a three-phase inverter, 7 different candidate voltage vectors can be generated, see Figure 1. Set a vector S = (a, b, c) to describe the status of the inverter, where a/b/c = 1 means the upper bridge is switched on, the lower bridge is switched off, and a/b/c = 0 means the upper bridge is switched off, the lower bridge is switched on. The vector S = (0, 0, 0) and S = (1, 1, 1) define the same status that the three phases of the motor are on equal potential. The remaining 6 statuses reform the DC bus voltage in 6 different directions as shown in Figure 1 right. These candidate vectors are described in the static orthogonal coordinate frame (αβ frame), whose α-axis matches the direction of phase a. According to the electrical angle θ from the α-axis to the d-axis, the candidate voltage vectors can be transformed in the dq-coordinate. Thus, the u d and u q in Equation (6) are determined. Figure 3 shows the time flow of the torque control. At moment k, the measured current I k will be changed toÎ k+1 under the action of V k (as well as U k ) generated between the k − 1 and k moment.Î k+1 = A·I k + B·V k (10) omachines 2022, 13, x FOR PEER REVIEW Figure 3 shows the time flow of the torque control. At m current will be changed to under the action of (a between the k − 1 and k moment. The task of the controller is to find out the most suitable vol * from 7 candidate voltage vectors to minimize the trac reference Torque received at this moment * and predictive tor ( ) Compared with the electromagnetic system, the mechanica much slower, so the rotational speed can be regarded as a constan = . A tolerance band is introduced to balance the torque trac performance, as seen in Figure 4. If the change of the reference t candidate vector can generate the torque in the band, such as the the one with the minimal tracking error will be conducted at the  The task of the controller is to find out the most suitable voltage for the next moment U * k+1 from 7 candidate voltage vectors to minimize the tracking error between the reference Torque received at this moment T * k and predictive torqueT k+2 .
Compared with the electromagnetic system, the mechanical response of a motor is much slower, so the rotational speed can be regarded as a constant value in the calculation,ω k+1 = ω k .
A tolerance band is introduced to balance the torque tracking accuracy and other performance, as seen in Figure 4. If the change of the reference torque is too large that no candidate vector can generate the torque in the band, such as the situation from k to k + 1, the one with the minimal tracking error will be conducted at the next moment. If there are more candidates which enforce the torque in the band, such as the situation from k + 1 to k + 2, the one with the minimal value of the cost function will be conducted. much slower, so the rotational speed can be regarded as a constant value in the calculation, = . A tolerance band is introduced to balance the torque tracking accuracy and other performance, as seen in Figure 4. If the change of the reference torque is too large that no candidate vector can generate the torque in the band, such as the situation from k to k + 1, the one with the minimal tracking error will be conducted at the next moment. If there are more candidates which enforce the torque in the band, such as the situation from k + 1 to k + 2, the one with the minimal value of the cost function will be conducted. Since the torque accuracy is guaranteed through the tolerance band, the design of the cost function is considered with the aspect of the switching times and the current. At Since the torque accuracy is guaranteed through the tolerance band, the design of the cost function is considered with the aspect of the switching times and the current. At moment k, a certain voltage is conducted, and the original weight of the switching times from moment k to k + 1 can be found in Table 1, where the original weight is the switching times power of 2 to avoid the value 0 multiplied in the cost function Equation (12). The cost function is designed as the multiplication of the weight of switching times and the motor predictive current, whereÎ S,k+2 is the predictive current at moment k + 2 with the certain candidate voltage S, w S is the element from Table 1 and the index factor p is applied for adapting the weight between the switching times and the current.

Compensation for the Torque Tracking Error
As a side effect, the introduction of the tolerance band will lead to a static tracking error. In order to attenuate the static error, the torque reference will be modified with the tracking error from the previous step. .
where K is the gain to be turned and T s is the control period. The effect of such a modification can be regarded as an integrator, which accumulates the previous tracking error and compensates it into the reference value with a certain factor. Besides the static error, the model used for the prediction (Equations (10) and (11)) is not free from deficiencies, since the motor resistance may be changed by the temperature, the switching should have dead time to avoid short circuits, etc. To improve the prediction accuracy, an observer is applied to estimate and compensate for the prediction error. Since the matrices A and B in Equation (10) are diagonal matrices, the observer can be designed independently. For d or q-phase, Equation (10) can be simplified as a scalar equation.
where ε denotes the lumped model error, which can be detected through the comparison of measured and estimated current.
where K p and K i are two parameters to be tuned. Insert Equation (14) into Equation (13) and substituteî k+1 with zî k and the following equation can be obtained.
Therefore, the observer is stable only if the roots of the following equation locate in the unit circle.

Implementation in FPGA
As a kind of semi-custom circuit, FPGA can hardware the system into the actual electronic circuit through the compilation and synthesis of hardware description language (HDL), which can be prepared for the development of custom-specific driver control chips. Therefore, the FPGA is applied as the platform to implement the algorithm of MPDTC proposed in this paper.
The design of FPGA adopts the top-down modular design method, including the top-level module, the core algorithm module, the peripheral interface control module and the upper computer receiving and transmitting module. Figure 5 shows the architecture diagram of the proposed FPGA drive system. Therefore, the FPGA is applied as the platform to implement the algorithm of MPDTC proposed in this paper.
The design of FPGA adopts the top-down modular design method, including the toplevel module, the core algorithm module, the peripheral interface control module and the upper computer receiving and transmitting module. Figure 5 shows the architecture diagram of the proposed FPGA drive system. A finite synchronous state machine (FSM) is used for the timing planning of the FPGA system. According to the time sequence, the FPGA system can be divided into five stages: IDLE, INITIAL, SAMPLE, MPDTC and PWM. The FPGA system is in the IDLE state at the beginning of the work. After the system reset, the system clock of the FPGA system begins to work. Then, the system runs into the INITIAL state. The controller rotates the motor to the position where the d-axis matches the a-axis. Then, the system runs into the SAMPLE state to collect the current and encoder angle signal through the ADC and digital inputs, respectively. After the signal collection, it enters the MPDTC algorithm processing state to find out the most suitable candidate voltage. Finally, the FPGA system outputs the switching signal of the selected voltage to complete a control cycle. Figure 6 shows the transition of the FSM status. A finite synchronous state machine (FSM) is used for the timing planning of the FPGA system. According to the time sequence, the FPGA system can be divided into five stages: IDLE, INITIAL, SAMPLE, MPDTC and PWM. The FPGA system is in the IDLE state at the beginning of the work. After the system reset, the system clock of the FPGA system begins to work. Then, the system runs into the INITIAL state. The controller rotates the motor to the position where the d-axis matches the a-axis. Then, the system runs into the SAMPLE state to collect the current and encoder angle signal through the ADC and digital inputs, respectively. After the signal collection, it enters the MPDTC algorithm processing state to find out the most suitable candidate voltage. Finally, the FPGA system outputs the switching signal of the selected voltage to complete a control cycle. Figure 6 shows the transition of the FSM status.

Experimental Verification
The test bench to verify the effectiveness of the proposed control method is d in Figure 7. The control algorithm is implemented in the ZynQ-7000 developmen (ALINX Electronic Technology Co., Ltd, Shanghai, China) with a sampling frequ 256 kHz and a control frequency of 64 kHz. Each four sampled phase current an angles are averaged for the controller to reduce the measurement noise. For com

Experimental Verification
The test bench to verify the effectiveness of the proposed control method is depicted in Figure 7. The control algorithm is implemented in the ZynQ-7000 development board (ALINX Electronic Technology Co., Ltd., Shanghai, China) with a sampling frequency of 256 kHz and a control frequency of 64 kHz. Each four sampled phase current and motor angles are averaged for the controller to reduce the measurement noise. For comparison, a PI current controller with the SVPWM is also implemented in the development board with a control frequency of 16 kHz, which is abbreviated as FOC in the following.

Experimental Verification
The test bench to verify the effectiveness of the proposed control method is depicted in Figure 7. The control algorithm is implemented in the ZynQ-7000 development board (ALINX Electronic Technology Co., Ltd, Shanghai, China) with a sampling frequency of 256 kHz and a control frequency of 64 kHz. Each four sampled phase current and motor angles are averaged for the controller to reduce the measurement noise. For comparison, a PI current controller with the SVPWM is also implemented in the development board with a control frequency of 16 kHz, which is abbreviated as FOC in the following. The generated signals for the IGBT are sent to a self-made power board with a threephase inverter. A high-dynamic synchronous motor EC60-647695 from Maxon (Maxon motor ag, Sachseln, Switzerland) is connected with the power board for the experiments. The parameters of the motor are listed in the Table 2.

Description
Value Unit Figure 7. Test bench.
The generated signals for the IGBT are sent to a self-made power board with a threephase inverter. A high-dynamic synchronous motor EC60-647695 from Maxon (Maxon motor ag, Sachseln, Switzerland) is connected with the power board for the experiments. The parameters of the motor are listed in the Table 2. The influence of the tolerance band (T tol ) on the control performance was investigated first, and the results are plotted in Figure 8. In the test, the torque step of 0.4 Nm is applied at t = 0.1 ms. If the tolerance is too small, there is no candidate voltage located in the tolerance band, so the choice of the voltage only depends on the tracking error between the reference and the predictive torque. Consequently, it results in a large current value of the d-axis and a high switching frequency ( f sw ). It can be seen from Table 3, that with the increasing T tol , the current value of the d-axis is decreased. However, if T tol is too large, the cost function will choose the voltage with minimal switching times and current, so the dynamic performance is damaged. located in the tolerance band, so the choice of the voltage only depends on the tracking error between the reference and the predictive torque. Consequently, it results in a large current value of the d-axis and a high switching frequency ( ). It can be seen from Table  3, that with the increasing , the current value of the d-axis is decreased. However, if is too large, the cost function will choose the voltage with minimal switching times and current, so the dynamic performance is damaged.  The tolerance band in the following experiments was set with the value of 0.08 Nm. The influence of the switching time weighting p in Equation (12) is then tested. The reference torque was given as the same as the test for . The results are listed in Table   0   The tolerance band in the following experiments was set with the value of 0.08 Nm. The influence of the switching time weighting p in Equation (12) is then tested. The reference torque was given as the same as the test for T tol . The results are listed in Table 4. The value of p has less effect on the settling time of the current or the torque. However, it is obvious that the weighting parameter p has the effect of reducing the average switching frequency. As a side effect, the meaningless current (here the current of the d-axis) is also increased, since the large value of p means the decreased relative weighting of current in the cost function. The parameter p = 0.1 and T tol = 0.08 Nm is chosen for the following experiments. With these parameters, the current of the three phases is plotted in Figure 9a. For compari-son, the phase current from the FOC is presented in Figure 9b. Because of the reduction of the unnecessary switching, the MPDTC shows a smoother phase current with less noise in some places. The parameter = 0.1 and = 0.08 Nm is chosen for the following experimen With these parameters, the current of the three phases is plotted in Figure 9a. F comparison, the phase current from the FOC is presented in Figure 9b. Because of t reduction of the unnecessary switching, the MPDTC shows a smoother phase current w less noise in some places. The step response of MPDTC and FOC is compared in Figure 10. For this test, t reference torque is switched to be −0.4 Nm and 0.4 Nm each 10 ms. The generated mo torque here is calculated offline through the measured phase current and the motor ang Compared with the FOC, the presented MPDTC decreases the torque settling time by 30 from 0.27 ms to 0.19 ms. It means the proposed method shows a better dynamic respon with fewer switching times than the commonly used FOC current control. The step response of MPDTC and FOC is compared in Figure 10. For this test, the reference torque is switched to be −0.4 Nm and 0.4 Nm each 10 ms. The generated motor torque here is calculated offline through the measured phase current and the motor angle. Compared with the FOC, the presented MPDTC decreases the torque settling time by 30% from 0.27 ms to 0.19 ms. It means the proposed method shows a better dynamic response with fewer switching times than the commonly used FOC current control.

Average
[kHz] 16.7 14.0 12.7 9 The parameter = 0.1 and = 0.08 Nm is chosen for the following expe With these parameters, the current of the three phases is plotted in Figure  comparison, the phase current from the FOC is presented in Figure 9b. Becaus reduction of the unnecessary switching, the MPDTC shows a smoother phase curr less noise in some places. The step response of MPDTC and FOC is compared in Figure 10. For this reference torque is switched to be −0.4 Nm and 0.4 Nm each 10 ms. The generate torque here is calculated offline through the measured phase current and the moto Compared with the FOC, the presented MPDTC decreases the torque settling time from 0.27 ms to 0.19 ms. It means the proposed method shows a better dynamic r with fewer switching times than the commonly used FOC current control. The benefits of dynamic performance can also be seen in the frequency domain. Figure 11 shows the tracking performance of the sine reference with different frequencies and the Bode-plot after the sine sweep. The amplitude of the reference torque is 0.3 Nm and the frequency is swept from 100 Hz to 8000 Hz. The generated torque is calculated through the measured motor current. It can be seen that the bandwidth of the torque close loop is about 5000 Hz, which also matches the result from the step response. The controlled motor can follow the sine torque reference well when the frequency is lower than the bandwidth.
The benefits of dynamic performance can also be seen in the frequency doma Figure 11 shows the tracking performance of the sine reference with different frequenc and the Bode-plot after the sine sweep. The amplitude of the reference torque is 0.3 N and the frequency is swept from 100 Hz to 8000 Hz. The generated torque is calcula through the measured motor current. It can be seen that the bandwidth of the torque cl loop is about 5000 Hz, which also matches the result from the step response. T controlled motor can follow the sine torque reference well when the frequency is low than the bandwidth.

Conclusions
A novel model predictive torque control method for PMSM is presented in this pap to meet the dynamic demand of legged robots. The motor torque is estimated considering the delay of calculation and measurement. A tolerance band is introduced balance the tracking accuracy and switching frequency. The estimating error and accumulative torque tracking error are observed and compensated. The control algorith was implemented on an FPGA board, where the torque generated by the 7 candid voltages can be calculated in parallel. The influence of the value of the torque toleran band and the weighting for switching times is experimentally analyzed. Compared w the commonly used FOC current controller, the proposed MPDTC can not only impro the dynamic performance of the motor but also reduce the average switching times of inverter.

Conclusions
A novel model predictive torque control method for PMSM is presented in this paper to meet the dynamic demand of legged robots. The motor torque is estimated by considering the delay of calculation and measurement. A tolerance band is introduced to balance the tracking accuracy and switching frequency. The estimating error and the accumulative torque tracking error are observed and compensated. The control algorithm was implemented on an FPGA board, where the torque generated by the 7 candidate voltages can be calculated in parallel. The influence of the value of the torque tolerance band and the weighting for switching times is experimentally analyzed. Compared with the commonly used FOC current controller, the proposed MPDTC can not only improve the dynamic performance of the motor but also reduce the average switching times of the inverter.