Demonstration of Resilient Microgrid with Real-Time Co-Simulation and Programmable Loads

: In recent years, the foment for sustainable and reliable micro energy grid (MEG) systems has increased signiﬁcantly, aiming mainly to reduce the dependency on fossil fuels, provide low-cost clean energy, lighten the burden, and increase the stability and reliability of the regional electrical grid by having interconnected and centralized clean energy sources, and ensure energy resilience for the population. A resilient energy system typically consists of a system able to control the energy ﬂow effectively by backing up the intermittent output of renewable sources, reducing the effects of the peak demand on the grid side, considering the impact on dispatch and reliability, and providing resilient features to ensure minimum operation interruptions. This paper aims to demonstrate a real-time simulation of a microgrid capable of predicting and ensuring energy lines run correctly to prevent or shorten outages on the grid when it is subject to different disturbances by using energy management with a fail-safe operation and redundant control. In addition, it presents optimized energy solutions to enhance the situational awareness of energy grid operators based on a graphical and interactive user interface. To expand the MEG’s capability, the setup integrates real implemented hardware components with the emulated components based on real-time simulation using OPAL-RT OP4510. Most hardware components are implemented in the lab to be modular, expandable, and ﬂexible for various test scenarios, including fault imitation. They include but are not limited to the power converter, inverter, battery charger controller, relay drivers, programmable AC and DC loads, PLC, and microcontroller-based controller. In addition, the real-time simulation offers a great variety of power sources and energy storage such as wind turbine emulators and ﬂywheels in addition to the physical sources such as solar panels, supercapacitors, and battery packs.


Introduction
Increasingly, the world is becoming more dependent on electricity, directly and indirectly.Almost every sector in the globalized world has its process linked to the electric industry.In addition to the conventional use of electricity, an unreliable energy system negatively impacts sectors such as transportation, security, food, health, etc. [1].For this reason, outages are more than an inconvenience; they seriously threaten community safety, economic stability, and national security [2].Some factors can significantly impact an energy grid reliability, such as more frequent natural disasters, the current aged energy networks, the asynchrony between energy demand and supply, and the vulnerable energy control system [3].
The rise in the severity and frequency of power outages due to extreme weather conditions has made studying grid resilience crucial.Furthermore, weather events are expected to become more severe due to climate change and global warming in the following years [4].Nowadays, several reliability indices are used to evaluate the power system performance, such as the System Average Interruption Duration Index (SAIDI), the System Average Interruption Frequency Index (SAIFI), and the Customer Average Interruption Index (CAIDI), among others [5,6].However, these indices are not long enough to evaluate the whole system because they are focused only on high probability low impact disturbances, and the grid operates passively.They do not account for the primary power outages caused by extreme weather events; consequently, the recovery mechanism is limited to a specific point where the outage occurs [7].The entire grid reliability is only analyzed when a considerable and broad disruption happens.For that reason, new studies are needed to encompass the grid reliability to deal with both the impact caused by extreme weather and the fact that the current energy grid is aging and overdue for an upgrade [8].
Additionally, with technological advances, smart grids are expected to spread in the following years, consequently resulting in intelligent homes.This scenario means that basically, everything in a house will need electricity, such as turning on or off the heating, cooling, doors, windows, everything, resulting in a society more connected and more dependent on electricity than ever [9].The same happens with businesses and other buildings that have their daily activity linked directly to electricity use.This interconnectedness means that every sector is negatively affected when part of the grid needs to be repaired [10].That is why it is important to design resilient energy systems; to prevent power disruptions or restore electricity quickly if an outage occurs [11].Additionally, the increase in advanced energy loads, such as smart appliances and electric vehicles, leads to another concern in the electric sector: the volatility and the asynchrony between demand and load, resulting in a struggle to provide a stable energy flow.In most cases, the utility grid needs to be oversized to supply peak demand, even for a short period [12].
Research has shown that the way to improve the resiliency of the energy grid is to invest in microgrids integrated with renewable sources, especially by using a distributed system.Distributed generation has grown considerably all over the world, and this is basically due to the incentives for the use of renewable sources as the key to fighting climate change, as well as the advances in technologies and market expansion, which have increased the viability of the installation of small generators connected directly to the distribution network, as well as the advancement of new technologies and the need for the small power grid in remote places [12].To be considered a microgrid, a system needs to consist of an energy load and generators with a control capability, which means it can disconnect from the traditional grid and operate autonomously [13].In other words, a microgrid is generally connected to a utility grid; however, in the case of extreme weather and power outages, it can break off and operate on its own by using a local energy generation and, consequently, keep the load supplied.
According to the U.S. Department of Energy Microgrid Exchange Group, a microgrid can be defined as a group of interconnected loads and distributed energy resources within clearly defined electrical boundaries that act as a single controllable entity concerning the grid, which can be controlled as a grid-connected system or works in an off-grid mode.Different designs of microgrids are being developed to provide reliable energy using emissions-free sources integrated with energy storage systems, with a tendency to increase over time due to the falling cost of renewable energy sources associated with the efforts to replace fossil fuels and the frequent transmission line failures [14].
A lot of research has been conducted regarding the possible scenarios and microgrid benefits.In [15], the author states an overview of the integration of MEG with the existing utility grid and its main problems and points out the most relevant research, including distributed generation, applications with energy converters, management and control, protection, and communications.However, not much is found about the many challenges that must be dealt with.In [16], the author summarizes different approaches and technologies that have been studied to address the complexity and challenges of microgrids, mainly regarding the power quality, which includes energy flow balancing, real-time management, frequency control, efficiency, and economical operation, as well as highlights the importance of focusing on fail-safe control and fault tolerance systems to improve the resiliency in advanced microgrids.In [17], the paper identifies possible controller designs used in existing MEG, including the control system's challenges, and proposes research systems with fault-tolerant control applied to a hierarchical architecture to enhance the smartness of control systems.More recently, many studies have focused on research and development in the area of fail-safe and resilience techniques for MG [18][19][20].Due to its multiple functions and many possible solutions proposed in the literature, the design of control systems for MEG is a complex engagement [21].
Since microgrids are typically composed of different technologies and energy physics, power electronics converters are essential components that must be included in the MEG systems to integrate various energy networks, which consist of electronic devices able to convert electric energy from one form to another, such as alternating (AC) and direct current (DC), and also allowing the adjustment in energy voltage, current, and frequency [22].Additionally, power converters can be used to increase maneuver abilities in hybrid systems, especially with renewable sources, by controlling the extracted power in each source and stabilizing the energy flows between components [23].For these reasons, researchers are constantly exploring power converters technologies, and topologies to meet the more complex microgrid components integration [24]; however, most of them have some limitations in adapting different energy flows and technologies.
In [25] is presented a multi-input convert to be used in renewable energy applications; however, by using only a unidirectional power flow with limited components and a nondispatchable current source.In [26], the load can be supplied by different voltage levels prevenient from two sources without circulating current, using the multi-input converter, but it lacks modularity.The proposed converter in [27] has fewer conduction losses, and the load supply can be performed individually or simultaneously from two different sources, which have different voltage-current characteristics with three power switches only; however, the proposed converter can be used only in DC microgrid applications, and the sources cannot transfer the power between them.For this paper, the proposed multi-input converter aims to work in bidirectional power flow capability and exchange the energy between the DC sources with minimum components parts.In addition, it has the modularity feature, so it can easily be adapted to different energy sources and consequently increase the microgrid reliability.
To develop reliable microgrids, it is crucial to focus on research and lab experiments and ensure that existing infrastructure adapts to new technologies.Lab experiments must simulate threats and responses and validate new technologies to help grid operators against outages.Performing experiments also help visualize the impact of climate change and the increasing of sophisticated cyber attackers to enhance the electric grid.One way to do this is by performing real-time simulations, which consists of testing computer modeling and small-scale energy system with real-life input and output.OPAL-RT Technologies is the leading developer of open real-time digital simulators and hardware in the loop testing equipment in the energy sector.OPAL-RT can be used to design, test, and optimize control and protection systems for power grids, power electronics, etc.In addition, the RT-LAB, core OPAL-RT software, enables users to develop models suitable for real-time simulation.RT-LAB models are fully integrated with MATLAB/Simulink [28].Simulink, developed by MathWorks, is data-flow graphical programming software for modeling, simulating, and analyzing dynamic systems.It supports simulation, automatic code generation, continuous tests, and verification of embedded systems.Integrated with MATLAB, it can incorporate MATLAB algorithms into models and export simulation results to MATLAB for further analysis [29].
This paper aims to introduce an experimental platform for a micro energy grid with unique merits such as having sizable and extensible AC and DC loads, hybrid power and energy storage sources through real-time co-simulation, and a redundant control system for enabling the fail-safe and resilient control to the MEG.A sizeable load is considered the first merit and is developed through an array of relays to dynamically change the arrangement of series and parallel connections between loads to determine the designated load value, which is applicable for AC and DC loads, including capacitive, inductive, and resistive load types.The second merit is combining a real-time simulation to emulate power and energy sources that are impracticable to be considered in lab sizes, e.g., wind turbines as a power source and flywheels as energy storage.The real-time simulation is designed based on OPAL-RT simulator OP4510 to connect the real-time hardware signals with the Simulink models.The signals that could be manipulated and connected are input signals from sensors and switches, while output signals like relaying simulation output signals are used to activate and run actuators, e.g., motors.The third merit is the redundant control system which utilizes two controllers: the first is based on a microcontroller array, and the second is based on a PLC controller aiming to back up each other and maintain the system availability.
The paper is outlined starting with the introduction section, followed by Section 2 presenting the design and co-simulation of the microgrid, and introduces the proposed microgrid's design and structure, highlighting the proposed system innovation.Section 3 demonstrates the testing and validation.Section 4 shows the resiliency, fail-safe control, and fault-tolerant capacity of the proposed microgrid.Finally, Section 5 concludes the work.

