PSO Tuning of a Second-Order Sliding-Mode Controller for Adjusting Active Standard Power Levels for Smart Inverter Applications

In recent years, due to their ability to supply electricity in isolated places where building electrical transmission networks are expensive, Microgrids (MGs) have gained much attention. A new technology called smart inverters (SIs) is currently implemented in inverter-based MGs. SIs are designed to regulate energy under given standards for connecting inverters to the grid. The closed-loop control of SIs technology is still under study and improvement due to several challenges in fields such as stability and reliability. This paper proposes a DQ control for active power regulation on a single-phase voltage source inverter (SPVSI) using a second order sliding mode control (SMC-2) for addressing the abovementioned concerns. The SMC-2 tuning is performed by a metaheuristic algorithm known as particle swarm optimization (PSO). Moreover, to simulate domestic MGs, the SPSVI operation for tracking active power values is performed by ramp rate references based on standard IEEE Std 1547–2018 for inverters connected to the grid. The SMC-2 was appropriately tuned by a PSO algorithm through MATLAB™ and the system simulation through PSCAD™. The results show that the algorithm performed better compared to a classical algorithm such as proportional-integral control in terms of integral absolute error (IAE) and integral square error (ISE).


I. INTRODUCTION
T ODAY, the use of fossil fuels for electricity genera- tion is decreasing.The reasons are twofold: humanity wants to mitigate climate change, and fossil fuel reserves are depleting [1].Moreover, population and industrial growth have drastically increased the demand for energy, and fossil fuel energy generation fails to meet the electrical load.In this scenario, microgrid (MG) implementation could help to reduce the use of energy produced from fossil fuels.MGs produce electricity from diverse small sources, becoming a support entity for any electrical power system (EPS) [2].Smart inverters (SIs) are the essential core of alternate current (AC) MGs, and they generate electricity from direct current (DC) sources.They serve as energy conversion systems for large quantities of energy [3].AC MGs have been implemented in diverse applications.However, the rapid introduction of MGs has encountered some problems, such as expensive battery costs, synchronization problems with the grid, the generation of excessive reactive power, cooperation problems between various VSIs in parallel, and the null inertia of VSIs that give rise to MG instabilities.To solve these problems, many solutions have been proposed [1].
In the same field, some challenges are encountered in the closed-loop control of VSIs.The VSI control methodology is constantly under research.The most important objective is reliability, which has different conditions: maintaining active power, voltage and frequency under standard operational values [4].In this context, research on control strategies for VSIs has encountered some problems for proper regulation.The most commonly understood drawbacks are the nonlinear nature of the VSI and the intermittent response of its power devices.A nonproper control strategy leads to accuracy and stability loss, resulting in low MG reliability.The problems of reliability of SI-based MGs include management strategies, technology costs, communications, electronic converter topologies, plug and play functionalities, protection systems, etc. [3], [5].In particular, several works have considered robust and optimum control strategies to improve their performance [6], [7], [8], [9].
The known methods exhibit good performance when managing energy in SIs, while maintaining the reliability of MGs at the same time.In each experiment, they successfully controlled the voltage, active power, and frequency.However, they lack a fast response and a steady-state stability.The study of three-phase VSIs has widely been explored for its economic impact on industries, but today, single-phase VSIs (SPVSIs) are used because they are cheaper and functional.The massive integration of SPVSIs promotes self-consumption in small consumers who seek energy independence by implementing MGs in their homes [10].
The sliding mode controller (SMC) plays a crucial role when seeking optimal controllers.It is a robust algorithm applicable to linear and nonlinear processes [11].However, one of its weaknesses is the chattering effect due to the aggressiveness of the discontinuous component of the control law. 1n the other hand, the SMC presents high capabilities for robust control actions [7].A prominent example that reduces the chattering effect is the high-order SMC (HOSMC) [12].
In this article, the design and optimal tuning of a robust algorithm of HOSMC type are presented.This manuscript demonstrates that the proposed algorithm can improve the reliability problem for active power generation over conventional control methods, for example, the PI controller.Electricity generation follows linear references without the generation of reactive power.The proposal presented herein approaches a fast response in the transient regime and produces a minor steady-state error for active power tracking compared to a PI controller.The innovative contributions of this paper are highlighted as follows: • The design of the HOSMC is proposed for use in a fast dynamic system such as the SPVSI.In such converters, several authors have implemented the conventional SMC.The use of the HOSMC has been shown in the literature to avoid the effect of chattering on the control signal.• To offer a wider path for tracking the active power reference, the sliding surface for the HOSMC has a new PI form.This new form leads to an increase in the robustness and stability of the SPVSI.It overcomes the problem of nonlinearity presented in the dynamical equivalents of the SPVSI.• An intelligent algorithm such as particle swarm optimization (PSO) tuned the parameters of the HOSMC.This approach offers a more efficient solution over heuristic methods, which are used in many SMC applications that do not consider optimal values for the controller's constants.• The ramp reference values for active power generation in the grid-connected scheme are applied following the standard IEEE Std 1547-2018.Most works employ step references that do not consider the voltage and frequency stability in the grid for sudden changes in the power reference.This paper is organized as follows.Section II describes the background of the SPVSI and the mathematical formulation of the active power generation scheme in AC MGs.Section III presents the proposed control algorithm.Section IV describes the methodology developed to obtain the control law.Section V summarizes the main results and provides their discussion.Finally, Section VI offers our conclusions.

