Capacitance type liquid level sensor temperature compensation method based on improved BP neural network

By improving the temperature compensation method of BP neural network, fitting the relative permittivity of air and water, and using PSO and GA algorithms to optimize weights and thresholds, the temperature drift problem of liquid level sensor is solved, and the accuracy and efficiency of temperature compensation are improved.

CN119962384BActive Publication Date: 2025-11-07DALI BUREAU OF ULTRA HIGH VOLTAGE TRANSMISSION CO CHINA SOUTHERN POWER GRID CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510063444.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-15
Publication Date
2025-11-07
Estimated Expiration
2045-01-15

AI Technical Summary

Technical Problem

Existing liquid level sensors exhibit significant temperature drift when the ambient temperature changes, leading to measurement errors. Traditional temperature compensation methods fail to effectively consider the influence of dielectric constant, resulting in insufficient compensation accuracy.

Method used

A temperature compensation method based on an improved BP neural network is constructed. By fitting the relative permittivity of air and water, the weights and thresholds of the BP neural network are optimized using PSO and GA algorithms, respectively. The temperature compensation is performed by considering the characteristics of the permittivity changing with temperature.

Benefits of technology

It significantly improves the temperature compensation accuracy and efficiency of capacitive liquid level sensors, avoids local optima problems, enhances global search capabilities, and ensures the accuracy of liquid level measurement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119962384B_ABST
    Figure CN119962384B_ABST
Patent Text Reader

Abstract

The application discloses a kind of temperature compensation method of capacitive liquid level sensor based on improved BP neural network, including establishing the capacitive liquid level sensor capacitance output model based on temperature compensation of relative dielectric constant;Based on the capacitive liquid level sensor capacitance output model, the relative dielectric constant of water and air in the corresponding capacitive liquid level sensor under different environmental temperature conditions is obtained according to different liquid level values, to be used as sample data;And sample data is randomly divided into sample training set and sample test set;Temperature compensation BP neural network of capacitive liquid sensor is constructed;According to sample training set and sample test set, the initial weight and threshold of temperature compensation BP neural network are optimized, and the optimized temperature compensation BP neural network is obtained;According to the optimized temperature compensation BP neural network, temperature compensation of capacitive liquid level sensor under different environmental temperatures is realized.The problem that the compensation precision is insufficient is solved, which is that the traditional temperature compensation model obtains compensated liquid level by inputting temperature data and to be compensated liquid level data, which is equivalent to directly finding the relationship between temperature and sensor liquid level, and ignoring the influence of intermediate variable dielectric constant.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of sensor temperature compensation, and in particular to a capacitive liquid level sensor temperature compensation method based on an improved BP neural network. BACKGROUND

[0002] In the industrial field, accurate liquid level measurement is crucial, which has driven the development and wide application of various technologies. However, when the ambient temperature changes greatly, the liquid level sensor will have a significant temperature drift phenomenon, causing measurement errors of the liquid level sensor. Therefore, temperature compensation needs to be performed on the liquid level sensor to ensure high-precision measurement of the sensor.

[0003] In the prior art, commonly used temperature compensation methods include hardware compensation and software compensation. Hardware compensation methods include line compensation method, bridge compensation method, etc. In actual application, hardware compensation has the disadvantages of complex circuit, poor universality, difficult debugging, and high cost, which is not conducive to engineering application. Software compensation methods include least squares method, multiple regression, neural network method, etc. In the actual model, the temperature affects the dielectric constant of the liquid and air in the capacitive liquid level sensor, thereby causing the output capacitance to change, resulting in inaccurate liquid level. The traditional temperature compensation model obtains the compensated liquid level by inputting temperature data and liquid level data to be compensated, which is equivalent to directly finding the relationship between temperature and sensor liquid level, while ignoring the influence of the intermediate variable dielectric constant, thereby causing the problem of insufficient compensation accuracy. SUMMARY

[0004] The present application provides a capacitive liquid level sensor temperature compensation method based on an improved BP neural network to overcome the above technical problems.

[0005] To achieve the above purpose, the technical solution of the present application is as follows:

[0006] A capacitive liquid level sensor temperature compensation method based on an improved BP neural network, specifically comprising the following steps:

