A New Optimal Current Controller for a Three-Phase Shunt Active Power Filter Based on Karush–Kuhn–Tucker Conditions

This paper presents an algorithm for finding the optimal control for a current controller that operates as a part of a control system of a shunt active power filter. The algorithm is based upon the Karush–Kuhn–Tucker conditions for finding an optimal value where control signal is limited and constraints create a cube. The explicit solution of the Karush–Kuhn–Tucker problem is presented and simplified calculations are given to lower calculation complexity. The presented Karush–Kuhn–Tucker algorithm is compared with a classical PI controller. It is given the algorithm for finding the optimal parameters of the PI controller and the behavior of the PI controller is compared with the presented algorithm. Attention has been paid to the saturation of controllers in commutation states of load currents, which has a negative impact on the final performance of the controllers and the controlled shunt active power filter. The paper also presents the software and hardware platforms applied to run the presented algorithms in real-time. For both controllers, the shunt active power filter response is shown using real experimental results. The results of the experiments prove better behavior regarding the presented algorithm, especially in the case of commutative load currents, where the output signals from other controllers become saturated.


Introduction
In modern electrical engineering, it is important to ensure good power quality. It contributes to improved efficiency and functioning of a power system and connected consumers. For this reason, power conditioner systems are increasingly used [1,2].
Active power filters (APFs) are considered to be one of the best tools for harmonic reduction as well as reactive power elimination, symmetrization of supply currents, decreasing neutral current, voltage stabilization, and the mitigation of voltage fluctuations. These broad goals are achieved individually or in combination. Depending on requirements, a control system and its configurations should be chosen appropriately. The most popular APF is the shunt (parallel) APF (S-APF), which is controlled to produce the necessary compensation currents. In the area of control methods and topologies of power electronic parts, new solutions are being sought all the time.
The control system is one part of the APF design, but it is crucial. A control system is built with a variety of modules and performs various tasks. However, two modules are the most important: the control algorithm and the current controller. The main purpose of the control algorithm is to determine reference signals based on information about voltages and currents at the point of common coupling.
The main task of the current controller is to control the operation of the power electronic part. This is related to the proper tracking of reference current values.
In order to achieve the elimination of adverse current components, the applied S-APF control algorithm must appropriately determine the current components corresponding to higher harmonics, reactive power (defined for 50 Hz), and the load currents negative sequence component. This depends on the selected control algorithm. There are several methods to implement S APF control algorithms in the time domain or in the frequency domain.
A popular method regarding current controllers is the application of hysteresis blocks [3]. Hysteresis controllers require low computing effort and can be easily implemented in both microprocessor controllers and in FPGAs, operating at high sampling rates [4][5][6][7]. The current stabilization can be realized by either two-level or multi-level hysteresis blocks [8]. Hysteresis blocks can also coexist with other control blocks, e.g., PI [9,10], including an adaptive approach [5]. PI controllers lose their effectiveness along with changes in the parameters of the object, requiring retuning every time the parameters change significantly. Tuning can follow the classic Ziegler-Nichols algorithm, but modern optimization methods such as particle swarm optimization can also be used in this case [11].
PI controllers are widely used because of their performance and well-known tuning methods, but they are limited in their effectiveness because of their sensitivity to the parameters of a given system. Simulation results have claimed superiority regarding particle swarm optimization, while the Ziegler-Nichols tuning method is acceptable in a limited area of operation.
Several attempts have been made to adopt the classical Model Predictive Control (MPC) algorithm to control power electronic devices [12]. In [13], the authors present the application of the MPC to improve generated waveform harmonics. It has to be mentioned that MPC is one of the few algorithms that enables the construction of an optimal controller, considering the limits of the control signal. Predictive controllers can also be divided into two parts: proportional predictive controllers and integral predictive controllers [14]. The two-stage structure successfully stabilizes the S-APF, at the output of which there is a connected LCL filter that eliminates the switching frequency current components. The predictive method of current control for the grid-connected three-level neutral point clamped inverter is presented in [15], and the finite-set MPC that utilizes the set of possible switching states of power converters for solving the optimization problem online is investigated in [7]. Predictive controllers [16], consisting of an outer closedloop current reference control and an inner model-based predictive current controller, are sensitive to parameters and require precise tuning and stability analysis [16].
Moreover, other controller design methodologies and operating principles have been tested, such as harmonic component compensation by a deadbeat controller to guarantee a low steady-state error and fast dynamic response [17,18], a second-order sliding-mode control applied to a hybrid active power filter [19], and the global current control method where a controller consists of a linear proportional resonant controller and a non-linear sliding mode controller [20]. The authors in [21] propose and analyze the H∞ current control loop and compare its behavior to the PI controllers. Cascade controllers were also tested including two control loops: an inner loop for harmonic current compensation and an outer loop for the DC voltage control [6].
A separate group is defined by controllers with operating principles derived from artificial intelligence. These methods work well in nonlinear load cases where formal mathematical analysis is difficult. In these applications, expert knowledge-based fuzzy controllers, or learning neural networks, are applied to build viable controllers [22][23][24].
In [25], technical reviews and comparisons of fifteen control techniques have been presented, such as hysteresis-band current control, sliding mode control, negative sequence current component control, deadbeat control, predictive control, space vector modulators, delta modulation control, triangle-comparison PWM control, repetitive control, one-cycle control, and soft computing algorithms (fuzzy control, artificial neural network, genetic algorithm, particle swarm optimization, wavelet theory). This work reveals the advantages and disadvantages of the practiced control strategies. This paper is structured as follows. In the second section, the principle of the APF operation is given. This section presents the mathematical equations of the current controller.
The Karush-Kuhn-Tucker (KKT) problem is specified in the third section. The problem is solved and twenty-seven candidates for the optimal solution are explicitly presented. The simplification of the algorithm is described, which limits the number of candidates for the optimal solution to twenty-two. This section also presents the software and hardware platforms applied to run the algorithm in real-time. The fourth section covers the tests. The presented KKT algorithm is compared with the classical PI controller. It is given the algorithm to find the optimal parameters of the PI controller. For both controllers, the reaction of the S-APF is presented. It is proposed that a quality criterion is applied to the comparison of the controllers. The last section covers our conclusions. The presented solution gives the optimal control values for the APF current controller taking into account the existence of control limits. The S-APF equipped with the presented KKT algorithm shows an advantage over the PI controller in both reference current tracking and THD currents' reduction at the grid side. Figure 1 shows a block diagram of the three-phase, three-wire S-APF system studied. As a non-linear load, a thyristor rectifier with resistance load at the DC side has been used. The S-APF configuration is based on a voltage source inverter connected to a capacitor at the DC side. The reduction in unwanted load currents Il abc components is obtained by injecting equal but reverse sign compensating currents I abc , which are produced by S-APF in accordance with the control algorithms. The shape of the compensating currents is fully controlled by the S-APF and finally determines the shape of the grid currents Is abc .

