Secondary Control for Storage Power Converters in Isolated Nanogrids to Allow Peer-to-Peer Power Sharing

It is usual in literature that power sharing among grid-forming sources of an isolated microgrid obeys their energy rating, instead of economic agreements between stakeholders, and circulating energy among them is usually avoided. However, these energy interchanges make strong sense and classical power sharing methods must be reformulated in the context of prosumer-based microgrids. This paper proposes a secondary control method for a prosumer-based low-voltage nanogrid that allows for energy interchange between prosumers, where storage systems, together with PV generators, are the controllable grid-forming sources. A power flow technique adapted to islanded microgrids is used for secondary control algorithm and the whole hierarchical control strategy for the prosumer converter is simulated and validated. This hierarchical control consists of three stages: tertiary control plans the energy interchange among prosumers, secondary obtains different voltage and power setpoints for each of the grid-forming sources, and, finally, primary control guarantees stable voltage and frequency values within the nanogrid with droop rules. Inner control loops for the power converter are also defined to track setpoints and assure stable performance. Simulation tests are carried out, which prove the stability of the proposed methods and the accuracy of the setpoint tracking.


Introduction
These days, it is generally accepted that microgrids are a key structure to integrate Distributed Generation (DG) and energy storage into the smart grids [1][2][3][4]. Hierarchical control for microgrids constitutes a trade-off between the accuracy of centralized control techniques and the flexibility and resilience that are presented by the distributed control ones [2]. Under this control scheme, primary control assures power balance within the microgrid, when it is islanded, usually by means of well-known droop rules, at the cost of frequency and voltage deviations; secondary control is responsible for restoring frequency and voltage to reference values and tertiary control (sometimes only present in grid-connected situation) performs economic optimization, according to energy price, energy efficiency targets, or agreements between stakeholders [3].
Moreover, most recent and complete overview on secondary control for AC microgrids [4] assigns to this control stage the mission of obtaining a correction term for the droop controller of islanded microgrids in such a way that, after a finite time period, both the frequency and voltage amplitude reach their respective reference values. These reference values are the same for every grid-forming DERs of the microgrid, according to the desired values in the common PCC. Under this premise, the active and reactive power of loads are shared among DERs, but no power interchange is allowed in the steady state among them. Therefore, collaborative economy and P2P agreements are not possible in those islanded microgrids.
However, in a microgrid or nanogrid composed by several prosumers, DG and loads (and ESS, if they are included) are located together in each load bus of the nanogrid. There is not a common PCC, whose voltage is the common voltage setpoint, and circulating currents among prosumers cannot be avoided, but they are even desirable to accomplish with collaborative energy trading. In this context, different voltage setpoints are required for each DER, along with different power setpoints. Power flow equations must be considered within the microgrid to assure the technical feasibility of the adopted solution to address this challenge.
The strategy presented in [14] develops an optimization method to obtain different voltage and reactive power setpoints for each of the agents of a microgrid. Only voltage control is performed in this paper, whereas frequency control is assumed to be performed by other DERs. The power flow equations within the microgrid are also considered as constraints for the method. However, both voltage and reactive power setpoints obey to the objective to improve accuracy in the setpoint accomplishments, according to DER rating and voltage and power allowed range. Therefore, neither tertiary control nor active/reactive power interchange among DERs are considered in this control technique. On the other hand, [15] proposes a hierarchical control scheme for islanded microgrids in which estimations of the average values of power flows between neighboring DERs are used to control the power and frequency. This proposal decentralizes secondary control and, therefore, improves the resilience in case of communication faults, but it requires continuous updating of measured voltage and current values and calculated power and frequency, with the consequent computational cost.
The main contributions of this paper can be summarized, as follows: • P2P energy trading between prosumers is addressed in islanded microgrids, from the point of view of the voltage and power setpoint generation and how the DER converter can follow them. Power flow among prosumers is guaranteed due to different voltage setpoint in each prosumer's load bus. • A novel secondary control based on power flow algorithm in microgrids is proposed to reach classical secondary control target as well as allow energy interchange between DERs. • A residential nanogrid is simulated with all the necessary control loops to perform hierarchical control, starting from previously mentioned setpoints.
The nanogrid under study consists of two residential prosumers, both with PV generation and battery ESS systems, which are connected to their load buses by means of a single-phase converter. A two-wire cable connects load bus of both prosumers. The nanogrid operates islanded from the main grid.
The rest of the paper is organized, as follows: Section 2 describes the proposed control strategy for the nanogrid; in Section 3, case study and simulation model are described in detail; in Section 4, the simulation results are shown and discussed. Finally, Section 5 concludes the paper.

