# Predictive Control for Current Distortion Mitigation in Mining Power Grids
## 4 System Implementation and Results  
As (5) states magnitude and phase angle for each harmonic component, if power measurements are decomposed, then, these components can be controlled independently. In this sense, the proposed scheme for harmonics compensation uses a two-level hierarchy. The primary level is composed of a PI-based current control, where its reference is computed as a function of the local node voltage, and the power components, as shown in Figure 2.  
In order to preserve the proper synchronization, an additional PI control loop is required to adjust the phase angle, \(\phi_{h}\), according to the power decomposition estimated by a set of resonant Infinite Impulse Response (IIR-peak) filters. The resonant IIR-Peak type is a very-narrow bandpass filter, which is tuned to harmonic frequencies, preserving the magnitude inside the band, and mitigating frequencies outside it [38]. A PLL is used to estimate the instantaneous phase angle of each harmonic, which is compared locally with a phase oscillator. The whole primary control level and the three-phase three-wire power system of Figure 2 was deployed in an OPAL OP4510 real-time computer in a Hardware-In-the-Loop (HIL) configuration. On the other hand, the secondary control level is composed of the proposed MPC, which is deployed in a MicroLabBox-dSPACE platform. The QP optimization problem is solved using OPTI-CasADi [39], and voltage and current measurements, used to compute real power, were acquired via analog inputs from the OPAL platform. The control actions represented by harmonics magnitudes were sent through analog outputs to the OPAL platform. Although MPC, based on QP problems for power quality improvement, has been reported, the proposed scheme integrates power-based constraints, instead of current or voltage constraints, extending the scope of the power quality issues to be addressed. For instance, the selective harmonics compensation technique, presented in [32], can be implemented by settling \(P_{h,max}\) close to zero, whereas imbalance issues covered by [33] can be addressed by controlling triple harmonics. Another remarkable advantage of the proposed MPC is the IEEE std 1547 compliance, through harmonics management in a range, instead of a constant reference value. A detailed comparison is provided in Table 1, where the main features of the proposed scheme are compared against the approaches of [32,33]. Detailed information about the deployed algorithm used for MPC implementation is provided in Algorithm 1. Moreover, Figure 3 presents the HIL setup developed with the system parameters of Table 2.  
Figure 2: Proposed control diagram. **Inputs:** Measurements and estimations:  
\(\{[P_{1}^{PCC}(k),...,P_{H}^{PCC}(k)]\}\to From\ IIR\ peak\ filters+PLLs\)  
Set points and optimization parameters:  
\(\{P_{0}^{PC}(t),I_{1}(k),P_{Cap}\}\)  
**Outputs:**\([\mathcal{U}_{0},...\mathcal{U}_{H}]\)  
_Initialisation_ :  
```
1:State \(P_{0}^{CC}(0)=P_{0}^{*}(0)\) and compute \(P_{h,max}\) based on Equation (16). 2:for every \(k\)do
3: Compute \(P_{0}^{PCC}(k)\) and \(P_{h,max}\) based on Equations (15) and (16). 4: Update Inequality (18) based on (19). 5: Update set point \(P_{0}^{*}\) in cost function (21). 6: Solve QP problem using OPTI-CasADi framework. 7:if Optimal solution is feasible and \(t<k+T_{MPC}\)then
8: Extract \([\Delta U_{0}(k+1),...\Delta U_{H}(k+1)]\) from optimization output. 9:else
10: \([\Delta U_{0}(k+1),...\Delta U_{H}(k+1)]=0\). 11:endif
12: Send \([\Delta U_{0}(k+1),...\Delta U_{H}(k+1)]\) to integrators to update controller outputs \([U_{0}(k+1),...,U_{H}(k+1)]\)
13:endfor
```  
**Algorithm 1** DMPC solution for harmonics compensation