Modeling of the Inverter
The T 1 , T 2 , T 3 , T 4 , T 5 , and T 6 switches are controlled by three pairs of complementary PWM signals. The T 1 , T 3 , and T 5 signals are inverted to the signals T 2 , T 4 , and T 6 , respectively. Control signals d a , d b , and d c vary from −1.0 to +1.0. They are compared to the sawtooth carrier and applied to the generation of PWM waves, as shown in Figure 2. Figure 3 presents the equivalent configurations of the inverter for the first phase for the respective states of the T 1 , T 3 , and T 5 switches. From the figures, one can derive the equation for the first phase inverter current, and by analogy, the remaining two currents can also be given.  Considering inductance L of the S-APF, the equations of the currents at the end of the switching period are as follows: where: d a , d b , d c -are control signals applied to generate the PWM waves. E a , E b , E c -are the grid voltages. I a , I b , I c -are the output inverter currents at the beginning of a switching period. T 0 -is the switching period. U dc -is the DC voltage. The aim of the inverter is to follow the reference currents (2) calculated by the controller of the S-APF.
The control vector determines the behavior of the controller. The quality of the controller can be defined quantitatively as the distance between the reference and filter currents:

Calculation Algorithm for the Optimal Control
The current controller solves the following optimization problem: where vector g i (d) defines the constraints of the control signal: By applying the KKT conditions to (5) and (6), the following conditions for the optimal solution d* can be formulated: where: The gradients of f and g i functions can be calculated from (1), (4), and (6): The constraints (6) create a box; thus, for the convex function (4) there exist twentyseven possible locations of the optimal solution: a single location inside the box, six locations at the planes, twelve at the edges, and eight at the corners. Solving the first two equations of (7) gives the following solutions: The complexity of the solutions for six µ i multipliers is similar to (10)-(12); therefore, considering the time required to perform the calculations, the calculations of µ i and the checking of the inequality conditions in (7) to obtain the optimal solution are omitted. Alternatively, the following algorithm for finding the optimal solution is proposed:
From the list of candidates, remove the solutions which violate the constraints (6).

