Design of a Neural Super-Twisting Controller to Emulate a Flywheel Energy Storage System

: In this work, a neural super-twisting algorithm is applied to the design of a controller for a ﬂywheel energy storage system (FESS) emulator. Emulation of the FESS is achieved through driving a Permanent Magnet Synchronous Machine (PMSM) coupled to a shaft to shaft DC-motor. The emulation of the FESS is carried out by controlling the velocity of the PMSM in the energy storage stag and then by controlling the DC-motor velocity in the energy feedback stage, where the plant’s states of both electrical machines are identiﬁed via a neural network. For the neural identiﬁcation, a Recurrent Wavelet First-Order Neural Network (RWFONN) is proposed. For the design of the velocity controller, a super-twisting algorithm is applied by using a sliding surface as the argument; the latter is designed based on the states of the RWFONN, in combination with the block control linearization technique to the control of the angular velocity from both machines in their respective operation stage. The RWFONN is trained online using the ﬁltered error algorithm. Closed-loop stability analysis is included when assuming boundedness of the synaptic weights. The results obtained from Matlab/Simulink validate the performance of the proposal in the control of an FESS.


Introduction
For many years, flywheels made of stone or other primitive materials have been used for the operation of different mechanisms. Currently, there are mechanisms built from metal flywheels, powered by electric motors, which can work in both motor and generator mode and whose main function is to store energy in the flywheel; because of this property, these mechanisms are known as Flywheel Energy Storage Systems (FESSs) [1]. Induction motors and synchronous motors are some types of electrical machines used in the application of FESSs. For the proper functioning of the electrical grid, it is essential to have a balance between consumption and supply of electrical energy. Due to its rapid response of operation, an FESS has the ability to reduce some of the problems caused by power variations. The control and comparison between different electrical machines used in FESSs are shown in [2]. The FESSs have been studied by different authors showing the performance from different control strategies. Furthermore, in several published works, a complete FESS has been emulated through the use of electric motors where the main operation of the flywheel is the storage of mechanical energy in a rotating flywheel, which can then be converted to electrical energy using an electrical machine with power inverters [3]. An FESS has several advantages in contrast with other energy storage systems, including long useful life, and an FESS has multiple applications such as in wind generators, electric vehicles, etc. [4]. In [5], a vector control strategy was presented to emulate a FESS using a DC permanent magnet machine, where the machine was coupled to a PMSM to control the angular velocity of the flywheel in the charging and discharging stages. In [6], an integral sliding mode controller with a super-twisting algorithm was presented. In that work, the rotor side converter in the doubly-fed induction generator is used for controlling a wind generator, where the sliding surfaces are generated such that these are compatible with the errors in the stator active and reactive powers. In [7], emulation of an FESS using reconfigurable hardware test-bed of power converters was presented, where the emulation was carried out to the acceleration, deceleration and standby modes. The flywheel's model is described in the dq domain with relations among voltage, current and rotating speed. In [8], an adaptive control for high-speed FESSs was proposed where the controller has the task of controlling the DC-link voltage for the FESS and controlling the active power exchange between the FESS and the grid, whose advantage of inertia emulation is that the inertia and damping can be altered in real-time. In [9], under the assumption that all the states are measurable, a sliding mode control system for a 4-quadrant DC-DC converter was designed. Furthermore, a low voltage prototype for a flywheel application was constructed.
Recently, a control scheme applied to an FESS for the improvement of the dynamic performance of the utility grid, based on a PMSM incorporated into a multi-machine system, was presented in [10]. In that work, the speed and voltages generated were monitored by the FESS in order to generate the real and reactive power. Such control strategy was designed against three-phase faults.
On the one hand, considering that the fundamental parts of an energy storage system are the electric motors, the PMSM is a kind of synchronous motor that features low inertia, low noise, high power density and high efficiency, simple structure, and easy control. PMSMs have been used for the control of robotic movements, electric and aerospace propulsions, etc. [11]. The nonlinear mathematical model of a PMSM is strongly coupled. In addition, its parameters are not fixed but are kept within an operating range depending on the work environment. Angular velocity and torque can fluctuate in some parameter regions [12]. Recently, a feedback technique of dynamic surface control for a chaotic PMSM, based on nonlinear mappings using neural networks (NNs) to approximate the system dynamics as well as to estimate the unknown parameters, has been proposed in [13]. In [14], NNs were implemented in a PMSM for the detection of damage or failure in motor bearings by analyzing mechanical vibrations, comparing different types of NNs and the effectiveness of failure detection.
On the other hand, DC machines are generators that convert mechanical energy into DC electrical energy and motors that convert DC electrical energy into mechanical energy. Most DC machines are similar to alternating current machines in that they have AC voltages and currents inside them. DC machines have a DC output only because there is a mechanism that converts internal AC voltages into DC voltages at their terminals; since this mechanism is called a commutator, DC machinery is also known as a commutator or commutator machinery [15].
Implementation of the sliding-mode control to DC motors has been studied by different authors. In [16], an adaptive neural controller in discrete-time was proposed, where a NN was used to identify the plant model, using the Kalman extended filter training algorithm, when applying the block control in sliding mode for angular velocity control. A speed control scheme for a DC motor, based on state observers of sliding modes, was presented in [17]. In that work, the state observers estimate the angular velocity and the load torque; thus, in this way, it was possible to apply the controller, designed from the application of the exact linearization technique in combination with the supertwisting control.
The application of super-twisting control has been recently studied in [18], introducing the control to roll suppression of marine vessels subjected to harmonic wave excitations, where some of the main control objectives were to reduce the phenomenon of vibration over dynamic behaviors such as chaos, due to parametric variation.
The main contribution of this work is the proposal of a methodology to emulate a flywheel energy storage system by driving a motor-generator group formed by two machines, namely, a PMSM coupled with a DC-motor. The state variables of the system are identified via recurrent wavelet NNs of first-order trained online by the filtered error algorithm. By using these NNs, it is possible to involve unmodeled dynamics and parameter variations, avoiding uncertainty in the machine parameters. The PMSM velocity controller is designed to emulate the stored kinetic energy of the flywheel, while the DC-motor velocity controller is used to emulate the energy that is discharged towards the utility grid. Both controllers are synthesized based on the proposed NN model transformed into the block controllable form to define a sliding surface that is steered to the origin in finite time by the action of the super-twisting control algorithm. This paper is organized as follows. In Section 2, the mathematical background is presented, which is related to the kinetic energy storage, identification of the nonlinear system via recurrent wavelet first order neural network (RWFONN) using the filtered error training algorithm, and the super-twisting control algorithm; Section 3 presents the proposed methodology, where the procedures of charge/discharge are explained in detail; in Section 4, the simulation results are shown, from which the proposed methodology is validated; some important discussions are presented in Section 5; conclusion and some remarks about the application of the Neural Super-Twisting Control (NSTC) are drawn in Section 6. Furthermore, in Appendices A and B, the boundedness of the identification error and the complete closed-loop stability analysis are shown, respectively.