Proposed Control Strategy
A hierarchical control structure is proposed in this paper, which improves the structures that are generally accepted in literature [2]. Three stages, which range from the outer and slower control loop to the inner and faster one, are considered:

•
Tertiary control aims to optimize the energy use inside the nanogrid. Starting from generation and demand forecasting, demand and storage systems are managed at this stage to match power and energy balance in the isolated nanogrid with optimal resource exploitation. Energy interchange among the resources within the nanogrid presents a clear importance when it is grid-connected, with the aim of obtaining economic advantages and improving self-consumption and self-sufficiency. Another scenario for this tertiary control is P2P energy interchange, which schedules energy sharing under agreement in both grid-connected and isolated situation. • Secondary control determines the electrical magnitude setpoints for the DERs. In the context of isolated nanogrids, the target of this stage is usually to restore the voltage and the frequency in a unique PCC, with a power-sharing strategy that aimed at using the available resources to keep secure and stable electrical conditions, without considering the economic or agreement-based energy interchange among DERs. In this paper, the P2P energy interchange concept is taken into account at this control stage to allow for complying with economic or energy agreements among different prosumers. • Primary control acts automatically to obtain stable frequency and voltage magnitudes when power balance mismatching occurs due to unexpected changes in demand or generation. A decentralized droop control is the most frequently used strategy for this stage, whose formulation strongly depends on the resistive/inductive character of the system.
These three control stages are described below, although secondary control draws most of the attention in this paper.

Nanogrid Tertiary Control
This control stage constitutes the Energy Management System (EMS) of the nanogrid. It makes special sense when the nanogrid is grid-connected and the energy flows with the main grid are intended to be scheduled to achieve economic advantages and to shave power peaks, to improve self-consumption and self-sufficiency rates inside the nanogrid or to accomplish with P2P interchange agreements. However, an energy management procedure is also important in islanded nanogrids, to assure power balance with the highest benefit for the nanogrid stakeholders and with an optimal resource exploitation. These targets usually to active power interchanges among the prosumers or with the main grid (when grid-connected). It is desirable that power generated by PV installations is mostly used to improve self-consumption and reduce energy that is generated from polluting sources. Therefore, in this paper, it is assumed that PV generator is working at Maximum Power Point (MPP) regime unless surplus energy is produced. In that case, generated power is curtailed and the PV generator moves to the Reference Power Point (RPP) mode (see [16] for further explanation).
Similarly, demand is assumed to be managed according to a valid Demand Side Management (DSM) technique, like that proposed in [17]. Therefore, each battery charging/discharging power is obtained from the nanogrid power balance and the sharing method selected. An example of tertiary control for batteries in microgrids of prosumers can be seen in [18].
After this tertiary control stage, active power hourly setpoints are obtained for both PV generator and battery. Assuming that they are connected to prosumer's load bus by means of a common power converter, the setpoint for the output active power of the converter after tertiary control is obtained in (1) for each hour t of the day.
On the other hand, reactive power should not circulate among different DERs of the nanogrid, as it would produce higher losses and voltage drops than necessary. Therefore, the reactive power setpoint for each converter of the nanogrid is also obtained in (1). where: • P G-TERCi : hourly average active power setpoint for tertiary control (W) • Q G-TERCi : hourly average reactive power setpoint for tertiary control (VAr) • P Gi : hourly average forecasted PV generation power, once curtailed (W) • P Bi : hourly average scheduled battery power (positive values when charging, negative when discharging) (W) • Q Di : hourly average forecasted reactive power demanded by load in bus i (VAr)

