Real-Time Fuzzy Logic Based Energy Management System for Microgrid Using Hardware in the Loop

<jats:p>This research presents a hierarchical energy management strategy for isolated microgrids (MG). The strategy’s objectives are achieved through a master-slave topology where local controllers are managed and controlled through a central controller. This can provide many technical advantages, particularly regarding the microgrid’s performance and the supply of energy. The local controller is designed to meet the local objectives of the microgrid, such as stabilization of DC voltage and maximization of sources’ extracted power. The objectives of the central controller are achieved through a centralized approach based on fuzzy logic to preserve battery life and manage the energy balance between generation and consumption. The microgrid’s performances were investigated under a steady-state and faulty regime. A Hardware in the Loop (HIL) test based on the Simulink platform is established by RT-LAB real-time simulator. Results are presented to validate the proposed hierarchical control. The OP1400 test bench, based on the OP4150 digital simulator, is utilized to test and validate the proposed hierarchical control strategy. The results are compared to international standards IEEE 1547 and IEC 61727, which demonstrate excellent consistency.</jats:p>

section_content: Renewable energy has gained significant attention in recent years due to growing concerns about the environment. The International Energy Agency (IEA) has projected that conventional energy sources will soon be unable to meet the increasing demand for energy, making renewable energy systems (RESs) a key solution to the current global energy crisis [1]. To address this, research community are focusing on improving the efficiency and reliability of renewable energy systems. RESs such as solar and wind power are pollution-free and environmentally friendly, making them an attractive alternative to fossil fuels. In addition to environmental concerns, there are also issues related to the ability of the traditional power grid to meet the energy needs of the world [2, 3]. In rural areas, it is often not cost-effective or technically feasible to connect households to the utility grid. Microgrids (MGs) powered by renewable energy can provide a solution to this problem by supplying electricity in either connected or standalone mode. As the transformation towards cleaner and more efficient energy systems, the development of microgrids becomes increasingly important. 

Overall, the increasing attention on distributed generation (DG) and renewable energy systems (RESs) is driven by the need to address environmental concerns and the growing demand for energy. Improving the efficiency and reliability of renewable energy systems, and the development of microgrids, are key ways to address these challenges and provide sustainable energy solutions for the future. 

Microgrids, which are small-scale power systems that can operate independently or in conjunction with the main power grid, are a promising solution for providing energy in
section_name: Introduction 1.General Context and Motivation

section_content: Generating a defined set of criteria and specifications that can be used by the researchers involved; •

The ability to simulate complex systems under normal operating conditions as well as under extreme conditions;
section_name: •

section_content: Investigating the behavior of a system with regard to faults and defects in a simulated model, which is much safer and less expensive than testing on real hardware.
section_name: •

section_content: In [9], authors present the development of an islanding control strategy for a Photovoltaic (PV) based microgrid using a fuzzy logic controller. The algorithm uses the estimated power generated by the photovoltaic panel, which is used to decide when the switches can be connected or disconnected using a fuzzy-rules algorithm. The research presented in [10] introduces a supervisory control to fulfill the load power demand and Energies 2023, 16, 2244 3 of 21 monitor the batteries' State of Charge (SoC) to preserve their lifetime. In this study, the MG response under fault conditions was not examined. Based on the same strategy in [11], authors evaluated the power flow within a microgrid comprised of a PV generator, a Wind Turbine (WT) generator, and a storage system. Multiple components of the energy storage system make the control strategy more challenging. Indeed, the adopted EMS shows fluctuations and AC voltage drops. The aforementioned studies propose different energy management approaches that are based, in most cases, on fuzzy logic. Since they have been validated through simulation, it will be very interesting to see how they perform in real-time using simulators such as Opal-RT, National Instruments' RTDS, or Typhoon's Hardware in the Loop (HIL) Simulator, among others. 

A real-time examination using the RT-LAB simulator is performed in [12] to enhance a PV generator's performance and efficiency within a microgrid. The PV local controller is studied and developed in order to achieve an optimum operating mode of the PV arrays. This is accomplished by lowering the DC-DC converters' output ripple, which impacts and stresses sensible electronic loads. However, the development of the central controller is not reported in this study. To identify a feasible solution to the challenge of power dispatching within a microgrid without overloading one DG, authors in [13] establish a battery local controller. The proposed approach is based on a fuzzy logic controller, which is considered an effective technology in this study. Applying the same approach, the authors in [14] demonstrate that combining multiple energy storage systems, such as supercapacitors and batteries, improves the energy flow and batteries' lifetime. The authors of [15] propose a vector control design to manage the power exchange within a microgrid. The behavior of the developed algorithm is investigated in real-time using OPAL-RT (OP 4510) simulator. Relying on a well-structured control strategy, an optimal design layout and a hierarchical energy management strategy for a DC microgrid are presented in [16]. This study schedules a hierarchical level of EMS, including local and system control layers, to enhance the robustness and economy of DC-MG in steady-state mode. The strategy is tested using an HIL simulation. Based on the same approach and emphasizing the analysis of the microgrid's performance under fault conditions, an effective energy management system implemented on a FLC is presented in [17]. Under both normal and fault regimes, the suggested strategy's robustness and effectiveness are evaluated. Findings confirm that the proposed energy management technique performs efficiently under the simulation conditions, although the study lacks validation using real-time simulators.
section_name: Related Works