A. Modeling the Single-Phase Voltage Source Inverter
A single-phase voltage source inverter (SPVSI) generates AC voltage from a fixed DC voltage.There are several topologies for the SPVSI, but the most widely used is known as the H-bridge.In the H-bridge, the maximum AC voltage level is equal to the maximum value of the DC bus V DC .It has three output voltage levels +V DC , 0, and −V DC .Moreover, the maximum inverse voltage at each semiconductor is equal to the maximum voltage of the DC bus [13].This structure includes four power switches coupled in two branches.The switches change states according to a modulation technique from the control circuit.For most SPVSI applications, sinusoidal pulse width modulation (SPWM) is used to lighten the harmonics at the load.The SPWM compares a sinusoidal and a triangular signal to obtain the commutation states for the power devices.The states of the power semiconductor at the SPVSI are presented in Table I.
The output signal v o produces alternating voltage based on the SPWM switching logic.The grid-connected SPVSI scheme with an output filter is shown in Fig. 1.
The L, R and C elements constitute a low-pass filter that eliminates high-order harmonics. 2The cut-offf frequency depends on the grid system (50Hz or 60Hz).The SPVSI is connected to the grid v g through the line impedances L g and R g .Finally, R L is a resistive load that is related to electricity consumption [14].
Once more, Kirchhoff's voltage and current laws analysis is performed, including the voltage and impedance of the grid.In this situation, the voltage of the load is now addressed as the voltage of the point of common coupling (v PCC = v c ).The equations are: The SPVSI under study has the parameters shown in Table II.
The system (1)-( 3) models the SPVSI connected to the grid.The next step is to adapt a control strategy that keeps the active power generation under a reference value.In order to do so we relay in the high-order sliding mode controller (HOSMC).Sliding mode control (SMC) allows regulation of nonlinear process accuracy and robustness of the control action.Because of the chattering effect, the HOSMC is used [15].In the next section, a brief review of the formulation of the control algorithm is presented.

III. THE CONTROL ALGORITHM
The system of ordinary differential equations (ODEs) (1) to (3) can be written in the following form: where x is the state variable, u is the input of the system, f (t, x, u) is the function of the state variables, and u(t, x) is a time varying function of the control signal that comes from the control algorithm.For the system (1)-(3), the state variables are i Lg (t), v c (t), and i L (t) and are written in a vector , where t represents the transpose matrix.The sliding surface is required for controlling the system of ordinary differential equations (ODEs).The sliding surface is a hyperplane where the control signal follows an objective.Its purpose is to maintain the state trajectory as close as possible to the sliding surface until its path ends near zero.The sliding surface is defined by σ = σ (t, x) ∈ R. 3 Thus, the relative degree of a system is found by: where i constitutes the i-th derivative until a determinate relative degree is reached.Classical variable structure systems define the control variable u(t) as a relay output.Let us assume that t, u(t), σ (t, x) and the sign of the time derivative of σ are known.The control law of a HOSMC steers 3 For the HOSMC, the relative degree of a system represents the order of the control law.The HOMSC has order greater.σ to zero in finite time.Let us define U = {u : |u| ≤ U M } and assume that: • There exists u 1 ∈ (0, 1) for any continuous function u(t) with |u(t)| > u 1 .There is a t 1 , such that σ (t)u(t) > 0 for each t > t 1 and the control law u(t) = −sign[σ (t 0 )], where t 0 is the initial time that the control law hits the sliding surface in finite time.
and the inequality |u| > u 0 entails σ u > 0. Here, σ (t, x, u) represents the total time derivative of the sliding variable σ (t, x).• There is a 0 ≤ ∈ R in the region defined by |σ | < σ 0 such that The above conditions ensure that the control u(t) is defined no matter the starting point of the state variable and that it is stable.
Here, to reduce the chattering effect, the supertwisting algorithm is chosen.This algorithm is used for systems with a relative degree of one.This method makes the state of a function twist around the origin, while the objective derives the sliding surface and its derivatives to zero [15].
In the supertwisting control law based on the HOSMC, there are two terms.The first one is defined by its continuous time derivative, and the second represents a continuous function of the sliding variable: where: The sufficient conditions for finite time convergence of the sliding surface are defined as [16]: where W, λ, and ρ represent the gains on the HOSMC algorithm.These values are tuned using an intelligent algorithm called particle swarm optimization (SPO).This algorithm is a metaheuristic process originally developed by Kennedy and Eberhart [17] to simulate the behavior of biological systems.
The algorithm is presented in the next section.
Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.

