A method and system for switching between grid-connected and off-grid operation of a distributed photovoltaic energy storage microgrid

CN122678084APending Publication Date: 2026-09-01BAODINGTOU ENERGY (FOSHAN) CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611012554.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-08
Publication Date
2026-09-01

AI Technical Summary

Technical Problem

通过固定阈值和延时响应进行并离网切换,导致无法适应频率瞬时波动且功率补偿滞后

Benefits of technology

(1)本发明通过卡尔曼滤波对实时频率进行噪声滤除,计算滤波频率与额定频率的差值得到初始频率偏差,再与并网开关状态加权融合后与预设偏差范围比较生成初始切换信号,由于卡尔曼滤波抑制了频率测量噪声,加权融合综合了开关状态与频率偏差的影响,解决了现有技术固定阈值响应滞后的问题;实现了频率偏差的准确捕捉与模式切换信号的快速触发。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122678084A_ABST
    Figure CN122678084A_ABST
Patent Text Reader

Abstract

This invention relates to the field of microgrid control technology and discloses a method and system for grid-connected / off-grid switching of a distributed photovoltaic energy storage microgrid. The method includes acquiring the grid-connected switch status and real-time frequency, performing weighted deviation analysis to obtain an initial switching signal; calculating power compensation based on the initial switching signal to obtain a power compensation command; performing power rolling optimization control based on the power compensation command to obtain a final control output; performing fault backtracking processing based on the final control output to obtain a final frequency; and performing weighted deviation over-limit analysis based on the final frequency to obtain a final switching signal. This method can achieve seamless grid-connected / off-grid switching and maintain stable operation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of microgrid control technology, and in particular to a method and system for switching between grid connection and off-grid operation of a distributed photovoltaic energy storage microgrid. Background Technology

[0002] Currently, distributed photovoltaic energy storage microgrids rely on fixed thresholds or delayed responses for grid-to-grid switching when the main grid fails, making it difficult to adapt to dynamic fluctuations in frequency that momentarily deviate from the rated value. If the energy storage remains in current source mode, it cannot adjust its output in time to fill the power gap, easily causing voltage drops and equipment shutdowns. Existing data acquisition and control systems lack the ability to capture frequency deviations in real time and drive mode switching rapidly. There is an urgent need for a technology that can accurately trigger the energy storage to switch from a current source to a voltage source and generate active power compensation based on the switching status and real-time frequency data, in order to ensure power balance and stable operation during microgrid switching.

[0003] In one existing technology, the grid status is monitored in real time by a frequency relay and voltage transformer installed at the grid connection point, with preset frequency deviation thresholds and delay times. When the frequency deviation exceeds the set threshold, the grid connection switch is disconnected after a fixed delay, and the energy storage system is switched from current source mode to voltage source mode. The energy storage system uses a pre-calibrated frequency-power droop curve to look up the active power compensation amount in a table based on the current frequency deviation value, resulting in constant power output. The system does not collect real-time load and distributed power output data, nor does it calculate the actual power gap. When the frequency recovers to within the threshold, it reconnects to the grid after a fixed delay. The entire switching process relies on preset thresholds and delays; the power compensation amount is determined solely by the frequency deviation and is not dynamically adjusted with changes in load or output. Switching between grid connection and disconnection using fixed thresholds and delay responses results in an inability to adapt to instantaneous frequency fluctuations and lagging power compensation.

[0004] Therefore, existing technologies cannot achieve seamless switching between on-grid and off-grid operations. Summary of the Invention This invention provides a method and system for switching between grid connection and off-grid operation of a distributed photovoltaic energy storage microgrid, so as to achieve seamless switching between grid connection and off-grid operation and maintain stable operation.

[0005] In a first aspect, to solve the above-mentioned technical problems, the present invention provides a method for switching between grid connection and off-grid operation of a distributed photovoltaic energy storage microgrid, comprising: Obtain grid-connected switch status and real-time frequency; Based on the grid-connected switch status and the real-time frequency, a weighted deviation analysis is performed to obtain the initial switching signal; Based on the initial switching signal, power compensation calculation is performed to obtain a power compensation command; Based on the power compensation command, power rolling optimization control is performed to obtain the final control output; Based on the final control output, frequency closed-loop monitoring is performed to obtain the measured frequency, and based on the measured frequency, fault backtracking is performed to obtain the final frequency. Based on the final frequency and the grid connection switch status, weighted particle swarm optimization is performed to obtain adjusted fusion weights, and weighted deviation over-limit analysis is performed based on the adjusted fusion weights to obtain the final switching signal.

[0006] In a second aspect, the present invention provides a grid-connected / off-grid switching system for a distributed photovoltaic energy storage microgrid, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the methods described above.

[0007] Compared with the prior art, the present invention has the following beneficial effects: (1) The present invention uses Kalman filtering to filter out noise in real-time frequency, calculates the difference between the filtered frequency and the rated frequency to obtain the initial frequency deviation, and then weights and fuses it with the grid-connected switch status and compares it with the preset deviation range to generate the initial switching signal. Since Kalman filtering suppresses frequency measurement noise, the weighted fusion integrates the influence of switch status and frequency deviation, solving the problem of fixed threshold response lag in the prior art; and realizing accurate capture of frequency deviation and rapid triggering of mode switching signal.

[0008] (2) According to the initial switching signal, the present invention converts the energy storage inverter from the current source mode to the voltage source mode, obtains the battery state of charge and calculates the active power command through fuzzy PID, and calculates the difference between the load demand and the power output to obtain the active power compensation amount and generate compensation command. Since the fuzzy PID adaptively adjusts the charging and discharging power, the power compensation is calculated based on the actual supply and demand gap, which overcomes the defect of the existing technology that the power compensation only depends on the frequency-droop curve and does not dynamically adjust with the load; it realizes the accurate matching of energy storage output and real-time filling of power gap.