section_content: An enhanced energy management system based hierarchical control is presented in this paper. The dynamic performances of the MG are improved and assessed in both fault and steady-state modes. Furthermore, the proposed EMS is validated through real-time simulation using an OP1400 test bench. While there is a significant amount of research on MG's Energy Management Systems, it is typically limited to the permanent mode. The performance of the MG under fault circumstances is a less explored topic. The primary focus of this paper is to address this gap in the literature by investigating the performance of the proposed EMS under fault conditions. Indeed, the objectives of this research are as follows:
section_name: Contribution and Paper Organization

section_content: Develop Local Controllers (LCs), each of which is associated with an energy source or a storage system. The PV LC is responsible for maximizing the power extracted using Maximum Power Point Tracking (MPPT) techniques. The battery's LC maintains the voltage at the load bus, regardless of fluctuations in weather conditions or consumption.
section_name: •

section_content: Design a Central Controller (CC) to ensure coordination between the various LCs, while implementing adequate communication. Fuzzy logic is employed to provide quality voltage and frequency and guarantee the load and power supply balance within the microgrid.
section_name: •

section_content: Stabilize the microgrid under all possible operating conditions (normal and faulty)

• Establish HIL test based on the Simulink platform and RT-LAB real-time simulator to validate the hierarchical control. OP4150 is used as a digital simulator in this study.
section_name: •

section_content: Check the HIL results for compliance with IEEE 1547 and ICE 617227 standards, which regulate the performance of the microgrid. 

The rest of this paper is structured as follows. The energy sources and storage system of the studied microgrid are modeled in Section 2. The system's electrical layout is extensively discussed in Section 2. The microgrid fuzzy logic-based control design and implementation is carried out. In Section 4, the strategy validation and results discussion are illustrated. The conclusion is outlined in Section 5.
section_name: •

section_name: Microgrid Model

section_content: Numerous electrical models are reported in the literature to model a PV cell [18]. The one-and two-diode circuits are the most commonly adopted model to represent crystalline cells. Figure 1 exhibits the one diode electrical circuit of the PV cell and its current-voltage characteristic is expressed as follows:

where I pv is the photovoltaic current, V d is the diode voltage, I Gc is the generated current, I 0 is the saturation current of the solar cell, T c is the cell's absolute temperature, R p is the parallel resistance, q is the absolute value of electron's charge, and k is the Boltzmann constant. 

As the output power of a single solar cell is low, several solar cells need to be connected in series and/or parallel depending on the desired output voltage range. The equivalent model of a PV panel comprising a set of N s of solar cells in series in one branch and N p in parallel is illustrated in Figure 2. The series connection of solar cells expands the output voltage, while the parallel connection of solar cells expands the output current dimension. The series-parallel connection, on the other hand, allows for more power from the solar panel [19].
section_name: PV Model

section_content: There are several types of electrical machines that can act as generators in a wind power system. Technical and economical factors determine the type of machine for each application. The simplicity and low cost of the Permanent Magnet Synchronous Generator (PMSG) explain their dominance. According to research conducted in [20, 21], the mechanical power of a wind turbine can be expressed as follows (2):

where P m is the mechanical output power, λ is the tip speed ratio of the rotor blade, C p is the performance coefficient, β is the blade pitch angle, ρ is the air density, A is the turbine spin area, and V wind is the wind speed. 

The ratio between the power extracted from the wind and the total power theoretically available is, therefore:

The characteristic representing the performance coefficient C p from Equation (3) is shown in Figure 3. where is the photovoltaic current, is the diode voltage, is the generated rent, is the saturation current of the solar cell, is the cell's absolute temperature is the parallel resistance, q is the absolute value of electron's charge, and k is the Boltzm constant. As the output power of a single solar cell is low, several solar cells need to be nected in series and/or parallel depending on the desired output voltage range. The eq alent model of a PV panel comprising a set of of solar cells in series in one branch in parallel is illustrated in Figure 2. The series connection of solar cells expands output voltage, while the parallel connection of solar cells expands the output cur dimension. The series-parallel connection, on the other hand, allows for more power f the solar panel [19].
section_name: WT Model

section_content: There are several types of electrical machines that can act as generators in a wind power system. Technical and economical factors determine the type of machine for each application. The simplicity and low cost of the Permanent Magnet Synchronous Generator (PMSG) explain their dominance. According to research conducted in [20, 21], the mechanical power of a wind turbine can be expressed as follows (2):

where is the mechanical output power, λ is the tip speed ratio of the rotor blade, is the performance coefficient, β is the blade pitch angle, ρ is the air density, A is the turbine spin area, and is the wind speed. The ratio between the power extracted from the wind and the total power theoretically available is, therefore:

The characteristic representing the performance coefficient from Equation (3) is shown in Figure 3.
section_name: WT Model

section_content: The most commonly used battery model is shown in Figure 4 [14, 22]. It consists of an ideal voltage source E b and a constant equivalent internal resistance R bat. The voltage across the battery and the capacity model are given by ( 4 ) and (5), respectively.
section_name: Battery Model

section_content: The most commonly used battery model is shown in Figure 4 [14, 22]. It consists of an ideal voltage source and a constant equivalent internal resistance. The voltage across the battery and the capacity model are given by ( 4 ) and (5), respectively. = ± (4) where represents the voltage across the battery and represents the battery current, respectively, is the electromotive force of a cell, is the internal resistance, and represents the number of cells in series.
section_name: Battery Model