Nanogrid Secondary Control
Starting from hourly setpoints of the tertiary control, secondary control must provide active and reactive power and voltage setpoints for the converter output, with higher time resolution. The objective of secondary control is usually to restore frequency and voltage values in the nanogrid within proper values, once primary control has changed the values to stabilize them after unexpected changes in generated or demanded power values. In this paper, one-minute resolution time has been selected for secondary control. A demanding communication system is not required with this resolution time. Battery power (P B0i ) is obtained by linear interpolation between consecutive hourly scheduled power values, whereas the generated (P G0i ) and demanded (P D0i ) power values are both measured and values of the previous minute are used to obtain secondary control setpoints. In the case of communication fault, measured values can be substituted by an interpolation of forecasted values, with the consequent decrease in accuracy, which will be compensated by primary control.
Unlike those works in which every grid-forming converters are connected to the same PCC and voltage setpoints for them are equal, multi-bus prosumer nanogrids require different voltage setpoints for each bus, according to pursued power input and the output of each prosumer and power flow constraints due to nanogrid configuration and impedance between buses. Active and reactive power setpoints in secondary control are changed according to a droop technique, and they must assure consistent behavior with voltage setpoints and power flows. Therefore, a power flow algorithm for islanded microgrids is used in this paper to obtain both power and voltage setpoints. As updating of initial values is done once a minute, during the minute the nanogrid can be considered as a quasi-static system.
Power flow algorithms for islanded microgrids can be found in literature [19], although they usually aim to analyze the microgrid, instead of obtain control setpoints. Several differences exist between this problem and classical power flow problem in bulk power systems:

•
There is no slack bus in microgrids, as there is not a bus with a powerful generation capacity that assures stable frequency and provides power losses. Two kind of buses are usual in microgrids: PQ (load or grid-following generation buses) and droop buses (this is a new kind of bus, which shares the responsibility to keep stable and proper frequency values).

•
Frequency value of the system is not guaranteed, but it is a variable of the problem.

•
Active and reactive power generation is governed by droop rules.

Element Modelling for Power Flow Algorithm
The lines in nanogrids are short. Consequently, shunt admittance can be neglected according to the so-called short line model. Only series impedance is considered (2). where: Regarding loads, active and reactive power demanded depend on the voltage and frequency in the connection bus. The degree of this dependence varies with the kind of load. A general model for linear loads can be obtained from (3). where: • P D-SECi : active power demand estimation for secondary control (W) For dwelling loads, [20,21] propose the values in Table 1 for these factors. The modelling of a generating unit differs depending on its grid-following or grid-forming character. Generators that do not control voltage or frequency act as PQ buses and load model with the proper sign criterion is valid for them. However, generators that are responsible to control voltage and frequency of the microgrid respond to droop rules: (4) for mainly-inductive grids and (5) for mainly-resistive grids [22]. where: • P G-SECi : active power setpoint for the converter output, for secondary control (W) • Q G-SECi : reactive power setpoint for the converter output, for secondary control (VAr) • m p , m q , k p , k q : droop coefficients Droop coefficients control P or Q variations with voltage and frequency. They are usually obtained, starting from extreme values of proper ranges of voltage, frequency, and active and reactive power, although some authors propose their adjustment as a function of battery SoC [23,24].