[0009] (3) The present invention solves the control sequence by rolling optimization of the power balance prediction model, takes the first control quantity that meets the deviation threshold as the final control output, and performs weighted particle swarm optimization based on the final frequency to obtain the adjusted fusion weight, thereby generating the final switching signal and compensation command. Since the rolling optimization takes into account the power trajectory of multiple future sampling periods, the particle swarm optimization adaptively adjusts the fusion weight, solving the problem that the existing technology cannot adapt to instantaneous frequency fluctuations and the closed-loop feedback is insufficient; it realizes power balance and voltage stability during the grid-connected and off-grid switching process, and achieves the goal of seamless switching. Attached Figure Description

[0010] Figure 1 This is a schematic diagram of the grid-connected / off-grid switching method for distributed photovoltaic energy storage microgrids provided in the first embodiment of the present invention. Detailed Implementation

[0011] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0012] Reference Figure 1 The first embodiment of the present invention provides a method for switching between grid connection and off-grid operation of a distributed photovoltaic energy storage microgrid, comprising the following steps: S11, obtain grid connection switch status and real-time frequency; S12, perform weighted deviation analysis based on the grid-connected switch status and the real-time frequency to obtain the initial switching signal; S13, perform power compensation calculation based on the initial switching signal to obtain a power compensation command; S14, according to the power compensation command, perform power rolling optimization control to obtain the final control output; S15, based on the final control output, perform frequency closed-loop monitoring to obtain the measured frequency, and based on the measured frequency, perform fault backtracking processing to obtain the final frequency; S16. Based on the final frequency and the grid connection switch status, perform weighted particle swarm optimization to obtain adjusted fusion weights, and perform weighted deviation over-limit analysis based on the adjusted fusion weights to obtain the final switching signal.

[0013] In step S11, the grid-connected switch status and real-time frequency are obtained.

[0014] Specifically, real-time data is acquired through status sensors and frequency sensors deployed at the grid connection point. The grid-connected switch status sensor uses dry contacts or opto-isolation to output the switch's closed or open state in digital form (e.g., closed output is logic 1, open output is logic 0), sampling at a frequency of once per second, and the data is transmitted to the controller via a fieldbus. The frequency sensor uses a high-precision current transformer to collect the AC voltage waveform at the microgrid grid connection point at a sampling frequency of ten times per second, and calculates the real-time frequency value (e.g., 50 Hz as the rated value) through zero-crossing detection or phase-locked loop calculation. The data collected by these sensors, after analog-to-digital conversion and timestamping, is uploaded to the central controller via industrial Ethernet or a wireless communication module, forming a switch status sequence and a real-time frequency sequence. The preset rated frequency is the standard grid frequency (e.g., 50 Hz). This step provides the raw input data for subsequent deviation analysis and mode switching.

[0015] In step S12, a weighted deviation analysis is performed based on the grid-connected switch status and the real-time frequency to obtain the initial switching signal, including: Based on the real-time frequency, noise is filtered out using the Kalman filter algorithm to obtain the real-time filtered frequency; The difference between the real-time filtering frequency and the preset rated frequency is calculated to obtain the initial frequency deviation; Based on the preset initial fusion weights, the grid-connected switch status and the initial frequency deviation are weighted and fused to obtain the initial fusion deviation; When the initial fusion deviation does not exceed the preset initial deviation range, the current monitoring state is maintained; When the initial fusion deviation exceeds the initial deviation range, an initial switching signal is generated.

[0016] Specifically, Kalman filtering is applied to the real-time frequency. The initial state estimate for the Kalman filter is taken as the real-time frequency value at the first sampling moment, and the initial estimation error covariance is taken as the square of the initial frequency value. For each newly acquired frequency value, the current state estimate is first predicted based on the previous state estimate, and the predicted value is the previous state estimate; simultaneously, the current estimation error covariance is predicted and equal to the previous estimation error covariance plus the process noise covariance. The process noise covariance is determined by analyzing the frequency fluctuation variance of the sensor in a static state, taking 90% of the variance of historical frequency data. Then, the Kalman gain is calculated, which is the current predicted estimation error covariance divided by the sum of the predicted estimation error covariance and the measurement noise covariance. The measurement noise covariance is determined by collecting the measurement error variance from the sensor calibration data. Finally, the state estimate is updated using the current measured frequency value, and the updated state estimate is equal to the predicted state value plus the Kalman gain multiplied by the difference between the measured frequency value and the predicted state value. Finally, the estimated error covariance is updated. The updated estimated error covariance is equal to one minus the Kalman gain multiplied by the predicted estimated error covariance. This recursive step is repeated to process the frequency values ​​at all sampling times to obtain the real-time filtered frequency. This filtering process eliminates sensor white noise and random fluctuations, improving the signal-to-noise ratio of the frequency data.

[0017] Calculate the difference between the real-time filtering frequency and the preset rated frequency. The preset rated frequency is taken as the power grid standard frequency (e.g., 50 Hz), which is a fixed constant in power system standards and specifications. The initial frequency deviation is equal to the real-time filtering frequency minus the rated frequency. The deviation value can be positive or negative; a positive value indicates that the frequency is higher than the rated value, and a negative value indicates that the frequency is lower than the rated value.

[0018] Based on preset initial fusion weights, the grid-connected switch status and initial frequency deviation are weighted and fused. The initial fusion weights are determined through regression analysis of historical operating data. Data on the grid-connected switch status (closed state assigned a value of 1, open state assigned a value of 0), initial frequency deviation, and actual switching demand (manually labeled whether switching is required) of the microgrid during stable grid-connected operation over the past month are collected. Using the matching accuracy between the switching signal and the labeled results as the objective function, a grid search method is used to traverse the weight values ​​within the range of 0 to 1 with a step size of 0.05, selecting the weight value that achieves the highest accuracy as the initial fusion weight. The weighted fusion calculation process is as follows: multiply the grid-connected switch status value by the initial fusion weight, then multiply the normalized frequency deviation by one and subtract the initial fusion weight, and finally add the two products to obtain the initial fusion deviation. A value of 1 is assigned when the switch is closed, and 0 is assigned when it is open. This fusion deviation integrates the switch status and frequency deviation, reflecting the overall anomaly level of the microgrid.