A. Particle Swarm Optimization (PSO)
Broadly, the PSO algorithm is a searching process which explores the best tuning constants that minimize an objective function. 4First, N particles are distributed in the solution space in random points.Each particle position X i is determined by: Each particle moves with a velocity V i : The iterative process is executed when each particle updates its position and velocity.The movement of each member of the swarm is affected by its best position, namely, the iteration with the closest value to the maximum or minimum point of an optimization function experienced and the best position reached by any member of the swarm, The iteration of a new velocity value is updated based on three components: inertia, cognitive and social parameters of the swarm.In each iteration, the position and velocity variables exhibit a uniform distribution: where the sample time is t = 1, X ipbest(k) is the previous best position of each particle in the set, X inbest(k) is the previous best global position of a particle in the swarm, c 1 and c 2 represent learning factors that are constants, r 1(k) and r 2(k) are uniform distribution random numbers between 0 and 1 that tune the algorithm, and is the inertial constant taking values between 0.1 and 0.9.
The fitness function J that minimizes the tracking error of active power generation in the SPVSI was computed as follows: The mathematical optimization considers the square value of the tracking error e k between the active power of the SPVSI P k and the reference power value P ref for each k iteration in a maximum of iterations i t .The square value lets the algorithm find a minimum point of optimization.
The personal and best positions of the particles in the swarm represented a two-dimensional search space for λ and W, as seen in ( 14) to (17): The changes in positions X (k) will generate a new best position, and this point will be stored in X best(k) until a new point with better optimization results is found.The control algorithm with the tuning process is presented in the following diagram considering the topology and structure of the SPVSI (Fig. 2).
Since the control of the SPVSI is only of active power, the reference for the Q axis is zero.

IV. METHODOLOGY
In this section, the control law design is described.The dynamical equations of the SPVSI are analyzed to determine the relative degree of the system.The control law will be tuned using the PSO algorithm to minimize the quadratic error of the active power.To establish tuning parameters, Lyapunov's criteria are used.

