## 3 The Dynamic Harmonic Compensation Sliding Mode Control Method
### Design of the Current Error-Quasi-Proportional-Resonant-Sliding Mode Control Surface  
To achieve precise tracking of the current reference values in the presence of disturbances, the tracking errors for the d-axis and q-axis currents are defined as follows:  
\[\begin{cases}e_{d}=i_{dref}-i_{d}\\ e_{q}=i_{qref}-i_{q}\end{cases} \tag{12}\]  
To identify and compensate for the sixth harmonic component in the motor current, this error is fed into the quasi-proportional-resonant controller. This enables the system to achieve high gain at the frequency of the sixth current harmonic, thereby ensuring effective harmonic compensation. The harmonic current compensation is expressed as follows:  
\[\begin{cases}e_{d6h}=G_{PR}(s)\cdot e_{\text{d}}\ (s)\\ e_{q6h}=G_{PR}(s)\cdot e_{\text{q}}\ (s)\end{cases} \tag{13}\]  
Due to the continuous variation in rotor current frequency during changes in motor speed, real-time correction of harmonic compensation terms is required to suppress harmonic components in the motor control system. Since the harmonics induced by inverter nonlinearity in the d-q coordinate system appear at 6 k times the fundamental frequency, a resonant controller with the corresponding resonant frequency is considered to be cascaded with the sliding mode current loop to suppress high-order harmonics. By using the harmonic compensation current extracted by the proportional resonant controller, a new sliding mode control surface that combines current error and harmonic compensation terms is constructed:  
\[\begin{cases}s_{d}=e_{d}+e_{d6h}\\ s_{q}=e_{q}+e_{q6h}\end{cases} \tag{14}\]  
Due to the discontinuity of the sign function \(sign(s)\), which may cause significant chattering in the controller, the sign function is replaced by a saturation function \(z\) to reduce sliding mode chattering:  
\[z_{d,q}=\begin{cases}-k_{s},\ (G_{\text{PR}}(s)+1)\cdot\left(\hat{i}_{d,q}-i_{ d,q}\right)\leq-\delta\\ k_{s}/\delta\cdot(G_{\text{PR}}(s)+1)\cdot\left(\hat{i}_{d,q}-i_{ d,q}\right),-\delta<(G_{\text{PR}}(s)+1)\cdot\left(\hat{i}_{d,q}-i_{d,q}\right)< \delta\\ k_{s},\ (G_{\text{PR}}(s)+1)\cdot\left(\hat{i}_{d,q}-i_{d,q}\right)\geq\delta \end{cases} \tag{15}\]where \(k_{s}\) is the sliding mode gain and \(\delta\) is the boundary layer thickness, which is set to 1 in this study.  
By designing an appropriate control law, the state variables of the system can reach the sliding mode surface. However, merely reaching the sliding mode surface is not sufficient to meet high-performance control requirements. To further improve the tracking performance and convergence speed of the system, the exponential reaching law was chosen as follows:  
\[\left\{\begin{array}{l}\dot{s}_{q}=-\left(e_{q}z_{q}\left(s_{q}\right)+\eta_ {q}s_{q}\right)\\ \dot{s}_{d}=-\left(e_{d}z_{d}\left(s_{d}\right)+\eta_{d}s_{d}\right)\end{array}\right. \tag{16}\]  
where \(-ez(s)\) represents the constant rate reaching term in the reaching law, which ensures that the motion point reaches the sliding mode switching surface as quickly as possible during the reaching phase. The term \(\eta s\) represents the exponential reaching term in the reaching law, ensuring that the motion point maintains a high speed during the reaching phase when \(s\) is large.  
Combining Equations (1), (15), and (16), the control law for the sliding mode current controller is derived as follows:  
\[\left\{\begin{array}{l}u_{d}=Ri_{d}+L_{d}(ez_{d}(s_{d})+\eta s_{d})-\omega_{ e}L_{q}i_{q}\\ u_{q}=Ri_{q}+L_{q}\left(ez_{q}\left(s_{q}\right)+\eta s_{q}\right)+\omega_{e} \left(L_{d}i_{d}+\psi_{f}\right)\end{array}\right. \tag{17}\]