[0019] It should be noted that the initial frequency deviation is divided by the preset maximum allowable frequency deviation, such as 0.5Hz, to obtain the normalized frequency deviation; the normalized frequency deviation is used for calculation in the above weighted fusion process.

[0020] The preset initial deviation range is determined statistically from the initial fusion deviation data under historical normal operating conditions. A large number of initial fusion deviation values ​​are collected during the stable grid-connected operation of the microgrid (no faults, no switching requirements). The 95th percentile of all deviation values ​​is taken as the upper limit of the range, and the 5th percentile as the lower limit. The interval between the upper and lower limits is the preset initial deviation range. This range represents the allowable range under normal fluctuations. The calculated initial fusion deviation is compared with this range. If the initial fusion deviation does not exceed the preset initial deviation range, it indicates that the current grid-connected switch is closed and the frequency fluctuation is within the normal range. No grid-connected / off-grid switching is required, and the system maintains the current monitoring state, returning to step S11 to continue data collection. If the initial fusion deviation exceeds the preset initial deviation range, it indicates that the grid-connected switch status is abnormal or the frequency deviation is severe. The system determines that a switch to off-grid mode is required and generates an initial switching signal. This step, through weighted fusion and threshold comparison, achieves accurate judgment of grid-connected / off-grid switching requirements.

[0021] In step S13, power compensation calculation is performed based on the initial switching signal to obtain a power compensation command, including: Based on the initial switching signal, the control mode is switched to obtain the voltage source control state; Based on the voltage source control state, the battery state of charge is obtained, and active power is calculated using a fuzzy PID algorithm to obtain battery charging and discharging commands. Obtain the initial load demand and initial power output, and calculate the difference between the initial load demand and the initial power output to obtain the active power compensation amount; A power compensation command is generated based on the battery charging / discharging command and the active power compensation amount.

[0022] Specifically, the control mode of the energy storage inverter is switched based on the initial switching signal. The initial switching signal triggers the state machine inside the inverter controller, switching the inverter's control mode from current source mode to voltage source mode. In current source mode, the inverter output current follows the command value; in voltage source mode, the inverter output voltage and frequency are determined by local reference values. After the mode switch, the inverter output voltage is set to a preset rated voltage, such as 380 volts, and the output frequency is locked to a preset rated frequency, such as 50 Hz. The switch process is typically completed within 20 milliseconds, resulting in voltage source control. This switch ensures that the microgrid can still establish stable voltage and frequency references after disconnecting from the main grid.

[0023] Based on the voltage source control status, the battery state of charge (SOC) is collected by the battery management system. The SOC is calculated in real-time by the battery management system, monitoring battery voltage, current, and temperature, using the ampere-hour integral method. The SOC ranges from 0 to 1 and is updated every 0.5 seconds. Based on the SOC, active power is calculated using a fuzzy PID algorithm to obtain battery charging and discharging commands. The specific implementation of the fuzzy PID algorithm involves setting three input variables: frequency deviation, frequency deviation change rate, and battery SOC deviation. The frequency deviation is the difference between the real-time filtered frequency output in step S12 and the preset rated frequency; the frequency deviation change rate is the difference between the current frequency deviation and the frequency deviation at the previous sampling time divided by the sampling interval; the battery SOC deviation is the difference between the current SOC and the preset target SOC, which is typically set to 0.5. Each input variable defines five fuzzy subsets: negative large, negative small, zero, positive small, and positive large. The membership function adopts a triangular distribution, and its shape parameter is determined by analyzing the variable distribution range under various operating conditions in historical operating data. The fuzzy rule base contains 25 rules. For example, if both the frequency deviation and the state of charge deviation are negatively large, the power output is positively large; conversely, if both the frequency deviation and the state of charge deviation are positively large, the power output is negatively large. The inference process employs the Madanley minimization operation, taking the minimum membership degree of each rule's preconditions as the rule's trigger strength, and then truncating the fuzzy set of the conclusion. Finally, the centroid method is used for defuzzification, and the weighted average of the fuzzy sets output by each rule is taken as the precise output value, yielding the active power reference value. A positive reference value indicates discharging, and a negative value indicates charging, thus representing the battery charging / discharging command.

[0024] It is worth noting that in this embodiment, the vertices of the membership function for frequency deviation are -0.5Hz, -0.2Hz, 0Hz, 0.2Hz, and 0.5Hz, respectively; the vertices of the rate of change of frequency deviation are -2Hz / s, -1Hz / s, 0Hz / s, 1Hz / s, and 2Hz / s; the vertices of the battery state of charge deviation are -0.3, -0.1, 0, 0.1, and 0.3; and a triangular membership function is used.