Mathematical Background
This section describes the energy storage in an FESS, the nonlinear mathematical representation of a permanent magnet synchronous motor and a DC-motor, the mathematical model of the dynamic behavior for an RWFONN and summarizes the filtered error algorithm, the block control linearization technique, and the super-twisting control algorithm.

FESS
The main function of FESSs is to store rotational kinetic energy, which can then be converted into electrical energy by means of an electric machine. In order to generate rotational kinetic energy, the flywheel must be driven by an electric machine that meets the requirement of operating in both motor and generator mode, allowing to convert rotational kinetic energy into electric energy and vice versa [4]. The main components from an FESS are the steering wheel, a vacuum containment to avoid loss by air friction, magnetic or metallic bearings, an electric machine capable of operating in both operation modes, i.e., motor and generator mode, and a three-phase converter to connect the FESS with the utility-grid [1]. The kinetic energy stored in the flywheel can be approximated by the following equation [19] where E k is the stored kinetic energy in J, J m is the inertial moment in N·m·s 2 , and ω m is the rated angular velocity in rad/s. In order to emulate the FESS deceleration, it is considered the next equation which defines the mechanical behavior of the flywheel when the energy is delivered to the utility grid [20], with B m the frictional coefficient in N·m·s.

Nonlinear Systems
A class of nonlinear multi-input/multi-output system given in the general forṁ where χ ∈ X ⊂ R n is the state vector of the system, f(χ, t) is the nonlinear system function vector; u ∈ U ⊂ R m is the control input vector, B(χ, t) is a non-singular matrix that characterizes the system, and g(χ, t) is a smooth function vector that represents external disturbances and parametric variations. It must be noticed that in the present work, both PMSM and DC-motor mathematical models match with that given in the general form (3).
It is important to mention that due to the purpose of this work, these mathematical models are not shown here.