[0007] S1: Establish a capacitive liquid level sensor capacitance output model based on relative dielectric constant temperature compensation, and the relative dielectric constant includes air relative dielectric constant and water relative dielectric constant affected by temperature;

[0008] S2: Based on the capacitive liquid level sensor capacitance output model, obtain the relative dielectric constants of air and water of the capacitive liquid level sensor under different environmental temperature conditions according to different liquid level values, as sample data;

[0009] And randomly divide the sample data into a sample training set and a sample test set;

[0010] S3: Construct a temperature compensation BP neural network for the capacitive liquid sensor;

[0011] and the temperature compensation BP neural network comprises a first BP neural network fitted for air relative dielectric constant and a second BP neural network fitted for water relative dielectric constant;

[0012] S4: optimizing the initial weights and thresholds of the temperature compensation BP neural network according to the sample training set and the sample test set, and obtaining an optimized temperature compensation BP neural network;

[0013] The optimization of the initial weights and thresholds comprises:

[0014] optimizing the initial weights and thresholds of the first BP neural network based on a PSO algorithm, and optimizing the initial weights and thresholds of the second BP neural network based on a GA algorithm;

[0015] S5: realizing temperature compensation of the capacitive liquid level sensor at different ambient temperatures according to the optimized temperature compensation BP neural network.

[0016] Further, the random division into the sample training set and the sample test set comprises:

[0017] the first sample training set based on the ambient temperature, the air relative dielectric constant and the liquid level value;

[0018] the second sample training set based on the ambient temperature, the water relative dielectric constant and the liquid level value;

[0019] the first sample test set based on the ambient temperature, the air relative dielectric constant and the liquid level value;

[0020] the second sample test set based on the ambient temperature, the water relative dielectric constant and the liquid level value.

[0021] Further, the first BP neural network and the second BP neural network constructed in S2 have the same structure, comprising an input layer, at least one hidden layer and an output layer connected in sequence;

[0022] and the input layer comprises a temperature input layer and a dielectric constant input layer;

[0023] the temperature input layer is used for inputting the acquired ambient temperature of the capacitive liquid level sensor to the hidden layer;

[0024] the dielectric constant input layer is used for inputting the relative dielectric constant of the capacitive liquid level sensor capacitance output model to the hidden layer;

[0025] the hidden layer is used for performing a nonlinear fitting operation on the input of the temperature input layer and the input of the dielectric constant input layer;

[0026] the output layer is used for acquiring the liquid level value of the capacitive liquid level sensor according to the output of the hidden layer.

[0027] Further, in S4, the initial weights and thresholds of the temperature compensation BP neural network are optimized based on the Adam optimization algorithm according to the sample training set and the sample test set, and an optimized temperature compensation BP neural network is obtained, specifically:

[0028] S41: The ambient temperature and the relative dielectric constant of air are taken as input data, and the liquid level value of the capacitive liquid level sensor is taken as output data;

[0029] The initial weights and thresholds of the first BP neural network are defined as the coding information of the individual particles of the population to obtain the initial particle population of the PSO algorithm;

[0030] S42: Based on the population particle algorithm, the first BP neural network is trained according to the first sample training set combined with the initial particle population to obtain the trained first BP neural network;

[0031] S43: The trained first BP neural network is tested by the first sample test set:

[0032] If the output of the trained first BP neural network converges or reaches the preset training iteration number, the trained first BP neural network at this time is the optimal first BP neural network;

[0033] Otherwise, the position and speed of the particle are updated through the position updating formula and the speed updating formula with weight, and step S42 is repeatedly executed;

[0034] S44: The ambient temperature and the relative dielectric constant of water are taken as input data, and the liquid level value of the capacitive liquid level sensor is taken as output data;

[0035] The initial weights and thresholds of the second BP neural network are defined as the coding information of the population individuals to obtain the initial population of the GA algorithm;

[0036] S45: Based on the GA algorithm, the second BP neural network is trained according to the second sample training set combined with the initial population to obtain the trained second BP neural network;

[0037] S46: The trained second BP neural network is tested by the second sample test set:

[0038] If the output of the trained second BP neural network converges or reaches the preset training iteration number, the trained second BP neural network at this time is the optimal second BP neural network;