Design and Co-Simulation of Microgrid
The MEG consists of three main components: power sources, controllers, and energy loads.Therefore, it is possible to develop hybrid energy systems by combing different components technologies with hardware and emulators subsystems.The main features of the microgrid proposed in this paper consist of: The system schematic proposed in this paper consists of a microgrid with an interconnected power system, including physical sources, such as the utility grid and a solar panel, and emulated power sources, such as a wind turbine, using a real-time simulator.In addition, the system includes energy storage systems, physically and simulated, such as battery bank and flywheel, respectively.Furthermore, the system has a redundant control system based on microcontrollers and PLCs, as well as a dynamic load system, which consists of an AC and DC relay controlled sizable load.The following subsections elaborate on the system structure, including system components and parameters and the co-simulator based on Opal-RT OP4510.

Microgrid Structure and Resources
The structure of the proposed microgrid is shown in Figure 1.The system consists of AC and DC load, controllers, and power sources, including PV panels, emulated wind turbines, and flywheels based on real-time simulation, battery bank, and supercapacitors.Due to the complexity of using actual wind turbine and flywheel systems on a small scale for laboratory purposes, both approaches are emulated by using real-time simulations, which mimic the actual behavior of these technologies.The wind turbine and flywheel emulators using MATLAB/Simulink and testing using an OPAL-RT real-time simulator.lighted in green and emulated energy sources such as emulated flywheel are highlighted in green and yellow border.The figure shows the bus and energy management controllers in the middle.In addition, the co-simulation based on OPAL-RT (OP4510) is connected between the hardware and simulation Simulink for cooperating between the emulated components, called emulated plant, e.g., flywheel or wind turbine, and the hardware components of the systems.Regarding the energy loads, the system includes AC and DC programmable loads by changing the series and parallel arrangement of the loads using a bank of relays controlled by microcontroller-based relay drivers.In addition, the controller can insert or withdraw some loads based on the system capacity limit or according to the user's request.Figure 1 shows two types of power sources: physical power sources such as PV and the utility grid are highlighted in dark solid blue and emulated power sources such as wind emulators are highlighted in dark blue with a yellow border.Additionally, it shows two types of energy sources: physical energy sources such as supercapacitor and battery pack are highlighted in green and emulated energy sources such as emulated flywheel are highlighted in green and yellow border.The figure shows the bus and energy management controllers in the middle.In addition, the co-simulation based on OPAL-RT (OP4510) is connected between the hardware and simulation Simulink for cooperating between the emulated components, called emulated plant, e.g., flywheel or wind turbine, and the hardware components of the systems.
Table 1 lists the system components describing their types and parameters, stating the physical and emulated power sources, energy storage, AC and DC loads, converter, inverter, and real-time simulator.It shows each component's capacity and limits, voltage, input, and output parameters.