A. Control Law Design
Before choosing a specific order of the HOSMC, the relative degree is obtained.The voltage is constant due to the grid side with a value of 230V rms , and the error of active power is achieved across the output current value.The current control error 5 : The derivative of the error is ė(t) = i L (t), where i L (t) is given in (3).The conventional sliding surface is a linear plane: σ (t) = e(t) + λė(t).In this paper, as a novelty, we propose the sliding surface σ as a PI hyperplane, and it is expressed as: This type of sliding surface reaches the error softly by the effect of integral action in the error value [18].The derivative of ( 22) is: 5 e(t, x) is referred to as e(t) for evaluating the function in a specific time.The same criterion applies to σ (t, x).
Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
Using (5), the relative degree r of the system can be determined: As a consequence, the dynamical equations of the SPVSI have a relative degree r = 1, and the second-order SMC (SMC-2) is chosen. 6A simplified model [15] for Eq. ( 8) that is linearly dependent is expressed as: where An advantage of the supertwisting, compared with other SMC alternatives, is that it does not need σ to be known [15].To establish independent active power control in the SPVSI, this proposal uses the DQ reference frame.
Using a Park transformation [19], a complex time-domain system can be converted into a DC equivalent.Since this work uses an SPVSI, it is mandatory to first obtain the alpha-beta (AB) orthogonal components.In this sense, the first-order lowpass filter is used twice to obtain the 90 • difference between the A and B signals.The low-pass filter is applied to i L and v g .
where i L b = i L and v g b = v g .The time constant τ is set based on the grid's frequency, and s represents a pole in the frequency domain.The SPVSI equivalent in AB coordinates is presented as follows: After obtaining the AB components, the DQ components can be calculated as: where X represents any value of voltage and current of the SPVSI, and T DQ is given by: The transformation is applied to voltage and current values from the VSI [20].The current controller uses the current of the DQ coordinate frame.These expressions can be expressed as: (34) 6 The control variable u HOSMC shown in Eq. ( 8) is now defined as u SMC−2 .The DQ model of the SPSVI presents coupled values that need to be solved to apply a control algorithm.The method used to avoid coupled expressions is shown in Fig. 3.
The decoupled expressions are: These new equivalent expressions are replaced in Eqs. ( 33) and (34).
As presented in Eq. ( 25), the parameter ρ = 0.50 provides maximal realization for SMC-2 [15].The control law can be rewritten as follows: To determine the effectiveness of the new proposal, two performance indices are calculated.The first is the integral absolute error (IAE), and the other is the integral square error (ISE) [21].They are defined by: The smallest value in each case will indicate the best performance of the control method.The IAE is a conventional method that quantifies objective tracking, and the ISE indicates another approach where the square error represents the precision of the controller in different situations, for example, oscillations of the system's response.

B. Stability Through Lyapunov's Function
The Lyapunov's criteria for dynamical system stability needs to define a function V * by using the sliding surface function σ .In this work, the function Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
is considered.This novel function has not been studied before and is pivotal for the stability criteria presented in this work.Then, The sliding surface σ from error signal e is chosen as a PI function in DQ coordinates σ d/q = K pd e d/q + K id/q t 0 e d/q , (44) Therefore, Lyapunov's criterion must be satisfied in the sliding surfaces for Axes D and Q.Thus, in the D-axis, the following expression is obtained: where the error in the D-axis is the difference between the current value and its reference, Hence, (45) changes to: Using (33) and taking the values u d and u SMC−2 from ( 35) and (39), respectively, the following expression is obtained: Because i > i, from (46) e(t) > 0 and therefore t 0 e(t)dt < 0 for all t > 0, then σ < 0. This result implies that to show that inequality (48) is true, it is necessary to show that: where the condition sign(σ and R id > 0, both sides of the previous inequality are positive, and therefore they provide a bound that must be satisfied simultaneously for W and λ.Thus, for a fixed W, a λ is obtained, and in the other way around, for a given λ a W is obtained which is bounded from below.Note that in both cases, there is a bound from below that must be satisfied.The condition (49) leads to a constraint that must be satisfied by λ and W at the same time.Every pair of variables provides a different scenario for the simulations.The right member of the inequality (49) is always a positive number; therefore, for a given λ, a bound for W from below will be obtained and vice versa.Thus, for a given λ o < 0, the value for W must satisfy The right-hand side of (50) is a positive number; therefore, W must also be a positive number.If λ o > 0, then two options exist.If

TABLE III PSO SCENARIO FOR TUNING THE CONTROL METHOD
then the bound for W is a positive number, and therefore W is a positive number.However, if then the bound from below is a negative number, and therefore, W can take negative values.In any case, for sufficiently large positive values of λ and W, the system will satisfy (43) as a stable system according to the Lyapunov criteria.

C. Tuning the Controller
The following pseudocode 1 shows the criterion for tuning SMC-2.The search objectives are the optimal values of λ and W.
In this approach, the PSO demands considerable computational cost, but it is stable.The SPVSI control with PSO tuning was modeled in MATLAB TM .The simulation of the scenarios was performed in PSCAD TM with the tuning values received by MATLAB TM , as shown in Fig. 4.
The PSO was adjusted to obtain a functional response based on the following parameters shown in Table III: Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.The final parameters found by the tuning algorithm are presented in Table IV.