3.
For the remaining elements, use Equation (1) to calculate the current; next, calculate the values of the penalty function (4).

4.
Select for optimal control d * , which is the element with minimum value of the penalty function (4).

Simplification of the Algorithm
The presented optimal control calculation algorithm must be calculated in real-time by the APF controller. As formulas (10)-(12) require a significant amount of calculations, it is essential to try and simplify the algorithm to reduce the computation time.
One can notice that, according to Equation (1), adding a constant value to all control signals (d a , d b , and d c ) does not change the value of the I(t + T 0 ) current. Of course, the control values have to meet the constraints. This means that by shifting the control values, the smallest control can always have the value −1.0 or the greatest control value +1.0.
Let us assume that, from the three control signals, the d a is minimal, so it can be fixed to the value −1.0. Equations (1) and (3) can be reformulated as: The new optimization problem can be stated as: and the new KKT conditions are: The respective gradients are as follows: The solution of the first two equations of (17) gives the set of possible optimal solutions. Taking into account that d a = −1.0, nine possible solutions are given as follows: The same steps can be repeated for the assumption that d b and d c are minimal. In these cases, the possible optimal sets of control signals are as follows: Like Equations (10)- (12), Equations (20)-(22) define twenty-seven control vectors, one of which has to be an optimal control. However, one can notice that: 1.

2.
In Equations (20)- (22), five rows are duplicated, so only twenty-two control vectors have to be checked to find the optimal one.
The simplified version of the algorithm works almost identically to the version presented in the previous chapter; the only difference is the use of Equations (20)-(22) instead of Equations (10)- (12) to find the optimal solution. The limited number of tested control vectors and the reduced computation complexity only reduce computation time, facilitating the implementation of the algorithm in real-time.

Proposed Control System Implementation Method
The APF controller runs on a MicroZed board [26]. The MicroZed is plugged into the carrier board containing A/D converters and an interface to the IGBT drivers (see Figure 4). MicroZed contains an integrated circuit, Xilinx Zynq, which includes two ARM Cortex A9 processors and a reconfigurable FPGA fabric. The task of the S-APF controller has been divided between both the processors and FPGA ( Figure 5): 1.
The first ARM processor runs the Linux operating system. It runs all non-real-time tasks, such as RTOS supervision, tuning parameters, network services (FTP, HTTP), on-line monitoring and communication with a user, and SCADA systems.

