A LQR water pump motor control method based on improved genetic algorithm optimization
By improving the genetic algorithm to optimize the LQR pump motor control method, the speed instability problem caused by the traditional LQR controller was solved, and higher irrigation accuracy and controller stability were achieved.
Patent Information
- Application Number
- CN202311150641.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-07
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2043-09-07
AI Technical Summary
The existing water pump motor control method uses the traditional LQR controller, which leads to unstable speed and affects irrigation accuracy.
An improved genetic algorithm is used to optimize the LQR water pump motor control method. By initializing the state weighted matrix Q and the control weighted matrix R, encoding, selection, crossover and mutation operations are performed to iteratively optimize the controller parameters and obtain the optimal control input vector.
The stability of water pump motor control and irrigation accuracy are improved, local optimality is avoided, and the stability and response speed of the controller are improved.
Smart Images

Figure CN117031925B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of water pump motor control, and in particular to an LQR water pump motor control method based on improved genetic algorithm optimization. Background Art
[0002] With the emergence of innovative technologies such as big data, blockchain, artificial intelligence, the Internet of Things, and 5G communications, integrating agricultural production with IoT technology has become an inevitable trend in the future development of agricultural technology. Relying on agricultural IoT technology, smart irrigation can not only reduce the labor demand in agricultural production, but also significantly reduce water waste.
[0003] The current water pump motor control method uses a traditional LQR controller. However, this control method requires a lot of actual testing and adjustment to obtain a suitable weight matrix and threshold value. It can only achieve good control effects in specific application scenarios. However, due to the uneven irrigation pipelines in the farmland and the existence of electromagnetic interference in the farmland, the use of the existing traditional LQR controller to control the water pump motor will cause unstable speed, resulting in low irrigation accuracy. Summary of the Invention
[0004] The purpose of the present invention is to solve the problem of unstable speed of existing water pump motors, which leads to low irrigation accuracy, and proposes an LQR water pump motor control method based on improved genetic algorithm optimization.
[0005] The specific process of an LQR water pump motor control method based on improved genetic algorithm optimization is as follows:
[0006] Step 1: Initialize the state weight matrix Q and the control weight matrix R to obtain the initial matrix population;
[0007] An individual in the initial matrix population consists of a matrix Q and a matrix R;
[0008] Step 2: Encode the initial matrix population and convert the individuals in the initial matrix population into chromosomes;
[0009] Step 3: Perform selection, crossover and mutation operations on the chromosomes obtained in step 2 to obtain a new generation of chromosomes;
[0010] Step 4: Determine whether the current iteration termination condition is met. If the iteration termination condition is met, the new generation chromosome obtained in step 3 is output as the optimal genotype. If the iteration termination condition is not met, return to step 3 for the next iteration.
[0011] Step 5: Decode the optimal genotype and use the decoded optimal genotype to obtain the control input vector to realize the water pump motor control.
[0012] Furthermore, the encoding of the initial matrix population in step 2 is specifically as follows:
[0013] The elements in the matrix Q and the matrix R of each individual in the initial matrix population are binary-encoded to obtain the transformed chromosomes of the individuals in the initial matrix population.
[0014] Furthermore, in step three, the chromosomes obtained in step two are subjected to selection, crossover and mutation operations to obtain a new generation of chromosomes, specifically:
[0015] Step 3. Calculate the fitness value of each individual using the fitness function, and use the fitness value to select the chromosome to obtain the selected chromosome;
[0016] The fitness function is as follows:
[0017]
[0018] Where F is the fitness value, t is the time, x is the system state vector, and u is the control input vector;
[0019] Step 32: Perform a crossover operation on the selected chromosome to obtain a crossover chromosome;
[0020] Step 33: Perform mutation operation on the chromosomes after crossover to obtain a new generation of chromosomes.
[0021] Furthermore, the step 31 uses the fitness value to select the chromosome to obtain the selected chromosome, specifically:
[0022] First, the fitness value of the chromosome is normalized to obtain the selection probability of each individual. Then, the chromosomes are sorted from large to small according to the selection probability using the sorting method to obtain the sorted chromosome sequence.
[0023] Then, a preset number of chromosomes are randomly selected from the sorted chromosome sequence to obtain the selected chromosomes.
[0024] Furthermore, a preset number of chromosomes are randomly selected from the sorted chromosome sequence, and the probability of each individual being selected is as follows:
[0025] P=S(1-P0) b-a
[0026]
[0027] Where a is the population size, P0 is the selection probability, S is the probability of the rearranged chromosome being selected, b is the position number of the individual after sorting, S is the probability of the optimal individual being selected, and P is the probability of the sorted individual being selected.
[0028] Furthermore, the iteration termination condition is any one of the following:
[0029] a. The current number of iterations reaches the preset number of iterations;
[0030] b. Calculate the fitness value of the new generation chromosome obtained in step 3. When the difference between the fitness values of the new generation chromosome obtained in two rounds of iteration is lower than the preset fitness value threshold, it means that the termination condition is met.
[0031] Furthermore, the optimal genotype is decoded in step 5, and the control input vector is obtained using the decoded optimal genotype, specifically:
[0032] Step 51: Perform binary decoding on the optimal genotype to obtain the state weight matrix Q' and control weight matrix R' corresponding to the optimal genotype;
[0033] Step 52: Using Q' and R' obtained in step 51, calculate the cost function weight matrix P' of the LQR controller;
[0034] Step 53: Use P′ obtained in step 52 to obtain the control input u.
[0035] Furthermore, in step 52, the cost function weighted matrix P′ of the LQR controller is calculated using Q′ and R′ obtained in step 51, specifically:
[0036] A T P′+P′A+Q′=P′BR′ -1 B T P′
[0037] Among them, A is the state transfer matrix and B is the control input matrix.
[0038] Furthermore, in step 53, the control input u is obtained by using P′ obtained in step 52, as shown in the following formula:
[0039] u=-Kx
[0040] Where K is the feedback gain matrix.
[0041] Furthermore, the feedback gain matrix K is obtained by the following formula:
[0042] K=R′ -1 B T P′
[0043] Where P′ is the cost function weighting matrix of the LQR controller.
[0044] The beneficial effects of the present invention are:
[0045] This invention leverages the global search and optimization capabilities of genetic algorithms, avoiding local optimality and improving the stability of genetic algorithm-based LQR controller optimization. By iteratively optimizing controller parameters, the invention obtains the optimal control parameter combination (state weighting matrix Q and control weighting matrix R), thereby obtaining the optimal state feedback gain matrix K. This in turn obtains the control input vector u for controlling the water pump motor, enabling the water pump motor controller to reach its optimal state and stabilizing the water pump motor speed, thereby improving irrigation accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 It is a schematic diagram of the process of the present invention;
[0047] Figure 2 A genetic iteration graph of the objective performance function of the present invention;
[0048] Figure 3 This is a control model diagram of the DC motor system of the present invention;
[0049] Figure 4 The open-loop control speed curve of the DC motor of the present invention;
[0050] Figure 5 This is the PID closed-loop control DC motor speed curve of the present invention;
[0051] Figure 6 This is the LQR closed-loop control DC motor speed curve of the present invention;
[0052] Figure 7 This is the starting speed curve of the DC motor of the present invention. DETAILED DESCRIPTION
[0053] Specific implementation method 1: Figure 1 As shown, the specific process of the LQR water pump motor control method based on the improved genetic algorithm optimization in this embodiment is as follows:
[0054] Step 1: Randomly initialize the state weight matrix Q and the control weight matrix R to obtain the initial matrix population;
[0055] The initial matrix population includes 60 individuals; one individual includes a matrix Q and a matrix R;
[0056] Step 2: Encode the initial matrix population and convert it into chromosomes:
[0057] Binary encode the elements of matrix R and matrix Q in the initial matrix population to obtain 60 chromosomes;
[0058] Step 3: Perform selection, crossover, and mutation operations on the chromosomes obtained in step 2 to obtain a new generation of chromosomes, specifically:
[0059] Step 3.1: Use the fitness function to calculate the fitness value of each individual, and use the fitness value to select the chromosome:
[0060] First, the fitness function is used to calculate the fitness value of each individual:
[0061]
[0062] Where u is the control input vector, t is time, and x is the system state vector;
[0063] Then, the fitness value is normalized to obtain the selection probability of each individual, and then the chromosomes are sorted from large to small according to the selection probability using the sorting method to obtain the sorted chromosome sequence;
[0064] Finally, a preset number of chromosomes are randomly selected from the sorted chromosome sequence.
[0065] When selecting individuals, the "roulette wheel" method is commonly used. The probability of an individual being selected is random. This selection method may lose the best individual. Therefore, the present invention uses a sorting method to rearrange the chromosome pairs. The probability of an individual being selected after the rearrangement is as follows:
[0066] P=S(1-P0) b-a
[0067]
[0068] Where a is the population size, P0 is the selection probability, S is the probability of the rearranged chromosome being selected, b is the position number of the individual after sorting, S is the probability of the optimal individual being selected, and P is the probability of the sorted individual being selected;
[0069] The fitness function is an indicator to measure the quality of the genotype. Choosing a reasonable fitness function can speed up the calculation speed of the genetic algorithm and improve the algorithm's optimization performance. The present invention adopts the inverse of the objective function J in the LQR algorithm as the fitness function of the genetic algorithm. The gene that maximizes the fitness function is the optimal solution. The larger the inverse of the objective function J, the better the system control performance and the higher the corresponding fitness value.
[0070] Step 3.2: Perform a crossover operation on the selected chromosome pairs and calculate the crossover probability using the fitness function:
[0071] During the crossover operation, two individuals are randomly selected from the selected chromosome pair as crossover parents. A single-point crossover method is used, which randomly selects a crossover point and exchanges the genetic information of the two parents after the crossover point, thereby generating two offspring individuals. Multiple crossover operations are then performed to generate more offspring individuals.
[0072] The crossover probability determines the probability of individual pairs undergoing a crossover. In each generation, the genetic algorithm selects some individuals for crossover, while others are passed directly to the next generation. A higher crossover probability results in more individual pairs undergoing crossover, thereby increasing the exchange of genetic information and diversity.
[0073] The crossover operation is a process that imitates the phenomenon of chromosome fragment crossover and exchange, and obtains new chromosomes through chromosome crossover and exchange. The crossover operation makes the population evolve towards the optimal solution and is an important step for the genetic algorithm to obtain better genes. The crossover operation formula is as follows:
[0074] Before crossover operation:
[0075] A:a1a2···a n-1 a n
[0076] B:b1b2···b n-1 b n
[0077] After the crossover operation:
[0078] A:b1a2···a n-1 a n
[0079] B:a1b2···b n-1 b n
[0080] Step 3. Perform mutation operation on the chromosome pairs after the crossover operation to obtain a new generation of chromosomes, and use the fitness function to calculate the mutation probability:
[0081] During the mutation operation, select an individual from the offspring after the crossover operation as the target for mutation. Select the basic mutation method and perform the mutation operation on the selected individual to generate a new individual. Repeat the mutation operation multiple times to generate more mutant individuals.
[0082] The mutation operation imitates the mutation phenomenon of chromosome segments and obtains new chromosomes through the mutation of chromosome segments. The mutation operation has a similar function to the crossover operation. Its purpose is to make the population evolve towards the optimal solution and obtain excellent genes. The mutation operation formula is as follows.
[0083] Before mutation operation:
[0084] A:a1a2···a n-1 a n
[0085] B:b1b2···b n-1 b n
[0086] After the mutation operation:
[0087] A:a1c2···a n-1 a n
[0088] B:b1d2···b n-1 b n
[0089] Step 4: Determine whether the current iteration meets the termination condition. If so, output the new generation chromosome obtained in step 3 as the optimal genotype. If not, return to step 3 and repeat the chromosome selection, crossover and mutation operations.
[0090] If any of the following conditions is met, the current iteration meets the termination condition:
[0091] a. The current number of iterations reaches the preset number of iterations;
[0092] b. Calculate the fitness value of the new generation chromosome obtained in step 3. When the difference between the fitness values of each iteration is lower than the preset fitness value threshold, it is considered to have converged, indicating that the termination condition is met;
[0093] The preset fitness value threshold is 0.01;
[0094] The objective performance function of the present invention is as follows Figure 2 As shown, the horizontal axis is the genotype, the vertical axis is the fitness value, the solid point is the optimal individual fitness value, and the hollow circle is the average fitness value.
[0095] Step 5: Decode the optimal genotype, convert it into actual parameters, obtain the state feedback gain matrix K, and thus obtain the control input:
[0096] Step 51: Perform binary decoding on the optimal genotype to obtain the state weight matrix Q' and control weight matrix R' corresponding to the optimal genotype;
[0097] Step 52: Using Q' and R' obtained in step 51, calculate the cost function weight matrix P' of the LQR controller:
[0098] A T P′+P′A+Q′=P′BR′ -1 B TP′
[0099] Among them, a is the state transfer matrix and B is the control input matrix.
[0100] Step 53: Use the cost function weighted matrix P′ obtained in step 52 to calculate the state feedback gain matrix K, thereby obtaining the control input:
[0101] K=R′ -1 B T P′
[0102] u=-Kx
[0103] Where x is the system state vector.
[0104] The present invention first creates an initial population and encodes the population according to the problem to be solved; secondly, a suitable objective function is selected as the fitness function; then, operations such as selection, crossover and mutation are performed on the encoded chromosomes to obtain a new generation of genotypes; finally, it is determined whether the genotype is the optimal solution. If it is the optimal solution, the optimal genotype is output and decoded. If not, the next iteration is performed until the optimal solution is obtained.
[0105] Example:
[0106] In order to verify the beneficial effects of the present invention, the control model is simulated and analyzed using the Simulink simulation toolbox, a DC motor control model is built, and simulation experiments are carried out on the open-loop DC motor system model without feedback, the PID closed-loop control model, and the genetic algorithm optimized LQR closed-loop control model through the simulation toolbox. The simulation results are compared and analyzed. During the experiment, disturbances are added to the system to simulate the situation where the motor system is disturbed by external noise. By drawing a motor speed curve, the change of the motor speed is observed. Finally, the startup response of the control model is tested. The DC motor system control model is as follows: Figure 3 Show, Figure 3 Where L is armature inductance (H); R is armature resistance (Ω); i is armature current (A); E is back electromotive force (V); K m ——torque coefficient; J c ——moment of inertia; ω——angular velocity of rotation (rad); f——friction damping coefficient (N·s·m -2 ); D(t) is the external disturbance (N). Ke is the electromotive force constant of the motor, and s is the complex variable obtained by Laplace transform in solving the equation, where the real part represents the frequency and the imaginary part represents the damping.
[0107] No feedback control is added to the DC motor system to keep the system in an open-loop state. The speed change of the motor after being disturbed is tested. The initial parameter settings of the DC motor are shown in Table 1.
[0108] Table 1 DC motor parameters
[0109]
[0110] The running speed is set to ω = 1 rad / s, and the tracking speed of the DC motor gradually increases from 0 to the preset value. After the speed stabilizes, external noise interference is added to the system at time t = 5s. The disturbance amount is D = 0.1N·m. The system has no suppression effect on the disturbance, and the motor speed drops to around 0.5 rad / s. After the disturbance lasts for 5s, the disturbance disappears at time t = 10s, and the system returns to the preset speed. The DC motor open-loop control speed curve is as follows Figure 4 shown.
[0111] The DC motor system is controlled by the PID closed-loop control model. In the PID algorithm, the proportional gain K p , integral gain K i and differential gain K d The three parameters also need to be obtained through experience. It is time-consuming to adjust the three parameters by trial and error, and it cannot guarantee the optimal result. The genetic algorithm is used to optimize the PID to obtain the optimal K p , K i and K d After the parameters are set, the DC motor system is controlled by the PID control model. The PID closed-loop control DC motor speed curve is as follows: Figure 5 shown.
[0112] Depend on Figure 5 It can be seen that when the operating speed is set to ω = 1rad / s, after a period of time, the speed of the DC motor is the same as the preset speed and remains at 1rad / s. At time t = 5s, a disturbance is added with a disturbance amount of 0.1N·m. The motor speed decreases but quickly returns to the preset state. At time t = 10s, the disturbance disappears, the motor speed increases but quickly returns to the preset state. Therefore, the PID closed-loop control model can keep the motor speed stable and has certain anti-interference performance.
[0113] The DC motor system is controlled by optimizing the LQR control model through genetic algorithm. The speed curve of the DC motor under LQR closed-loop control is as follows: Figure 6 shown.
[0114] Depend on Figure 6It can be seen that when the operating speed is set to ω = 1rad / s, the genetic algorithm optimized LQR control model can make the speed of the DC motor the same as the preset speed. When a disturbance is added at time t = 5s, the disturbance amount is 0.1N·m, and the motor speed drops and then quickly returns to the preset state. When the disturbance disappears at time t = 10s, the motor speed rises and then quickly returns to the preset state. Therefore, the genetic algorithm optimized LQR control model can maintain the motor speed stable and has certain anti-interference performance.
[0115] The starting speed of the PID control model and the LQR control model were tested and analyzed. When the motor starting speed is set to ω = 1rad / s, the actual motor speed will have a certain delay and the speed will gradually increase. The PID control model reaches the preset value after a delay of 3s, while the genetic algorithm optimized LQR control model reaches the preset value before 1s. Therefore, the genetic algorithm optimized LQR control model has a faster response speed and a shorter starting time. The DC motor starting speed curve is shown as follows: Figure 7 shown.
[0116] In summary, the PID control model and the genetic algorithm optimized LQR control model can improve the stability of the DC motor system. At the same time, both models have a suppressive effect on external disturbances. Figure 5 It can be seen that the PID control model produces overshoot in the process of suppressing disturbances, causing fluctuations in the motor speed, while the genetic algorithm optimized LQR control model can quickly restore the motor speed to the preset state when the motor is disturbed, and no overshoot occurs. Figure 7 It can be seen that after analyzing the motor starting performance, it was found that the genetic algorithm optimized LQR control model takes less time to reach the preset speed and has a faster response speed than the PID control model. Therefore, the control model designed in the present invention has better stability and can meet the design requirements of the irrigation controller.
Claims
1. A LQR water pump motor control method based on improved genetic algorithm optimization, characterized in that The specific process of the method is: Step 1: Initialize the state weight matrix Q and the control weight matrix R to obtain the initial matrix population; An individual in the initial matrix population consists of a matrix Q and a matrix R; Step 2: Encode the initial matrix population and convert the individuals in the initial matrix population into chromosomes; Step 3: Perform selection, crossover, and mutation operations on the chromosomes obtained in step 2 to obtain a new generation of chromosomes, specifically: Step 3. Calculate the fitness value of each individual using the fitness function, and use the fitness value to select the chromosome to obtain the selected chromosome; The fitness function is as follows: Where F is the fitness value, t is the time, x is the system state vector, and u is the control input vector; The fitness value is used to select the chromosome to obtain the selected chromosome, specifically: First, the fitness value of the chromosome is normalized to obtain the selection probability of each individual. Then, the chromosomes are sorted from large to small according to the selection probability using the sorting method to obtain the sorted chromosome sequence. The probability of each individual being selected is as follows: P=S(1-P0) b-a Where a is the population size, P0 is the selection probability, S is the probability of the rearranged chromosome being selected, b is the position number of the individual after sorting, S is the probability of the optimal individual being selected, and P is the probability of the sorted individual being selected; Then, a preset number of chromosomes are randomly selected from the sorted chromosome sequence to obtain the selected chromosomes; Step 32: Perform a crossover operation on the selected chromosome to obtain a crossover chromosome; Step 33: Perform mutation operation on the chromosome after crossover to obtain a new generation of chromosomes; Step 4: Determine whether the current iteration termination condition is met. If the iteration termination condition is met, the new generation chromosome obtained in step 3 is output as the optimal genotype. If the iteration termination condition is not met, return to step 3 for the next iteration. Step 5: Decode the optimal genotype and use the decoded optimal genotype to obtain the control input vector to realize the water pump motor control.
2. The LQR water pump motor control method based on improved genetic algorithm optimization according to claim 1, characterized in that: The encoding of the initial matrix population in step 2 is specifically as follows: The elements in the matrix Q and the matrix R of each individual in the initial matrix population are binary-encoded to obtain the transformed chromosomes of the individuals in the initial matrix population.
3. The LQR water pump motor control method based on improved genetic algorithm optimization according to claim 2, characterized in that: The iteration termination condition is any of the following: a. The current number of iterations reaches the preset number of iterations; b. Calculate the fitness value of the new generation chromosome obtained in step 3. When the difference between the fitness values of the new generation chromosome obtained in two rounds of iteration is lower than the preset fitness value threshold, it means that the termination condition is met.
4. The LQR water pump motor control method based on improved genetic algorithm optimization according to claim 3 is characterized in that: The optimal genotype is decoded in step 5, and the control input vector is obtained using the decoded optimal genotype, specifically: Step 51: Perform binary decoding on the optimal genotype to obtain the state weight matrix Q' and control weight matrix R' corresponding to the optimal genotype; Step 52: Using Q' and R' obtained in step 51, calculate the cost function weight matrix P' of the LQR controller; Step 53: Use P′ obtained in step 52 to obtain the control input u.
5. The LQR water pump motor control method based on improved genetic algorithm optimization according to claim 4 is characterized in that: In step 52, the cost function weighted matrix P′ of the LQR controller is calculated using Q′ and R′ obtained in step 51, specifically: A T P′+P′A+Q′=P′BR′ -1 B T P′ Among them, A is the state transfer matrix and B is the control input matrix.
6. The LQR water pump motor control method based on improved genetic algorithm optimization according to claim 5, characterized in that: In step 53, the control input u is obtained by using P′ obtained in step 52, as shown in the following formula: u=-Kx Where K is the feedback gain matrix.
7. The LQR water pump motor control method based on improved genetic algorithm optimization according to claim 6, characterized in that: The feedback gain matrix K is obtained by the following formula: K=R′ -1 B T P′ Where P′ is the cost function weighting matrix of the LQR controller.