# Predictive Control for Current Distortion Mitigation in Mining Power Grids
## 2 Preliminaries
### Cost Function Formulation  
The cost Function (21) weighs, through the \(\lambda\) terms, the error of each power harmonic component delivered by the DG and its respective reference. For the fundamental component, \(P_{0}^{DC}\), a regulation around the set point \(P_{0}^{*}\) is stated according to the generation capacity or the active power transferred between two microgrids when the DG is an interlinking converter. The other harmonic components are expected to be in the range defined by \(P_{h,min}\) and \(P_{h,max}\). To avoid possible infeasibility issues, the slack variable \(P_{h,s}\) is strongly penalized, forcing the convergence of this control objective. In the same way, additional slack variables, \(P_{c,s}\) and \(THD_{s}\), are used in (18) and (20), to avoid infeasibility issues when power capacity and THD constraints are not numerically satisfied. The weighting terms were adjusted following the guidelines in [35], i.e., aiming for a trade-off between the control objectives and, if necessary, giving one objective a higher priority than the others. Other tuning methods, for instance, heuristic algorithms, such as particle swarm optimization (PSO) algorithm [36] or genetic algorithms [37], could be used. However, such methods require several tests and, in some cases, significant computational effort.  
\[J =\sum_{m=1}^{N}\sum_{h=0}^{H}\lambda_{u}\Delta U_{h}^{2}(k+m-1)+ \sum_{m=1}^{N}\lambda_{0}(P_{0}^{*}(k)-P_{0}^{DC}(k+m))^{2}+\sum_{m=1}^{N}\sum _{h=1}^{H}\lambda_{p}P_{h,s}^{2}(k+m) \tag{21}\] \[\quad+\lambda_{c}P_{c,s}^{2}(k+1)+\lambda_{THD_{s}^{2}(k+1)}\]  
The optimization problem, therefore, pursues the minimization of (21) subject to (13)-(16) and (18)-(20). This optimization problem is synthesized as a canonical quadratic programming (QP) problem, guaranteeing a global solution, being the optimized output vector composed of predicted values \(\{P_{0}^{DC}(k+m),P_{h}^{PCC}(k+m),P_{h,s}(k+m),THD(k+N)\mid 1\leq m\leq N,1\leq h \leq H\}\), and \(\{\Delta U_{h}(k+m)\mid 1\leq m\leq N,0\leq h\leq H\}\). From the MPC point of view, the values refer to the changes of the control action \(U_{h}\) required to achieve the active power reference \(P_{0}^{*}\) to the grid, and to control power harmonics \(P_{1}^{PCC},\ldots,P_{H}^{PCC}\). Note that in steady state \(\Delta U_{h}=0\) holds, the disturbances are mainly due to changes in the power harmonics profile on the load side. In the mining industry, the power consumption, and its harmonics profile, mainly depend on the features of the extracted materials [13], so the related disturbances cannot be forecast, amd only current measurements (see (15) and (16)), but not predictions, are included in the optimization problem.  
The optimization is solved for every sampling period \(T_{MPC}\), and only \(\{\Delta U_{h}(k+1)\mid 0\leq h\leq H\}\) are used in the rolling horizon scheme. Due to the computational burden of MPC increasing with the optimization vector length, the amount of harmonics to be compensated and the prediction horizon should be adjusted depending on the hardware platform where the MPC is deployed. On the other hand, convergence speed and damping are tuned according to the values of \(\lambda_{u}\), \(\lambda_{0}\), \(\lambda_{p}\) and \(\lambda_{c}\). Details about MPC deployment are provided in the next section.