Circuit Design
Figure 2 depicts the schematic of the MEG circuitry, including relay array and microcontrollers, PLCs, inverter, converter interfaces, and dynamic loads.Since the system has been designed in the lab and consists of modular sectors, i.e., controlling units, signal acquisition boards, inverter, and power converter circuits, it makes easy maintenance and upgrading flexibility possible.Regarding the schematic details, the system consists of relay driver boards for driving the variable DC and AC loads, a variable capacitor for power factor correction, a charging controller of the battery pack, sensor boards for adapting the sensors' readings with the acceptable limits of microcontrollers, Arduino boards, communication devices for TCP ethernet connections, Modbus connectivity, pure sine wave inverter, bidirectional and multi-input power converter, and the PLC controllers in master-to-slave topology.Additionally, the system provides hybrid AC and DC bus systems that can feed different loads.

Fail-Safe and Resiliency Design of Microgrid
The concept of a resilient, intelligent, and effective microgrid brings forth promising enhancements for the current energy scenario without the necessity of redesigning the existed transmission lines, increasing the ability to integrate different types of energy demand with advanced energy storage systems, and with a high share of distributed power generation from renewable energy sources.However, as the diversity of distributed generators and energy load increases, the complexity of operating, controlling, and monitoring all the nodes within the system to maintain the power flow stability increases.Therefore, in addition to a myriad of benefits that a theoretical MEG can provide, there are some challenges that an effective energy management system needs to bear to become reliable [30].

Fail-Safe Algorithm
An essential factor that impacts the power quality is the ability to smoothly switch between energy sources and controllable loads that become undetectable for emergency loads.The necessity to change between the energy source surge for different reasons, mainly due to problems on the transmission side, such as climate destruction or utility grid maintenance, resulting in the necessity of switching between the grid-tied and islanded mode.This transition needs to be smooth enough to avoid or cause a less possible interruption in the energy supply.When it is necessary to change to an island mode, the energy management needs to identify a better scenario to meet the energy demands, activating the energy storage system and auxiliary generators.

Fail-Safe and Resiliency Design of Microgrid
The concept of a resilient, intelligent, and effective microgrid brings forth promising enhancements for the current energy scenario without the necessity of redesigning the existed transmission lines, increasing the ability to integrate different types of energy demand with advanced energy storage systems, and with a high share of distributed power generation from renewable energy sources.However, as the diversity of distributed generators and energy load increases, the complexity of operating, controlling, and monitoring all the nodes within the system to maintain the power flow stability increases.Therefore, in addition to a myriad of benefits that a theoretical MEG can provide, there are some challenges that an effective energy management system needs to bear to become reliable [30].

Fail-Safe Algorithm
An essential factor that impacts the power quality is the ability to smoothly switch between energy sources and controllable loads that become undetectable for emergency loads.The necessity to change between the energy source surge for different reasons, mainly due to problems on the transmission side, such as climate destruction or utility grid maintenance, resulting in the necessity of switching between the grid-tied and islanded mode.This transition needs to be smooth enough to avoid or cause a less possible interruption in the energy supply.When it is necessary to change to an island mode, the energy management needs to identify a better scenario to meet the energy demands, activating the energy storage system and auxiliary generators.
This mechanism is commonly performed by using electric actuates, which require a constant energy source to operate and that can identify power loss in the system and drive actuators to a predetermined safe position to maintain the energy supply for the system [31,32].Figure 3 charts the logic flow of the fail-safe algorithm that guarantees the balance between load demand and available power source capacity by monitoring the status of loads and sources.It calls for a fail-safe routine to detect a change in any contact's position This mechanism is commonly performed by using electric actuates, which require a constant energy source to operate and that can identify power loss in the system and drive actuators to a predetermined safe position to maintain the energy supply for the system [31,32].Figure 3 charts the logic flow of the fail-safe algorithm that guarantees the balance between load demand and available power source capacity by monitoring the status of loads and sources.It calls for a fail-safe routine to detect a change in any contact's position by calculating the load demand and source capacity smartly based on current statuses and checking the power availability to fulfil the request load demand.If there is plenty of power to satisfy the loads, it updates the system accordingly.However, if there is a power shortage, it calculates for emergence loads.Then, if the amount of available power sources can satisfy the emergency loads, it activates the emergency loads only.Or, it loads the previous safe settings of loads and sources.

The Resiliency of the Microgrid
Figure 4 demonstrates the resilient design of the microgrid by showing the remote access ability to monitor, control, and perform maintenance to the microgrid by using the modbus-based communication between two PLC controllers.This way, the microgrid can be accessed from anywhere without having operators on site.In addition, the redundant control topology between PLC and microcontrollers maintains the microgrid secured when one controller goes down.Thanks to the firm and safe control algorithm, the microgrid can simultaneously be commanded from both sides.