[0039] Otherwise, the population of the GA algorithm is arranged in descending order according to the fitness to obtain a fitness list;

[0040] And according to the preset fitness threshold, the population of GA algorithm is divided into the first segmented population satisfying the preset fitness threshold and the second segmented population not satisfying the preset fitness threshold according to the fitness sequence table;

[0041] The second segmented population is subjected to cross / mutation operation to obtain an optimized population;

[0042] The optimized population and the first segmented population are recombined to obtain a new population, and the new population is taken as an initial population, and step S45 is repeatedly executed.

[0043] Further, the expression of the position updating formula and the speed updating formula with weight of the particle in S43 is

[0044] v i (k+1) = ω·v i (k) + c1·r1·[P best·i -x i (k)] + c2·r2·[G best -x i (k)]

[0045] x i (k+1) = x i (k) + v i (k+1)

[0046] In the formula, v i (k+1) and x i (k+1) represent the speed and position of particle i in the k+1 iteration; v i (k) and x i (k) represent the speed and position of particle i in the k iteration; P best·i represents the individual extremum of the current iteration of particle i; G best represents the global extremum of the particle population; c1 and c2 represent learning factors; ω represents an inertia weight; and r1 and r2 represent random numbers in [0, 1].

[0047] Further, it is judged whether the trained first BP neural network or the second BP neural network outputs a converged fitness function, i.e., a loss function, and the expression is

[0048]

[0049] In the formula, E represents the mean square error between the actual liquid level value and the liquid level value calculated from the compensated relative dielectric constant output by the network through a formula; N represents the number of samples of a test set, h i represents the dielectric constant output by the BP neural network through the i-th test sample, and h iactual liquid level value of the ith test sample.

[0050] Further, the capacitance output model of the capacitive liquid level sensor established in S1 is expressed as

[0051]

[0052] wherein C p represents the overall output capacitance of the capacitive liquid level sensor; C a represents the capacitance of the air medium above the liquid surface of the capacitive liquid level sensor; C w represents the capacitance of the liquid medium below the liquid surface; C F,a represents the capacitance of the air medium when the insulation sheath is used as the medium; and the capacitance of the liquid is C F,w represents the capacitance of the liquid when the insulation sheath is used as the medium; C 01 and C 02 respectively represent the additional capacitance of the capacitive liquid level sensor caused by the edge effect of the bottom of the inner and outer electrodes; R1 represents the design parameter of the outer diameter of the inner electrode; R3 represents the design parameter of the inner diameter of the outer electrode; R2 represents the design parameter of the outer diameter of the insulation sheath; H represents the distance between the bottom of the inner electrode and the outer electrode; h0 represents the total length of the capacitive liquid level sensor container; h represents the liquid level height in the container; H1 represents the length of the inner electrode immersed in the liquid; h1 represents the height of the air part above the liquid surface and h1 = h0 - h; ε0 represents the dielectric constant of ideal vacuum; ε a represents the relative dielectric constant of the air; ε w represents the relative dielectric constant of the water; ε F represents the relative dielectric constant of the insulation medium; C0 represents the capacitance of the edge space part at the bottom of the capacitive liquid level sensor; ε e represents the equivalent dielectric constant of the edge space insulation medium and the liquid.

[0053] Beneficial effects: the application provides a capacitive liquid level sensor temperature compensation method based on improved BP neural network, compared with the traditional method of directly performing temperature compensation, the first BP neural network fitting the relative dielectric constant of air and the second BP neural network fitting the relative dielectric constant of water are constructed, the relative dielectric constant of air and the relative dielectric constant of water are respectively corrected, so as to confirm the liquid level data of the capacitive liquid level sensor after temperature compensation, by fully considering the influence of environmental temperature on the intermediate variable dielectric constant, the temperature compensation precision is greatly improved. At the same time, considering the characteristics of the air medium constant and the water relative dielectric constant changing with temperature, the PSO algorithm and the GA algorithm are respectively used to optimize the weights and thresholds of the BP neural network of the air and water dielectric constant, that is, since the relative dielectric constant of air changes little with temperature, the PSO directly optimizes in the local, avoiding the problem that it is easy to fall into local optimum; and since the relative dielectric constant of water decreases with the increase of temperature, the global search ability is enhanced to determine the solution space through the GA algorithm, so that the precision and efficiency of the capacitive liquid level sensor temperature compensation are greatly improved. BRIEF DESCRIPTION OF DRAWINGS