[0025] Specifically, the fuzzy rule base contains 25 core rules, as shown in the table below. It is a preferred embodiment that follows the basic control logic of increasing discharge (positive power) when the frequency is low / decreasing and the SOC is low; and increasing charging (negative power) when the frequency is high / increasing and the SOC is high, so as to achieve power balance and energy storage state management. Those skilled in the art can adjust the specific rules based on their understanding of this logic. Rule Number Frequency deviation (E) Rate of change of frequency deviation (E) Battery state-of-charge deviation (SOC) Power output (P) 1 Large Negative (NB) Negative (NB) Large Negative (NB) CP Group (PB) 2 Negative (NB) Negative small (NS) Large Negative (NB) CP Group (PB) 3 Large Negative (NB) Zero (Z) Negative (NB) CP Group (PB) 4 Negative (NB) Zheng Xiao (PS) Negative (NB) CP Group (PB) 5 Negative (NB) CP Group (PB) Negative (NB) CP Group (PB) 6 Negative small (NS) Negative (NB) Negative small (NS) Zheng Xiao (PS) 7 Negative small (NS) Negative small (NS) Negative small (NS) Zheng Xiao (PS) 8 Negative small (NS) Zero (Z) Negative small (NS) Zheng Xiao (PS) 9 Negative small (NS) Zheng Xiao (PS) Negative small (NS) Zero (Z) 10 Negative small (NS) CP Group (PB) Negative small (NS) Zero (Z) 11 Zero (Z) Negative (NB) Zero (Z) Zheng Xiao (PS) 12 Zero (Z) Negative small (NS) Zero (Z) Zheng Xiao (PS) 13 Zero (Z) Zero (Z) Zero (Z) Zero (Z) 14 Zero (Z) Zheng Xiao (PS) Zero (Z) Negative small (NS) 15 Zero (Z) CP Group (PB) Zero (Z) Negative small (NS) 16 Zheng Xiao (PS) Large Negative (NB) Zheng Xiao (PS) Zero (Z) 17 Zheng Xiao (PS) Negative small (NS) Zheng Xiao (PS) Zero (Z) 18 Zheng Xiao (PS) Zero (Z) Zheng Xiao (PS) Negative small (NS) 19 Zheng Xiao (PS) Zheng Xiao (PS) Zheng Xiao (PS) Negative small (NS) 20 Zheng Xiao (PS) CP Group (PB) Zheng Xiao (PS) Large Negative (NB) 21 CP Group (PB) Large Negative (NB) CP Group (PB) Large Negative (NB) 22 CP Group (PB) Negative small (NS) CP Group (PB) Negative (NB) 23 CP Group (PB) Zero (Z) CP Group (PB) Large Negative (NB) 24 CP Group (PB) Zheng Xiao (PS) CP Group (PB) Negative (NB) 25 CP Group (PB) CP Group (PB) CP Group (PB) Large Negative (NB)

[0026] The initial load demand and initial power output are obtained. The initial load demand is collected in real time by power sensors installed on each load branch of the microgrid. The total load demand is obtained by summing the power of all branches, with a sampling frequency of once per second. The initial power output is obtained in real time through the communication interface of the grid-connected inverter of the distributed photovoltaic power generation unit, also with a sampling frequency of once per second. The difference between the initial load demand and the initial power output is calculated. If the load demand is greater than the power output, the difference is positive, indicating that energy storage discharge is needed to compensate for the power shortfall; if the load demand is less than the power output, the difference is negative, indicating that energy storage charging is needed to absorb excess power. This difference is the active power compensation amount.

[0027] A power compensation command is generated based on the battery charge / discharge command and the active power compensation amount. Specifically, the active power reference value from the battery charge / discharge command is summed with the active power compensation amount to obtain the total active power value that the energy storage system needs to execute. This value is then packaged with the voltage and frequency reference value under voltage source control to generate a complete power compensation command. This command includes the active power value that the energy storage system should output and the inverter's voltage and frequency setpoints, and is sent to the energy storage converter for execution via a communication protocol. This step uses fuzzy PID adaptive adjustment of the energy storage output, combined with the actual power gap, to ensure that the energy storage system can accurately fill the power supply-demand imbalance.

[0028] In step S14, power rolling optimization control is performed according to the power compensation command to obtain the final control output, including: Based on the power compensation command, a rolling optimization is performed using a pre-built power balance prediction model to obtain a balance control sequence and a power supply-demand balance. When the power supply and demand balance is less than the preset power deviation threshold, the first balance control value in the balance control sequence is taken as the final control output. When the power supply and demand balance is not less than the power deviation threshold, rolling optimization is re-executed until the power supply and demand balance is less than the power deviation threshold, and the final control output is obtained.

[0029] Specifically, based on the power compensation command, rolling optimization is performed using a pre-built power balance prediction model. The construction process of this power balance prediction model is as follows: Data from the microgrid for at least 30 days during its historical operation is collected. At each sampling moment, the power compensation command value, the actual output power value of the energy storage system, the real-time load demand value of the microgrid, and the real-time output value of the distributed generation are recorded as input feature data for the model. Simultaneously, the actual power balance value for the next 10 sampling periods (each period corresponding to a control step size, e.g., 0.5 seconds) after each sampling moment is recorded as the model's output label. The collected data is divided into a training set and a validation set in chronological order, with the training set accounting for 80% of the total data and the validation set accounting for 20%.

[0030] The input data undergoes normalization preprocessing. For each input feature dimension (power compensation command, energy storage output power, load demand, power output), the mean and standard deviation of that feature dimension in the training set are calculated. Each value in that dimension is subtracted from the mean and then divided by the standard deviation, resulting in a preprocessed training data distribution with a mean of 0 and a standard deviation of 1. The validation set and subsequent input data in real-time applications also undergo the same normalization process using the mean and standard deviation of the training set.

[0031] The model's input-output relationship employs an autoregressive moving average model structure with external inputs. Mathematically, this can be described as follows: the predicted power balance value at the current moment equals the actual power balance values ​​at several past moments multiplied by the corresponding autoregressive coefficients, plus the input feature values ​​at several past moments multiplied by the corresponding external input coefficients, plus the prediction errors at several past moments multiplied by the corresponding moving average coefficients. The model order (i.e., autoregressive order, external input order, and moving average order) is determined using the Akaike Information Criterion. The Akaike Information values ​​for different order combinations are calculated, and the combination with the smallest value is taken as the model order. The coefficients in the model are estimated using the least squares method. The input features and output labels from the training data are constructed into a system of linear equations, and the coefficient vector that minimizes the sum of squared residuals is solved to obtain the model parameters.