Power Flow Algorithm Formulation
The authors in [19] develop the algorithm for three-phase systems, with independent equations for each phase and imposing balanced voltage in droop buses. In this paper, the model in [19] is reformulated for single-phase microgrids.
The power flow equations are similar to the classical power flow algorithm for bulk power systems. Net injected active (P SECi ) and reactive (Q SECi ) power in bus i are calculated in (6). with: • U SECi , δ SECi : RMS value (V) and phase angle (rad) of i-bus voltage • Y ik , γ ik : magnitude (S) and phase angle (rad) of ik-element of Ybus admittance matrix The equations to solve for each bus are (7) for PQ buses (unknown variables U SECi and δ SECi ) and (8) for droop buses (unknown variables P SECi , Q SECi , U SECi and δ SECi ). One of the droop buses acts as phase angle reference (δ SEC1 = 0), whereas frequency f is an unknown variable. Therefore, the same number of equations and variables are provided.
Electronics 2020, 9, 140 7 of 18 In this paper, resistive grids have been assumed and the trust-region Newton method has been selected to solve the problem, as suggested in [19,25].
Therefore, secondary control provides power and voltage setpoints in each prosumer's load bus (Figure 1), according to initial agreed power flows and voltage and frequency control within the nanogrid.
In this paper, resistive grids have been assumed and the trust-region Newton method has been selected to solve the problem, as suggested in [19,25].
Therefore, secondary control provides power and voltage setpoints in each prosumer's load bus ( Figure 1), according to initial agreed power flows and voltage and frequency control within the nanogrid.

PV Generation Battery
Dwelling Loads Dwelling Loads Figure 1. Secondary control setpoints in the nanogrid.

Nanogrid Primary Control
The primary control acts in each prosumer converter, which intends to follow power and voltage setpoints obtained in secondary control, but it makes adjustments to dynamically stabilize the frequency and voltage in a decentralized procedure. Figure 2 shows the electric scheme of the converter AC filter, where the power and voltage magnitudes are also depicted.
ith Prosumer Figure 2. Converter magnitudes for primary control.
Inductances L1 and L2 and capacitance C constitute the LCL output filter of the converter. Setpoints in prosumer's load bus have been provided by secondary control. Primary control firstly obtains setpoints for capacitor voltage and the power injected in L2, necessary to perform primary control.
Equation (9) allows for obtaining the voltage setpoint for the capacitor (Uc-PRIMi, δc-PRIMi) and the active and reactive power setpoints (PG-PRIMi, QG-PRIMi) in the input terminal of reactance L2.

Nanogrid Primary Control
The primary control acts in each prosumer converter, which intends to follow power and voltage setpoints obtained in secondary control, but it makes adjustments to dynamically stabilize the frequency and voltage in a decentralized procedure. Figure 2 shows the electric scheme of the converter AC filter, where the power and voltage magnitudes are also depicted.
In this paper, resistive grids have been assumed and the trust-region Newton method has been selected to solve the problem, as suggested in [19,25].
Therefore, secondary control provides power and voltage setpoints in each prosumer's load bus (Figure 1), according to initial agreed power flows and voltage and frequency control within the nanogrid.

PV Generation Battery
Dwelling Loads Dwelling Loads Figure 1. Secondary control setpoints in the nanogrid.

Nanogrid Primary Control
The primary control acts in each prosumer converter, which intends to follow power and voltage setpoints obtained in secondary control, but it makes adjustments to dynamically stabilize the frequency and voltage in a decentralized procedure. Figure 2 shows the electric scheme of the converter AC filter, where the power and voltage magnitudes are also depicted.
ith Prosumer Figure 2. Converter magnitudes for primary control.
Inductances L1 and L2 and capacitance C constitute the LCL output filter of the converter. Setpoints in prosumer's load bus have been provided by secondary control. Primary control firstly obtains setpoints for capacitor voltage and the power injected in L2, necessary to perform primary control.
Equation (9) allows for obtaining the voltage setpoint for the capacitor (Uc-PRIMi, δc-PRIMi) and the active and reactive power setpoints (PG-PRIMi, QG-PRIMi) in the input terminal of reactance L2. Inductances L 1 and L 2 and capacitance C constitute the LCL output filter of the converter. Setpoints in prosumer's load bus have been provided by secondary control. Primary control firstly obtains setpoints for capacitor voltage and the power injected in L 2 , necessary to perform primary control.
Equation (9) allows for obtaining the voltage setpoint for the capacitor (U c-PRIMi , δ c-PRIMi ) and the active and reactive power setpoints (P G-PRIMi , Q G-PRIMi ) in the input terminal of reactance L 2 .
Electronics 2020, 9, 140 8 of 18 In (9), i L2 is the current in the filter inductance L 2 and * denotes complex conjugate.
A droop control is added to keep frequency and voltage stable, besides the required inner voltage and current control loops for following these setpoints. In this case, the impedance between the filter capacitor and the load bus is mainly inductive, therefore the droop condition is that of (4). Droop control obtains corrected setpoints of capacitor voltage u ci_ref , according to measured values and droop characteristic in (4): where: Droop constants both in secondary and primary control have been obtained, starting from extreme values of the proper range of frequency (±1 Hz) and voltage (±7% rated voltage), according to Spanish regulation [26], and from the available capacity of each prosumer's resources (while considering PV generation, battery charge/discharge maximum power, and SoC).
It is worth noting that droop rules have been split into two stages (one in secondary control through the resistive line between prosumers and another one in primary control through the inductive filter). Therefore, decoupling between active/reactive power and frequency/voltage is assured and virtual impedance is not required.