section_content: 1. 67 1 + 0. 67

. 

(1 + 0. 005)

where is the nominal battery current, is the nominal capacity of the battery (Ah) in a constant current discharge regime for 10 h ( = 10 ), and ΔT is the battery heating compared to the ambient temperature.
section_name: 𝐶 =

section_content: Hierarchical control is performed through two control layers-local and central-to optimize microgrid operation in diverse conditions, as shown in Figure 5. The fluctuating profile of the PV and WT sources affects the stability of the microgrid. As a result, the frequency and voltage may diverge, requiring appropriate control. DC/DC converters in distributed power generation are managed at the local control layer using a wide variety of control strategies, each designed for the specific characteristics of the converters in question. 

The proposed LC is developed according to the following objectives:

• Control the boost converter to extract the maximum of power from DGs using the perturb-and-observe (P&O) algorithm.
section_name: MG Hierarchical Control

section_content: Limit the WT speed using a PI regulator.
section_name: •

section_content: Regulate the AC voltage and frequency.
section_name: •

section_content: Extend the longevity of the batteries by avoiding repeated cycles of deep charging and discharging.
section_name: •

section_content: Control the bidirectional converter in order to maintain the desired voltage on the DC bus. 

To increase microgrid stability and energy flow, EMS-based fuzzy logic distributes power between sources, batteries, and dump load. The central controller is in charge of this process.
section_name: •

section_name: Local Control

section_content: As depicted in Figure 5, the MPPT control approach is utilized to harvest the maximum power from the PV system under various operating scenarios. Typically, the DC/DC converter of a PV system operates in MPPT mode to maximize the amount of energy produced by the source. There are several MPPT methods to locate the maximum power point (MPP). The P&O method is the most popular. The P&O method can be implemented in low-cost digital devices while still providing high robustness and performance [23]. The circuit diagram in Figure 6 shows the boost converter that allows the PV generator to operate at maximum power through an MPPT controller.
section_name: PV Local Controller

section_content: As depicted in Figure 5, the MPPT control approach is utilized to harvest the ma mum power from the PV system under various operating scenarios. Typically, the DC/ converter of a PV system operates in MPPT mode to maximize the amount of energy p duced by the source. There are several MPPT methods to locate the maximum power po (MPP). The P&O method is the most popular. The P&O method can be implemented low-cost digital devices while still providing high robustness and performance [23]. T circuit diagram in Figure 6 shows the boost converter that allows the PV generator to erate at maximum power through an MPPT controller. Figure 7 shows that the connected loads severely impact the PV generator's operation. For distinct values, the best adaptation occurs at one operational point called MPP. Consequently, for the same irradiance, the power delivered by the PV generator will be different depending on the power requested on the DC bus. Figure 7 shows that the connected loads severely impact the PV generator's operation. For distinct R i values, the best adaptation occurs at one operational point called MPP. Consequently, for the same irradiance, the power delivered by the PV generator will be different depending on the power requested on the DC bus. Figure 7 shows that the connected loads severely impact the PV generator's tion. For distinct values, the best adaptation occurs at one operational point MPP. Consequently, for the same irradiance, the power delivered by the PV generat be different depending on the power requested on the DC bus.
section_name: PV Local Controller

section_content: Figure 8 depicts the WT generator power curve as a function of the rotor sp can be noted that, for each wind speed, there is a single rotor speed allowing to hav imum power. 

Influence of the load on the operating point.
section_name: WT Local Controller

section_content: Figure 8 depicts the WT generator power curve as a function of the rotor speed. It can be noted that, for each wind speed, there is a single rotor speed allowing to have maximum power. Figure 7 shows that the connected loads severely impact the PV generator's operation. For distinct values, the best adaptation occurs at one operational point called MPP. Consequently, for the same irradiance, the power delivered by the PV generator will be different depending on the power requested on the DC bus.
section_name: WT Local Controller

section_content: Figure 8 depicts the WT generator power curve as a function of the rotor speed. It can be noted that, for each wind speed, there is a single rotor speed allowing to have maximum power. As with the PV generator, the MPPT technique allows the maximum power to be delivered to the DC bus, which corresponds to the maximum voltage for each irradiation and temperature level. Similarly, the wind power, at a given wind speed, is directly related to the rotation speed imposed by the mechanical load. Thus, the speed control of the WT allows for controlling wind power. It remains to define the speed setpoint according to an MPPT function. Therefore, in order to deliver the optimal power to the load, a speed regulation corresponding to the optimal wind speed must be performed. The optimal point of a WT is characterized by the pair (C p opt,λ opt ). Once the optimal point is reached, it is possible to calculate the optimal speed from the value of the optimal power. More details on the algorithm applied in this study are reviewed in [24].
section_name: WT Local Controller

section_content: The power delivered or consumed by each of the MG's elements must be controlled to maintain the power flow balance. Indeed, if the current delivered by each element on the DC bus is controlled, the power will be maintained. The power share between the batteries and DC bus is stabilized using a cascade structure, as reported in [25]. Indeed, an inner control loop regulates the battery current, and an outer control loop regulates the DC bus energy. The current regulation loop, using the duty cycle as a reference, generates control signals to the bidirectional converter. There are two possible options for the current reference:
section_name: Battery Local Controller