[0032] After model training, real-time rolling optimization is required during use. At each sampling time, the current power compensation command, energy storage output power, load demand, and power output are first acquired, and these values ​​are normalized using the same mean and standard deviation as the training set. The normalized input data is then fed into the power balance prediction model, which outputs the predicted power balance value for each sampling time within the next 10 sampling periods. Then, using the target power value in the power compensation command as a reference trajectory, and within the upper and lower limits of the energy storage output power, a control sequence is found that minimizes the sum of squared deviations between the predicted power balance value and the reference trajectory within the next 10 sampling periods. This solution process employs a quadratic programming algorithm, with the objective function being the sum of squared deviations plus a penalty term for the rate of change of the control quantity. The constraints include the upper and lower limits of the energy storage output power and the power change rate limit. The resulting control sequence is a vector containing 10 elements, each corresponding to the energy storage output power setpoint for one sampling period, and is called the balance control sequence. Meanwhile, the first control variable in the control sequence is substituted into the power balance prediction model to calculate the power balance prediction value of the first sampling period under the action of the control variable. Then, the absolute value of the deviation between the prediction value and the reference trajectory is calculated, which is the power supply and demand balance value.

[0033] It should be noted that the preset power deviation threshold is taken as the maximum absolute value of the power supply and demand balance during historical normal operation multiplied by 1.2, or 0.05 times the rated power. When the power supply and demand balance value is less than the preset power deviation threshold, the first balance control value in the balance control sequence is taken as the final control output. When the power supply and demand balance value is not less than the preset power deviation threshold, the system re-acquires the latest system state data at the next sampling time, repeats the above normalization, model prediction, quadratic programming solution, and deviation judgment steps until the power supply and demand balance value is less than the threshold, and the first balance control value obtained in the last calculation is taken as the final control output. If the number of times rolling optimization is re-executed exceeds 10, the first value of the last obtained balance control sequence is taken as the final control output. This step, through rolling optimization and closed-loop iteration, ensures that the energy storage output power can respond quickly and accurately to the power compensation command, maintaining the power balance of the microgrid.

[0034] In step S15, frequency closed-loop monitoring is performed based on the final control output to obtain the measured frequency, and fault backtracking processing is performed based on the measured frequency to obtain the final frequency, including: Based on the final control output, microgrid frequency monitoring is performed to obtain the measured frequency; Based on the measured frequency, noise is filtered out using the Kalman filter algorithm to obtain the optimized filter frequency. Calculate the difference between the optimized filtering frequency and the rated frequency to obtain the optimized frequency deviation; When the optimized frequency deviation is not greater than the preset fault deviation threshold, the optimized filtering frequency is directly used as the final frequency. When the optimized frequency deviation is greater than the fault deviation threshold, the grid-connected switch status and the real-time frequency are reacquired, and power compensation calculation and rolling optimization control are re-performed until the optimized frequency deviation is no greater than the fault deviation threshold, and the final frequency is obtained.

[0035] Specifically, the microgrid frequency monitoring module is activated based on the final control output. The final control output is the energy storage output power command value determined in step S14, which is sent to the energy storage converter for execution via the communication bus. Simultaneously with the execution of the final control output, the system continuously collects real-time frequency data using a frequency sensor installed at the microgrid's grid connection point. The frequency sensor employs a high-precision instrument transformer, sampling the AC voltage waveform at a frequency of ten times per second, and calculates the frequency value at each sampling moment using a phase-locked loop algorithm. The frequency value at each sampling moment is recorded to obtain the original frequency monitoring sequence, which is referred to as the measured frequency. The measured frequency reflects the actual frequency response of the microgrid under the action of the final control output and serves as the initial input for subsequent filtering and deviation judgment.

[0036] Kalman filtering is applied to the measured frequencies to eliminate sensor measurement noise and transient disturbances. The initial state estimate for the Kalman filter is taken from the first measured frequency value, and the initial estimation error covariance is the square of the initial frequency value. The process noise covariance is determined by analyzing the natural fluctuation variance of the microgrid's frequency under steady-state operation. Frequency data from the past 24 hours of steady-state operation are collected, and their variance is calculated. Ninety percent of this variance is taken as the process noise covariance. The measurement noise covariance is determined from sensor calibration data. A standard signal is input to the frequency sensor in a laboratory environment, and the variance between the output and input values ​​is statistically analyzed. This variance is taken as the measurement noise covariance. For each newly acquired measured frequency value, state prediction, covariance prediction, Kalman gain calculation, state update, and covariance update are performed sequentially to obtain the optimized filtered frequency. This filtered frequency more accurately reflects the true frequency variation trend of the microgrid.

[0037] Calculate the difference between the optimized filter frequency and the preset rated frequency. The preset rated frequency is taken as the standard frequency of the power grid, for example, 50 Hz, and this value is a fixed constant. The optimized frequency deviation is equal to the optimized filter frequency minus the rated frequency. The difference can be positive or negative; a positive value indicates that the frequency is higher than the rated value, and a negative value indicates that the frequency is lower than the rated value.

[0038] The preset fault deviation threshold is determined through statistical analysis of historical anomaly event data. All frequency anomaly events occurring in the microgrid over the past year are collected. For each event, the absolute value of the optimized frequency deviation at the time of occurrence is calculated, and the 95th percentile of all absolute deviation values ​​is taken as the fault deviation threshold. This threshold represents the value at which, under anomaly conditions, 95% of events have a frequency deviation below this value. The absolute value of the optimized frequency deviation is then compared with the fault deviation threshold.

[0039] When the absolute value of the optimized frequency deviation is not greater than the fault deviation threshold, it indicates that the current microgrid frequency is within an acceptable normal range and no frequency anomaly has occurred. In this case, the optimized filter frequency is directly used as the final frequency output. This final frequency is used for the weighted particle swarm optimization process in step S16.

[0040] When the absolute value of the optimized frequency deviation exceeds the fault deviation threshold, it indicates that the current frequency deviation has exceeded the normal range and a frequency anomaly exists. At this point, the system triggers a fault backtracking mechanism, abandoning the currently acquired measured frequency and reacquiring the grid-connected switch status and real-time frequency data. This involves returning to step S11, reacquiring the original data, and sequentially executing steps S12, S13, S14, and this step S15, repeating the cycle until the absolute value of the optimized frequency deviation obtained from a monitoring test is no greater than the fault deviation threshold. The last optimized filter frequency that meets the condition is then used as the final frequency output. If the number of times data is reacquisitioned and power compensation calculations and rolling optimization control are performed exceeds 10, the last optimized filter frequency that meets the condition is used as the final frequency. This fault backtracking mechanism ensures accurate detection of frequency anomalies and data reacquisition, guaranteeing the reliability of the final frequency.