Power Converter Inner Voltage and Current Control Loops
Proportional-resonant (PR) controllers have been selected for both control loops, since they can track sinusoidal references with zero steady-state error and present high disturbance rejection capability [27]. At the same time, these controllers perform with constant switching frequency in comparison with another non-linear alternatives as hysteresis or predictive controllers [28]. Besides, PR controllers do not include any parameter of the plant in the feedback loop and they also reduce the computational burden (PR works in the αβ-stationary reference frame, avoiding dq-rotational transformation [29]). The ideal transfer function of a PR controller is shown in (11): where ω n is the reference angular frequency, in this case, 2π50 rad/s. The converter voltage controller obtains a reference current according to the error between reference and measured values of capacitor voltage. A PR controller has been used for this loop, with k P-PR = 0.001 and k R-PR = 100, as was previously mentioned.
Finally, the current controller compares reference and measured values of the converter output current and it obtains the modulating signal for the converter switching by means of another PR controller with k P-PR = 20 and k R-PR = 2000. The voltage and the current PR controller coefficients were both tuned by means of the guidelines provided in [30]. Figure 3 depicts these control loops, where u ci is the measured voltage signal in the filter capacitor of the ith converter and i L1 is the current in the inverter-side reactance of the LCL filter.
controller with kP-PR = 20 and kR-PR = 2000. The voltage and the current PR controller coefficients were both tuned by means of the guidelines provided in [30]. Figure 3 depicts these control loops, where uci is the measured voltage signal in the filter capacitor of the ith converter and iL1 is the current in the inverter-side reactance of the LCL filter.
From the obtained modulating signal, the switching signals for the converter gates S1-S4 (see Figure 5) are generated by means of the Sinusoidal Pulse Width Modulation (SPWM) technique.

Battery DC/DC Converter Control Loop
The last controller is that of the DC/DC converter that connects the battery to the DC-link. This converter has two simultaneous targets: keeping power values according to scheduled setpoints and controlling a constant value for the voltage of the converter DC-link. Two terms for the battery current are obtained to address both of the targets. The first one is obtained in (12) from the expected power of the converter, which was provided by the PV generator and the battery voltage. The second term adjusts the current to keep DC-bus voltage stable around 400 V (Figure 4). This second term is also responsible to cover the converter losses and the mismatch between power setpoint and actual values.
where: From the obtained modulating signal, the switching signals for the converter gates S1-S4 (see Figure 5) are generated by means of the Sinusoidal Pulse Width Modulation (SPWM) technique.