section_content: Either the reference is derived from a voltage regulation loop,

Or it is provided by a central controller (EMS). 

In the proposed architecture illustrated in Figure 9, the bi-directional converter connecting MG's component to the DC bus is assumed to be voltage-controlled. The role of the central controller is to select the DG or batteries as a source of energy according to several parameters detailed later. 

regulation corresponding to the optimal wind speed must be performed. The optima point of a WT is characterized by the pair (, ). Once the optimal point is reached it is possible to calculate the optimal speed from the value of the optimal power. Mor details on the algorithm applied in this study are reviewed in [24].
section_name: •

section_content: The power delivered or consumed by each of the MG's elements must be controlle to maintain the power flow balance. Indeed, if the current delivered by each element o the DC bus is controlled, the power will be maintained. The power share between th batteries and DC bus is stabilized using a cascade structure, as reported in [25]. Indeed an inner control loop regulates the battery current, and an outer control loop regulates th DC bus energy. The current regulation loop, using the duty cycle as a reference, generate control signals to the bidirectional converter. There are two possible options for the cur rent reference:
section_name: Battery Local Controller

section_content: Either the reference is derived from a voltage regulation loop,

Or it is provided by a central controller (EMS). 

In the proposed architecture illustrated in Figure 9, the bi-directional converter con necting MG's component to the DC bus is assumed to be voltage-controlled. The role o the central controller is to select the DG or batteries as a source of energy according t several parameters detailed later.
section_name: •

section_name: Central Control

section_content: The main reason for using FLC instead of traditional mathematical methods is it ability to deal with knowledge represented in a linguistic form. FLC development is gen erally based on the designer's experience rather than the mathematical modeling of th system, which requires solving complex equations as researchers used to do convention ally. The fuzzy logic concept was first developed and established by Pr. Lotfi Zadeh in hi paper entitled 'Fuzzy sets' in 1965 [26]. An intelligent EMS based on Mamdani's Fuzz Inference System (FIS) is adopted for designing the central controller.
section_name: FLC Design

section_content: The main reason for using FLC instead of traditional mathematical methods is its ability to deal with knowledge represented in a linguistic form. FLC development is generally based on the designer's experience rather than the mathematical modeling of the system, which requires solving complex equations as researchers used to do conventionally. The fuzzy logic concept was first developed and established by Pr. Lotfi Zadeh in his paper entitled 'Fuzzy sets' in 1965 [26]. An intelligent EMS based on Mamdani's Fuzzy Inference System (FIS) is adopted for designing the central controller. 

To guarantee the MG's performance, EMS regulates the flow of power between generators and loads, protects the batteries from deep charge/discharge, and stabilizes the DC bus voltage. The suggested FLC, presented in Figure 10, is based on the following criteria and objectives:
section_name: FLC Design

section_content: The priority is to supply loads through DGs.
section_name: •

section_content: Battery life can be preserved by keeping the SoC between 20% and 80% and avoiding overcharging or overdischarging.
section_name: •

section_content: Both the frequency and the voltage have to be kept within a margin that is equivalent to ±10 V and ±0. 05 Hz, respectively. 

and objectives:
section_name: •

section_content: Both the frequency and the voltage have to be kept within a margin that is equivalent to ±10 V and ±0. 05 Hz, respectively.
section_name: •

section_content: The central controller is responsible for managing the various functional modes and regulating the flow of power throughout the MG. The management algorithm is represented in Figure 11.
section_name: Management Algorithm

section_content: If the DGs are producing more power than is being used ( > 0), and batteries are charged ( ≥ ), the reference power of the batteries must be zero. In this case, the dump load will be turned on. Otherwise, the batteries would have already started charging with an amount of energy equal to = < 0.
section_name: •

section_content: If the energy supplied by the DGs is insufficient to meet demand and the batteries are empty, the loads are immediately disconnected, and the reference power of the batteries is set to zero. In any other case, batteries would have begun discharging ( = > 0).
section_name: •

section_content: Batteries are disconnected when the DGs can individually supply the load. 

Through the switch, the dump load is connected to the DC link and absorbs extra power under failure or overgeneration conditions. The surplus energy can be transformed into a heat load, which acts as a dump load.
section_name: •

section_content: The central controller is responsible for managing the various functional modes and regulating the flow of power throughout the MG. The management algorithm is represented in Figure 11. The rules of the FLC are based on the consideration of the batteries' SoC and the MG's stabilization. 

In the following the steps involved in designing a fuzzy inference system using Mamdani's method are presented. These steps include the process of fuzzification of inputs, defuzzification of outputs, utilizing fuzzy operators, and creating if-then rules. The rules shown in Figure 12 serve as the foundation of the FLC and are based on factors such as the state of charge of batteries and the stabilization of the MG. The proposed FLC system is composed of four inputs, three outputs, and five rules. Input 1 pertains to the state of charge of the batteries, input 2 relates to the net power, input 3 concerns the load power, and input 4 relates to the power source. The outputs control the signal for the switches, such as, and. 

Step 1: Fuzzification of Inputs
section_name: Management Algorithm

section_content: If the DGs are producing more power than is being used (P net > 0), and batteries are charged (SoC ≥ SoC max ), the reference power of the batteries must be zero. In this case, the dump load will be turned on. Otherwise, the batteries would have already started charging with an amount of energy equal to P bat = P net < 0.
section_name: •