[0041] In one specific implementation, frequency monitoring is initiated based on the final control output (energy storage output power of 24.8 kW). The sensor continuously collects five cycles of measured frequency values: 49.86 Hz, 49.82 Hz, 49.80 Hz, 49.78 Hz, and 49.75 Hz. After Kalman filtering, the optimized filtered frequency sequence is obtained as 49.85 Hz, 49.83 Hz, 49.81 Hz, 49.79 Hz, and 49.77 Hz. The difference between the filtered frequency and the rated frequency (50 Hz) is calculated, and the absolute values ​​of the optimized frequency deviations are 0.15 Hz, 0.17 Hz, 0.19 Hz, 0.21 Hz, and 0.23 Hz, respectively. The preset fault deviation threshold is 0.20 Hz. The first three deviations (0.15, 0.17, and 0.19) are all less than the threshold; therefore, the corresponding optimized filtered frequencies are directly used as the final frequency output. When the fourth deviation of 0.21 is greater than the threshold, fault backtracking is triggered, the grid-connected switch status and real-time frequency are reacquired, and steps S11 to S15 are repeated until the new frequency deviation is no greater than 0.20 Hz, and the final frequency of 49.82 Hz is obtained.

[0042] In step S16, based on the final frequency and the grid-connected switch state, weighted particle swarm optimization is performed to obtain adjusted fusion weights, and weighted deviation exceedance analysis is performed based on the adjusted fusion weights to obtain the final switching signal, including: Calculate the difference between the final frequency and the rated frequency to obtain the optimized frequency deviation; The initial fusion weights are iteratively optimized using a particle swarm optimization algorithm to obtain adjusted fusion weights. Based on the adjusted fusion weights, the grid connection switch status and the optimized frequency deviation are weighted and fused to obtain the optimized fusion deviation; When the optimized fusion deviation exceeds the preset optimized deviation range, a final switching signal is generated; When the optimized fusion deviation does not exceed the optimized deviation range, power rolling optimization control is performed again to obtain an updated final control output; Based on the updated final control output, microgrid frequency monitoring and fault tracing are performed again, and the optimized fusion deviation is recalculated until the optimized fusion deviation exceeds the optimized deviation range, thus obtaining the final switching signal.

[0043] Specifically, the difference between the final frequency output in step S15 and the preset rated frequency is calculated. The preset rated frequency is the grid standard frequency, for example, 50 Hz. The final frequency is a reliable frequency value obtained after closed-loop monitoring and fault backtracking. When calculating the difference, the rated frequency is subtracted from the final frequency to obtain the optimized frequency deviation. This deviation value reflects the degree of deviation of the current frequency of the microgrid from the rated value, and can be positive or negative; the optimized frequency deviation is divided by the preset maximum allowable frequency deviation, such as 0.5 Hz, to obtain the normalized optimized frequency deviation.

[0044] The initial fusion weights are iteratively optimized using a particle swarm optimization algorithm to obtain adjusted fusion weights. The initial fusion weights are derived from the preset values ​​in step S12, determined through historical data regression analysis, reflecting the relative importance of grid-connected switch status and frequency deviation in the fusion process. The specific implementation process of the particle swarm optimization algorithm is as follows: the particle swarm size is set to 30 particles, each particle's position vector is one-dimensional, corresponding to a fusion weight value ranging from 0 to 1. Each particle's velocity vector is also one-dimensional, with initial velocities randomly distributed between -0.1 and 0.1. The algorithm iteration count is set to 20 times. The fitness function is defined as follows: using the current particle's weight value to perform weighted fusion of grid-connected switch status and optimized frequency deviation to obtain the fusion deviation, the absolute value of the deviation between this fusion deviation and the standard switching threshold marked at historical switching times is calculated as the fitness value; the standard switching threshold is set to 0.25, which is the critical value of the fusion deviation obtained through statistical analysis of historical fault event data, specifically the arithmetic mean of the fusion deviation values ​​at the time of all historical fault events. A smaller fitness value indicates a better weight. In each iteration, the fitness value of each particle is calculated, the individual optimal position of each particle (i.e., the position with the lowest fitness in the particle's history) is updated, and the global optimal position of the entire particle swarm (i.e., the position with the lowest fitness among all particles) is also updated. Then, the velocity and position of each particle are updated based on the individual and global optimal values. The velocity update formula is: the new velocity equals the inertia weight multiplied by the current velocity, plus the individual learning factor multiplied by a random number multiplied by the difference between the individual optimal position and the current position, plus the social learning factor multiplied by a random number multiplied by the difference between the global optimal position and the current position. The inertia weight is set to 0.8, and both the individual and social learning factors are set to 2.0. The position update formula is: the new position equals the current position plus the new velocity, constrained to the range of 0 to 1. After the iteration ends, the weight value corresponding to the global optimal position is used as the adjustment fusion weight.

[0045] Based on the adjusted fusion weights, a weighted fusion is performed on the grid-connected switch status and the normalized optimized frequency deviation. The grid-connected switch status is the current switch value, set to 1 when closed and 0 when open. The weighted fusion is calculated by multiplying the grid-connected switch status value by the adjusted fusion weight, then multiplying the normalized optimized frequency deviation by one and subtracting the adjusted fusion weight, and finally adding the two products to obtain the optimized fusion deviation. This fusion deviation integrates switch status and frequency deviation information, reflecting the overall anomaly level of the microgrid.