[0054] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, below will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the application, and for those skilled in the art, other drawings can also be obtained without creative labor.

[0055] Figure 1 The flow chart of the capacitive liquid level sensor temperature compensation method based on improved BP neural network of the application;

[0056] Figure 2 The structure diagram of the capacitive liquid level sensor in the embodiment;

[0057] Figure 3 The topology diagram of the temperature compensation BP neural network in the embodiment;

[0058] Figure 4 The optimization flow chart of the PSO algorithm for the weights and thresholds of the BP neural network in the embodiment;

[0059] Figure 5 The optimization flow chart of the GA algorithm for the weights and thresholds of the BP neural network in the embodiment. DETAILED DESCRIPTION

[0060] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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, 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.

[0061] This embodiment provides a temperature compensation method for a capacitive liquid level sensor based on an improved BP neural network, such as... Figure 1 As shown, the specific steps include:

[0062] S1: Establish a capacitive output model for a capacitive liquid level sensor based on temperature compensation using relative permittivity, where the relative permittivity includes the temperature-dependent relative permittivity of air and water.

[0063] Specifically, the established capacitive output model of the capacitive liquid level sensor is expressed as follows:

[0064]

[0065] In the formula: C p C represents the total output capacitance of the capacitive level sensor. a C represents the capacitance of a capacitive liquid level sensor above the liquid surface when air is the medium. w C represents the capacitance below the liquid surface with the liquid as the medium. F,a This represents the capacitance in air when the insulating sheath acts as the medium; while the capacitance in a liquid is C. F,w Indicates the capacitance in the liquid when the insulating sheath acts as the medium; C 01 With C 02 These represent the additional capacitance caused by the edge effect at the bottom of the inner and outer electrodes of the capacitive liquid level sensor, respectively; R1 represents the design parameter of the outer diameter of the inner electrode, such as... Figure 2 As shown, 1 represents the outer diameter of the inner electrode J; 2 represents the insulating sleeve; 3 represents the outer electrode K; 4 represents the solution; and the inner electrode J is a solid stainless steel tube with an outer diameter of 2R1; R3 represents the design parameter of the inner diameter of the outer electrode, and the outer electrode K is a hollow stainless steel tube with an inner diameter of 2R3; R2 represents the design parameter of the outer diameter of the insulating sleeve, and the outer diameter of the insulating sleeve is 2R2; H represents the distance between the bottom of the inner electrode and the outer electrode; h0 represents the total length of the capacitive liquid level sensor container; h represents the liquid level height in the container; H1 represents the length of the inner electrode that extends beyond the top of the container and is immersed in the liquid because the inner electrode is long enough; h1 represents the height of the air portion above the liquid surface and h1 = h0 - h; ε0 represents the dielectric constant of an ideal vacuum; ε a ε represents the relative permittivity of air;w represents the relative dielectric constant of water; ε0represents the relative dielectric constant of vacuum; ε F represents the relative dielectric constant of the insulating medium; C0represents the capacitance of the bottom edge space part of the capacitive liquid level sensor obtained by finite element analysis calculation, wherein the implementation method of the capacitance of the bottom edge space part of the capacitive liquid level sensor obtained by finite element analysis calculation is a prior known technical means and is not the point of the application, and will not be described in detail here; ε e represents the equivalent dielectric constant of the edge space insulating medium and the liquid;

[0066] S2: Based on the capacitive liquid level sensor capacitance output model, the relative dielectric constants of air and water corresponding to different environmental temperature conditions are obtained according to different liquid level values as sample data;

[0067] and the sample data is randomly divided into a sample training set and a sample test set;

[0068] Specifically, the random division into a sample training set and a sample test set includes:

[0069] including a first sample training set based on environmental temperature, air relative dielectric constant and liquid level value;

[0070] a second sample training set related to environmental temperature, water relative dielectric constant and liquid level value;