section_content: If the energy supplied by the DGs is insufficient to meet demand and the batteries are empty, the loads are immediately disconnected, and the reference power of the batteries is set to zero. In any other case, batteries would have begun discharging (P bat = P net > 0).
section_name: •

section_content: Batteries are disconnected when the DGs can individually supply the load. 

Through the switch K dump, the dump load is connected to the DC link and absorbs extra power under failure or overgeneration conditions. The surplus energy can be transformed into a heat load, which acts as a dump load. 

The rules of the FLC are based on the consideration of the batteries' SoC and the MG's stabilization. 

In the following the steps involved in designing a fuzzy inference system using Mamdani's method are presented. These steps include the process of fuzzification of inputs, defuzzification of outputs, utilizing fuzzy operators, and creating if-then rules. The rules shown in Figure 12 serve as the foundation of the FLC and are based on factors such as the state of charge of batteries and the stabilization of the MG. The proposed FLC system is composed of four inputs, three outputs, and five rules. Input 1 pertains to the state of charge of the batteries, input 2 relates to the net power, input 3 concerns the load power, and input 4 relates to the power source. The outputs control the signal for the switches, such as K bat, K dump and K loads. puts of all the rules. The list of truncated output functions returned by each rule's implication process serves as the input for the aggregation process. In the proposed design, this process can result in five inputs corresponding to five rules. 

Step 4: Defuzzification The final step in the decision-making process is the defuzzification, which begins by merging the outputs of the fuzzy rules from the aggregation process. In this implementation, the aggregation is carried out by summing up the output trigger weights for each membership function across all the rules that affect the function. One of the most commonly used methods for defuzzification is the calculation of the centroid, which returns the center point of the area under the curve. In the proposed design, the centroid calculation method is chosen because it is an effective and efficient way to obtain an accurate value from a fuzzy set, while maintaining consistency in the results. Step 1: Fuzzification of Inputs In this step, inputs such as the SoC and net power are transformed into fuzzy sets through the use of membership functions. Prior to this transformation, the SoC input ranges from 0 to 100%, and the net power input ranges from -8000 to 8000 W. After the fuzzification process, the SoC parameter is represented with three fuzzy sets: "High", "Medium", and "Low", while the power input is represented with two fuzzy sets: "negative" and "positive". 

Step 2: Application of fuzzy operator The initial step in this process involves creating three fuzzy values for the SoC and two fuzzy values for the net power, all of which range from 0 to 1. These values are then used in the second step, where fuzzy operators are applied using a set of five rules. For instance, the first rule states that "if the SoC is low and the net power is positive, the batteries should be charged". In other words, the fuzzy values generated in the first step are used to determine appropriate actions through a series of logical statements known as "if-then" rules. 

Step 3: Aggregation of rules output The process of making decisions in Mamdani's FIS is based on the evaluation of all the rules. The rules must be combined in some way to reach a final decision. This combination is achieved through a process called aggregation, which involves merging the outputs of all the rules. The list of truncated output functions returned by each rule's implication process serves as the input for the aggregation process. In the proposed design, this process can result in five inputs corresponding to five rules. 

Step 4: Defuzzification The final step in the decision-making process is the defuzzification, which begins by merging the outputs of the fuzzy rules from the aggregation process. In this implementation, the aggregation is carried out by summing up the output trigger weights for each membership function across all the rules that affect the function. One of the most commonly used methods for defuzzification is the calculation of the centroid, which returns the center point of the area under the curve. In the proposed design, the centroid calculation method is chosen because it is an effective and efficient way to obtain an accurate value from a fuzzy set, while maintaining consistency in the results. 

Figure 13 illustrates the outcome of the defuzzification process. The FLC creates three control signals, K bat, K dump and K load, which are based on four inputs: load power, source power, net power (P net ), and SoC of the batteries. These control signals are the final output of the FLC, and they are used to control the system. value from a fuzzy set, while maintaining consistency in the results.
section_name: •

section_content: To achieve MG's stability, the power difference must be determined. The net power is equal to the difference between the surplus and the deficit. Equations ( 6 ) and (7)
section_name: Functioning Modes

section_content: To achieve MG's stability, the power difference must be determined. The net power is equal to the difference between the surplus and the deficit. Equations ( 6 ) and ( 7 ) are used to obtain P net and P S, respectively. 

P S = P pv + P wind (7) Table 1 lists the different switching combinations, where:

Energies 2023, 16, 2244