[0046] The preset optimization deviation range is determined through statistical analysis of optimization fusion deviation data under historical normal operating conditions. This range is dimensionless and is directly compared with the normalized optimization fusion deviation. A large number of optimization fusion deviation values ​​are collected during the stable grid-connected operation of the microgrid (no faults, no switching requirements). The 95th percentile of all deviation values ​​is taken as the upper limit of the range, and the 5th percentile as the lower limit. The interval between the upper and lower limits is the preset optimization deviation range. This range represents the permissible range under normal fluctuations.

[0047] The calculated optimized fusion deviation is compared with a preset optimized deviation range. If the optimized fusion deviation exceeds this range (i.e., less than the lower limit or greater than the upper limit), it indicates that the current microgrid state is abnormal and needs to be switched to off-grid mode or further adjusted. At this time, a final switching signal is generated. This final switching signal is used to trigger subsequent charge and discharge compensation updates.

[0048] If the optimized fusion deviation does not exceed the optimized deviation range, it indicates that the current state is still within the normal range and there is no need for immediate switching. At this time, the system re-executes the power rolling optimization control in step S14 to obtain an updated final control output. Based on the updated final control output, steps S15 and this step S16 are re-executed to recalculate the optimized fusion deviation until the optimized fusion deviation exceeds the optimized deviation range, generating a final switching signal. This closed-loop iteration ensures that the switching signal is only generated when the state is truly abnormal, avoiding false triggering; if the number of iterations exceeds 10, the final switching signal is generated directly. This step adaptively adjusts the fusion weights through particle swarm optimization, improving the accuracy and adaptability of the switching judgment.

[0049] In one specific implementation, the final frequency is 49.82 Hz. The difference from the rated frequency of 50 Hz is calculated, resulting in an optimized frequency deviation of -0.18 Hz and a normalized optimized frequency deviation of -0.36 Hz. The initial fusion weight is 0.35. The particle swarm optimization algorithm is set to 30 particles and iterated 20 times. The fitness function uses the standard switching threshold of 0.25 from historical switching times. After iteration, the global optimal position is 0.44, resulting in an adjusted fusion weight of 0.44. The grid connection switch is in a closed state (value 1). Weighted fusion calculation yields the optimized fusion deviation: 10.44 + (-0.36)(1-0.44) = 0.44 - 0.2016 = 0.2384. The preset optimized deviation range is [-0.22, 0.22]. 0.2384 exceeds the upper limit, therefore the final switching signal is generated. If the fusion deviation in a certain optimization is 0.15, it is within the range. The system returns to step S15 to re-monitor the frequency based on the final control output until the fusion deviation exceeds the range, and then obtains the final switching signal.

[0050] It should be noted that when step S15 is called in the loop of step S16, if step S15 triggers fault backtracking and returns to step S11, the current loop of step S16 will terminate. After steps S11 to S15 are re-executed and a new final frequency is obtained, step S16 will be re-entered for judgment.

[0051] In one implementation, based on the final switching signal, a charge / discharge compensation update is performed to obtain a final compensation instruction, including: Based on the final switching signal, the battery charging and discharging commands are optimized and adjusted to obtain updated charging and discharging commands; Obtain the update load demand and update power output, and calculate the difference between the update load demand and the update power output to obtain the update power compensation amount; Based on the updated charge / discharge command and the updated power compensation amount, a final compensation command is generated.

[0052] Specifically, the battery charging and discharging commands are optimized and adjusted based on the final switching signal. The final switching signal is generated in step S16, indicating that a grid-connected or off-grid switching or power compensation update is required. The battery charging and discharging commands are derived from the active power reference value calculated using the fuzzy PID algorithm in step S13. The specific method for optimization and adjustment is to recalculate the charging and discharging commands based on the current microgrid operating state and frequency deviation, using the final switching signal as the trigger condition. During the adjustment process, the real-time frequency and battery state of charge are first obtained. The same fuzzy PID algorithm as in step S13 is used, but the weights of the input variables are replaced according to the adjustment fusion weights obtained in step S16. The weights of the remaining input variables (frequency deviation change rate, battery state of charge deviation) remain unchanged. The updated active power reference value is then recalculated, which is the updated charging and discharging command. This updated charging and discharging command reflects the power value that the energy storage system should output under the latest current state.

[0053] The system acquires updated load demand and updated power output. Updated load demand is collected in real-time by power sensors installed on each load branch of the microgrid. The total load demand is obtained by summing the active power of all branches. The sampling frequency is once per second, and the average value of the most recent sampling period is taken as the current updated load demand. Updated power output is acquired in real-time through the communication interface of the grid-connected inverter of the distributed photovoltaic power generation unit, also using the average value of the most recent sampling period. The difference between the updated load demand and the updated power output is calculated. Subtracting the updated power output from the updated load demand yields the updated power compensation amount. If the load demand is greater than the power output, the difference is positive, indicating that energy storage discharge is needed to compensate for the power shortfall; if the load demand is less than the power output, the difference is negative, indicating that energy storage charging is needed to absorb excess power.

[0054] The final compensation command is generated based on the updated charge / discharge commands and the updated power compensation amount. Specifically, the active power reference value from the updated charge / discharge commands is superimposed with the updated power compensation amount using a summation method to obtain the total active power value that the energy storage system needs to execute. This total active power value is then packaged with the voltage and frequency reference values ​​(rated voltage 380V, rated frequency 50Hz) under voltage source control to generate a complete final compensation command. This command is sent to the energy storage converter for execution via a communication protocol. The final compensation command is the final output of this invention, used to drive the energy storage system to maintain the power balance and voltage stability of the microgrid during grid-connected / off-grid switching, achieving seamless switching. This step ensures accurate matching between the compensation command and the current microgrid state by re-acquiring real-time data and optimizing the charge / discharge commands.

[0055] The second embodiment of the present invention provides a grid-connected / off-grid switching system for a distributed photovoltaic energy storage microgrid, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps of the method described in any of the above-mentioned embodiments.