A. Active Power Transfer Between the SPVSI and the Grid
To verify the performance of the aforementioned SPVSI connected to the grid, a computer-based simulation using PSCAD TM together with MATLAB TM is carried out.For validation purposes, the PSVSI scheme is used with the parameters from Table II.The active power transfer between the SPVSI and the grid must comply with the regulations in [22], [23].The active power transfer between the grid and the SPVSI is determined by ramp reference values to soften the energy transfer in MGs.The value of the ramp is determined to be 20% per minute of the maximum active power available.To determine the magnitude of the active power ramp, the following procedure is performed: the battery bank voltage and capacity are V bat = 400V and C bat = 100Ah, respectively.The total active power available is P tot = 40000W = 40kW, where the rate of the active ramp is defined as: In Fig. 5, the optimization cost of Eq. ( 18) for tuning SMC-2 using PSO is depicted as follows.
The optimization process illustrated in Fig. 5 demonstrates how the minimization of the fitness function changes as more iterations are carried out.A significant decrease in the cost function was observed during the first three iterations.Subsequent iterations continued to find lower costs until reaching a final value of 0.07729.One of the advantages of PSO compared to other metaheuristic methods is its ability to optimize quickly.This algorithm can find global minima, which is suitable for nonlinear and fast-dynamic systems like the SPVSI in this case study.Although other methods, such as genetic algorithms, can achieve these results, speed and cost may vary significantly compared to PSO [24], [25].
In Fig. 6, two sections have been magnified to analyze and compare the response of PI and SMC-2.The SMC-2 tuned by PSO has reached the ramp reference better than the PI controller.In the first magnified image, SMC-2 follows closer to the reference ramp.In the second magnified image, SMC-2 seeks to be closer to the constant reference signal, decreasing the error value.The rate ramp value is set in watts per second for producing/receiving energy from the SPVSI.
The voltages from the grid and the SPVSI are shown in Fig. 7.
It can be observed that both signals are synchronized in magnitude and frequency to perform the trade-off of active power.The voltage peak value is approximately 325V, and the frequency is 50Hz in both signals.The current between the grid and the SPVSI is shown in Fig. 8.
Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.The current values are the same between the grid and the SPVSI.The only difference lies in the course of the current; while the current direction from the SPVSI is positive, the current direction on the grid is negative, and vice versa.Additionally, 3 segments are chosen to note the current changes in the time domain.These segments show the current change in relation to the ramp rate for active power transfer.The values chosen indicate the moments where the ramp rate achieves values of 2A, 5A, and 8A.Due to the use of a stationary reference frame, the D and Q currents from the grid are shown in Fig. 9.
The current in Axis D changes according to the ramp rate reference.The mean value of the current in the Q-axis reaches zero with minor oscillations around this point.The SPVSI achieves stable values of 5A, 8A, and 4A.This current guarantees the trade-off only of active power without generating reactive power.
The following scenario is also presented to test the control proposal in the presence of external disturbances.The disturbances considered in this test are listed as follows: • Overcurrent in the grid of 23 A at 3 s.
• Voltage sags in the grid of 20% of V g between 16 to 17 s.• Voltage swells in the grid of 30% of V g between 26 to 27 s.Fig. 10 shows the sags and swells disturbances on the grid.In the overcurrent case, this phenomenon can be observed in the power and current figures shown below.
In Fig. 11, the effects of disturbances on the power transfer process between the grid and the SPVSI can be observed.At the time of 3 s in section A, the power peak is approximately 2 kW in the SMC-2, while the PI has a value of 2.194 kW.In this section, the error tracking criterion outlined in Eq. ( 21) is used again.At the time of 16s in section B, a lower tracking error by the SMC-2 compared to the PI for voltage sags is shown.The same occurs at 17 s, corresponding to section C for voltage swells.
In Fig. 12, the current generated on the D axis in response to external disturbances is observed.This parameter was chosen because i d (current on axis D) is directly related to active power generation.At time t= 3 s in section A, an overcurrent disturbance is seen to have a greater impact on the PI controller due to greater distortion in the current.At time t = 16 s in section B and at time t = 27 s in section C, it can be observed that the effect of voltage sag and swell causes Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.the PI controller to oscillate and takes longer to recover to the reference compared to the SMC-2.In the case of the SMC-2, it demonstrates greater robustness to disturbances without experiencing sustained oscillations.
A load is placed between the SPVSI and the grid to evaluate the performance of each controller, as shown in Fig. 1.The figures presented show the reference value represented by the load.This value is taken from a load profile of a home of low-voltage consumption.The load data represent home appliances turned on, as seen in Fig. 13 (fridge, induction cooktop, heater, etc.).
The period response for SPVSI performance is 12 hours between 6:00 and 18:00 hours.Four magnifications (A, B, C, and D) have been analyzed in the simulation.Magnifications A and B show a faster response from SMC-2 compared to PI in a change of reference by connecting/disconnecting loads.The rising time t r is taken from both signals to evaluate the fast response.This parameter measures the when the output response starts from 10% and reaches the 90% of its end value.In SMC-2, t r = 0.003508h and t r = 0.003188h for magnifications A and B, respectively, while in PI, t r = 0.003512h and t r = 0.003196h for magnifications A and B, respectively.Magnifications C and D show minor steady-state errors achieved by SMC-2 for dynamical tracking.The absolute error e A is taken from both signals to evaluate the steady-state error.This parameter measures how far the controller response is from the reference value.In SMC-2, e A = 0.99% and e A = 0.93% for magnifications C and D, respectively, while in PI, e A = 2.81% and e A = 3.47% for magnifications C and D, respectively.
In this scenario, the voltages of the grid, the SPVSI, and the load are synchronized in both magnitude and frequency to perform the trade-off of active power.In the same context as in Fig. 7, the signals achieve peak values of 325V and frequencies of 50Hz due to their synchronization.The SPVSI generates its output signals with the load demands.The currents from the grid, the SPVSI, and the load are shown in Fig. 14.
The current values from the SPVSI change according to the load requirements.The SPVSI provides enough current to stop the consumption of the current from the grid to the load.A set of 3 magnifications were performed to see in detail the current values at specific time intervals.The magnifications have been selected in 3 segments (A, B, and C) that belong to the grid, the SPVSI, and the load (Fig. 15), respectively.The segments show the generation of current values of 11A, 0.5A, and 8A due to the load demands, respectively.
The D and Q currents from the grid are shown in Fig. 16.
The current in Axis D changes according to the load demand.The mean value of the current in the Q-axis reaches zero with minor oscillations around this point.In this scenario, the trade-off of active power is guaranteed again.The maximum current consumption achieves 20A.The minor changes in current from the Q-axis do not generate reactive power, while the active power is generated from the current in the D-axis.
In Table V, the IAE and ISE indices are calculated following the equations defined in Section IV-B to determine the performance of controllers PI and SMC-2.
The standard of IEEE Std 1547-2018 [23] requires inverterbased MGs to be operated in a voltage range operation.The system in this work is recognized as Category A related to reactive power capability and voltage regulation.The proposed system covers the minimum performance capabilities needed for electric power systems, where the DG resources are fewer [23], as seen in Fig. 17 The V rms (root-mean-square voltage) value can oscillate between 0.95V N and 1.05V N , where V N is 230V (V N -nominal value of voltage).The results in Fig. 13 show proper control of the generated voltage by the SPVSI, where the values do not reach the minimum and maximum limits of the IEEE Std 1547-2018.The maximum reached value is 232.9V.
From the point of view of abnormal performance categories, the IEEE Std 1547-2018 is considered in Category I for all installations that cover minimal bulk power systems.Reliability is attainable for all distributed resources that are in common use [23].
The value of 0.5Hz is placed as the maximum and minimum deviation limits for inverter-based MG operation.The DQ algorithm synchronizes to grid frequency in less than 1s, as seen in Fig. 17.In addition to the ramp active power references, the SPVSI maintains the frequency at 50Hz.The small variations do not represent a significant disturbance that may lead to instability.These oscillations depend on the synchronization of the DQ reference frame.
One additional feature of the analysis to determine the applicability of control strategies is measuring the time it takes for the algorithm to calculate its control law.To measure each Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.control iteration, two points were considered.The generation of the error signal was taken as the starting point, and the endpoint was the generation of the control signal that must pass through the inverse DQ to AB coordinate transformation.As seen in Fig. 18, the following time measurements depict the calculation of the control law in the scenario of tracking active power ramps.
From the results in Fig. 18, no significant differences exist in the time that each algorithm takes to generate the control signal.The average calculation time for PI is 0.18μs, while  for SMC-2, it is 0.27μs, with a ratio of 0.68:1.The maximum time employed by for PI to calculate the control law is 29.10μs while for SMC-2 the time was 58.40μs, with a ratio of 0.49:1.In the case of the minimum time, both algorithms have equal times of 0.10μs as seen in the results of Table VI.These results show that SMC-2 does not represent a high computational cost algorithm for its implementation in electronic power converters.Industrial inverters  contain high-quality electronic processors, which are DSPbased microcontrollers with clock frequencies around 60MHz (0.016μs) [26].