Fault-Tolerant Control of Microgrid
The concept of fault-tolerant power systems consists of a technique in which the energy system can ensure continuous and uninterrupted functionality.One of the requirements for a resilient system is to avoid outages.The system must be immune to single or multiple failures in the primary energy supply, which is made by developing architectures with backup and redundancy power sources.
Fault-tolerant control can be classified into active management and passive control.Passive control is widely used due to its robustness.Prior knowledge of possible faults is required for such control that may alter the system's stability.Due to those faults, the elements installed, such as consumers and subsystem components, might affect their fundamental performance.Therefore, fault tolerance is required to provide the continuity of the microgrid functionality, and the following techniques can achieve it:

•
Fault detection: it consists of the appearance and detection of possible faults within the microgrid system.

•
Recovery: it means the replacement of the fault states with a particular state.It consists of two mechanisms: • Fault management: fault state needs to be eliminated to clear the erroneous state of the microgrid.

•
Fault handling: diagnosis, isolation, reconfiguration, and reset are required to resolve the fault.
This experimental work, stated in Figure 5, uses a fault tolerance algorithm based on PLC and relays logic control.PLC scans the loads, power sources, and energy storage statuses by reading the relays contacts statuses.Then, it checks the type of faults; if it is related to load, it isolates the faulty load(s), but if it is related to source(s), it isolates that source.Then, it calculates balanced load demands and power source generation.Ultimately, it activates and deactivates load(s) accordingly.In other words, it carries out a corrective action based on balancing the demanded load with the available power after isolating the faulty source(s) and or load.The main features of the proposed control are:

•
Regulating microgrid voltages considering faults within the supplies and loads.

•
The control strategy is robust against those faults, disturbances, and harmonics as changing the controller structure is not required like the existing controller.Therefore, even when some part of the system fails due to fault conditions, the proposed controller enables the continuity of the safe operation of the microgrid and thus increases the system's reliability.

•
Finally, two case scenarios have been designed, the controller has been implemented in hardware to demonstrate its performance, and the results are described.

Microgrid Control
The redundant control technique has been designed based on three microcontrollers and two PLC controllers connected based on master-to-slave topology.Figure 6 shows the design of the microgrid control system that has been driven redundantly by microcontrollers and PLC, meaning when one controller is down, the other takes over the control to increase the reliability of the MEG.In addition, the system may receive commands from any of them to maintain a fail-safe system.Additionally, by applying master-to-slave control, one PLC works as a master controller (remote) that can send commands to the slave controller (local) to enable remote access to the system from anywhere.In addition to the remote access, the system can monitor all metrics, faults, and measurements of the system that can be used in analysis work for concluding and forecasting purposes.The figure also shows the interconnected system components, including the connection between the master PLC and slave PLC and the HMI screen connected to the master controller as a user interface to the control system.In addition, it shows the ethernet communication based on eight ports ethernet switch and how the two ways controllers, Arduino-based and PLC-based controllers can share the responsibility of controlling loads.controller (local) to enable remote access to the system from anywhere.In addition to the remote access, the system can monitor all metrics, faults, and measurements of the system that can be used in analysis work for concluding and forecasting purposes.The figure also shows the interconnected system components, including the connection between the master PLC and slave PLC and the HMI screen connected to the master controller as a user interface to the control system.In addition, it shows the ethernet communication based on eight ports ethernet switch and how the two ways controllers, Arduino-based and PLC-based controllers can share the responsibility of controlling loads.

Co-Simulation Based on OPAL-RT
Real-time simulation is a technique used to mimic and analyze the system performance at the same rate as the actual physical system using computer modelling.Real-time simulations are used widely in several engineering fields and can be configured in hardware-in-the-loop simulations by testing controllers using real-life conditions.
OPAL-RT Technologies is the leading developer of open real-time digital simulators and hardware in the loop testing equipment in the energy sector. Figure 7 depicts the outstanding features of OPAL-RT (Model OP4510), which include 32 channels of digital inputs (DIs), 32 channels of digital outputs (DOs), and 16 channels of analog inputs (AIs), and 16 channels of analog outputs (AOs).These features allow the MEG system to emulate complex subsystems, such as flywheels, wind turbines, and nuclear reactors, which are unlikely to be hosted indoor, e.g., on a lab scale.In addition, OPAL-RT enables interfacing with external world devices, including switches, relays, motors, and sensors.So, these capabilities of OPAL-RT OP4510 have been utilized to process all the digital inputs from the user, such as the switches and feedback signals that relays' contacts have relaid.Furthermore, analog inputs from measurement devices and sensors such as voltages and currents, and battery temperature, are transferred from hardware to the Simulink model by using OPAL-RT to be processed.Similarly, the generating outputs from the Simulink model are converted into physical signals to either be displayed on scopes or be used to

Co-Simulation Based on OPAL-RT
Real-time simulation is a technique used to mimic and analyze the system performance at the same rate as the actual physical system using computer modelling.Realtime simulations are used widely in several engineering fields and can be configured in hardware-in-the-loop simulations by testing controllers using real-life conditions.
OPAL-RT Technologies is the leading developer of open real-time digital simulators and hardware in the loop testing equipment in the energy sector. Figure 7 depicts the outstanding features of OPAL-RT (Model OP4510), which include 32 channels of digital inputs (DIs), 32 channels of digital outputs (DOs), and 16 channels of analog inputs (AIs), and 16 channels of analog outputs (AOs).These features allow the MEG system to emulate complex subsystems, such as flywheels, wind turbines, and nuclear reactors, which are unlikely to be hosted indoor, e.g., on a lab scale.In addition, OPAL-RT enables interfacing with external world devices, including switches, relays, motors, and sensors.So, these capabilities of OPAL-RT OP4510 have been utilized to process all the digital inputs from the user, such as the switches and feedback signals that relays' contacts have relaid.Furthermore, analog inputs from measurement devices and sensors such as voltages and currents, and battery temperature, are transferred from hardware to the Simulink model by using OPAL-RT to be processed.Similarly, the generating outputs from the Simulink model are converted into physical signals to either be displayed on scopes or be used to switch actuators on and off or control signals that drive the power switches in controller and converter devices.
switch actuators on and off or control signals that drive the power switches in controller and converter devices.