[0056] It should be noted that the grid-connected / off-grid switching system for a distributed photovoltaic energy storage microgrid provided in this embodiment of the invention is used to execute all the process steps of the grid-connected / off-grid switching method for a distributed photovoltaic energy storage microgrid in the above embodiment. The working principles and beneficial effects of the two are one-to-one, so they will not be described again.

[0057] It should be noted that the system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0058] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.

Claims

1. A method for switching between grid connection and off-grid operation of a distributed photovoltaic energy storage microgrid, characterized in that, include: Obtain grid-connected switch status and real-time frequency; Based on the grid-connected switch status and the real-time frequency, a weighted deviation analysis is performed to obtain the initial switching signal; Based on the initial switching signal, power compensation calculation is performed to obtain a power compensation command; Based on the power compensation command, power rolling optimization control is performed to obtain the final control output; Based on the final control output, frequency closed-loop monitoring is performed to obtain the measured frequency, and based on the measured frequency, fault backtracking is performed to obtain the final frequency. Based on the final frequency and the grid connection switch status, weighted particle swarm optimization is performed to obtain adjusted fusion weights, and weighted deviation over-limit analysis is performed based on the adjusted fusion weights to obtain the final switching signal.

2. The grid-connected / off-grid switching method for distributed photovoltaic energy storage microgrids according to claim 1, characterized in that, The step of performing weighted deviation analysis based on the grid-connected switch status and the real-time frequency to obtain the initial switching signal includes: Based on the real-time frequency, noise is filtered out using the Kalman filter algorithm to obtain the real-time filtered frequency; The difference between the real-time filtering frequency and the preset rated frequency is calculated to obtain the initial frequency deviation; Based on the preset initial fusion weights, the grid-connected switch status and the initial frequency deviation are weighted and fused to obtain the initial fusion deviation; When the initial fusion deviation does not exceed the preset initial deviation range, the current monitoring state is maintained; When the initial fusion deviation exceeds the initial deviation range, an initial switching signal is generated.

3. The grid-connected / off-grid switching method for distributed photovoltaic energy storage microgrids according to claim 1, characterized in that, The step of performing power compensation calculation based on the initial switching signal to obtain a power compensation command includes: Based on the initial switching signal, the control mode is switched to obtain the voltage source control state; Based on the voltage source control state, the battery state of charge is obtained, and active power is calculated using a fuzzy PID algorithm to obtain battery charging and discharging commands. Obtain the initial load demand and initial power output, and calculate the difference between the initial load demand and the initial power output to obtain the active power compensation amount; A power compensation command is generated based on the battery charging / discharging command and the active power compensation amount.

4. The grid-connected / off-grid switching method for distributed photovoltaic energy storage microgrids according to claim 1, characterized in that, The step of performing power rolling optimization control according to the power compensation command to obtain the final control output includes: Based on the power compensation command, a rolling optimization is performed using a pre-built power balance prediction model to obtain a balance control sequence and a power supply-demand balance. When the power supply and demand balance is less than the preset power deviation threshold, the first balance control value in the balance control sequence is taken as the final control output. When the power supply and demand balance is not less than the power deviation threshold, rolling optimization is re-executed until the power supply and demand balance is less than the power deviation threshold, and the final control output is obtained.

5. The grid-connected / off-grid switching method for distributed photovoltaic energy storage microgrids according to claim 2, characterized in that, The process of performing frequency closed-loop monitoring based on the final control output to obtain the measured frequency, and then performing fault backtracking processing based on the measured frequency to obtain the final frequency, includes: Based on the final control output, microgrid frequency monitoring is performed to obtain the measured frequency; Based on the measured frequency, noise is filtered out using the Kalman filter algorithm to obtain the optimized filter frequency. The difference between the optimized filtering frequency and the rated frequency is calculated to obtain the optimized frequency deviation; When the optimized frequency deviation is not greater than the preset fault deviation threshold, the optimized filtering frequency is directly used as the final frequency. When the optimized frequency deviation is greater than the fault deviation threshold, the grid-connected switch status and the real-time frequency are reacquired, and power compensation calculation and rolling optimization control are re-performed until the optimized frequency deviation is no greater than the fault deviation threshold, and the final frequency is obtained.

6. The grid-connected / off-grid switching method for distributed photovoltaic energy storage microgrids according to claim 2, characterized in that, The step of performing weighted particle swarm optimization based on the final frequency and the grid-connected switch state to obtain adjusted fusion weights, and performing weighted deviation over-limit analysis based on the adjusted fusion weights to obtain the final switching signal, includes: Calculate the difference between the final frequency and the rated frequency to obtain the optimized frequency deviation; The initial fusion weights are iteratively optimized using a particle swarm optimization algorithm to obtain adjusted fusion weights. Based on the adjusted fusion weights, the grid connection switch status and the optimized frequency deviation are weighted and fused to obtain the optimized fusion deviation; When the optimized fusion deviation exceeds the preset optimized deviation range, a final switching signal is generated; When the optimized fusion deviation does not exceed the optimized deviation range, power rolling optimization control is performed again to obtain an updated final control output; Based on the updated final control output, microgrid frequency monitoring and fault tracing are performed again, and the optimized fusion deviation is recalculated until the optimized fusion deviation exceeds the optimized deviation range, thus obtaining the final switching signal.

7. The grid-connected / off-grid switching method for distributed photovoltaic energy storage microgrids according to claim 3, characterized in that, After obtaining the final switching signal, the method further includes: Based on the final switching signal, the battery charging and discharging commands are optimized and adjusted to obtain updated charging and discharging commands; Obtain the update load demand and update power output, and calculate the difference between the update load demand and the update power output to obtain the update power compensation amount; Based on the updated charge / discharge command and the updated power compensation amount, a final compensation command is generated.

8. A grid-connected / off-grid switching system for a distributed photovoltaic energy storage microgrid, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method according to any one of claims 1 to 7.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the program implements the steps of the method described in any one of claims 1 to 7.