• M1 (000): all relays are turned off if there is no energy demand, or if there is a power shortage and the batteries are completely drained (SoC < 25% and P S = 0 and (P L = 0 or P L = 0)). • M2 (010): energy is dissipated through the dump load if there is a substantial amount of surplus energy and the batteries are fully charged, but instead, there is no energy demand. • M3 (011): loads are first supplied then the energy surplus is dissipated if the production is high and batteries are fully charged ((SoC > 85% and P S = 0 and P L = 0). • M4 (100): batteries are partially charged if the consumption is weak but the production is high. Midnight, when wind resources are at their peak but demand is low, is an appropriate moment to switch to this mode. • M5 (101): batteries supplement DGs to supply loads, when demand exceeds generation. 

Table 1. Switching modes of relays.
section_name: Functioning Modes

section_content: To test the hierarchical control, an MG HIL platform based on RT-LAB real-time simulation system is designed in this study. As depicted in Figure 14, the HIL platform consists of an OP1400 simulator, an FPGA controller, and a work-station assisting as a monitoring interface. A precise mathematical model of the isolated MG is compiled and converted to C-code, which can then be uploaded into an OP4510 simulator. Kintex-7 FPGA is a suitable platform on which the proposed control algorithm can be executed. Some information about operating frequencies of used FPGA and converters is highlighted in Table 2. The Xilinx FPGA KintexTM-7 325T, in particular, has advanced PWM generation capabilities, with a high operating frequency of up to 200 kHz and a resolution of 5 ns, making it more than capable of controlling converters with lower operating frequencies such as the PV converter at 20 kHz and the battery converter at 10 kHz. 

The OP1400 is a real-time digital simulator that allows users to simulate and test control systems, power electronics systems, and other real-time embedded systems. In the present study, the simulator contains both electrical model of the microgrid being simulated, as well as local and central controllers. The electrical model represents the electrical behavior of the system and its components, while the controllers are responsible for controlling the system and implementing the control strategy. 

The SimPowerSystems model needs to be partitioned into many sub-systems so that it may be simulated in real-time using the OPAL-RT platform. As shown in Figure 15, the MG's components are organized into two distinct subsystems, namely the Master Subsystem (SM) and the Console Subsystem (SC). The SM includes the entire electrical models of the microgrid, while the blocks responsible for data communication from/to the simulator are located in the SC. The Xilinx FPGA KintexTM-7 325T, in particular, has advanced PWM generation capabilities, with a high operating frequency of up to 200 kHz and a resolution of 5 ns, making it more than capable of controlling converters with lower operating frequencies such as the PV converter at 20 kHz and the battery converter at 10 kHz. 

The OP1400 is a real-time digital simulator that allows users to simulate and test control systems, power electronics systems, and other real-time embedded systems. In the present study, the simulator contains both electrical model of the microgrid being simulated, as well as local and central controllers. The electrical model represents the electrical behavior of the system and its components, while the controllers are responsible for controlling the system and implementing the control strategy. 

The SimPowerSystems model needs to be partitioned into many sub-systems so that it may be simulated in real-time using the OPAL-RT platform. As shown in Figure 15, the MG's components are organized into two distinct subsystems, namely the Master Subsystem (SM) and the Console Subsystem (SC). The SM includes the entire electrical models of the microgrid, while the blocks responsible for data communication from/to the simulator are located in the SC.
section_name: Results and HIL Test

section_content: Three experimental cases have been chosen to demonstrate the effectiveness of the proposed hierarchical control approach. The first case involves testing of local controllers under various weather conditions, such as wind, irradiation, and temperature, and under
section_name: Scenario Description

section_content: Three experimental cases have been chosen to demonstrate the effectiveness of the proposed hierarchical control approach. The first case involves testing of local controllers under various weather conditions, such as wind, irradiation, and temperature, and under extreme load profiles. In the second case, the central controller based on fuzzy logic, which is used to balance the power between sources, batteries, and dump load, is evaluated. Lastly, the microgrid control is evaluated under failure scenarios, including different types of faults such as short-circuits and overvoltages. The results are also compared to international standards, namely IEEE 1547 and IEC 61727, to determine their compliance. 

The view depicted in Figure 16 was elaborated using data obtained from the various MG sensors. The wind is blowing at a speed of 7 m/s while the temperature is set at 8 Datasets used in this study were retrieved from an original publication made in 2018 [27]. The microgrid being studied is located in a remote area in Morocco, and meteorological data such as solar radiation, wind speed, and ambient temperature were obtained from NASA's Surface Meteorology and Solar Energy programs. 

Figure 17 represents the solar irradiance and wind speed profiles considered during the test. To accurately estimate daily load consumption, the daytime hourly average consumption was evaluated, and then some randomization was applied for different hours to achieve a moderate profile. Datasets used in this study were retrieved from an original publication made in 2018 [27]. The microgrid being studied is located in a remote area in Morocco, and meteorological data such as solar radiation, wind speed, and ambient temperature were obtained from NASA's Surface Meteorology and Solar Energy programs. 

Figure 17 represents the solar irradiance and wind speed profiles considered during the test. To accurately estimate daily load consumption, the daytime hourly average consumption was evaluated, and then some randomization was applied for different hours to achieve a moderate profile. [27]. The microgrid being studied is located in a remote area in Morocco, and meteorological data such as solar radiation, wind speed, and ambient temperature were obtained from NASA's Surface Meteorology and Solar Energy programs. 

Figure 17 represents the solar irradiance and wind speed profiles considered during the test. To accurately estimate daily load consumption, the daytime hourly average consumption was evaluated, and then some randomization was applied for different hours to achieve a moderate profile.
section_name: Scenario Description

section_content: Figure 18a depicts the energy generated by solar panels, while Figure 18b depicts the energy gained from the wind generator. It is worth noting that, despite the extreme weather changes and unpredictable load demand, the Microgrid (MG) was able to respond accurately. As shown in Figure 19 and throughout the entirety of the real-time simulation, the voltage on the DC bus remains constant at a fixed value of 500 V and matches the reference voltage flawlessly with an overshoot of +/-1 V.
section_name: Test 1-Local Controllers

section_content: As seen in Figure 20a, the AC voltage remains constant despite changes in the levels of irradiance and wind speed. The voltage and frequency of the load respond rapidly to changes in the DC bus, which is connected directly to the inverter. The proposed EMS can ensure a consistent and high-quality voltage and current to the load, meeting the require- As shown in Figure 19 and throughout the entirety of the real-time simulation, the voltage on the DC bus remains constant at a fixed value of 500 V and matches the reference voltage flawlessly with an overshoot of +/-1 V. As shown in Figure 19 and throughout the entirety of the real-time simulation, the voltage on the DC bus remains constant at a fixed value of 500 V and matches the reference voltage flawlessly with an overshoot of +/-1 V.
section_name: Test 2-Central Controller

section_content: As seen in Figure 20a, the AC voltage remains constant despite changes in the levels of irradiance and wind speed. The voltage and frequency of the load respond rapidly to changes in the DC bus, which is connected directly to the inverter. The proposed EMS can
section_name: Test 2-Central Controller

section_content: As seen in Figure 20a, the AC voltage remains constant despite changes in the levels of irradiance and wind speed. The voltage and frequency of the load respond rapidly to changes in the DC bus, which is connected directly to the inverter. The proposed EMS can ensure a consistent and high-quality voltage and current to the load, meeting the requirements for waveform and harmonic distortion. Figure 20b illustrates that the SoC of the batteries stays consistently within a safe range, between 20% and 80%. This means that the objectives outlined in Figure 10, such as maintaining the SoC within a safe range, have been successfully met by the control system. Additionally, this shows that the microgrid is able to effectively manage the energy produced by the renewable sources, and supply the load with stable and high-quality power, despite the weather changes and unpredictable load demand. The load power and its reference are identical, as can be seen in Figure 22a, which indicates that the microgrid is able to maintain a steady flow of power even when there is a shortage of energy from the DGs. This is possible due to the use of energy storage systems such as batteries, which can supply power to the load during shortages, as shown in The load power and its reference are identical, as can be seen in Figure 22a, which indicates that the microgrid is able to maintain a steady flow of power even when there is a shortage of energy from the DGs. This is possible due to the use of energy storage systems such as batteries, which can supply power to the load during shortages, as shown in Figure 22b. The power of the batteries is positive when they are charging and negative The load power and its reference are identical, as can be seen in Figure 22a, which indicates that the microgrid is able to maintain a steady flow of power even when there is a shortage of energy from the DGs. This is possible due to the use of energy storage systems such as batteries, which can supply power to the load during shortages, as shown in Figure 22b. The power of the batteries is positive when they are charging and negative when they are discharging. This means that the MG is able to effectively balance the power flow between the DGs and the load, by storing excess energy in the batteries during periods of surplus, and releasing it during periods of shortage.
section_name: Test 2-Central Controller

section_content: In the final test, the proposed hierarchical control strategy is evaluated for its effectiveness in handling short circuits. Figure 23a illustrates two potential scenarios. The Point of Common Coupling (PCC) experiences a three-phase short circuit at around 10-10. 1 s, followed by a breakdown on the DG-side at around 15-15. 1 s. The goal of this test is to examine the behavior and response of the central controller in regard to these failures. Even though faults were emulated, the system was able to stabilize after the fault was cleared. As the short circuit occurs, the DC bus voltage drops significantly and experiences a notable fluctuation, as seen in Figure 23b. However, it returns to normal after the fault is cleared at 12. 2 s, which proves the robustness and efficacy of the proposed hierarchical control approach in handling short circuits. The frequency remains stable, with a fluctuation of only 0. 2% when the fault occurs. As can be seen in Figure 24a, after the problem has been fixed, the frequency maintains its original value of 50 Hz. As shown in Figure 24b, THD variation over time can reach 2. 5 during 100 ms, which remains relatively low in the faulty regime.
section_name: Test 3-Microgrid Performances under Faulty Conditions

section_content: In the final test, the proposed hierarchical control strategy is evaluated for its effectiveness in handling short circuits. Figure 23a illustrates two potential scenarios. The Point of Common Coupling (PCC) experiences a three-phase short circuit at around 10-10. 1 s, followed by a breakdown on the DG-side at around 15-15. 1 s. The goal of this test is to examine the behavior and response of the central controller in regard to these failures. Even though faults were emulated, the system was able to stabilize after the fault was cleared. As the short circuit occurs, the DC bus voltage drops significantly and experiences a notable fluctuation, as seen in Figure 23b. However, it returns to normal after the fault is cleared at 12. 2 s, which proves the robustness and efficacy of the proposed hierarchical control approach in handling short circuits.
section_name: Test 3-Microgrid Performances under Faulty Conditions

section_content: In the final test, the proposed hierarchical control strategy is evaluated for its effectiveness in handling short circuits. Figure 23a illustrates two potential scenarios. The Point of Common Coupling (PCC) experiences a three-phase short circuit at around 10-10. 1 s, followed by a breakdown on the DG-side at around 15-15. 1 s. The goal of this test is to examine the behavior and response of the central controller in regard to these failures. Even though faults were emulated, the system was able to stabilize after the fault was cleared. As the short circuit occurs, the DC bus voltage drops significantly and experiences a notable fluctuation, as seen in Figure 23b. However, it returns to normal after the fault is cleared at 12. 2 s, which proves the robustness and efficacy of the proposed hierarchical control approach in handling short circuits. The frequency remains stable, with a fluctuation of only 0. 2% when the fault occurs. As can be seen in Figure 24a, after the problem has been fixed, the frequency maintains its original value of 50 Hz. As shown in Figure 24b, THD variation over time can reach 2. 5 during 100 ms, which remains relatively low in the faulty regime. The frequency remains stable, with a fluctuation of only 0. 2% when the fault occurs. As can be seen in Figure 24a, after the problem has been fixed, the frequency maintains its original value of 50 Hz. As shown in Figure 24b, THD variation over time can reach 2. 5 during 100 ms, which remains relatively low in the faulty regime. Results must comply with international guidelines to evaluate the approach's effectiveness in the fault regime. IEEE 1547 [28] and IEC 61,727 [29] specify recommendations for voltage overshoots and response time. Overvoltage at the PCC for a prolonged period of time reduces system safety. IEC 61,727 states that the overvoltage in an isolated microgrid falls within four ranges:
section_name: Test 3-Microgrid Performances under Faulty Conditions

section_content: When < 50%, the maximum allowable trip time is 0. 1 s.
section_name: •

section_content: When 50% < < 85%, the maximum allowable trip time is 2 s.
section_name: •

section_content: When 110% < < 120%, the maximum allowable trip time is 2 s.
section_name: •

section_content: When 120% <, the maximum allowable trip time is 0. 16 s. 

Additionally, the MG should be able to endure a frequency range of ±1 Hz at the PCC while maintaining a THD that is less than 5%. 

Table 3 provides a concise summary of the power and frequency quality provided to the load within the investigated microgrid. A total of five parameters are examined, and they all compare favorably to the standards set out by IEEE 1547 and IEC 61727
section_name: •

section_content: This study addresses the issues of power continuity and battery management in microgrids, specifically focusing on frequency and voltage stability in both steady-state and fault conditions. This is achieved through the implementation of a hierarchical controller with a master-slave topology, where local controllers are managed and controlled by a central controller. The local controllers are designed to meet the specific needs of the microgrid, such as stabilizing the microgrid and maximizing the power generated from renewable energy sources. The central controller, on the other hand, uses a fuzzy logicbased approach to regulate power supply and demand equilibrium, and preserve the lifespan of the batteries. The performance of the microgrid was evaluated under both steady-state and fault conditions using a hardware-in-the-loop simulation platform based on RT-LAB and an OP1400 test bench. The results showed that the PCC's voltage and frequency remained stable even under a wide range of disturbances in both conditions. Furthermore, even with significant fluctuations in system parameters during fault conditions, the voltage, power, and frequency all quickly recovered once the fault was cleared. Results must comply with international guidelines to evaluate the approach's effectiveness in the fault regime. IEEE 1547 [28] and IEC 61727 [29] specify recommendations for voltage overshoots and response time. Overvoltage at the PCC for a prolonged period of time reduces system safety. IEC 61727 states that the overvoltage in an isolated microgrid falls within four ranges:
section_name: Conclusions

section_content: When Voltage < 50%, the maximum allowable trip time is 0. 1 s.
section_name: •

section_content: When 50% < Voltage < 85%, the maximum allowable trip time is 2 s.
section_name: •

section_content: When 110% < Voltage < 120%, the maximum allowable trip time is 2 s.
section_name: •

section_content: When 120% < Voltage, the maximum allowable trip time is 0. 16 s. Additionally, the MG should be able to endure a frequency range of ±1 Hz at the PCC while maintaining a THD that is less than 5%. 

Table 3 provides a concise summary of the power and frequency quality provided to the load within the investigated microgrid. A total of five parameters are examined, and they all compare favorably to the standards set out by IEEE 1547 and IEC 61727
section_name: •

section_content: This study addresses the issues of power continuity and battery management in microgrids, specifically focusing on frequency and voltage stability in both steady-state and fault conditions. This is achieved through the implementation of a hierarchical controller with a master-slave topology, where local controllers are managed and controlled by a central controller. The local controllers are designed to meet the specific needs of the microgrid, such as stabilizing the microgrid and maximizing the power generated from renewable energy sources. The central controller, on the other hand, uses a fuzzy logicbased approach to regulate power supply and demand equilibrium, and preserve the lifespan of the batteries. The performance of the microgrid was evaluated under both steadystate and fault conditions using a hardware-in-the-loop simulation platform based on RT-LAB and an OP1400 test bench. The results showed that the PCC's voltage and frequency remained stable even under a wide range of disturbances in both conditions. Furthermore, even with significant fluctuations in system parameters during fault conditions, the voltage, power, and frequency all quickly recovered once the fault was cleared. These results were compared with the international standards IEEE 1547 and IEC 61727, both of which display an exceptional level of consistency.
section_name: Conclusions

section_name: Institutional Review Board Statement: Not applicable.

section_content: Funding: This research received no external funding.

section_content: Informed Consent Statement: Not applicable.
section_name: Institutional Review Board Statement: Not applicable.

section_name: Conflicts of Interest:

section_content: Data Availability Statement: Not applicable.

section_content: The authors declare no conflict of interest.
section_name: Conflicts of Interest: