A power distribution network protection semi-physical simulation system and method based on MATLAB-STM32 cooperation

CN122549334APending Publication Date: 2026-08-11LINYI UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-16
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0006]本发明目的是提供,解决现有半实物仿真平台依赖工业级设备导致的成本高、部署复杂的问题,同时解决现有平台不支持训练-推理分离架构、难以实现保护算法快速验证转化的问题

Benefits of technology

本发明采用民用级STM32F407嵌入式平台替代传统RT-LAB/dSPACE工业级实时仿真系统,通过以太网UDP协议实现周期性数据交互,显著降低了半实物仿真系统的硬件成本与部署门槛,使保护算法的嵌入式验证更加便捷。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122549334A_ABST
    Figure CN122549334A_ABST
Patent Text Reader

Abstract

This invention discloses a hardware-in-the-loop (HIL) simulation system and method for power system relay protection based on MATLAB-STM32 collaboration, belonging to the field of power system relay protection testing technology. It includes: an upper-level simulation layer running a Simulink electromagnetic transient model of the power distribution network to complete offline adaptive optimization of setpoints and training of machine learning models; a communication adaptation layer enabling periodic bidirectional data interaction between the upper and lower levels via Ethernet UDP; a lower-level control layer performing lightweight model lookup table reasoning and protection logic operations based on STM32F407; a mode switching layer supporting pause-switch-resume operation in both pure simulation and HIL modes, sharing the same model topology; and a human-computer interaction layer enabling full-process visual monitoring. This invention solves the problems of high cost and complex deployment caused by the reliance on industrial-grade equipment in existing HIL platforms, and realizes rapid verification and transformation of protection algorithms from MATLAB simulation to STM32 embedded deployment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of power system relay protection testing technology, specifically to a hardware-in-the-loop simulation system and method for distribution network protection based on MATLAB-STM32 collaboration. Background Technology

[0002] The penetration rate of distributed generation (DG) power, represented by photovoltaic (PV) and wind power, in distribution networks is continuously increasing. DG power is connected to the grid via power electronic converters, and its fault output characteristics are dominated by control strategies such as low-voltage ride-through, which significantly differs from traditional synchronous generators. The protection settings of distribution networks containing DG power need to be dynamically adjusted according to operating conditions, which places higher demands on the verification of protection algorithms.

[0003] The verification of existing protection algorithms mainly relies on pure software simulation, which makes it difficult to verify the real-time performance and resource consumption of the algorithms on embedded hardware. Furthermore, existing hardware-in-the-loop (HIL) simulation verification platforms often employ industrial-grade real-time simulation systems such as RT-LAB and dSPACE, which suffer from high hardware costs, complex deployment, and steep learning curves, hindering the rapid transformation of protection algorithms from theoretical research to engineering applications.

[0004] Furthermore, existing hardware-in-the-loop (HIL) simulation platforms often use proprietary communication protocols and hardware interfaces for their host and slave computers, lacking versatility and scalability. When protection algorithms need to run in a separate architecture where training is done on the host computer and deployment is done on the slave computer, existing platforms struggle to support the lightweight deployment mode that separates training and inference.

[0005] Therefore, there is an urgent need for a low-cost, easy-to-deploy, and hardware-in-the-loop simulation system that supports the separation and verification of algorithm training and embedded inference, so as to realize the rapid verification and engineering transformation of distribution network protection algorithms containing distributed power sources. Summary of the Invention

[0006] The purpose of this invention is to provide solutions to the problems of high cost and complex deployment caused by the reliance on industrial-grade equipment in existing hardware-in-the-loop simulation platforms, as well as the problems of existing platforms not supporting training-inference separation architecture and difficulty in achieving rapid verification and transformation of protection algorithms.

[0007] To achieve the above objectives, the present invention employs the following technical solutions.

[0008] A hardware-in-the-loop simulation system for distribution network protection based on MATLAB-STM32 collaboration, characterized in that it includes: The upper computer simulation layer is used to run the Simulink electromagnetic transient simulation model of the distribution network, generate fault electrical quantities in the scenario of distributed power source access, and perform offline setpoint adaptive optimization and machine learning model training for the fault current-constrained characteristics of the distribution network with distributed power source. The communication adaptation layer is used to realize periodic bidirectional data interaction between the upper computer simulation layer and the lower computer control layer through the Ethernet UDP protocol with a preset step size. The data interaction includes the transmission of fault electrical quantities and the transmission of circuit breaker control commands. The lower-level control layer, built on the STM32F407 embedded microcontroller, is used to receive fault electrical quantities, execute lightweight machine learning model lookup reasoning and protection logic operations, and output circuit breaker control commands. The mode switching layer is used to support pause-switching-resumption during operation between pure simulation mode and semi-physical simulation mode. The two modes share the same power distribution network model topology. In pure simulation mode, the Simulink model runs in a self-loop, while in semi-physical simulation mode, the Simulink model and the lower-level control layer form a closed loop. The human-machine interaction layer is used to synchronously display simulation waveforms, protection action status, lower-level machine operating parameters, and communication status information.

[0009] Furthermore, the host computer simulation layer includes: The electromagnetic transient simulation module for distribution networks is used to build a 10.5kV distribution network model with distributed power sources in the MATLAB / Simulink environment and generate fault current and fault voltage electrical quantities under single-phase grounding faults. The algorithm training and setting generation module is used to execute offline optimization algorithm and machine learning model training, generate protection setting parameters including instantaneous overcurrent setting I50, overcurrent setting I51 and overcurrent protection delay T51, and output them as C language header file format; The graphical user interface module provides functions such as mode selection, parameter configuration, operation control, real-time waveform display, and protection status monitoring.

[0010] Furthermore, the data packet format of the communication adaptation layer includes a data frame header identifier, an electrical quantity data field, a control command field, and a status feedback field; the communication adaptation layer also has an application layer reliability mechanism: the electrical quantity data packets sent by the host computer carry a timestamp and a sequence number, and the slave computer stores them in a circular buffer according to the sequence number after receiving them. The slave computer sends back an acknowledgment frame for each valid data packet received, and if the host computer does not receive an acknowledgment frame within the timeout period, it retransmits the data packet.

[0011] Furthermore, the lower-level control layer includes: The fixed value storage and retrieval module is used to load the protection fixed value parameters from the Flash memory to the RAM running area; The electrical quantity receiving and parsing module is used to receive and parse fault electrical quantity data packets from the host computer via an Ethernet interface; The protection decision engine module is used to perform lightweight machine learning model lookup reasoning, fault direction determination, instantaneous overcurrent protection determination, overcurrent protection delay determination, and circuit breaker drive logic. The control command output module is used to encapsulate the protection action results into data packets and send them back to the host computer simulation layer; The local display module is used to drive the LCD screen to display network configuration, setpoint parameters, fault direction, trip status, and running time information.

[0012] Furthermore, the execution logic of the protection decision engine module includes: Load the machine learning model lookup table structure, traverse the model node array based on the fault feature vector, and output the protection action results; Receive the instantaneous value of the fault current and calculate its effective value. Compare the effective value of the fault current with the instantaneous trip setting value I50. If it is greater than I50, output the instantaneous trip command. When the instantaneous overcurrent protection is not triggered, the overcurrent delay counter is started. When the fault current continues to be greater than the overcurrent setting I51 and the delay reaches T51, the overcurrent trip command is output. The fault direction is determined synchronously, and the result of the determination of positive direction, reverse direction or uncertain direction is output according to the current phase relationship on both sides of the line. When the determination is reverse direction, the protection trip output is blocked.

[0013] Furthermore, the switching logic of the mode switching layer includes: The operating mode selected by the user is received through the human-computer interaction layer; The Simulink model topology is reconstructed according to the selected mode. In pure simulation mode, the circuit breaker control commands are generated by the internal logic module of Simulink, while in semi-physical simulation mode, they are transmitted back by the lower-level control layer. Synchronize the current protection setting parameters to the execution unit corresponding to the selected mode; Pause the simulation and save the current distribution network state variables. After switching the model topology, load the state variables and resume the simulation, maintaining the continuity of the simulation clock.

[0014] A hardware-in-the-loop simulation method for distribution network protection based on MATLAB-STM32 collaboration includes the following steps: S1. Run the Simulink electromagnetic transient simulation model of the power distribution network on the host computer, configure the distributed power source and fault parameters, and generate fault electrical quantities in the scenario with distributed power source access. S2. On the host computer, offline adaptive optimization of setpoints is performed for the fault current limiting characteristics of the distribution network with distributed power sources. The machine learning model is trained, protection setpoint parameters are generated and hardened to the flash memory of the lower computer. S3. Establish periodic bidirectional data interaction between the host computer and the slave computer through the Ethernet UDP protocol with a preset step size, transmit fault electrical quantities to the slave computer, and receive control commands and status information transmitted back from the slave computer. S4. The lower-level machine receives the fault electrical quantity, loads the protection setting parameters, executes the lightweight machine learning model lookup reasoning and protection logic operation, and outputs the circuit breaker control command. S5. Select pure simulation mode or semi-physical simulation mode to run. Supports pause-switch-resume during operation. Both modes share the same power distribution network model topology. S6. Synchronously display simulation waveforms, protection action timing, and lower-level machine operating status, and record protection action results.

[0015] Furthermore, the curing process for protecting the setpoint parameters in step S2 includes: The host computer generates a C language header file containing an array of fixed-value structures; The C language header file is transferred to the lower-level machine development environment, and the fixed-value structure is linked to the specified sector of Flash during compilation. During runtime, the lower-level machine loads fixed parameters from Flash into the RAM running area through memory mapping.

[0016] Furthermore, the synchronization mechanism for periodic data interaction in step S3 includes: After each simulation step, the host computer Simulink model calls the UDP send function to transmit fault electrical quantity data packets. The lower-level machine receives data packets via Ethernet interrupt, parses them, and updates the electrical quantity buffer. The lower-level protection decision engine scans the electrical quantity buffer at fixed intervals and executes protection logic. It then sends the protection action results back to the upper-level computer via UDP to update the circuit breaker status in the Simulink model.

[0017] Furthermore, the method for pausing-switching-resumption during runtime in step S5 includes: Before switching, save the distribution network state variables at the current simulation moment. The distribution network state variables include the voltage, current and circuit breaker position of each node. After switching, the saved state variables are loaded into the model instance corresponding to the target mode, the communication buffer is reset, and the data synchronization between the upper and lower computers is re-established. Resume simulation operation to maintain the temporal continuity of fault events.

[0018] The advantages of this invention are: This invention uses a civilian-grade STM32F407 embedded platform to replace the traditional RT-LAB / dSPACE industrial-grade real-time simulation system. It achieves periodic data interaction through the Ethernet UDP protocol, which significantly reduces the hardware cost and deployment threshold of the hardware-in-the-loop simulation system, making the embedded verification of protection algorithms more convenient.

[0019] This invention designs a separate architecture for upper-level computer training and lower-level computer inference. The upper-level computer performs offline adaptive optimization of setpoints for the fault current-constrained characteristics of distribution networks with distributed power sources, while the lower-level computer executes lightweight machine learning model lookup inference and protection logic. This fully utilizes the computing resources of the upper-level computer and the real-time response capability of the lower-level computer to achieve seamless integration of algorithm research and engineering deployment.

[0020] This invention proposes a pause-switching-resumption method for pure simulation mode and semi-physical simulation mode. The two modes share the same power distribution network model topology and support flexible switching between the algorithm verification stage and the embedded verification stage, which improves verification efficiency and ensures the temporal continuity of fault events.

[0021] This invention establishes a status synchronization mechanism between the upper computer waveform display and the lower computer LCD display, realizing full-process visual monitoring of the verification process, which facilitates researchers to intuitively compare the consistency between pure simulation results and semi-physical simulation results. Attached Figure Description

[0022] Figure 1 This is a system architecture diagram of the hardware-in-the-loop simulation system for power distribution network protection based on MATLAB-STM32 collaboration of the present invention; Figure 2 The following is a flowchart illustrating the execution logic of the decision engine protected by this invention. Figure 3 This is a flowchart illustrating the switching logic of the mode switching layer in this invention. Figure 4 This is a timing diagram of the periodic synchronization mechanism of the present invention; Figure 5 This is a comparison of the simulation waveforms before and after the mode switching of this invention. Figure 5 (a) shows a comparison of the simulated waveforms of the three-phase AC currents Ia, Ib, Ic and the zero-sequence current I0 in pure simulation mode. Figure 5 (b) is a comparison of the simulated waveforms of the three-phase AC currents Ia, Ib, Ic and the zero-sequence current I0 in the hardware-in-the-loop simulation mode. Figure 6 This is a schematic diagram of the LCD display interface of the lower-level machine in this invention. Detailed Implementation

[0023] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0024] This embodiment provides a hardware-in-the-loop simulation system for distribution network protection based on MATLAB-STM32 collaboration. The overall architecture is as follows: Figure 1As shown, it includes an upper-level computer simulation layer, a communication adaptation layer, a lower-level computer control layer, a mode switching layer, and a human-computer interaction layer. It should be noted that, in this embodiment, the preset step size refers to the data interaction between the upper-level computer simulation and the lower-level computer control at a fixed or variable period. This period is determined by the computational load of the Simulink model solver and the network transmission delay to ensure simulation continuity.

[0025] Upper computer simulation layer: built on the MATLAB / Simulink platform, including a power distribution network electromagnetic transient simulation module, an algorithm training and setpoint generation module, and a graphical user interface module.

[0026] A 10.5kV distribution network model with distributed generation (DG) was constructed using the electromagnetic transient simulation module of the distribution network as the simulation object for the upper-level computer simulation layer. The system consists of the upper-level power grid, two feeders L1 and L2, and one inverter-type DG. L1 and L2 operate in a closed loop via a tie switch, and the DG is connected to the point of common coupling. The system's base load is 5MW, and the short-circuit capacity of the upper-level power grid is 200MVA. The feeders adopt a π-type equivalent circuit with positive-sequence parameters of R1=0.12Ω / km, L1=1.2mH / km, and C1=0.01μF / km; and zero-sequence parameters of R0=0.3Ω / km, L0=3.5mH / km, and C0=0.006μF / km. The DG has a rated capacity of 2MVA and adopts a standard low-voltage ride-through control strategy, limiting the output current to 1.2 times the rated current during faults. The system neutral point employs a flexible hybrid grounding device, consisting of an arc suppression coil and a small resistor connected in parallel via a bidirectional controllable power electronic switch. This device can simulate three operating modes: pure arc suppression coil grounding, pure small resistor grounding, and arc suppression coil with a small resistor in parallel. Three typical fault locations are set: F1 at the point of common coupling, F2 upstream of feeder L1, and F3 downstream of feeder L2. The transition resistance can be adjusted within the range of 0.1-100Ω. The model can generate electrical quantities such as fault current and fault voltage under single-phase grounding faults.

[0027] The algorithm training and setting generation module employs a Bayesian optimization algorithm to perform offline setting optimization. Optimization variables include the instantaneous overcurrent setting I50, the overcurrent setting I51, and the overcurrent protection delay T51. A machine learning model is used to evaluate the protection performance of the settings under different distributed power supply penetration rates. After training, the setting parameters and the machine learning model lookup table structure are output as a structure array in the C language header file rf_model.h for use by the lower-level machine.

[0028] The graphical user interface module is developed based on MATLAB AppDesigner and provides functions such as mode selection, parameter configuration, operation control, real-time waveform display, and protection status monitoring.

[0029] Communication Adaptation Layer: Ethernet UDP protocol is used for data interaction between the upper and lower level machines. The upper level machine IP address is configured as 192.168.1.100, and the lower level machine IP address is configured as 192.168.1.10. The upper level machine uses port 5001 for sending and port 5002 for receiving, while the lower level machine uses port 5002 for sending and port 5001 for receiving. The data interaction step size is dynamically adjusted according to the Simulink model solver, with a typical value of 10ms~50ms. The step size includes the total time for upper level machine simulation calculation, UDP data transmission, and lower level machine protection decision-making. The data packet format includes four parts: a data frame header identifier for frame synchronization and verification; an electrical quantity data field containing the instantaneous values ​​of the A-phase fault current and A-phase fault voltage; a control command field containing circuit breaker trip commands, reclosing commands, and protection direction flags; and a status feedback field containing the lower level machine operating status code, protection action flags, and fault direction determination results. The communication adaptation layer sets up an application layer reliability mechanism: the data packets sent by the host computer carry timestamps and sequence numbers. After receiving them, the slave computer stores them in a circular buffer according to the sequence number, discards duplicate packets, and detects packet loss. The slave computer sends back an acknowledgment frame for each valid data packet it receives. If the host computer does not receive an acknowledgment frame within the timeout period, it retransmits the corresponding data packet.

[0030] The lower-level control layer is implemented based on the Zhengdian Atom DMF407 development board, with the core chip being an STM32F407IGT6 with a main frequency of 168MHz. It is equipped with 1MB Flash and 192KB RAM, and an external 3.5-inch LCD display. The lower-level machine includes a setpoint storage and retrieval module, an electrical quantity receiving and parsing module, a protection decision engine module, a control command output module, and a local display module.

[0031] The fixed value storage and retrieval module compiles and links rf_model.h to the Sector5 to Sector7 region of Flash (starting address 0x08020000). When the program starts, the fixed value parameters are loaded into the RAM running area through memory mapping.

[0032] The electrical quantity receiving and parsing module receives UDP data packets through the Ethernet interface integrated on the development board, parses them, and then updates the electrical quantity buffer.

[0033] The protection decision engine module scans the electrical quantity buffer at 10ms intervals and executes the following logic: Figure 2As shown: First, the machine learning model lookup table structure is loaded. Based on the fault feature vector, the model node array is traversed to output the protection action result. The instantaneous value of the fault current in phase A is received and its effective value is calculated. It is compared with the instantaneous trip setting I50. If it is greater than I50, an instantaneous trip command is output. If the instantaneous trip protection is not triggered, an overcurrent delay counter is started. When the fault current continuously exceeds the overcurrent setting I51 and the delay reaches T51, an overcurrent trip command is output. Simultaneously, fault direction determination is performed. Based on the current phase relationship on both sides of the line, a positive direction, reverse direction, or uncertain result is output. If the determination is reverse direction, the protection trip output is blocked. In this embodiment, the machine learning model is a random forest model, trained by the host computer and compressed into a node array lookup table structure. The protection decision engine supports extended access to adaptive protection, differential protection, and fault component-based directional protection algorithms. The control command output module encapsulates the protection action result into a UDP data packet and sends it back to the host computer. The local display module drives the LCD screen to display the IP address, connection status, setting parameters, fault direction, trip status, and running time. The display interface is as follows: Figure 6 As shown.

[0034] Mode switching layer: Supports runtime switching between pure simulation mode and semi-physical simulation mode. The switching logic is as follows: Figure 3 As shown. In pure simulation mode, the Function module inside the Simulink model directly generates circuit breaker control commands without going through the lower-level machine, which is used to verify the correctness of the algorithm itself. In hardware-in-the-loop simulation mode, the Simulink model sends electrical quantities to the lower-level machine via UDP, and the lower-level machine's protection decision engine generates control commands and sends them back, forming a closed loop, which is used to verify the equivalence between the embedded implementation and the upper-level machine algorithm.

[0035] The switching process is as follows: The host computer pauses the Simulink simulation, saves the current distribution network state variables (voltage, current, and circuit breaker positions at each node) using the Simulink.State object; switches the VariantSubsystem activation state using the set_param function, reconstructs the model topology; loads the saved state variables into the target mode model instance, resets the communication buffer, and re-establishes data synchronization; and resumes simulation operation. The switching process is completed within a single simulation step, maintaining the temporal continuity of fault events. The waveforms before and after the switching are compared. Figure 5 As shown.

[0036] Human-Machine Interface Layer: This layer includes a host computer display panel, a slave LCD display panel, and a status synchronization mechanism. The host computer display panel shows fault current waveforms, fault voltage waveforms, circuit breaker status indicators, relay protection signal indicators, and fault event logs. The slave LCD display panel shows network configuration information, setting parameters, real-time fault direction, protection action status, and system runtime. The status synchronization mechanism ensures the timing consistency of protection action events between the host and slave computers.

[0037] This embodiment sets up two verification modes for performance comparison under the same test environment: Pure simulation mode: The protection action is executed by Simulink's internal logic and is used to verify the correctness of the algorithm itself.

[0038] Hardware-in-the-loop simulation mode: The protection action is executed by the lower-level STM32, which is used to verify the equivalence between the embedded implementation and the upper-level algorithm.

[0039] The test conditions include: distributed power penetration rates of 0.1, 0.3, 0.5, 0.7, and 0.9; fault locations of F1, F2, and F3; and transition resistances of 0.1Ω, 10Ω, 50Ω, and 100Ω.

[0040] Test results show that, under all test conditions, the consistency of protection actions between the hardware-in-the-loop simulation mode and the pure simulation mode reaches 100%, and the protection action time deviation is less than 2ms, verifying the effectiveness and reliability of the system.

[0041] Lower-level machine resource usage: Flash usage is approximately 320KB, RAM usage is approximately 48KB, and CPU load peak is approximately 35%, which meets the resource constraints of STM32F407.

[0042] Example 2 This embodiment provides a semi-physical simulation method for distribution network protection based on MATLAB-STM32 collaboration, executed according to the system described in Embodiment 1, including the following steps: S1. Upper computer model operation and electrical quantity generation: Start the distribution network Simulink model in the upper computer simulation layer, configure the distributed power source penetration rate, power factor, fault location and transition resistance parameters, start the simulation and generate electrical quantities such as fault current and fault voltage under single-phase ground fault.

[0043] S2. Offline Training and Fixing of Protection Settings: On the host computer, a Bayesian optimization algorithm is used to perform offline adaptive optimization of the settings, training a random forest machine learning model. Setting parameters and a model lookup table structure containing instantaneous overcurrent setting I50, overcurrent setting I51, and overcurrent protection delay T51 are generated, compiled into a C language header file, and then written to a specified sector of the lower-level machine's Flash memory. The setting parameter writing process is as follows: The host computer generates a C header file containing an array of setting structures; the C header file is transmitted to the lower-level machine's development environment via serial port or Ethernet; the lower-level machine program links the setting structures to the specified sector of Flash memory during compilation; and at runtime, the Flash settings are loaded into the RAM running area through memory mapping.

[0044] S3. Communication Link Establishment and Data Interaction: An Ethernet UDP connection is established between the host computer and the slave computer through the communication adaptation layer. Fault electrical quantity data packets are periodically transmitted with a preset step size. Simultaneously, control commands and status information transmitted back from the slave computer are received. The timing of the periodic synchronization mechanism is as follows: Figure 4 As shown, t0~t5 is a complete synchronization cycle with dynamically adjustable step size. The mechanism is as follows: after each simulation step, the host computer Simulink model calls the UDP send function through the S-Function or MATLABFunction module; the slave computer receives data packets through Ethernet interrupt, parses them, and updates the electrical quantity buffer; the slave computer protection decision engine scans the buffer and executes protection logic at fixed intervals; the protection action results are transmitted back to the host computer via UDP to update the circuit breaker status in the Simulink model.

[0045] S4. Lower-level protection decision execution: The lower-level machine receives and parses electrical quantity data packets, loads setpoint parameters from Flash to RAM; the protection decision engine scans the electrical quantity buffer at fixed intervals, executes machine learning model lookup reasoning and three-stage overcurrent protection logic, outputs circuit breaker control commands and drives the local LCD display.