2.
The second ARM processor runs the FreeRTOS real-time operating system. Both processors communicate via a shared memory buffer. It performs time-critical tasks, e.g., controlling the A/D converters to read the values of voltages and currents, calculating the control values, and setting the duty cycle of the output PWM blocks. It also performs tasks related to ensuring the safe operation of the APF and supervises the sequences of safe start and termination of the S-APF operation. Most of these tasks are performed with a sampling frequency of 14.629 kHz, providing 2048 samples per 7 grid periods. The sampling frequency determines a maximum period of approximately 68 µs during which all calculations have to be performed, including the calculation of the optimal control vector presented in this paper. The implementation of the S-APF controller was made according to the Model-Based Design (MBD) principle. The MBD focuses on the modelling and validation of a model by simulation while the implementation details are hidden and performed automatically [27][28][29]. The design and simulation stages are conducted in Simulink and after the validation of the model, the C-code of the real-time controller, which is functionally equivalent to the model, is automatically generated.
Due to the high sampling rate of 14.629 kHz, FreeRTOS was used as a real-time operating system to guarantee the accuracy of the calculations. Equations (20)- (22), along with the algorithm for finding the optimal control vector, have been implemented in the "KKT solution" block ( Figure 6). The generated code with real-time kernel files is automatically compiled and an application is created that performs calculations every 68 ms. Besides the execution of the algorithm for finding the optimal control vector, the real-time application performs other functions related to S-APF control, e.g., the reading of voltages and currents from ADC converters, implementation of the PLL algorithm synchronizing the S-APF to the grid, calculation of the reference currents in the control algorithm module, and communication with output PWM blocks and functions monitoring safe S-APF operation. The algorithm is executed on the ARM A9 processor working with a 667 MHz clock. The execution time of the algorithm is about 45 ms, of which the discussed algorithm for finding the optimal control vector calculates about 13 ms.

Experimental Results
The algorithm was verified on a laboratory stand with a 30 kVA three-phase three-wire S-APF (Figure 7).
The basic parameters of the test system: supply voltages U abc 3 × 400/230 V, fundamental harmonic f (1) = 50 Hz, choke inductance at the AC side of S-APF: L = 2 mH, capacitor capacitance at the DC side of S-APF: C = 6.6 mF, reference voltage in the DC circuit U dc,ref = 800 V, switching frequency of IGBT transistors f sw = 14.6 kHz. To verify the quality of the presented algorithm, its operation with the classical PI algorithm was compared. Two series of experiments were performed for the identical non-linear load, one for the PI algorithm and the other for the presented algorithm for finding optimal controls. In both cases, the accuracy of following the reference current values was applied as a quality criterion, defined by Equation (23).
In the case of the PI controller, the value of criterion (23) depends on the settings of the K p and K i parameters. The parameter values optimizing the cost function (23) were obtained by scanning the values in the neighborhood of the presumed optimal values for the PI controller. Scanning was performed during the S-APF operation. The values of the criterion function for different pairs of parameter values K p and K i are shown in Figure 8. The optimal parameters of the PI controller obtained in the sense of criterion (23) are K p = 150 and K i = 0.05. An example of load compensation controlled by the PI is shown in Figure 9. Grid voltages U abc = E abc , load currents Il abc , reference filter currents If refabc , filter output currents If abc = I abc , and reference and real grid currents Is abc , Is refabc = Il abc − If refabc , respectively, are presented. Additionally, the value of the DC circuit voltage U cap = U dc and the output from the PI controller d abc are presented. The THD factor of the load current is 33%. The filter operation reduces the THD of the grid currents to a level of 19.5%.  Figure 10 shows the regulation error as the difference between the reference and actual filter current. In the presented time horizon, the cumulative control error (23) is equal to approximately 2600. One can notice that the commutation changes in the load current have the greatest impact on the error. The PI controller saturates in these cases, going into a state that can be interpreted as a lack of feedback. It results in a high THD grid current level due to a lack of good compensation of rapid commutation changes in the load currents, which is a characteristic state of operation of power electronic systems. The results of the presented optimal controller are shown in Figure 11. It can be observed that there is a significant improvement in the shape of the grid current Is abc in comparison to the PI controller. Of course, the optimal controller also sets the control at the limit levels, but these are the optimal values from the point of view of tracking the reference filter current. The control limit values correspond to the selection of controls located on the vertexes, edges, or planes of the control space defined by the constraints (6). The THD value of the grid currents is about 8.4%. Figure 11. Results of the optimal controller. Figure 12 shows the control error. The cumulative control error (23) is equal to approximately 1680 in this case. The impact of the rapid commutation changes on the load currents is significantly lower than that presented in Figure 10.  Figure 13 shows the percentage of harmonics in relation to the fundamental harmonic. One can notice a reduction in the level of harmonics; although, for the 17th harmonic (850 Hz), the optimal PI tracking controller increases the amplitude. There is also a more effective reduction in harmonics by the KKT controller, with the exclusion of the 19th harmonic where the PI controller is slightly more effective. Figure 13. The currents spectra of the selected phase (up to 1 kHz): blue-the load current; red-the grid current for the PI optimal controller; yellow-the grid current for the KKT controller.
Inductance L is the only parameter of the proposed controller. However, filter inductance is not the only inductance that determines the rate of current change. Since the APF inductance value is small, the line inductance may influence the filter behavior. The grid impedance is much smaller than the L impedance of the APF in the vast majority of cases. Figure 14 shows the changes in the value of the quality factor (23) as a function of the L inductance of the controller given by formulas (20)- (22). As expected, a slight increase in the APF inductance improves the results. The most important feature of the proposed controller appears to be a flat criterion function around the optimal value of the L parameter, indicating a low sensitivity of the controller to the L parameter. If one takes the quality factor of the optimal PI controller equal to 2600 as a reference point, a change in the L parameter value in the range from 1.6 to 2.8 mH still provides a controller that is better than the PI controller.