RWFONN
First-order NNs are used for system identification as well as to design neural controllers for some electrical, mechanical or electromechanical systems. A novel neural identification scheme, namely a Recurrent Morlet Wavelet Neural Network (RMWNN) also known as RWFONN, based on a recurrent high-order neural network (RHONN) structure was proposed in [21]. In the NN propose in this work, the classical sigmoid activation function has been replaced by a Morlet wavelet function. The general structure from an RWFONN is given by [22] where x i j is the state of the i-th neuron, a i j > 0 for i = 1, 2, . . ., n is part of the underlying network architecture and it is fixed during the training process, w i jk is the k-th adjustable synaptic weight connecting the j-th state to the i-th neuron, and ψ i jk is a Morlet wavelet activation function. The dynamic behavior of the whole neural network can be described by expressing Equation (4) in the vector notatioṅ where x = x 1 j x 2 j . . . x n j ∈ R n is the state vector of the NN, w = w 1 j w 2 j . . . w n j ∈ R L×n is the synaptic weights vector, with L representing the total number of weights used to identify the plant behavior, A = diag −a 1 j − a 2 j . . . − a n j ∈ R n×n is the parameter (Hurwitz) matrix, and ψ is the regressor vector. In this work, ψ(χ) = e (−χ 2 /β) cos(λχ) is the Morlet wavelet function used here as the activation function where χ is the state from the plant (Equation (3)) and the parameters β, λ are the expansion and dilation terms [22], respectively. Thus, the nonlinear system (3) is identified online by using an RWFONN (Equation (5)), where the synaptic weights vector w is adjusted via a filtered error algorithm.

Filtered Error Training Algorithm
For the application of the filtered error algorithm, this study begins under the assumption of an unknown system (3), which can be modeled (identified) by using an RWFONN structure (5). The synaptic weights are adjusted according to the following update law [23,24] where Γ ∈ R L×L is a definite positive gain matrix, ψ is the Morlet wavelet activation function, and ξ is the identification error, i.e., the difference between the states from the RWFONN (Equation (5)) and those from the plant (3), namely, ξ i j = x i j − χ i j . The update law (Equation (6)) corresponds to the filtered error training algorithm [23]. Since the RWFONN is given in a generalized way from the structure for a RHONN, the following theorem establishes that identification and parametric errors for the RWFONN are bounded. Theorem 1. Consider the RWFONN model whose weights are adjustable according to Equation (6) for each i = 1, 2, . . ., n;

1.
ξ i j , w i j ∈ L ∞ (i.e., ξ i j and w i j are uniformly bounded); 2.
Appendix A presents the boundedness of the identification error ξ i j given by the synaptic weights w i j .

Nonlinear Block Controllable Form
One of the main characteristics of the block control linearization technique is to transform a nonlinear system into an equivalent form expressed by first-order subsystems consisting of r blocks, which can be solved independently one from each other. Such equivalent form is commonly known as the block controlled form whose representation is described by [26]ẋ where f(x, t) is a smooth and bounded mapping, . ., r, xˆi is a nˆi × 1 vector, and the subscripts (n 1 , n 2 , . . ., n r ) define the structure of the system. The matrix Bˆi, since the fictitious xˆi +1 for eachî-th block has full rank, rank(Bˆi) = nˆi, ∀x ∈ X ⊂ R n and t ∈ [0, ∞],î = 1, . . ., r. Therefore, in this work, the block control technique is applied to the NN structure (5) to define a sliding surface, which is the argument of the super-twisting controller.