Battery DC/DC Converter Control Loop
The last controller is that of the DC/DC converter that connects the battery to the DC-link. This converter has two simultaneous targets: keeping power values according to scheduled setpoints and controlling a constant value for the voltage of the converter DC-link. Two terms for the battery current are obtained to address both of the targets. The first one is obtained in (12) from the expected power of the converter, which was provided by the PV generator and the battery voltage. The second term adjusts the current to keep DC-bus voltage stable around 400 V (Figure 4). This second term is also responsible to cover the converter losses and the mismatch between power setpoint and actual values.
where: The voltage and the current PR controller coefficients were both tuned by means of the guidelines provided in [30]. Figure 3 depicts these control loops, where uci is the measured voltage signal in the filter capacitor of the ith converter and iL1 is the current in the inverter-side reactance of the LCL filter.
From the obtained modulating signal, the switching signals for the converter gates S1-S4 (see Figure 5) are generated by means of the Sinusoidal Pulse Width Modulation (SPWM) technique.

Battery DC/DC Converter Control Loop
The last controller is that of the DC/DC converter that connects the battery to the DC-link. This converter has two simultaneous targets: keeping power values according to scheduled setpoints and controlling a constant value for the voltage of the converter DC-link. Two terms for the battery current are obtained to address both of the targets. The first one is obtained in (12) from the expected power of the converter, which was provided by the PV generator and the battery voltage. The second term adjusts the current to keep DC-bus voltage stable around 400 V (Figure 4). This second term is also responsible to cover the converter losses and the mismatch between power setpoint and actual values.
where: A dead-beat technique is used to control the battery current, according to (13) [31].
where: A Pulse Width Modulation (PWM) technique is used to convert this duty cycle to switching signals for the converter gates S5-S6 (see Figure 5). them having PV generation, battery ESS, and dwelling loads. Their load buses are connected by a 6 mm 2 cross-section, 20 m long two-wire cable. As PV generation is not the matter of study in this work, it has been modelled as a DC current source that is assumed to be working at MPP at each house. However, battery ESS consists of a battery source and a DC/DC converter, whose control strategy has been discussed in Section 2.3. A common inverter connects both PV generation and ESS to the load bus of each prosumer. The nanogrid is islanded, i.e., it is disconnected from the main grid. Figure 5 depicts the nanogrid schematic and Table 2 shows the simulation parameters. It can be observed that the droop constants used in primary control are the same or proportional (scaled for stability reasons) to those of secondary control, but changing the relationship between Reactive Power-Frequency and Active Power-Voltage (in resistive line between prosumers for secondary control) and between Active Power-Frequency and Reactive Power-Voltage (in inductive filter for primary control).