Discussion and Conclusions
Most of control algorithms do not consider the effect of saturation on control signal. An example is PID controllers, during the analysis of which an unsaturated value of the controller output is assumed. In real situations, the controller always has a limited value of the output signal because of a limited power range that can be used to control the object. Tuning such controllers to obtain the optimal behavior in terms of a given quality criterion neglects the processes of entry and exit from the saturation state. Meanwhile, saturation is an important state because it allows an object to be controlled by the extreme power value; however, at the same time, it breaks the feedback loop because the output signal of the controller does not depend on the value of the input signals.
The control method that takes into account the saturation of the control values is Model Predictive Control (MPC). MPC algorithms calculate the optimal control in a given prediction horizon, taking into account the limits of control values and the limits of state variables. Convex state and input constraints and a convex objective function require a convex optimization numerical method to calculate the outputs of the MPC controller. The presented method behaves in the same way. Depending on the state of the S-APF, it is selected as the optimal control, including boundary controls. Optimal control minimizes the control error, resulting in the three currents approaching the setpoints. Contrary to MPC, the presented method does not solve the complex numerical optimization problem but uses the explicitly given formulas. Efficient quadratic programming algorithms that rapidly solve the MPC problem also exist. Unfortunately, the calculation time remains significantly longer than the 10-20 ms period, which a control system with a sampling period of 68 ms can spend on this calculation. The explicit control formulas given enable their use in real-time control with sampling frequencies of several dozen kilohertz. The presented comparison of the optimal PI and KKT algorithms proves a better operation of the KKT algorithm both in tracking reference currents and THD reduction in grid currents.
The formulas presented for calculating optimal control (20)- (22) are calculated on modern microprocessors within several dozens of microseconds. The experimental results presented in this paper used APF equipped with IGBT transistors. The control computation period and the control PWM signal period were equal to each other and equal to 68 ms. Modern power electronics systems use transistor bridges made of SiC and GaN technology, operating with switching frequencies of the order of megahertz. The conversion of the presented algorithm to a fixed-point form and its implementation in an FPGA fabric may be a challenging issue. Then, in the case of SiC and GaN bridges, it would be possible to calculate the optimal control with the switching frequency determined by the PWM control signal.