[0046] S5. Mode Switching and Closed-Loop Verification: The operating mode is selected through the human-computer interaction layer, supporting pause-switch-resume during operation. Before switching, the current distribution network state variables at the simulation moment are saved, including the voltage, current, and circuit breaker positions of each node. After switching, the saved state variables are loaded into the model instance corresponding to the target mode. The communication buffer is reset and data synchronization between the host computer and the slave computer is re-established. After switching, the simulation continues, maintaining the continuity of fault event timing. In the semi-physical simulation mode, the equivalence between the host computer algorithm and the embedded implementation of the slave computer is verified; in the pure simulation mode, the correctness of the algorithm itself is verified. The specific method of pause-switch-resume is as follows: S6. Visual monitoring and result recording: Simulated waveforms, protection action sequence and lower-level machine operation status are displayed synchronously through the human-machine interaction layer. The protection action time, action correctness and other indicators under different working conditions are recorded for system performance evaluation.

[0047] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A hardware-in-the-loop simulation system for distribution network protection based on MATLAB-STM32 collaboration, characterized in that, include: The upper computer simulation layer is used to run the Simulink electromagnetic transient simulation model of the distribution network, generate fault electrical quantities in the scenario of distributed power source access, and perform offline setpoint adaptive optimization and machine learning model training for the fault current-constrained characteristics of the distribution network with distributed power source. The communication adaptation layer is used to realize periodic bidirectional data interaction between the upper computer simulation layer and the lower computer control layer through the Ethernet UDP protocol with a preset step size. The data interaction includes the transmission of fault electrical quantities and the transmission of circuit breaker control commands. The lower-level control layer, built on the STM32F407 embedded microcontroller, is used to receive fault electrical quantities, execute lightweight machine learning model lookup reasoning and protection logic operations, and output circuit breaker control commands. The mode switching layer is used to support pause-switching-resumption during operation between pure simulation mode and semi-physical simulation mode. The two modes share the same power distribution network model topology. In pure simulation mode, the Simulink model runs in a self-loop, while in semi-physical simulation mode, the Simulink model and the lower-level control layer form a closed loop. The human-machine interaction layer is used to synchronously display simulation waveforms, protection action status, lower-level machine operating parameters, and communication status information.

2. The hardware-in-the-loop simulation system for distribution network protection according to claim 1, characterized in that, The host computer simulation layer includes: The electromagnetic transient simulation module for distribution networks is used to build a 10.5kV distribution network model with distributed power sources in the MATLAB / Simulink environment and generate fault current and fault voltage electrical quantities under single-phase grounding faults. The algorithm training and setting generation module is used to execute offline optimization algorithm and machine learning model training, generate protection setting parameters including instantaneous overcurrent setting I50, overcurrent setting I51 and overcurrent protection delay T51, and output them as C language header file format; The graphical user interface module provides functions such as mode selection, parameter configuration, operation control, real-time waveform display, and protection status monitoring.

3. The hardware-in-the-loop simulation system for distribution network protection according to claim 1, characterized in that, The data packet format of the communication adaptation layer includes a data frame header identifier, an electrical quantity data field, a control command field, and a status feedback field. The communication adaptation layer also has an application layer reliability mechanism: the electrical quantity data packets sent by the host computer carry a timestamp and a sequence number. After receiving the data packets, the slave computer stores them in a circular buffer according to the sequence number. The slave computer sends back an acknowledgment frame for each valid data packet received. If the host computer does not receive an acknowledgment frame within the timeout period, it retransmits the data packet.

4. The hardware-in-the-loop simulation system for distribution network protection according to claim 1, characterized in that, The lower-level control layer includes: The fixed value storage and retrieval module is used to load the protection fixed value parameters from the Flash memory to the RAM running area; The electrical quantity receiving and parsing module is used to receive and parse fault electrical quantity data packets from the host computer via an Ethernet interface; The protection decision engine module is used to perform lightweight machine learning model lookup reasoning, fault direction determination, instantaneous overcurrent protection determination, overcurrent protection delay determination, and circuit breaker drive logic. The control command output module is used to encapsulate the protection action results into data packets and send them back to the host computer simulation layer; The local display module is used to drive the LCD screen to display network configuration, setpoint parameters, fault direction, trip status, and running time information.