[0071] a first sample test set related to environmental temperature, air relative dielectric constant and liquid level value;

[0072] a second sample test set related to environmental temperature, water relative dielectric constant and liquid level value;

[0073] In this embodiment, since the influence of environmental temperature on the intermediate variable dielectric constant is different, the sample data is divided into two data sets, which facilitates the subsequent BP neural network training to fully consider the influence of different medium constants on the temperature compensation of the capacitive liquid level sensor, so as to improve the temperature compensation precision; wherein since the vacuum dielectric constant ε0in the capacitive liquid level sensor capacitance output model and the relative dielectric constant ε F are not affected by temperature, only the air relative dielectric constant and the water relative dielectric constant affected by environmental temperature are considered;

[0074] S3: Constructing a temperature compensation BP neural network of the capacitive liquid sensor;

[0075] and the temperature compensation BP neural network includes a first BP neural network fitting the air relative dielectric constant and a second BP neural network fitting the water relative dielectric constant;

[0076] Specifically, as Figure 3As shown, the first BP neural network and the second BP neural network have the same structure, including an input layer, at least one hidden layer, and an output layer connected in sequence;

[0077] The input layer includes a temperature input layer and a dielectric constant input layer;

[0078] The temperature input layer is configured to input the acquired ambient temperature of the capacitive liquid level sensor to the hidden layer;

[0079] The dielectric constant input layer is configured to input the relative dielectric constant of the capacitive liquid level sensor capacitor output model to the hidden layer;

[0080] The hidden layer is configured to perform a nonlinear fitting operation on the input of the temperature input layer and the input of the dielectric constant input layer;

[0081] The output layer is configured to acquire the liquid level value of the capacitive liquid level sensor according to the output of the hidden layer.

[0082] In this embodiment, the determination of the BP neural network topology is as follows: according to the actual requirements of the capacitive liquid level sensor temperature compensation, the number of nodes of the input layer and the output layer of the BP neural network, the number of nodes of the hidden layer, and the number of layers of the hidden layer are determined, and one layer is selected to realize arbitrary nonlinear fitting. In addition, a sigmoid activation function is selected after the input layer to activate the output data, which is beneficial to control the signal within an effective range. A purelin function is selected after the hidden layer to perform an identity mapping process on the output of the hidden layer, which ensures the possibility of various values of the output signal. The formula for confirming the number of nodes of the hidden layer is as follows:

[0083]

[0084] In the formula, p represents the number of nodes of the hidden layer; p in and p out respectively represent the number of nodes of the input layer and the output layer; and c represents a constant between 1 and 10 selected according to experience.

[0085] S4: Based on the Adam optimization algorithm, the initial weights and thresholds of the temperature compensation BP neural network are optimized according to the sample training set and the sample test set, and an optimized temperature compensation BP neural network is obtained.

[0086] In this embodiment, since the relative dielectric constant of air is less affected by temperature changes according to experience, and the relative dielectric constant of water is greatly affected by temperature changes, and decreases as the temperature increases, the PSO algorithm can be used to optimize the BP neural network fitting the relative dielectric constant of air, and the GA algorithm can be used to optimize the BP neural network fitting the relative dielectric constant of water.

[0087] The optimization of the initial weights and thresholds includes:

[0088] The initial weight and threshold of the first BP neural network are optimized and fitted based on a PSO algorithm, and the initial weight and threshold of the second BP neural network are optimized and fitted based on a GA algorithm.

[0089] The Particle Swarm Optimization (PSO) algorithm is an intelligent optimization algorithm simulating the foraging behavior of a bird swarm or a fish swarm, which searches the position and speed of particles in a D-dimensional space through iterative search to find a global optimal solution. The Genetic Algorithm (GA) can perform extensive search in a solution space through selection, crossover, mutation and other operations, and has strong global search capability.

[0090] The method comprises the following steps:

[0091] S41: The ambient temperature and the relative dielectric constant of air are taken as input data, the liquid level value of the capacitive liquid level sensor is taken as output data, and the initial weight and threshold of the first BP neural network are defined as the coding information of the individual particles of the population particles to obtain the initial particle population of the PSO algorithm;