B. Discussion
Since most common home appliances consume AC energy, SPVSI control is fundamental in MGs.The criterion in this study is based on technical details considered from the standard IEEE Std 1547-2018.The approach to manage the energy between the grid and the SPVSI is achieved in this work by proper closed-loop control.
The control algorithm in VSIs represents one of its essential components in closed-loop control.Generally, the PI regulator is used as a control algorithm in most SPVSIs.This algorithm is simple but efficient for accomplishing control objectives such as fast response or lower steady-state error.Most manufacturers continue to use PI for the abovementioned reasons.Other control structures may be more complex but present important advantages, as it has been shown in this work.The fundamental structure of SMC-2 can be implemented as it contains parameters similar to those of the PI regulator.As a novelty, the authors have implemented a PI-type sliding surface in this work.The integral part of the PI surface presents advantages in target reachability compared to typical linear sliding surfaces.
Currently, electrical systems depend on reliability parameters to offer a better experience to their final users.The authors demonstrated that reliability was reached through the higher quality performance of the SPVSI with the SMC-2.The response was quicker than using a PI control in the ramp rate references and the load tracking tests.Additionally, the stability during all the SPVSI performances showed that the closed-loop controller can achieve objectives such as synchronization and proper active power trade-off, while keeping objective values of voltage and current.
The improvement in energy management on MGs through better control algorithms improves MG efficiency.These actions can support the idea of increasing the performance of MGs for low-scale consumers, particularly in places where distributed generation sources are not abundant.
As discussed in the introduction, SIs represent a new technology trend with the constant evolution of MGs.These electronic devices contain technical developments in various areas, such as control, communications, and electrical protection.Studies such as this one can support novel proposals SIs to support the constant research in the of MGs.
Future works might consider other intelligent algorithms for tuning SMC-2.PSO is one of many metaheuristic algorithms that can be employed for optimization.Using other metaheuristic methods can generate novel proposals or even the online tuning of SMC-2.