Super-Twisting Control Algorithm
The first-order sliding mode has long been used as a robust control technique to cancel nonlinear terms and uncertainties due to external disturbances in a system, but its main disadvantage is the presence of the chattering effect, which induces vibrations in the controlled system. In order to reduce the chattering effect, high-order sliding modes have been used. A particular case is the super-twisting algorithm (STA), which has been playing a very important role in sliding mode controllers. The super-twisting control (STC) algorithm of second-order can be applied to systems where the control appears in the first derivative of the sliding surface. The application of the STC allows to cancel perturbations and nonlinearities, forcing the sliding surface toward zero in finite time. Furthermore, the states that define the sliding surface are directed to zero with asymptotic motion. The dynamics of the sliding surface are known as sliding mode movement, and it is characterized by being a reduced-order system [27,28].
The sliding surface for the NSTC is defined from the nonlinear system once the latter resembles the block controllable form (7) for the variable on which the control input of the system appears. Therefore, the sliding surface is [29] where the dynamics of the sliding surface (Equation (8)), involving the STC algorithm and the system (7), take the forṁ with λ s = λ s11 0 0 λ s22 and α s = α s11 0 0 α s22 diagonal matrices. Then, the super-twisting control law provides finite-time convergence to zero, simultaneously s andṡ, where the term λ s |s| 1 2 sign(s) commutes its gain at high frequency for giving robustness to annul the nonlinearities f r (x r , t), and to cancel the external disturbances g r (x r , t), while the term u s reduces the chattering effect and the steady state error [28].
In order to ensure the stability of the system with the super-twisting control law (Equation (9)), the control matrix gains λ and α are holding to the following restrictions: where the disturbance norm is defined as |f r (x r , t + g r (x r , t| = δ|s| 1/2 , for δ > 0. The inequalities in Equation (10) are defined in the stability analysis presented in Appendix B.

Proposed Methodology
This section describes the procedure for emulating the FESS through a group motorgenerator formed by two electrical machines mechanically coupled. The angular velocity of the PMSM, when it is working in motor mode, is controlled in order to emulate the storing of energy, whereas the velocity for the DC-machine is controlled emulating the discharge of the flywheel where the PMSM is now working in generator mode. The FESS's emulator scheme is shown in Figure 1. The procedure followed to the emulation of the FESS is explained next: • The charging procedure (storing kinetic energy in the flywheel). This procedure consists of the PMSM in the dq coordinate frame [30] working in motor mode to the control the angular velocity through the RWFONN using the block control linearization technique. In this scenario, the kinetic energy is stored in the flywheel (dotted red block in Figure 1); • Discharging procedure (releasing energy). In this stage, the stored energy is now transferred to the PMSM working in generator mode. This scenario is considered in the case when there exists an electrical failure in the utility grid or when the flywheel is required to compensate with active power to the utility grid to solve a problem of the power management office, and the velocity controller for the DC-motor emulates the deceleration of the flywheel through the use of Equation (2). The flywheel energy discharge is emulated by the DC-machine (dotted blue block in Figure 1).
In this work, the sliding surface defined in Equation (8) is designed through the transformation of the RWFONN to the block controllable form involving the dynamics of the tracking error, such that this transformation resembles the structure described in Equation (7). By applying the super-twisting algorithm to the system (7) and using the RWFONN (Equation (5)), trained with the filtered error halgorithm (6), the result is the NSTC system, which is uniformly ultimately bounded (UUB). The stability proof is carried out in Appendix B.
Note that from Figure 1, the dotted blue block contains the motor-side converter gray block, where such block represents a future real-time implementation, while the dotted red block contains the gray blocks of the SVPWM and 3-phase inverter, which also represent a future real-time implementation. Additionally, Figure 2 shows a general flowchart of the proposed algorithm applied to the control of both electrical machines, namely, the PMSM and the DC-motor. Both identification and control processes are indicated separately. Note that in this figure, there are particular notations for the PMSM (ξ i , x 1 , u 1s , and ε 1 ) and for the DC-motor (ξ idc , x 1dc , u sdc , and ζ 1 ). The particular notations and the processes of identification and control will be explained in the following subsections.

Flywheel Storage System
In this section, the mathematical analysis of the stored kinetic energy from the flywheel, emulated by the DC-motor, is developed. Under the assumption that the mass is uniformly distributed and the axis of rotation passes through the mass center, the mass moment of inertia for a solid disk is given by [31] where J m is the mass moment of inertia and m, r are the mass and radius of the disk, respectively. Then, for the numerical calculation of the mass moment of inertia of the disk, when considering m = 2 kg and r = 0.3 m, Equation (11) yields Now, the kinetic energy storage equation is calculated when substituting Equation (12) into (1). Therefore, considering the angular velocity as ω m = 130 rad/s, the energy stored in the flywheel results when considering that the deceleration caused by the kinetic energy stored in the flywheel is emulated by the DC-motor and its drive. To calculate the deceleration of the emulated flywheel, from the knowledge of the mass moment of inertia in Equation (12), replacing J m in Equation (2), it is then possible to calculate the reference angular velocity ω mre f for the DC-motor and, consequently, to be able to apply the NSTC.

Nonlinear Identification and NSTC Applied to PMSM
To convert the electrical energy applied to the PMSM into kinetic energy, the PMSM is activated in motor mode with the inputs v d and v q . In the following subsections, the neural identification and the NSTC applied to the PMSM in motor mode are presented.

PMSM Neural Identification
In this work, the mathematical model of the PMSM is taken from [30], which consists of a third order nonlinear system given in the general form (3), which is modeled in a dq coordinated frame rotating at the rotor velocity. Then, the RWFONN with structure (5), proposed to identify the dynamic system of the PMSM mathematical model, is defined aṡ where the RWFONN's states x 1 , x 2 , and x 3 identify the states ω r = χ 1 (angular velocity), i d = χ 2 (d-current), and i q = χ 3 (q-current) from the PMSM, respectively. a 1 , a 2 , a 3 , b 1 , b 2 , and b 3 are positive fixed parameters; w 1 , w 2 , w 3 are the synaptic weights; ψ 1 (χ 1 ) = e (−χ 2 1 /β 1 ) cos(λ 1 χ 1 ), ψ 2 (χ 2 ) = e (−χ 2 2 /β 2 ) cos(λ 2 χ 2 ), and ψ 3 (χ 3 ) = e (−χ 2 3 /β 3 ) cos(λ 3 χ 3 ) are Morlet wavelet activation functions. The RWFONN's inputs are the same as PMSM, v d and v q . The filtered error algorithm used for training the RWFONN (Equation (14)) is performed as 3 are the respective identification errors. According to Equation (5) It should be noticed that the proposed structure (14) has only one neuron for each state, which represents a low computational burden in contrast with that from structures for high-order neural networks (HONNs). The parameters from the PMSM mathematical model are mentioned in [30], and the values are shown in Table 1 [32].

NSTC Application to PMSM
In order to control the angular velocity ω r of the PMSM, a first step toward that goal consists of transforming the RWFONN (Equation (14)) into the form (7) by using a recursive transformation of the tracking error ε i [29]. For this, the structure of the system (14) is rewritten in the vector formẋ with a 1 = 1 1 , and v = v d v q . Now, by applying the recursive transformation to the structure (15) to resemble it into the block control form, the tracking error ε 1 is defined by where ω rre f is the reference angular velocity to the PMSM, and x 1 represents the state of the neural network (15). Therefore, the tracking error dynamics are given aṡ   (15) into (17), and assigning the desired dynamics k 1 ε 1 , it yieldsε

PMSM Parameters Value
where k 1 is adjusted to vanish the tracking error. In this way, it is possible to synthesize a control law through the vector state x 2 , where the reference vector is defined as where the superscript "pinv" denotes the pseudo-inverse. Furthermore, the second error in vector form is defined as with dynamicsε Substituting Equation (15) into (21) yieldṡ Moreover, using Equations (18) and (22), the representation in the block control form from Equation (15), in terms of the tracking error ε i , is obtained aṡ Furthermore, defining the sliding surface s = ε 2 , with the relative degree from Equation (23) equals to 1, and applying the NSTC Equation (9) in (23) resultṡ where u 1s represents the control vector. Note that in Equation (23), the control input vector v = v d v q is replaced by the STC resulting Equation (24) under the fact that the tracking error variables ε 1 and ε 2 are decoupled. This latter will guarantee that the tracking errors be steered to zero in finite time. From Equation (24), selecting the sliding surface s = x 2 arises the system given by [29] s =a pinv 1 [ where Equation (25) is the NSTC applied to the PMSM through the RWFONN structure.

Nonlinear Identification and NSTC Applied to DC-Motor
In order to convert the kinetic energy stored by the flywheel into electrical energy, the PMSM must be operated in generator mode. The discharge of the kinetic energy is controlled by the angular velocity of the DC-motor, this can be achieved by decelerating the angular velocity taking into account the reference velocity generated by Equation (2).
It must be noticed that the proposed RWFONN (Equation (26)) has only one neuron for each state, in a similar way as in Equation (14), which represents a low computational burden in contrast with HONN. The parameters of the DC-motor mathematical model are mentioned in [16], whose values are shown in Table 1.

NSTC Application to DC-Motor
By following the methodology as that in Section 3.2.2, the recursive transformation is now applied to the structure (26), where the generation of the tracking error ζ 1 is defined by (27) where ω mre f represents the reference angular velocity of the DC-motor and x 1dc is the state variable from Equation (26). The dynamics of the tracking error ζ 1 is given bẏ By substituting Equation (26) into (28) yieldṡ where k 1dc ζ 1 constitutes the desired dynamics to vanish the tracking error. In this way, it is possible to synthesize a control law through the state x 2dc , so, to such an end consider Furthermore, the second error is defined as with error dynamicsζ By substituting Equation (26) in (32) it yieldṡ Moreover, using Equations (29) and (33), the block control form for Equation (26) is defined asζ Thus, based on the error dynamics ζ i , the Equation (34) represents the block control transformation with structure (26). Furthermore, from the system (26) with relative degree equals to 1, the NSTC is given bẏ It should be noticed from Equation (35), regarding the tracking error variables ζ 1 and ζ 2 , that the control input u sdc = u adc guarantees that these errors will be steered to zero in finite time.

Simulation Results
This work presents the simulation results of the NSTC for controlling the angular velocity of a PMSM and a DC-motor to emulate an FESS. The angular velocity of the PMSM is controlled to store kinetic energy in the flywheel, meanwhile the angular velocity of the DC-machine is controlled to emulate the deceleration of the flywheel by transferring kinetic energy to the PMSM working in generator mode, where it is converted into electrical energy and delivered to the utility grid. The used parameters of the motors are shown in Table 1. The simulation was performed using Matlab/Simulink (Matlab TM ) with a Runge-Kutta solver and a step size of 100 µs.

Neural Identification
This subsection presents the simulation results of the neural identification of the PMSM state variables, as well as the DC-motor state variables using the RWFONN structure.

PMSM States Identification
For the neural identification of the PMSM states, the parameter values are: a 1 = 6000, a 2 = a 3 = 4000 and b 1 = 6000, b 2 = b 3 = 4000; the parameters for the Morlet Wavelet activation functions are: β 1 = 75 × 10 3 , β 2 = 22 × 10 3 , β 3 = 35 × 10 3 , λ 1 = λ 2 = λ 3 = 0.001; the parameters of the filtered error are: γ 1 = γ 2 = γ 3 = 855 × 10 2 . In Figures 3-5, the neuronal identification of the PMSM states is shown, where, in Figure 3 the identification of the angular velocity is the red dashed line that represents the angular velocity of the PMSM (ω r ) and the blue continuous line represents the state of RWFONN (x 1 ). In order to show the convergence of these results, the initial conditions are given as: ω r = 0 and x 1 = −1. Note that in the detail of the figure, the identification convergence is given in 0.0002 s, approximately. The transient is shown when the PMSM is started in the energy storage, where the velocity response has a settling time of 0.15 s, approximately.
The identification of current i d is presented in Figure 4, where the red dashed line represents the current of the PMSM (i d ) and the blue continuous line represents the state of RWFONN (x 2 ); the initial conditions are given as: i d = 0 and x 2 = 0.5. The identification convergence is given in 0.0003 s approximately, as is shown in the detail of the Figure 4. In the transient response, the inrush current i d achieves a maximum value of the 132 A with an oscillation frequency of 0.0014 Hz. As it is shown, the identification process is effectively realized.
In Figure 5 the identification of current q is shown, where the red dashed line represents the current i q of the PMSM, and the blue continuous line represents the state of the RWFONN (x 3 ), and where the initial conditions are given as: i q = 0 and x 3 = −0.5. The identification convergence is given in 0.0003 s, approximately. Figure 5 shows the transient when the PMSM is started, and in the process of energy storage, the inrush current i q achieves a maximum value of the 153 A with an oscillation frequency of 0.0489 Hz. In the transient, the identification procedure is more demanding and is effectively realized.
In Figure 6, the neural identification of the angular velocity of the DC-motor is shown. In this figure, ω m is a state variable of the motor, and x 1dc is a state variable of the NN. As it can be seen in the detail of the figure  In order to make a comparison of the performance of the RWFONN used in this work, numerical simulation results about the identification process from both Recurrent Sigmoid First-Order Neural Network (RSFONN) and RHONN have been obtained. This comparison consists of using the RHONN and RSFONN structures, instead of that for the RWFONN, to the dynamics identification of the plant, training them via a filtered error algorithm. Then, from the data obtained by the identification process, the root mean square (RMS) error is computed, which represents the difference between the actual state and the estimated state when using approaches with different NNs. The comparison is made by estimating the states from both PMSM and DC-motor, where Tables 2 and 3 show the RMS for each state from both motors, respectively. It can be seen in Table 2 that the lowest RMS values (bold values) are for ω r and i d from the RSFONN and for i q from the RHONN. In Table 3, the results show that the lowest RMS values (bold values) are for ω m from the RSFONN and for i a from the RWFONN. Even when different NNs obtain the lowest RMS in the identification process, there are different reasons to consider when choosing the NN structure. Such is the case with the RWFONN, having a very single structure, for which it is easy to apply the STA, contrary to the case with the RHONN or even the RSFONN. Another important thing is that the computational burden is lower for simple structures such as the RWFONN but not for the RHONN or when increasing the high-order terms of the latter.

PMSM and DC-motor Controller-Emulation of Flywheel
In this subsection, the NSTC for PMSM and a DC-motor controller for emulating the complete system of the flywheel are presented. For the case of the PMSM, the controller is designed to control the angular velocity (ω m ) indirectly through the states of the NN, where the parameters and gains for the NSTC of PMSM are defined as: k 1 = 8000, λ 1s = 0.1, λ 2s = 2.5, and α 1s = 0.1, α 2s = 2.5.
In Figure 8, the behavior of the PMSM in motor and generator modes is shown. In the case of motor mode, the velocity tracking performances from 0 to 10 and from 30 to 52 s are shown, where the blue dashed line represents ω rre f , and black continuous line is ω m . In this time, the tracking is to ω rre f = 130 rad/s, and there is kinetic energy storage during this operation mode. A detail of the transient is shown where a fast convergence can be seen. Due to consideration of a grid failure, the case of PMSM as a generator mode is plotted during the period of time from 10 to 30 and from 52 to 70 s. In this time, the deceleration of the flywheel is emulated by controlling the angular velocity of the DC-motor (see Figure 9 on the sign named Discharge of flywheel) and in this figure, the velocity reference ω mre f (blue dashed line) is described by Equation (2) and meanwhile, ω m is the gray continuous line; a detail is shown in the middle of the figure where the very good results of the tracking can be noted. To ensure the NSTC of the DC-motor, the parameters and gains are defined as: k 1dc = 8000, λ sdc = 3 and α sdc = 3.   Figure 10 shows the PMSM velocity controller performance, where tracking velocity error ε 1 (Figure 10a) is steered to zero effectively by the super-twisting control law v q (Figure 10a). Note that the transient response at 30 s corresponds to the change from the generator to motor mode. The error diminishes to zero in 0.015 s, as can be seen in the detail of Figure 10a. Figure 11 shows the DC-motor velocity controller performance. Figure 11a displays the tracking error signal in the intervals (10-30 s) and (52-70 s), which is steered to zero in finite time by the action of the super-twisting control law shown in Figure 11b. When the tracking error is zero, then the velocity control of the DC-motor is achieved, and the control goal is fulfilled, which consists of emulating the deceleration of the flywheel.

Power Delivery
In Figure 12, the kinetic energy stored in the flywheel is shown from 0 to 10 s and from 30 to 52 s due to the fact that PMSM is in motor mode, generating 760.5 J in steady-state. From 10 to 30 s and from 52 to 70 s, the PMSM is in generator mode, and it shows the discharge of the energy when considering a fault in the utility grid or when the flywheel is required to compensate for the utility grid with active power to solve a problem of the electrical office.

Discussion
There exists a variety of three-phase electrical machines that can be implemented in an FESS, such as wound squirrel cage [34] and doubly-fed asynchronous machines [35]. In this work, we used the PMSM to emulate a flywheel storage system because, based on the literature, the small and medium capacity applications of the flywheels make it more convenient to use the PMSM since it is more efficient and less difficult to control. The doubly-fed induction generator is used more in large capacities because the control is carried out by the rotor circuit, where the power flow is proportional to the slip of the machine. Consequently, the electronic power drive is of lower capacity, near 30% of the flywheel capacity, which allows a considerable economic saving in the converter.
This proposal can be extended to other applications in energy storage systems such as power compensators in wind generators as well as wind diesel power systems, electric vehicles, direct electrical grid applications, i.e., applications where it is possible to involve charge/discharge cycles.
Regarding the advantages, this work can be used as a general methodology where it is possible to work as a motor/generator, such as wound squirrel cage, doubly fed asynchronous machines, and of course the PMSM. It is clear that this is possible by making the corresponding changes for the mathematical model of the machine to be used, which all depends on the range of speeds that it is going to operate at, and taking advantage of the benefits offered by the material with which the machine is built (low-speed FESS, or high-speed FESS [35]), and the particular features (electrical, mechanical) of the three-phase machine, etc. It is possible to control nonlinear and linear systems using the NSTC based on RWFONNs trained via a filtered error algorithm. These plants to be controlled are considered unknown regarding the parameters, and only the state-space variables are measured. This work can be extended to other three-phase machines, such as doubly fed asynchronous machines or wound squirrel cage motors.
The main limitation is that this work is an emulated system in simulation, and even when different real scenarios are considered, a real system will always show all the benefits of the proposal. Furthermore, this work is limited by the structure of the RWFONN, as even when the obtained numerical results are good, the computational process can be degraded.
The following interpretation of the results are made: the identification (Figures 3-7) results offer a good approximation of the plants by the RWFONN, and the filtered error algorithm that causes the tracking results in Figures 8 and 9 is good, including the tracking error maintained at zero for ε 1 and ζ 1 , Figures 10 and 11, respectively. This demonstrates that the proposed methodology is viable for use in the applications already mentioned. It is clear that they are considered ideal switching processes when the grid failure is presented and there is the change from motor to generator in the PMSM also in the DC-motor, such as in the case in Figures 8 and 9, from which a good tracking is noted when there is a change in the storage-discharge modes.
The perspective of this work is obtaining results when considering more real scenarios in order to have a better approximation of a real-system. This will contribute to making real-time experiments with this proposal considering different structures of NN with the same or even other control algorithms.

Conclusions
Simulation results from this work show the emulation of the FESS through identification and control of the states from the models for two different electrical machines, namely, the PMSM and the DC-motor. This is achieved through the use of a RWFONN, the block control linearization technique, and the NSTC, by controlling the velocity of the PMSM in the energy storage stage and controlling the velocity of the DC-motor in the energy feedback stage. The stability analysis demonstrates the convergence of the whole system in a closed-loop using the boundedness of the identification error. It is worth mentioning that the authors intend to continue with the study of this work in real-time until laboratories can be accessed and tests can be performed. Then, using the Bellman-Gronwall Lemma [36], it is obtained that the identification error ξ = x − χ is bounded by Proof. See Reference [37].

Appendix B. Closed-Loop Stability Analysis
In order to analyze the stability of Equations (25) and (35), a representation in scalar form is made as follows [29]:ṡ Considering µ h = |x 1 | 1 2 sign(x 1 ), x 2 as the state vector of the super-twisting algorithm, µ h can be rewritten in terms of s h , then µ h = |s h | 1 2 sign(s h ) u h and considering that the matrix P is positive definite, the derivative of µ h is defined as [38]: Equation (A3) can be expressed as the following linear system: From Equation (A2), f h is bounded with the following restrictions: Assuming that f h in (A2) is an external disturbance bounded by: To construct a complete family of strong Lyapunov functions for Equation (A2) of the form (A8) the matrix P = P > 0, the Lyapunov function can be reduced to the solution of an algebraic Lyapunov equation (ALE) [38] as: Lyapunov's candidate function can be written as follows [29,38]: Considering that the matrix A = 1 is a scalar depending on the selection of the Q matrix [38].
Proof. The Lyapunov function (A8) is continuous, positive definite and radially unbounded in R 2 , it is differentiable everywhere, except on the line s 1 = 0. As the trajectories of Equation (A2) cannot stay on this set, before reaching the origin, the derivative of V(µ) can be written from Equation (A3) as follows: Involving Equation (A6) in the term ρ of Equation (A11), it yields: Now, defining P = 1 2 k 2 h + 2k h − 1 2 k h − 1 2 k h 1 and using the standard inequality for quadratic forms where µ 2 2 = µ 2 1 + µ 2 2 = |s 1 | + s 2 2 is the Euclidean norm of µ. Equation (A11) along the solutions of the system (A2) can be rewritten as follows: V h (µ) is negative definite if Q > 0, which is the case when k h > 0. Where , therefore the matrix Q is positive definite if k h satisfies the following condition: Equations (A13) and (A14) and the fact that |s 1 | is satisfied. Now, the convergence of ξ i j should be considered, involving in this way the identification error boundedness (Equation (A1)), then, the Lyapunov function (A8) can be rewritten as follows: where the time derivative of Equation (A15) is: substituting the time derivative of ξ i 1 = x i 1 − χ i 1 , which is obtained through the filtered error algorithm (6) and is applied in Equation (A16) In order to guarantee that Equation (A17) is negative definite, the desired dynamics for x 2d is with c 1 > 0 real value. In this way, by Theorem (1) and Equation (A1), the uniformly ultimately bounded stability of the complete system is ensured.