**5. EMS Testing Results**

In order to verify the proposed management strategy, at first, the manager architecture (see Figure 4) was entirely implemented using MATLAB software with a conceptual microgrid (see Figure 2). Additionally, the EMS algorithms were also implemented using the Python language and executed in a Raspberry Pi 3 platform. A MicroLabBox dSPACE was used to verify the real-time EMS behavior on a microgrid emulation platform, and its schematic is presented in Figure 6.

**Figure 6.** Platform schematic of system emulation with MicroLabBox dSPACE, a Raspberry Pi 3, and a PC host.

The power electric system was emulated within the dSPACE, and all required data were made available by the software dSPACE/ControlDesk. Since the data must be managed by the Raspberry, a TCP/IP protocol was chosen for the communication path. The energy management was computed by the Raspberry, then all reference signals were sent back to the power system emulation platform, through the PC host. To verify the EMS operation, the emulation results obtained by the platform, illustrated in Figure 6, were compared and matched to the simulation results that are presented in this section.

Figure 7 presents the measured data along with the energy price curve provided by [23], based on the commercial mode fee. The predicted data were determined using the measured data for a week before with 30 minute sample time decimation. Since the main scope of this paper is on the optimization and management logic, the EMS evaluation considered a constant temperature value throughout the day *Tamb* in order to highlight the effect of main variables *PPV*, *PL*, *rG*, and EV charging operation.

**Figure 7.** Microgrid profile used in EMS analysis: price of the grid energy (*rG*), load demand (*PL*), PV generation (*PPV*), and the net PCC power (*Pnet*).

Ten EV slots were considered in the facility parking lot, with distributed modes and parking periods. This arrangement was defined in order for it to be possible to identify the manager performance against connection variability and operation modes. Table 1 presents the EMS parameters used in the analysis, while the EV charger was considered a commercial model Terra 54, developed by ABB company, which provided 50 kW of nominal power [24]. It can be seen that *Pevpossible* had two different ranges, and the total number of values (quantization) was determined by *Pevvalues*, as for SOC range, which was defined by *SOCvalues*.


**Table 1.** Simulation and real-time emulation parameters.

In order to validate the algorithms developed for management, microgrid evaluations were performed using the the proposed EMS, the Terra 54 charger, a 420 kWp PV distributed generation, and a 450 kW load demand. Figure 8 shows the microgrid power flows, emphasizing the V2G mode, which is separated by two regions: charging (V2G+) and discharging (V2G−). The required of the microgrid from the external grid (*Pgrid*) is highlighted in red.

**Figure 8.** Power flow of charging modes and the liquid power delivered to the PCC, highlighting the external grid power (*Pgrid*) with the red line.

When V2G− was present, part of the microgrid demand was supplied by the vehicles in V2G mode. During the surplus period, it can be noticed that the energy was used more efficiently, being applied to charge those vehicles set on ECO and V2G modes instead of being exported to the external grid. Hence, it is important to note that vehicles set on V2G mode only charged when the energy price was appropriate. Moreover, between 6 p.m. to 8 p.m., the V2G stored energy was discharged, generating economic benefits for the microgrid owner such as the energy purchase in moments of peak demand, reducing the facility operation costs. Figure 9 shows the charging mode (1, ULTRA; 2, FAST; 3, ECO; 4, V2G), power flow, and SOC for each EV in the parking lot. The gray regions represent the parking duration for each EV, while the solid line presents the instantaneous power and SOC defined/optimized by the EMS.

An analysis of each EV indicated that the ones in ULTRA mode were charged at nominal power while the vehicles in FAST mode had a slight reduction during the period of limited demand. Vehicles in ECO mode were charged at periods with PV surplus, avoiding demand peaks. In addition, EVs on V2G mode supplied energy to all other vehicles during moments of peak demand, around 6 p.m. To achieve this condition, the EMS commanded the energy surplus storage from 11:30 a.m. to 1:30 p.m. to sell it for a higher price during demand peaks. Since vehicles in V2G mode included discharging possibilities, the SOC and power flow of these vehicles are depicted individually in Figure 10.

**Figure 9.** EV instantaneous power (**left**) and corresponding SOC (**right**), with the charging mode and the connection period. The modes are represented by: 1, ULTRA; 2, FAST; 3, ECO; and 4, V2G.

**Figure 10.** Charging power profile and SOC of a vehicle in V2G mode.

Region A in the Figure 10 represents the initial *EVV*<sup>2</sup>*<sup>G</sup>* discharging. The discharge was related to the high initial *EVV*<sup>2</sup>*<sup>G</sup>* SOC and to the predicted charging period in Region B, where a PV surplus existed, and the energy cost was lower considering the action of *α* proposed in Generation Surplus subsection. In Region C, the price of the grid energy had its highest value, so it was convenient that *EVV*<sup>2</sup>*<sup>G</sup>* vehicles assisted in power supply for the microgrid. The charging power spikes close to the disconnection instant were related to the factor state in the final time. The dark part in Region C was associated with the demand limitation, since in this condition, the *EVV*<sup>2</sup>*<sup>G</sup>* was commanded up to its nominal power in order to supply the microgrid overdemand power.

In the presented evaluation, there was a charging limitation only for FAST mode, confirming the priority employed by ULTRA mode. ECO mode also met the priority set and achieved an optimal charging profile without exceeding demand limits. V2G mode fulfilled the preferences defined by the user and the facility, and a more efficient use of the energy from the microgrid was obtained. The overall influence of the EMS for EV parking lot can be seen in Figure 11, where the *Pnet* and *Pgrid* flows are shown individually.

**Figure 11.** Resulting power between demand and generation and the power exchange with the external grid considering the EVs.

It can be seen that EV charging increased the microgrid demand at night, but the effect of valley filling was obtained throughout the afternoon. The proposed EMS behaved appropriately to supply the demand peaks, both limiting the charging of the *EVF*, as well as providing the valley filling from PV surplus using *EVV*<sup>2</sup>*G*.

A comparison of numerical analysis is presented in Table 2, wherein four scenarios are shown: 1, the microgrid without the EV parking lot; 2, with the EV parking lot, but no EMS; 3, with EV with a conventional EMS, with only ULTRA and FAST modes; and 4, with the EV parking lot with the proposed EMS. All scenarios that utilized EV slots took the configuration presented in Figure 9 into account, except for some changes among the scenarios. The second scenario considered EV only in ULTRA mode, without any EMS strategy. The third scenario considered a conventional EMS where only ULTRA and FAST modes were applied. ECO mode EVs in Figure 9 were considered in FAST mode, and the vehicle in V2G mode was assumed in ULTRA mode. The last scenario applied the proposed EMS entirely.

**Table 2.** Comparison for the operation of the parking lot with different EMS scenarios.


It can be seen that the system without an EV parking lot had the minimum cost with grid purchase; however, the increase of the EV market will make this arrangement more common. Then, if the system has no EMS to manage the charge/discharge, the price spent may rise, as can be noticed in the second

scenario, which presented a cost increase of 20.93%. This cost was considered a penalty for exceeding the demand limit [25] along 2.5% of the day above its demand limit. This situation was improved with the conventional EMS, which reduced back to 0% the exceeding the energy of the microgrid, and decreased to 8.8% the cost of grid energy purchase. The influence of ECO and V2G modes can be seen in the fourth scenario, which reduced the energy cost to 7.43%, maintaining the system demand within the limits.