[0092] In specific embodiments, as shown in Figure 4 The initial weight and threshold of the first BP neural network are represented as a D-dimensional vector as the coding information of the individual particles, that is, one coding information contains all the weight and threshold of the entire BP neural network, that is, one particle individual. Before using the population particle algorithm, the PSO parameters are initialized, that is, the number of particle individuals of the particle population, the maximum number of iterations T, the upper and lower limits of the position of the particle population x max and x min , the upper and lower limits of the particle velocity v max and v min , the learning factors c1 and c2, the inertia weight ω, and the particle position is randomly set. Since the relative dielectric constant of air changes little, the particle velocity is set to a small value according to the experience value.

[0093] S42: Based on the population particle algorithm, the first BP neural network is trained based on the initial particle population and the first sample training set to obtain the trained first BP neural network;

[0094] S43: The trained first BP neural network is tested through the first sample test set:

[0095] If the output of the trained first BP neural network converges or reaches the preset number of training iterations, the trained first BP neural network at this time is the optimal first BP neural network.

[0096] Otherwise, the position and velocity of the particle are updated by the position update formula and the weighted velocity update formula of the particle, and step S42 is repeatedly executed;

[0097] Specifically, the expression of the position update formula and the weighted velocity update formula of the particle is v i (k+1) = ω·v i (k) + c1·r1·[P best·i -x i (k)] + c2·r2·[G best -x i (k)]

[0098] x i (k+1) = x i (k) + v i (k+1)

[0099] wherein v i (k+1) and x i (k+1) represent the velocity and position of the particle i in the k+1th iteration, respectively; v i (k) and x i (k) represent the velocity and position of the particle i in the kth iteration, respectively; P best·i represents the individual extremum of the particle i in the current iteration; G best represents the global extremum of the particle population; c1 and c2 represent learning factors; ω represents an inertia weight; and r1 and r2 represent random numbers in [0, 1];

[0100] S44: Taking the environmental temperature and the water relative dielectric constant as input data, taking the liquid level value of the capacitive liquid level sensor as output data, and defining the initial weight and threshold of the second BP neural network as the coding information of the population individuals to obtain the initial population of the GA algorithm;

[0101] In specific embodiments, as shown in Figure 5 Before using the GA algorithm, at least the following steps are further included: initializing the GA parameters, setting the number of population individuals, and setting the maximum number of iterations, etc.

[0102] S45: Based on the GA algorithm, the second BP neural network is trained based on the second sample training set combined with the initial population to obtain the trained second BP neural network;

[0103] S46: The trained second BP neural network is tested by using the second sample test set:

[0104] If the output of the trained second BP neural network converges or reaches the preset training iteration number, the trained second BP neural network at this time is the optimal second BP neural network;

[0105] Otherwise, the population of the GA algorithm is arranged in descending order according to the fitness, and a fitness sequence table is obtained;

[0106] According to the preset fitness threshold, the population of the GA algorithm is divided into a first segmented population G1 satisfying the preset fitness threshold and a second segmented population G2 not satisfying the preset fitness threshold according to the fitness sequence table;

[0107] The optimized population is obtained by performing a crossover / mutation operation on the second segmented population G2;

[0108] The optimized population and the first segmented population G1 are recombined to obtain a new population, the new population is taken as the initial population, and step S45 is repeatedly executed;

[0109] The recombination is random mixing of the optimized population and the first segmented population G1;

[0110] S5: According to the optimized temperature compensation BP neural network, temperature compensation of the capacitive liquid level sensor in different environmental temperatures is implemented.

[0111] In specific embodiments, whether the trained first BP neural network or the second BP neural network outputs a converged fitness function, i.e., a loss function, is determined, and the expression is

[0112]

[0113] In the formula, E represents the mean square error between the actual liquid level value and the liquid level value calculated from the compensated relative dielectric constant output by the network; N represents the number of samples in the test set, h i represents the dielectric constant output by the BP neural network through the i-th test sample, the liquid level value of the capacitive liquid level sensor is obtained, and h i is the actual liquid level value of the i-th test sample.