5. The hardware-in-the-loop simulation system for distribution network protection according to claim 4, characterized in that, The execution logic of the protection decision engine module includes: Load the machine learning model lookup table structure, traverse the model node array based on the fault feature vector, and output the protection action results; Receive the instantaneous value of the fault current and calculate its effective value. Compare the effective value of the fault current with the instantaneous trip setting value I50. If it is greater than I50, output the instantaneous trip command. When the instantaneous overcurrent protection is not triggered, the overcurrent delay counter is started. When the fault current continues to be greater than the overcurrent setting I51 and the delay reaches T51, the overcurrent trip command is output. The fault direction is determined synchronously, and the result of the determination of positive direction, reverse direction or uncertain direction is output according to the current phase relationship on both sides of the line. When the determination is reverse direction, the protection trip output is blocked.

6. The hardware-in-the-loop simulation system for distribution network protection according to claim 1, characterized in that, The switching logic of the mode switching layer includes: The operating mode selected by the user is received through the human-computer interaction layer; The Simulink model topology is reconstructed according to the selected mode. In pure simulation mode, the circuit breaker control commands are generated by the internal logic module of Simulink, while in semi-physical simulation mode, they are transmitted back by the lower-level control layer. Synchronize the current protection setting parameters to the execution unit corresponding to the selected mode; Pause the simulation and save the current distribution network state variables. After switching the model topology, load the state variables and resume the simulation, maintaining the continuity of the simulation clock.

7. A semi-physical simulation method for distribution network protection based on MATLAB-STM32 collaboration, characterized in that, Includes the following steps: S1. Run the Simulink electromagnetic transient simulation model of the power distribution network on the host computer, configure the distributed power source and fault parameters, and generate fault electrical quantities in the scenario with distributed power source access. S2. On the host computer, offline adaptive optimization of setpoints is performed for the fault current limiting characteristics of the distribution network with distributed power sources. The machine learning model is trained, protection setpoint parameters are generated and hardened to the flash memory of the lower computer. S3. Establish periodic bidirectional data interaction between the host computer and the slave computer through the Ethernet UDP protocol with a preset step size, transmit fault electrical quantities to the slave computer, and receive control commands and status information transmitted back from the slave computer. S4. The lower-level machine receives the fault electrical quantity, loads the protection setting parameters, executes the lightweight machine learning model lookup reasoning and protection logic operation, and outputs the circuit breaker control command. S5. Select pure simulation mode or semi-physical simulation mode to run. Supports pause-switch-resume during operation. Both modes share the same power distribution network model topology. S6. Synchronously display simulation waveforms, protection action timing, and lower-level machine operating status, and record protection action results.

8. The hardware-in-the-loop simulation method for distribution network protection according to claim 7, characterized in that, The curing process for protecting the setpoint parameters in step S2 includes: The host computer generates a C language header file containing an array of fixed-value structures; The C language header file is transferred to the lower-level machine development environment, and the fixed-value structure is linked to the specified sector of Flash during compilation. During runtime, the lower-level machine loads fixed parameters from Flash into the RAM running area through memory mapping.

9. The hardware-in-the-loop simulation method for distribution network protection according to claim 7, characterized in that, The synchronization mechanism for periodic data interaction in step S3 includes: After each simulation step, the host computer Simulink model calls the UDP send function to transmit fault electrical quantity data packets. The lower-level machine receives data packets via Ethernet interrupt, parses them, and updates the electrical quantity buffer. The lower-level protection decision engine scans the electrical quantity buffer at fixed intervals and executes protection logic. It then sends the protection action results back to the upper-level computer via UDP to update the circuit breaker status in the Simulink model.

10. The hardware-in-the-loop simulation method for distribution network protection according to claim 7, characterized in that, The methods for pausing-switching-resumption during runtime in step S5 include: Before switching, save the distribution network state variables at the current simulation moment. The distribution network state variables include the voltage, current and circuit breaker position of each node. After switching, the saved state variables are loaded into the model instance corresponding to the target mode, the communication buffer is reset, and the data synchronization between the upper and lower computers is re-established. Resume simulation operation to maintain the temporal continuity of fault events.