{'fraction_non_alphanumeric': 0.022612191256619382, 'fraction_numerical': 0.0075373970855397935, 'mean_word_length': 5.130805687203791, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Power Hardware-In-the-Loop Testing of a Peer-to-Peer Energy Trading Framework

This paper demonstrates the value of power hardware-in-the-loop (PHIL) testing for the study of peer-to-peer (P2P) energy trading. P2P has emerged as a promising candidate for coordinating large numbers of distributed energy resources (DER) that pose a risk to network operations if left unmanaged. The existing literature has so far relied on pure software simulations to study DER and distribution networks within this context. This requires the development of simplified models for complex components due to the computational limitations involved. Issues that arise through the operation of physical hardware in real-world applications are therefore neglected. We present PHIL testing as a solution to this problem by exhibiting its ability to capture the complex behaviors of physical DER devices. A high-fidelity PHIL test environment is introduced that combines key hardware elements with a simulated network model to study a P2P trading scenario. The initial findings reveal several underlying challenges of coordinating DER that are not typically discussed in prior works.


I. INTRODUCTION
Distributed energy resources (DER) are quickly becoming a critical component of modern electricity networks. The Australian Electricity Market Operator (AEMO) projects that the installed capacity of DER will double or triple by 2040 and form between 13% to 22% of all electricity generation in the National Electricity Market [1]. This level of growth is also being observed in many other jurisdictions around the world [2].
High penetrations of DER lead to violations of network constraints when not managed effectively [2]- [4]. This has sparked research into methods of coordinating large numbers of these devices that preserve system integrity and incentivize efficient usage. Such methods aim to strike a balance between maximizing social welfare and minimizing network instability.
There are several leading approaches towards solving this emerging problem. Among these is peer-to-peer (P2P) energy trading, which employs a market-driven strategy to encourage efficient DER operation. Under this strategy, energy can be transacted directly between participating energy prosumers and traditional consumers. Excess generation from DER can be routinely auctioned to potential buyers who wish to purchase energy at lower prices than the retail value. Buyers and sellers are matched during predetermined trading periods, with transacted energy then being dispatched to fulfill the conditions of each executed trade.
This structure brings added efficiency to several key areas of electricity networks. Local supply-demand balancing is encouraged through the market clearing process which reduces overall system losses [3]. P2P trading reliably converges to optimal pricing in each trading window which has a positive effect on social welfare [5], [6]. Other benefits include the improved utilization of excess generation (or reduced energy spillage) and clear incentives for new DER installations [7].
A key limitation of current P2P trading frameworks is the exclusion of network constraints. Trading without oversight from a network operator can lead to violations of voltage, frequency and thermal operating limits [5]. Methods of intervention by an entity such as a Distribution System Operator (DSO) have subsequently been proposed in [7] to address this.
A review of existing literature has revealed that the testing of P2P DER coordination methods has largely been confined to simulations and real-world trials. While such approaches do yield valuable insight into overall performance, each comes with distinct limitations. Pure software simulations allow for a wide range of operating scenarios to be tested but often lack the ability to model complex system elements accurately. In contrast, real-world trials provide the most accurate test setting but at the cost of flexibility to model a range of potential operating scenarios.
Marrying the two approaches -explicit hardware device testing and software simulations -can yield the benefits of both testing methods [8]. This has led to the development of hybrid Power Hardware-In-the-Loop (PHIL) testing techniques which have garnered significant attention in this research space. The complex behavior exhibited by DER devices presents a challenge that is ideal for the application of this technology.
This observation motivated us to apply state-of-the-art PHIL techniques to the study of P2P energy trading. A full hardware prosumer model -containing local PV generation, battery storage and variable load -was interfaced through a Spitzenberger & Spies linear power amplifier to a RTDS realtime digital simulator running a simple distribution network model. Equipment was selected to maximize the accuracy of operating data transferred between the software and hardware test components. A wireless communication network was also implemented through the use of Raspberry Pi devices to replicate real-world data collection conditions. This paper aims to demonstrate the efficacy of P2P trading for coordinating multiple prosumers in a high-fidelity environment. Specific attention is given to the effects of hardware devices on the overall performance of the scheme.
The remainder of this paper is structured as follows. In Section II, a detailed description of the P2P energy trading framework is provided. Section III summarizes the challenges and design considerations of PHIL test environments. Section IV then gives an overview of the PHIL test setting used to study P2P energy trading. Preliminary results are then presented in Section V to demonstrate the performance of the P2P trading approach on a simple radial distribution system. Concluding remarks are provided in Section VI.
II. P2P ENERGY TRADING P2P energy trading differs from traditional electricity market structures by allowing prosumers to trade energy directly with neighboring users [7]. This has been found to introduce many efficiencies to both the transactive environment and physical generation of electricity [3], [5], [7], [9]- [13]. In particular, P2P facilitates: • improved incentives for prosumers compared to traditional retail arrangements, • reduced spillage of DER generation due to improved prosumer coordination, • lower grid losses by encouraging shorter transmission distances between consumers and generation sources, and • less reliance on intermediaries to perform transactions. These benefits can be largely attributed to a core outcome of P2P energy trading: the transition from a centralized architecture to a decentralized architecture. While this in particular applies to the way electricity is generated and transacted, it also extends to other components of electricity networks. Recent work has identified the need for decentralized control, computation and communication infrastructure to overcome issues of scalability when coordinating large numbers of DER [7], [9], [14].
From a market perspective, there have been several candidate methods proposed in the literature for hosting P2P energy trading. These largely differ in the overall market structure used and the market operating strategy employed. Market structures range from discrete-time call auctions to continuous double auctions (CDAs), with each method offering different levels of scalability, awareness of network constraints, and computational overheads [9]. Operating strategies range from centralized architectures that employ cloud-based infrastructures to decentralized approaches that use distributed ledger technologies (DLTs) such as blockchains [15].
The use of a CDA has gained particular attention for being the chosen format for stock and commodity markets around the globe [16]- [18]. In addition, CDAs composed of rational participants are Pareto-improving and result in a highly efficient allocation of resources [7], [16]. This makes them an attractive option for optimizing DER usage in a P2P trading environment. Under a CDA P2P format, buyers and sellers of energy are matched according to a set of pre-defined trading rules. Participants lodge either buy orders (bids) or sell orders (asks) for electricity at any time during each trading period. Sellers of energy are solely composed of prosumers with dispatchable DER. Priority is always given to the best standing offer (highest bid or lowest ask), with matches occurring when the best bid exceeds the best ask at any given time [17]. If no match is found for a new order, it is stored until either a match is found or the current trade period ends, in which case, all outstanding orders are canceled. All executed trades are settled immediately after each trading interval, with sellers dispatching energy according to each contract. Any energy not secured in the P2P market to satisfy a trader's demand is typically purchased through a traditional retailer.
Market participants are frequently modeled as Zero-Intelligence Plus (ZIP) traders to represent human decisionmaking in an auction setting [17], [18]. This assumes that orders are submitted randomly by participants without any detailed underlying strategy. Bid and ask prices are instead adjusted by each trader based on the most recently matched orders. For example, traders with a bid price lower than the last executed order will decrease their margins by raising the previous bid amount.
Despite demonstrating excellent performance for improving social welfare in energy markets, several drawbacks of P2P energy trading schemes have been identified. Foremost among these is the absence of network constraint considerations and the spillage of DER generation that is not traded in the P2P market [3]. Current research is being conducted into overcoming these challenges and transforming theoretical P2P approaches into real-world solutions.

III. PHIL TESTING
PHIL testing seeks to gain the benefits of pure software simulations and real-world hardware experimentation by combining elements from both methods [8]. Traditional pure-software simulations offer a high degree of flexibility for power system studies by allowing the analysis of a wide range of scenarios. However, this comes at the cost of accuracy due to the need to develop software models for highly-complex hardware devices. In contrast, real-world testing offers the reverse; the presence of physical hardware yields high accuracy but lowers testing flexibility due to the risks of damaging equipment and endangering personnel. PHIL testing embeds complex hardware devices within a software environment capable of performing simulations in real time, resulting in both a highly accurate and flexible test environment.
Interest in PHIL testing methods has been increasing within the field of power systems engineering [8], [19]- [28]. Technological advancements in Real-Time Simulation (RTS) and power interfacing devices have improved the fidelity of PHIL test environments for studying the complex dynamic behavior of electricity networks [29], [30]. This has led to recent applications of PHIL techniques for the study of DER integration due to the complexity of the hardware interactions involved.
The two primary challenges of PHIL testing are the preservation of system stability and simulation accuracy [8], [24], [25], [27], [30]- [34]. As PHIL consists of high-power signals, instability can quickly lead to equipment damage and the endangerment of personnel [31]. The ideal test environment should therefore be capable of capturing system behavior with high accuracy while avoiding unbounded growth in any of the signals involved. This is difficult in practice due to the inherent errors introduced by the equipment used. In particular, the interface between the hardware and software components of the test system has a significant impact on overall stability and accuracy [27]. Errors are introduced through sensor noise, time delays, finite signal sampling rates and the response characteristics of the power amplifier device [31]. These culminate in lower quality test results and an increased risk of system collapse when amplified through the power interface device.
Recent work has been done on quantifying the effects of individual interface elements on overall PHIL stability [30], [32], [33]. This has allowed the time delays introduced by different power amplifiers, communication methods, RTS devices and other components to be directly contrasted when making design decisions. Improved stability and accuracy analysis are gained, which can be used to establish concrete operating boundaries for a particular PHIL test environment.
Simulation errors can be mitigated through the use of more advanced equipment. However, this comes with additional cost and may not always be possible within the budget of a development team. The trade-off between cost and system accuracy is, therefore, one of the major considerations in the field of PHIL testing.

IV. PHIL TESTING SET-UP
The PHIL test environment at the University of Sydney was designed to study DER coordination methods. The general concept was to model a typical residential prosumer entirely in hardware for connection to a real-time simulated distribution network model. This would allow all complex hardware interactions to be captured explicitly within the simulation environment. Their effects on the wider network could then be observed under different operating scenarios.
The typical prosumer was assumed to possess on-roof PV generation, local energy storage, and a variable load. This  was realized in hardware using the following key pieces of equipment: The communications required between the market platform 1 and each prosumer were also modeled explicitly in hardware.
To do this, four other neighboring prosumers were simulated on Raspberry Pi devices and interfaced wirelessly to a central computer hosting the CDA trading platform. This allowed the effects of communication delays and data loss on system operations to be directly incorporated.
An RTDS Technologies Mid-Size Cubicle was used to implement the simulated distribution model. The model design was done using the corresponding RSCAD graphical user interface. The real-time monitoring and control of network simulations were also done through this software.
The general arrangement of the PHIL test environment is shown in Figure 4. A key goal of this test environment was to obtain a very high level of accuracy for observing prosumer behavior. As a result, the interface between the software and hardware components were made to minimize time delays and noise as much as possible.
A linear power amplifier was chosen to achieve higher dynamic performance than switched-mode and synchronous generator amplifiers seen in other PHIL installations [30]. This amplifier operates with a slew rate of 52V/µs, which corresponds to time delays under 5µs for most operations [35]. In contrast, the switched-mode amplifier used in [33] was found to introduce a time delay of 66.67µs. Improved system accuracy and stability was gained as a result.
The analogue connections between the RTDS and power amplifier were replaced with a fiber-optic Aurora link after initial testing. This is known to be faster, more efficient and does not require anti-aliasing filters when compared to analogue interfaces [33]. The work in [32] found a time delay of <1µs for the Aurora protocol and 20µs for a standard analogue connection.
The installation of the Aurora link was done in response to stability and accuracy issues uncovered during the initial testing. The results in Section V were therefore obtained using analogue communications, with a discussion on the potential impact presented in Section V-B V. PHIL TESTING RESULTS Preliminary testing of a basic P2P market framework was conducted on the PHIL test environment to verify its performance. Tests were done prior to the installation of the Aurora link using a standard analogue interface as shown in Figure 4.
The P2P market operating algorithm was modeled off the approach developed in [7]. A CDA with hourly trading periods was used as the market structure and market participants were assumed to be ZIP traders. The matching of orders by the market platform was simulated using Algorithm 1. Participating ZIP energy traders updated their asks and bids in response to market events using Algorithm 2.
Any energy not secured through the P2P market to satisfy demand was purchased at the time-of-use (ToU) rates of a typical retailer. Likewise, surplus PV generation not able to be sold in the market was instead settled at a standard retail feed-in-tariff (FiT). The pricing used in the simulation was adapted from the 2021 residential standing offer of a large Australian energy retailer (AGL) [36].
A simple low-voltage distribution line served as the simulated network model ( Figure 5). The line was connected through an ideal 11/0.4kV Dyn1 distribution transformer to the wider network. Line conductors were assumed to be 7/4.50 single-core aerial bare aluminum, with impedances derived from [37]. The five single-phase market participants used in the simulation were connected to the network as shown in Figure 5. Connections to each household were staggered over the three phases to reflect real-world residential connection randomly select a new ZIP trader 3: Process orders with given (price, quantity, time) 4: if trader is buyer then  standards [38]. Line impedances separating each model element are shown in Table I. Three of the households had on-site PV generation, battery storage and a home energy management system (HEMS). The HEMS was modeled as a simple linear programming (LP) optimization problem with an objective function aimed at maximizing the savings of the prosumer. The forecasting of demand and PV generation at the beginning of the simulated period was assumed to be deterministic for the sake of simplicity. The effect of forecasting errors was, therefore, outside the scope of this study. The expected income from energy trading was also not included in the HEMS, with only retail pricing being used to form the objective cost function.
Of the two remaining households, one had only on-site PV generation and the other was a regular electricity consumer. The chosen battery and PV capacities for each household are shown in Table II.
The P2P market was operated over a one day period to verify its performance. Each prosumer was allocated an hourly PV generation profile and load profile to align with the chosen trading period duration. The profiles were adapted from actual meter data from Australian residences published by a large Australian distribution network operator (Ausgrid) [39].

A. P2P Trading Results
The trading activity resulting from the simulation is shown in Figure 7. The total value gained over a traditional retail arrangement for each household is shown in Table III.   Figure 7c shows that the total exports far exceeded imports over the course of the simulation. This signifies that a surplus of power generation was present during most periods, particularly during the daytime due to abundant PV generation. This caused a large number of trades to occur from prosumer households (Households 1, 2, 3 and 5) selling excess generation to the only available energy consumer (Household 4). Household 3 became available as a buyer outside of daylight hours due its the lack of on-site energy storage. Figure 7a shows that all trades were executed at prices under 10c/kWh. This was despite a FiT of 6.1c/kWh and a peak ToU price of 49.24c/kWh. The low execution prices were attributed to the large surplus of energy supply driving lower prices in the competitive market environment. The majority of value was therefore unlocked by buyers of electricity, as demonstrated in Table III. Figure 7b reveals that potential buyers often chose to purchase power at the retail ToU rate instead of the best available ask price. This always resulted in a higher price being paid for electricity. The irrational decision-making shown here highlights a key shortcoming of the chosen ZIP trader algorithm: buyers do not account for the inelastic nature of electricity demand. Most markets (such as stock markets) allow traders the freedom to forego transactions without incurring a direct loss at the end of a trade period. In contrast, P2P electricity markets require each participant to secure enough supply to meet demand during all trading intervals. This leads to traders being forced to purchase shortages of electricity at a higher retail price if not acquired elsewhere.

B. PHIL Testing Behaviour
The hardware prosumer model was allocated to Household 1 in the simulated scenario. The power interface was initially designed to transfer only the voltage at the grid connection point from the simulated network model to the hardware environment. The current measured at the amplifier output was then communicated back to the network model to complete the feedback loop, creating an arrangement similar to that shown in Figure 3. The communication of the signals was done through a basic analogue connection.
The simulation was found to be unstable under this arrangement. This was largely attributed to the high harmonic distortion present in the outputs of the commercial PV and battery inverters (Figure 8). It was concluded that reductions to the total time delay of the PHIL feedback loop would be needed to properly capture this behavior. The use of shorter simulation time steps and fiber communication over analogue connections are being explored as potential solutions.
Stability was obtained in the meantime by processing the measured hardware signals in RSCAD. To do this, voltage and current were measured synchronously from the power amplifier and communicated to the simulation environment. These signals were then converted artificially into pure active and reactive power values using the in-built PQ meter block. The effect of this transformation on removing harmonic distortion can be observed in Figure 8a.
RSCAD uses equations (1) and (2) to do this operation: This method enables waveform distortion to be factored into the result by explicitly handling non-sinusoidal conditions, as discussed in [40]. This is in contrast to calculating power values in (3) and (4), as done on the human-machine interface (HMI) of the power amplifier: These assume that no distortion is present by only considering the fundamental frequency of the waveform. It was discovered that this yielded values considerably different to real-time integration when applied to the measured signals.  The non-sinusoidal conditions created by inverter devices can therefore have a large impact on meter device readings depending on the calculation method. This could have realworld implications in networks with a high penetration of DER.
The PHIL system maintained stability under a wide range of conditions using the PQ block conversion. Active power settings issued to the battery inverter in response to P2P trading closely matched values measured in the network model, as shown in Figure 9. However, discrepancies could still be observed between the power traded in the P2P market and the amount actually dispatched. There is a need to further investigate methods of resolving these instances within the market framework.

VI. CONCLUSION
P2P energy trading is a viable alternative for coordinating DER. It incentivizes prosumers to preserve the local supplydemand balance through the underlying market mechanism. The competition created between buyers and sellers fosters more efficient pricing and allocations of resources when compared to traditional approaches.
Challenges are introduced through the underlying interactions between physical hardware devices. These included the high levels of harmonic distortion introduced by commercial PV and battery inverters and mismatches between traded energy and amounts actually dispatched. The non-sinusoidal conditions created by DER also highlight the importance of the method chosen for measuring real and reactive power. All of these issues are particular to the hardware used and are not easily replicable in pure software. This highlights the need for PHIL testing in the study of DER coordination strategies.
Capturing the harmonic distortion from inverter devices presented a challenge for the PHIL test environment. It was discovered that a highly-ideal power interface is necessary to preserve system stability when capturing this behavior. Reducing time delays through improved communication methods and smaller simulation time steps are being explored towards this end. The level of distortion observed could also have real-world ramifications for distribution networks and warrants additional investigation.
The effects of wireless communication methods on the scalability of P2P energy trading are yet to be investigated. Future studies will employ the RPi devices to explore the impact of data loss and communication delays. This will provide insight into the feasibility of large-scale P2P applications.
Further stability analysis is required to establish the exact operating limits of the PHIL test environment. Quantifying stability margins is critical for gauging which power system behaviors can be studied. The information can also be used to make informed decisions on future PHIL designs.
Finally, the inelastic nature of electricity demand was found to be problematic when modeling prosumer bidding strategies. ZIP traders were discovered to display irrational behavior when used in an energy market setting. Opportunities to purchase electricity in the CDA were routinely declined in favor of more expensive retail tariffs, leading to lower economic benefits for all parties. Future work is needed to refine the simulation of prosumers in P2P markets.