Experimental Setup of MEG
Based on the schematic design of the MEG circuitry described above, the experimental setup of the microgrid is pictured in Figure 8.It shows the integration of multiple power sources, including the grid, PV panels, battery pack, and supercapacitors in addition to the other emulated power and energy sources by OPAL-RT co-simulation.The figure also shows the redundant control system consists of a redundancy system including three microcontroller boards and two PLCs.
The setup provides two common power buses, AC and DC buses, for supplying different types of loads, which are sizable programmatically based on relay control logic.The load can be decided manually by switching on and off any load according to user demands.Additionally, it can be set automatically by selecting based on the total amount of load the user requested.It is important to highlight one crucial contribution that, for any load mode control, restrictions of balancing between the available power source and the requested loads can be selected by considering the priority of emergency loads according to a predefined plan.

Design of the Multi-Input Converter
The proposed multi-input converter is shown in Figure 9.The system is projected to charge the battery bank from DC-link or PV panel and discharge with the PV panel in the DC link to supply the AC and DC loads.The battery is used as an energy storage device

Experimental Setup of MEG
Based on the schematic design of the MEG circuitry described above, the experimental setup of the microgrid is pictured in Figure 8.It shows the integration of multiple power sources, including the grid, PV panels, battery pack, and supercapacitors in addition to the other emulated power and energy sources by OPAL-RT co-simulation.The figure also shows the redundant control system consists of a redundancy system including three microcontroller boards and two PLCs.

Experimental Setup of MEG
Based on the schematic design of the MEG circuitry described above, the experimental setup of the microgrid is pictured in Figure 8.It shows the integration of multiple power sources, including the grid, PV panels, battery pack, and supercapacitors in addition to the other emulated power and energy sources by OPAL-RT co-simulation.The figure also shows the redundant control system consists of a redundancy system including three microcontroller boards and two PLCs.
The setup provides two common power buses, AC and DC buses, for supplying different types of loads, which are sizable programmatically based on relay control logic.The load can be decided manually by switching on and off any load according to user demands.Additionally, it can be set automatically by selecting based on the total amount of load the user requested.It is important to highlight one crucial contribution that, for any load mode control, restrictions of balancing between the available power source and the requested loads can be selected by considering the priority of emergency loads according to a predefined plan.

Design of the Multi-Input Converter
The proposed multi-input converter is shown in Figure 9.The system is projected to charge the battery bank from DC-link or PV panel and discharge with the PV panel in the DC link to supply the AC and DC loads.The battery is used as an energy storage device The setup provides two common power buses, AC and DC buses, for supplying different types of loads, which are sizable programmatically based on relay control logic.The load can be decided manually by switching on and off any load according to user demands.Additionally, it can be set automatically by selecting based on the total amount of load the user requested.It is important to highlight one crucial contribution that, for any load mode control, restrictions of balancing between the available power source and the requested loads can be selected by considering the priority of emergency loads according to a predefined plan.

Design of the Multi-Input Converter
The proposed multi-input converter is shown in Figure 9.The system is projected to charge the battery bank from DC-link or PV panel and discharge with the PV panel in the DC link to supply the AC and DC loads.The battery is used as an energy storage device with high energy density, and the PV is used as a renewable energy source that will reduce the supply from the grid.The converter consists of six MOSFETs, two inductors, and one capacitor, as shown in Figure 9.The design can be modular by adding two power switches and one inductor to combine the switching leg to add more renewable energy sources or energy storage devices with high power density such as supercapacitors.Table 2 shows the equations used to calculate the minimum values of inductors L 1 and L 2 , and Table 3 shows the design specifications of the proposed converter.with high energy density, and the PV is used as a renewable energy source that will reduce the supply from the grid.The converter consists of six MOSFETs, two inductors, and one capacitor, as shown in Figure 9.The design can be modular by adding two power switches and one inductor to combine the switching leg to add more renewable energy sources or energy storage devices with high power density such as supercapacitors.Table 2 shows the equations used to calculate the minimum values of inductors L1 and L2, and Table 3 shows the design specifications of the proposed converter.The control strategy was implemented using the proportional-integral (PI) controller; therefore, the system's parameters can be adjusted easily by adjusting the PI gains.Flexibility and easy implementation are the main advantages of the PI controller.The error between the output voltage and the reference voltage is minimized using the PI controller, as shown in Figure 10, to generate the desired duty ratio for the pulses of the MOSFETs in the different operation modes.To make the system underdamped, the integral coefficient is regulated to be KI = 0.3, and the steady-state error and overshoot are minimized by controlling the proportional coefficient to be Kp = 0.001.

Converter Control
The control strategy was implemented using the proportional-integral (PI) controller; therefore, the system's parameters can be adjusted easily by adjusting the PI gains.Flexibility and easy implementation are the main advantages of the PI controller.The error between the output voltage and the reference voltage is minimized using the PI controller, as shown in Figure 10, to generate the desired duty ratio for the pulses of the MOSFETs in the different operation modes.To make the system underdamped, the integral coefficient is regulated to be KI = 0.3, and the steady-state error and overshoot are minimized by controlling the proportional coefficient to be Kp = 0.001.