Case Study and Simulation Parameters
As was previously described, the nanogrid in this study consists of two prosumers, each of them having PV generation, battery ESS, and dwelling loads. Their load buses are connected by a 6 mm 2 cross-section, 20 m long two-wire cable. As PV generation is not the matter of study in this work, it has been modelled as a DC current source that is assumed to be working at MPP at each house. However, battery ESS consists of a battery source and a DC/DC converter, whose control strategy has been discussed in Section 2.3. A common inverter connects both PV generation and ESS to the load bus of each prosumer. The nanogrid is islanded, i.e., it is disconnected from the main grid. Figure 5 depicts the nanogrid schematic and Table 2 shows the simulation parameters. It can be observed that the droop constants used in primary control are the same or proportional (scaled for stability reasons) to those of secondary control, but changing the relationship between Reactive Power-Frequency and Active Power-Voltage (in resistive line between prosumers for secondary control) and between Active Power-Frequency and Reactive Power-Voltage (in inductive filter for primary control).
In the test performed, firstly, the ESS charges the inverter DC-link up to a stable voltage of 400 V. Subsequently, the inverter is connected and the reference values for the different control loops are generated (Table 3 shows the initial values of power demand forecast and setpoints obtained from secondary control. Constant power load model has been used, with zero value for exponents and sensitivity factors, according to (3)). It can be observed that active power setpoint of each converter does not match demand power of its prosumer. The reason lies on the droop rule used in secondary control for power sharing, according to available energy resources of each prosumer (8).  The last control connected is the droop control, which adjusts active and reactive power with the aim of keeping stable frequency and voltage values. The PV current source is connected once the converter is supplying the load using only the ESS as a source, supplying part of the demanded load (each prosumer' PV installations is assumed to produce 200 W).
As it was described in the previous section, secondary control has provided a set of power and voltage setpoints to each converter, which start from the tertiary control strategy and the power flow rules within the nanogrid. It is assumed at the beginning of the test that the demanded load and PV generation have been properly forecasted, and the nanogrid converters are operating at the rated frequency and planned voltage. Afterwards, an unplanned change in load occurs, which increases the active power of prosumer 1 in 100 W and reactive power of prosumer 2 in 30 VAr. Consequently, droop control acts by slightly moving frequency and voltage from planned values.
Once the secondary control loop reaches a new cycle, updated setpoints are sent to both prosumers' converters (updated values in Table 3). These new setpoints are obtained, starting from the last PV generation and load measurements. In this test it is assumed that these measured loads match actual loads. Therefore, both of the converters reach their respective power and voltage setpoints and frequency and voltage are restored to planned values. In the other case, droop control should have kept a slight deviation in frequency and voltage magnitude until correct setpoint had been received.

Simulation Results and Discussion
The nanogrid in Figure 5 has been simulated by means of Matlab/Simulink ® . Table 4 depicts the time sequence of the simulation. It is the same for both prosumers.  Figure 6 shows the evolution of DC-link voltage with time, in converter of prosumer 1. The same behavior is observed in the other converter. At the beginning, the control loop of battery DC/DC converter charges the DC-link capacitor to a stable voltage of 400 V. After 0.6 s, the connection of the inverter produces a slight oscillation in DC-link voltage, but its value keeps very close to 400 V. The rest of the simulation shows how this voltage is corrected to 400 V after each event.

Simulation Results and Discussion
The nanogrid in Figure 5 has been simulated by means of Matlab/Simulink ® . Table 4 depicts the time sequence of the simulation. It is the same for both prosumers.  Figure 6 shows the evolution of DC-link voltage with time, in converter of prosumer 1. The same behavior is observed in the other converter. At the beginning, the control loop of battery DC/DC converter charges the DC-link capacitor to a stable voltage of 400 V. After 0.6 s, the connection of the inverter produces a slight oscillation in DC-link voltage, but its value keeps very close to 400 V. The rest of the simulation shows how this voltage is corrected to 400 V after each event.   Figure 7 depicts the voltage in the load bus and currents in both reactances of the LCL filter of both converters, once the converter and the PV have been connected and before the load change. Voltage is scaled by a factor 100 for better visibility. As can be seen, the current in L 2 is a filtered version of current in L 1 . They are both quite sinusoidal and their amplitude and phase-shift are consistent with the power setpoints of each converter. Voltage setpoint in the filter capacitor and frequency, both being obtained after droop correction (10), are shown in Figure 8. It can be observed how both of the parameters suffer from an initial transitory change at 0.65 s, when droop control is activated. After a short transient, they reach a stable value matching initial setpoints. At 1.2 s, when the loads change, frequency and voltage both slightly change their values according to droop rules. Once the secondary control setpoints are Voltage setpoint in the filter capacitor and frequency, both being obtained after droop correction (10), are shown in Figure 8. It can be observed how both of the parameters suffer from an initial transitory change at 0.65 s, when droop control is activated. After a short transient, they reach a stable value matching initial setpoints. At 1.2 s, when the loads change, frequency and voltage both slightly change their values according to droop rules. Once the secondary control setpoints are updated (1.6 s), rated frequency and new voltage setpoints are reached and kept stable after a short time period. Anyway, voltage and frequency deviations are both low enough for the nanogrid to properly work, even before the secondary control updating. Therefore, if high unexpected changes occur in generation or demand, or a communication fault avoid setpoint updating, the nanogrid can securely work until the abnormal situation is corrected. Voltage setpoint in the filter capacitor and frequency, both being obtained after droop correction (10), are shown in Figure 8. It can be observed how both of the parameters suffer from an initial transitory change at 0.65 s, when droop control is activated. After a short transient, they reach a stable value matching initial setpoints. At 1.2 s, when the loads change, frequency and voltage both slightly change their values according to droop rules. Once the secondary control setpoints are updated (1.6 s), rated frequency and new voltage setpoints are reached and kept stable after a short time period. Anyway, voltage and frequency deviations are both low enough for the nanogrid to properly work, even before the secondary control updating. Therefore, if high unexpected changes occur in generation or demand, or a communication fault avoid setpoint updating, the nanogrid can securely work until the abnormal situation is corrected.   The dynamic performance of controllers shows a proper combination of fast and low-oscillating response (after each change, new stable power values are reached after 0.2-0.3 s) and a negligible steady-state error, as can be observed in the power values in Figure 9. Regarding dynamic response of voltage and current signals, Figure 10 shows, as an example, a detail of the transient in voltage in the load bus and current in the outer filter reactance of prosumer 2, when the voltage and control loops are activated. It can be observed that the transient in voltage is fast and accurate, whereas current signal presents a low amplitude oscillation, consistent with transient observed in power values ( Figure 9). However, neither high frequency oscillations nor sudden peaks are observed. The dynamic performance of controllers shows a proper combination of fast and low-oscillating response (after each change, new stable power values are reached after 0.2-0.3 s) and a negligible steady-state error, as can be observed in the power values in Figure 9. Regarding dynamic response of voltage and current signals, Figure 10 shows, as an example, a detail of the transient in voltage in the load bus and current in the outer filter reactance of prosumer 2, when the voltage and control loops are activated. It can be observed that the transient in voltage is fast and accurate, whereas current signal presents a low amplitude oscillation, consistent with transient observed in power values ( Figure 9). However, neither high frequency oscillations nor sudden peaks are observed.

Conclusions and Future Works
This paper proposes and validates a hierarchical control scheme for prosumer nanogrids, which includes a novel secondary control strategy to allow for energy interchange between prosumers, aligned with P2P trading. Under the proposed secondary control, setpoints for active and reactive power and voltage in each prosumer load bus are generated to allow for energy interchange between them. Simultaneously, power flow equations, frequency reference value and power sharing based on droop rules are considered in the secondary control algorithm. All of the control loops that are required to manage a prosumer converter to connect both PV generation and battery ESS are designed and tested. Simulation results show a proper performance of the control loops, a very accurate tracking of the power and voltage setpoints and a very stable behavior of the voltage and the frequency within the nanogrid, even after unexpected changes in loads. Power flow between prosumers can be controlled, according to P2P agreements or other economic strategies, as a different controlled voltage value is obtained in each prosumer's load bus.
Future steps to continue this research project are the adaptation of the control scheme to grid-connected situation and seamless transition between both states. In addition, experimental tests are planned to demonstrate the method validity in actual lab conditions.

Conclusions and Future Works
This paper proposes and validates a hierarchical control scheme for prosumer nanogrids, which includes a novel secondary control strategy to allow for energy interchange between prosumers, aligned with P2P trading. Under the proposed secondary control, setpoints for active and reactive power and voltage in each prosumer load bus are generated to allow for energy interchange between them. Simultaneously, power flow equations, frequency reference value and power sharing based on droop rules are considered in the secondary control algorithm. All of the control loops that are required to manage a prosumer converter to connect both PV generation and battery ESS are designed and tested. Simulation results show a proper performance of the control loops, a very accurate tracking of the power and voltage setpoints and a very stable behavior of the voltage and the frequency within the nanogrid, even after unexpected changes in loads. Power flow between prosumers can be controlled, according to P2P agreements or other economic strategies, as a different controlled voltage value is obtained in each prosumer's load bus.
Future steps to continue this research project are the adaptation of the control scheme to grid-connected situation and seamless transition between both states. In addition, experimental tests are planned to demonstrate the method validity in actual lab conditions. Funding: This research was funded by the Spanish Agencia Estatal de Investigación (AEI), Fondo Europeo de Desarrollo Regional (FEDER), grant number TEC2016-77632-C3-1-R (AEI/FEDER, UE). Junta de Extremadura (Regional Government) also co-supported this work under the program "Ayudas Talento (TA18003)".