[0114] In this embodiment, the relative dielectric constant is corrected by the optimized temperature compensation BP neural network after training, and the corrected dielectric constant is used for the capacitance output model of the capacitive liquid level sensor to determine the temperature compensated liquid level value. Compared with the traditional method of directly performing temperature compensation, this embodiment constructs a first BP neural network for fitting the relative dielectric constant of air and a second BP neural network for fitting the relative dielectric constant of water, respectively corrects the relative dielectric constant of air and the relative dielectric constant of water, and determines the liquid level data of the capacitive liquid level sensor after temperature compensation. By fully considering the influence of environmental temperature on the intermediate variable dielectric constant, the temperature compensation accuracy is greatly improved. At the same time, considering the characteristics of the relative dielectric constant of air and water changing with temperature, the PSO algorithm and the GA algorithm are used to optimize the weights and thresholds of the BP neural networks of the dielectric constant of air and water, that is, since the relative dielectric constant of air changes little with temperature, the PSO directly optimizes in the local, avoiding the problem of easily falling into local optimum; and since the relative dielectric constant of water decreases with the increase of temperature, the global search ability is enhanced by the GA algorithm to determine the solution space, greatly improving the accuracy and efficiency of temperature compensation of the capacitive liquid level sensor.

[0115] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for temperature compensation of a capacitive liquid level sensor based on an improved BP neural network, characterized in that, Specifically comprising the following steps: S1: establishing a capacitive liquid level sensor capacitance output model based on temperature compensation of relative dielectric constant, and the relative dielectric constant includes air relative dielectric constant and water relative dielectric constant affected by temperature; The established capacitive liquid level sensor capacitance output model has an expression of where: Ctotai represents the overall output capacitance of the capacitive level sensor; C a Cair represents the capacitance of the air above the liquid level of the capacitive level sensor; C w Cliquid represents the capacitance of the liquid below the liquid level; C F,a Cair represents the capacitance of the air above the liquid level of the capacitive level sensor; C F,w Cliquid represents the capacitance of the liquid below the liquid level; C 01 Cair represents the capacitance of the air above the liquid level of the capacitive level sensor; C 02 Cair represents the capacitance of the air above the liquid level of the capacitive level sensor; C R 1 represents a design parameter for the outer diameter of the inner electrode; 2 R 3 represents a design parameter for the inner diameter of the outer electrode; 2 R 2 represents a design parameter for the outer diameter of the insulation sheath; 1 H 1 represents the distance between the bottom of the inner electrode and the outer electrode; 2 h 0 represents the total length of the capacitive level sensor container; 1 h 1 represents the height of the liquid level within the container; 2 H 1 represents the length of the inner electrode immersed in the liquid; 2 h 1 represents the height of the air portion above the liquid level; 2 h 1 = h 0 - h ; 1 represents the relative permittivity of an ideal vacuum; 2 2 represents the relative permittivity of air; 1 1 represents the relative permittivity of water; 2 2 represents the relative permittivity of the insulation medium; C0 represents the capacitance of the capacitive level sensor bottom edge space portion; 1 1 represents the equivalent permittivity of the edge space insulation medium and liquid; 2 S2: based on the capacitive liquid level sensor capacitance output model, obtaining the relative dielectric constants of water and air in the capacitive liquid level sensor under different environmental temperature conditions according to different liquid level values as sample data; and randomly dividing the sample data into a sample training set and a sample test set; S3: constructing a temperature compensation BP neural network of the capacitive liquid level sensor; And the temperature compensation BP neural network includes a first BP neural network for fitting the air relative dielectric constant and a second BP neural network for fitting the water relative dielectric constant; The first BP neural network and the second BP neural network have the same structure, including an input layer, at least one hidden layer, and an output layer connected in sequence; And the input layer includes a temperature input layer and a dielectric constant input layer; The temperature input layer is used for inputting the acquired environmental temperature of the capacitive liquid level sensor to the hidden layer; The dielectric constant input layer is used for inputting the relative dielectric constant of the capacitive liquid level sensor capacitance output model to the hidden layer; The hidden layer is used for performing a nonlinear fitting operation on the input of the temperature input layer and the input of the dielectric constant input layer; The output layer is used for obtaining the liquid level value of the capacitive liquid level sensor according to the output of the hidden layer; S4: based on the Adam optimization algorithm, optimizing the initial weights and thresholds of the temperature compensation BP neural network according to the sample training set and the sample test set to obtain an optimized temperature compensation BP neural network; Optimizing the initial weights and thresholds includes: Based on the PSO algorithm, the initial weights and thresholds of the first BP neural network are optimized; Based on the GA algorithm, the initial weights and thresholds of the second BP neural network are optimized; S5: according to the optimized temperature compensation BP neural network, temperature compensation of the capacitive liquid level sensor under different environmental temperatures is realized. 2.The method of claim 1, wherein, The random division into the sample training set and the sample test set includes: The first sample training set based on the environmental temperature, the air relative dielectric constant, and the liquid level value; The second sample training set based on the environmental temperature, the water relative dielectric constant, and the liquid level value; The first sample test set based on the environmental temperature, the air relative dielectric constant, and the liquid level value; The second sample test set based on the environmental temperature, the water relative dielectric constant, and the liquid level value. 3.The method of claim 2, wherein, In S4, based on the Adam optimization algorithm, the initial weights and thresholds of the temperature compensation BP neural network are optimized according to the sample training set and the sample test set to obtain an optimized temperature compensation BP neural network, specifically: S41: taking the environmental temperature and the air relative dielectric constant as input data and taking the liquid level value of the capacitive liquid level sensor as output data; and defining the initial weights and thresholds of the first BP neural network as the coding information of the individual particles of the population to obtain the initial particle population of the PSO algorithm; S42: training the first BP neural network according to the first sample training set and combining the initial particle population based on the population particle algorithm to obtain a trained first BP neural network; S43: testing the trained first BP neural network by using the first sample test set: If the output of the trained first BP neural network converges or reaches the preset training iteration number, the trained first BP neural network at this time is an optimal first BP neural network; Otherwise, the position and speed of the particle are updated by using the position updating formula and the speed updating formula with weight, and step S42 is repeatedly executed; S44: taking the environmental temperature and the relative dielectric constant of water as input data and taking the liquid level value of the capacitive liquid level sensor as output data; The initial weight and threshold value of the second BP neural network are defined as the coding information of the population individual to obtain an initial population of the GA algorithm; S45: training the second BP neural network according to the second sample training set and combining the initial population based on the GA algorithm to obtain a trained second BP neural network; S46: testing the trained second BP neural network by using the second sample test set: If the output of the trained second BP neural network converges or reaches the preset training iteration number, the trained second BP neural network at this time is an optimal second BP neural network; Otherwise, the population of the GA algorithm is arranged in descending order according to the fitness to obtain a fitness sequence table; According to the preset fitness threshold, the population of the GA algorithm is divided into a first segmented population satisfying the preset fitness threshold and a second segmented population not satisfying the preset fitness threshold according to the fitness sequence table; The optimized population is obtained by performing the crossover / mutation operation on the second segmented population; The optimized population and the first segmented population are recombined to obtain a new population, the new population is taken as the initial population, and step S45 is repeatedly executed.

4. The method according to claim 3, wherein, The expression of the position updating formula and the speed updating formula with weight of the particle in S43 is where: v i k x i k i The velocity and position of the particle in the first iteration; k v i k x i k The velocity and position of the particle in the second iteration; i k The velocity and position of the particle in the current iteration; The individual extremum of the particle in the current iteration; i The global extremum of the particle population; The learning factor; The inertia weight; The random number in [0, 1]; The expression of the fitness function, i.e. the loss function, of the trained first BP neural network or the second BP neural network is The random number in [0, 1]; The random number in [0, 1]; The random number in [0, 1];​​​​​​​​​ 5. The method according to claim 3, wherein, ​ In the formula: represents the mean square error between the actual liquid level value and the liquid level value calculated by the network output after compensation of the relative dielectric constant by the formula; N represents the number of samples in the test set, represents the dielectric constant output by the BP neural network of the i th test sample, the liquid level value of the capacitive liquid level sensor obtained, is the actual liquid level value of the i th test sample.

Citation Information

Patent Citations

  • Silicon microaccelerometer temperature compensation method and system based on GA-optimized BP neural network

    CN108073075A

  • Roller compacted concrete compaction degree evaluation method based on GA-BP network

    CN109783988A