VI. CONCLUSION
This paper presents the design and implementation of a HOSMC for an SPVSI connected to a grid.The active power, based on parameters of the electrical regulations IEEE Std 1547-2018, is produced and received in the SPVSI.
SMC-2 was implemented using the supertwisting algorithm.This algorithm helped to avoid the chartering effect but without decreasing the robustness of the algorithm.The performance indices (IAE and ISE) showed the best results coming from the algorithm used in this work.The results on ramp reference tracking showed precise control without damping and oscillations.
The tracking of reference values of active power complies with stability values of voltage and frequency on standard IEEE Std 1547-2018.These approaches are not yet covered for advanced algorithms.SMC-2 dealt with the coupled model of the SPVSI in the DQ reference frame.The robustness of SMC-2 surpasses the model uncertainties presented by parasite capacitance on the SPVSI.The PSO method is suitable for finding the controller's parameters.The procedure followed in this work separately developed the greater cost computational algorithm in MATLAB TM to give the control law's parameters to the main simulation in PSCAD TM .

) Algorithm 1 2 :
Pseudocode for PSO/SMC-2 Tuning Input: N-particle population; Output: Optimal output value Initialization: position and velocity of each particle for λ and W; LOOP Process 1: for Fitness value calculation to minimize error tracking (J); do Update personal and global best (X (k) and X best(k) ); 3: end for Meeting stopping criterion; 4: return Optimal output value;

Fig. 8 .
Fig. 8. Grid current in the time domain.

Fig. 12 .
Fig. 12. Scenario of active power response against disturbances in axis D. .

Fig. 15 .
Fig. 15.Grid, SPVSI and load current segments in the time domain.

Fig. 16 .
Fig. 16.SPVSI currents in Axes D and Q with the load demand.

Fig. 17 .
Fig. 17.Vrms voltage and frequency on the grid for the SMC-2 controller.

Fig. 18 .
Fig. 18.Calculation time performance of the control law.

TABLE I STATES
OF POWER SWITCHES ON THE SPVSI Fig. 1.Grid connected SPVSI scheme.

TABLE V PERFORMANCE
COMPARISON BETWEEN SMC-2 AND PI

TABLE VI TIME
PERFORMANCE COMPARISON BETWEEN SMC-2 AND PI