Operation Modes of the Converter
The proposed converter, presented in Figure 9, works in four different operatio modes, as we will discuss later to transfer the power between the DC link and the batter bank, discharge from the PV panel and battery bank simultaneously, and exchange th energy between the PV panel and battery bank.The four operating modes of the converte are: In the second interval, L1 discharge through diodes D1 and D4 while switches S2 an S3 are turned off to supply the DC link.To maintain the continuous discharging of energ from L1 in the DC link, the switches S1 and S4 are turned during the third time interv instead of the diodes in T2.The switches S1 and S4 operate as synchronous rectifiers t reduce the voltage drop to a level of about 0.2 V; hence, the system efficiency improved The voltage across L1 in , and is described by the following equation: By simplifying Equation (3), and by applying the principle of volt-second balance fo inductor L1 using Equations ( 1) and ( 2), the following equation can be deduced: Under the steady-state condition, the relation between DC-link voltage as an outpu and battery bank voltage as input is expressed using Equation (4).
where D is the duty cycle ratio defined by where is the total period of the switchin cycle, and can be expressed as: Additionally, can be expressed as: = 1 (6

Operation Modes of the Converter
The proposed converter, presented in Figure 9, works in four different operation modes, as we will discuss later to transfer the power between the DC link and the battery bank, discharge from the PV panel and battery bank simultaneously, and exchange the energy between the PV panel and battery bank.The four operating modes of the converter are: Mode 1: Battery Bank to DC link The inductor L 1 is charged and discharged during this operation mode in three time intervals T 1 , T 2 , and T 3 to discharge the battery bank only in the DC link to charge the DC and AC loads.The switches S 2 and S 3 are turned in the first time interval to charge the L 1 and hence the inductor voltage V L 1 is described by the following equation: In the second interval, L 1 discharge through diodes D 1 and D 4 while switches S 2 and S 3 are turned off to supply the DC link.To maintain the continuous discharging of energy from L 1 in the DC link, the switches S 1 and S 4 are turned during the third time interval instead of the diodes in T 2 .The switches S 1 and S 4 operate as synchronous rectifiers to reduce the voltage drop to a level of about 0.2 V; hence, the system efficiency improved.The voltage across L 1 in T 2 , and T 3 is described by the following equation: By simplifying Equation (3), and by applying the principle of volt-second balance for inductor L 1 using Equations ( 1) and ( 2), the following equation can be deduced: Under the steady-state condition, the relation between DC-link voltage as an output and battery bank voltage as input is expressed using Equation (4).
where D is the duty cycle ratio defined by where T S is the total period of the switching cycle, and T 1 can be expressed as: Additionally, T S can be expressed as: The battery bank voltage is boosted to the DC link with working in duty cycle equal D > 0.5.The DC link charges the battery bank by reversing the current in L 1 .Under the steady-state condition and taking into consideration D to be T 1 /T S , the relation between DC-link voltage and battery bank voltage can be expressed using Equation (7).
Mode 2: PV Panel to DC Link In this operating mode, the inductor L 2 is discharged in the DC link in three time intervals T 1 , T 2 , and T 3 , similar to the previous operation mode to supply the DC link from the PV only.The switches S 2 and S 5 are turned in the first time interval to charge the L 2 .
The following equation describes the voltage across the inductor L 2 .
In the second interval, the L 2 discharge through diodes D 1 and D 6 while switches S 2 and S 5 are turned off to supply the DC link.In the third interval, the switches S 1 and S 6 are turned on for continued discharging of L 2 in the DC link and to reduce the voltage drop of the diodes.During these intervals, V L 2 can be described by the following equations: By applying the principle of volt-second balance for inductor L 2 using Equations ( 8) and ( 9), the following equation can be deduced: Equation (11) shows the voltage of the DC link V DC as an output voltage as a function of the PV panel V PV input voltage.
where D is the duty cycle ratio equal , and T S is the total period of the switching cycle.The following equation expresses the relation between input and output voltages, and T 1 can be expressed as: Mode 3: Battery Bank and PV Panel In mode 3, the battery bank can be charged from the PV panel to extend the lifetime of the batteries during the peak hours and in sunny conditions.The PV panel work in buck operation mode to charge the battery bank, as shown in Equation ( 13), using the switches S 3 , S 5 , and S 6 . Where The switching sequence of the power switches in the three time intervals of the previous operation modes is summarized in Table 4.
Mode 4: Battery Bank and PV Panel to DC Link In this operation mode, the load from the grid can be mitigated during peak hours by simultaneously charging the loads from the battery bank and the PV panel.Inductors L 1 and L 2 are charged and discharged in five time intervals.Table 4 shows the DC link simultaneously from the battery bank and the PV panel using Equations ( 15) and ( 16).
where d 1 is the ratio of the on-time of switch S 3 to total switching period T S and, similarly, d 2 corresponds to switch S 2 .The switching sequence of the power switches in the five time intervals of the fourth operation mode is summarized in Table 5.

Testing and Validation
Table 6 summarizes the system's preliminary test and validation scenarios, which examine the proposed Microgrid's capabilities, function, and features.These tests and validations have been certified in the lab, including grid control, and switching between standalone and grid-connected systems considering islanding mode.In addition, battery charging and discharging control have been tested, showing the safe and accurate battery disconnection at threshold voltage values for a full charge and discharge checkpoints.
The variable AC and DC load based on relay-based logic control has been tested for manual and automatic modes.Bus management control for AC and DC buses has been evaluated at normal and fault conditions.Additionally, protection functions for load, battery pack, and power sources have been validated successfully.The functions of the co-simulation have been validated, showing how OPAL-RT interfaces the hardware components with the Simulink components of the MEG.In addition, the remote access control and data logging for monitoring purposes have been tested.The listed functions below can be considered the whole set of tasks that can be carried out with the proposed MEG setup.However, only some key functions and potential works that have been listed as the merits of the proposed MEG are selected to be presented in this section.
Because the proposed MEG has a redundant control system based on PLCs and microcontrollers, two graphical user interfaces (GUI) have been approached to facilitate the system's operation.Figure 11 shows the microcontroller-based GUI that includes a power source, battery charging, and load center control.The interface lets the user control the load, power sources, and energy storage.Figure 12 shows the HMI interface of PLC-based control that can carry out the load, power source, energy storage control, and battery charging control.Because the proposed MEG has a redundant control system based on PLCs and microcontrollers, two graphical user interfaces (GUI) have been approached to facilitate the system's operation.Figure 11 shows the microcontroller-based GUI that includes a power source, battery charging, and load center control.The interface lets the user control the load, power sources, and energy storage.Figure 12 shows the HMI interface of PLC-based control that can carry out the load, power source, energy storage control, and battery charging control.

Co-Simulation Based on OPAL-RT
As mentioned above, the main objective of co-simulation is to interface the hardware with the simulation software, the Simulink.To enable a Simulink model, flywheel and wind turbine, to act out like a physical power source or energy storage, the study utilizes OPAL-RT OP4510 with the input mentioned above and output resources to link between the physical signals in the experimental world with the input and output (IOs) data in a Simulink model.In this test scenario, Figure 13

Co-Simulation Based on OPAL-RT
As mentioned above, the main objective of co-simulation is to interface the hardware with the simulation software, the Simulink.To enable a Simulink model, flywheel and wind turbine, to act out like a physical power source or energy storage, the study utilizes OPAL-RT OP4510 with the input mentioned above and output resources to link between the physical signals in the experimental world with the input and output (IOs) data in a Simulink model.In this test scenario, Figure 13  Figure 14 shows the analogous signals received by OPAL-RT from sensors and measurement devices and generates switching pulses for driving the power switch elements, i.e., MOSFETS in power converters accordingly.Figure 14 shows the analogous signals received by OPAL-RT from sensors and measurement devices and generates switching pulses for driving the power switch elements, i.e., MOSFETS in power converters accordingly.

Testing Fail-Safe Logic
In this test case scenario, according to data listed in Table 7 that tabulates the collected statues of loads and power sources and their weights, the previous status of the loads and sources (On/Off), the total power of loads that were in ON status was 350 W (nodes 4, 5 and 6).Additionally, the full source power was 364 W (nodes 1, 2, and 3).The fifth column, which represents the new requested statues, shows a total load of 800 w (nodes 4 to 7) when the available power of sources was reported from the previous status to be 264 W (nodes 1 and 3).Therefore, emergency loads are the only ones that be allowed to be energized.As a result, nodes number 4 and 5 that are highlighted in red will be expected to be energized, and node 6 will be turned off to keep the balance between load demand and available power. Figure 15 shows the microgrid setup before and after requesting changes.The supper capacitor has been disconnected due to either fault-tolerant or user request as in Table 7, as shown by the meter reading in Figure 15.Consequently, the intelligent fail-safe algorithms determine that the system can continue running with the emergency loads only that is why AC lamp 1 keeps switched on as an emergency load.However, AC lamp 2 has been switched off as it is a normal load.Finally, after having the supercapacitor removed out of the system, the remaining available power will be sufficient for the demanded power.800 w (nodes 4 to 7) when the available power of sources was reported from the previous status to be 264 W (nodes 1 and 3).Therefore, emergency loads are the only ones that be allowed to be energized.As a result, nodes number 4 and 5 that are highlighted in red will be expected to be energized, and node 6 will be turned off to keep the balance between load demand and available power. Figure 15 shows the microgrid setup before and after requesting changes.The supper capacitor has been disconnected due to either fault-tolerant or user request as in Table 7, as shown by the meter reading in Figure 15.Consequently, the intelligent fail-safe algorithms determine that the system can continue running with the emergency loads only that is why AC lamp 1 keeps switched on as an emergency load.However, AC lamp 2 has been switched off as it is a normal load.Finally, after having the supercapacitor removed out of the system, the remaining available power will be sufficient for the demanded power.In this scenario, depicted in Figure 16, a fault condition has been considered within the power source to make an overload condition.In this condition, the controller will detect the faulty power source, calculate the total power generation, and compare it with the load demand.If the demand is high, the controller will disconnect some of the loads from the bus connector and only support the emergency load; thus, the system can achieve a continuation.In this scenario, depicted in Figure 16, a fault condition has been considered within the power source to make an overload condition.In this condition, the controller will detect the faulty power source, calculate the total power generation, and compare it with the load demand.If the demand is high, the controller will disconnect some of the loads from the bus connector and only support the emergency load; thus, the system can achieve a continuation.

Short Circuit Condition
In this scenario, depicted in Figure 17, a short circuit condition has been applied within the system to make the system stop by force.A circuit breaker is used within the components and controlled by the PLC to bypass this fault.Whenever a component gets short-circuited, the controller will detect and activate the breaker to bypass this component, and the system will continue its safe operation.

Short Circuit Condition
In this scenario, depicted in Figure 17, a short circuit condition has been applied within the system to make the system stop by force.A circuit breaker is used within the components and controlled by the PLC to bypass this fault.Whenever a component gets short-circuited, the controller will detect and activate the breaker to bypass this component, and the system will continue its safe operation.

Short Circuit Condition
In this scenario, depicted in Figure 17, a short circuit condition has been applied within the system to make the system stop by force.A circuit breaker is used within the components and controlled by the PLC to bypass this fault.Whenever a component gets short-circuited, the controller will detect and activate the breaker to bypass this component, and the system will continue its safe operation.Figure 18 shows the results of the fault-tolerant test on the microgrid experimental setup.The test scenario is that one of the power sources has gotten out of the system due to a breaker's reaction to a fault.Without fault-tolerant considerations, the system will be totally down.However, the fault-tolerant feature enables the system to disconnect the faulty power source and maintain the system operation.Because the remaining amount of power decreased by losing one of the power sources, the fault-tolerant combines with a fail-safe algorithm to calculate the emergence load.Therefore, the emergency loads are only allowed to continue energized, as shown before and after the fault.Figure 18 shows the results of the fault-tolerant test on the microgrid experimental setup.The test scenario is that one of the power sources has gotten out of the system due to a breaker's reaction to a fault.Without fault-tolerant considerations, the system will be totally down.However, the fault-tolerant feature enables the system to disconnect the faulty power source and maintain the system operation.Because the remaining amount of power decreased by losing one of the power sources, the fault-tolerant combines with a fail-safe algorithm to calculate the emergence load.Therefore, the emergency loads are only allowed to continue energized, as shown before and after the fault.

Conclusions
This study introduces an experimental platform for a microgrid with distinct features, such as enabling extensible and sizable AC and DC load and combining physical and emulated power sources and storage systems, aiming to increase the system flexibility by utilizing real-time simulation OPAL-RT OP4515.In addition, the design includes failsafe and resiliency features by developing a redundant control system based on microcontrollers and PLCs.Furthermore, PLC and relay logic control enable the sizing control of the load demand.
The system combines physical and emulated power sources and energy storage, aiming to increase flexibility and diminish the limitations of including different types and sizes of power and energy sources.For example, the wind turbine as a power source and flywheel as energy storages are impractical to incorporate within an indoor experimentation setup.Using co-simulation based on interfacing hardware components with Simulink based on OPAL-RT real-time simulation opened the door to include simulated components to act on the system the way the physical sources acts.Utilizing PLC combined with relay logic control successfully shows the ability to take the system from total failure and shutdown to fail-safe with balanced load demands and power generation.Applying the redundant control by utilizing PLC and microcontrollers increased the system reliability because controllers can cover each other.It only reinforces the benefits that microgrids

Conclusions
This study introduces an experimental platform for a microgrid with distinct features, such as enabling extensible and sizable AC and DC load and combining physical and emulated power sources and storage systems, aiming to increase the system flexibility by utilizing real-time simulation OPAL-RT OP4515.In addition, the design includes fail-safe and resiliency features by developing a redundant control system based on microcontrollers and PLCs.Furthermore, PLC and relay logic control enable the sizing control of the load demand.
The system combines physical and emulated power sources and energy storage, aiming to increase flexibility and diminish the limitations of including different types and sizes of power and energy sources.For example, the wind turbine as a power source and flywheel as energy storages are impractical to incorporate within an indoor experimentation setup.Using co-simulation based on interfacing hardware components with Simulink based on OPAL-RT real-time simulation opened the door to include simulated components to act on the system the way the physical sources acts.Utilizing PLC combined with relay logic control successfully shows the ability to take the system from total failure and shutdown to fail-safe with balanced load demands and power generation.Applying the redundant control by utilizing PLC and microcontrollers increased the system reliability because controllers can cover each other.It only reinforces the benefits that microgrids integrate physical and emulated energy sources with energy management and storage systems to pursue resiliency, fail-safe, and fault-tolerant capabilities.
Furthermore, a complex and long-term transition is necessary to achieve a resilient and reliable energy system, primarily based on renewable energy and high energy efficiency, aiming for sustainability, robustness, and adaptiveness.The paper presents the design of a proposed microgrid that is enriched with various power sources and energy storage along with variable AC and DC loads.This paper demonstrates a complete scenario of real-time simulation based on emulated energy sources to be integrated with the physical sources to complement the ecosystem of the proposed microgrid.Additionally, a novel fault-tolerant and fail-safe algorithm have been implemented and tested.In addition, a redundant control system based on a microcontroller array and PLC has been implemented and employed to provide the proposed microgrid's resiliency.Testing and validation of the claimed key features and potential merits of the implemented MEG platform yield results that prove the capabilities of reliability based on the redundant control system, fail-safe operation, fault tolerance, and resiliency of the proposed system.

Figure 4 .
Figure 4.The resilient design of the microgrid.

Figure 5 .
Figure 5. Fault tolerance algorithm based on PLC and relay control.
and converter devices.

Figure 9 .
Figure 9.The configuration of the multi-input converter with MEG DC sources.

Figure 9 .
Figure 9.The configuration of the multi-input converter with MEG DC sources.

Mode 1 :
Battery Bank to DC linkThe inductor L1 is charged and discharged during this operation mode in three tim intervals T1, T2, and T3 to discharge the battery bank only in the DC link to charge the D and AC loads.The switches S2 and S3 are turned in the first time interval to charge the L and hence the inductor voltage is described by the following equation:
shows Simulink's and OPAL-RT's analog inputs and outputs (IOs) interface.It shows how the IOs are connected to tags and variables in the Simulink model.This test scenario shows how the OPAL-RT IOs tags are connected to the simulation.

24 Figure 13 .
Figure 13.The interfacing between SM-OPAL and the analog IOs of OPAL-RT.

Figure 13 .
Figure 13.The interfacing between SM-OPAL and the analog IOs of OPAL-RT.

Figure 14
Figure14shows the analogous signals received by OPAL-RT from sensors and measurement devices and generates switching pulses for driving the power switch elements, i.e., MOSFETS in power converters accordingly.

Figure 13 .
Figure 13.The interfacing between SM-OPAL and the analog IOs of OPAL-RT.

Figure 14 .
Figure 14.Input and output analog channels signals in OPAL-RT.Figure 14. Input and output analog channels signals in OPAL-RT.

Figure 14 .
Figure 14.Input and output analog channels signals in OPAL-RT.Figure 14. Input and output analog channels signals in OPAL-RT.

Figure 15 .
Figure 15.Fail-safe test scenario results on microgrid setup.Figure 15.Fail-safe test scenario results on microgrid setup.

Figure 15 .
Figure 15.Fail-safe test scenario results on microgrid setup.Figure 15.Fail-safe test scenario results on microgrid setup.

Figure 18 .
Figure 18.Fault tolerance test results of the microgrid.

Figure 18 .
Figure 18.Fault tolerance test results of the microgrid.

Table 1
lists the system components describing their types and parameters, stating the physical and emulated power sources, energy storage, AC and DC loads, converter, inverter, and real-time simulator.It shows each component's capacity and limits, voltage, input, and output parameters.

Table 1 .
MEG system components and parameters.

Table 1 .
MEG system components and parameters.

Table 2 .
Inductance equations for different operation modes.

Table 3 .
Design specifications of the proposed converter.

Table 2 .
Inductance equations for different operation modes.

Table 3 .
Design specifications of the proposed converter.

Table 6 .
Testing and validation parameters.

Table 7 .
Collected status of load and power sources.