An Optimization Method for PID Parameters by Particle Swarm Optimization Algorithm
By dynamically adjusting the inertia factor and combining the sine and cosine adjustment formulas, the problem of poor global optimization ability and local optimal traps in PID parameter optimization is solved, and more efficient PID parameter optimization and control effects are achieved.
Patent Information
- Application Number
- CN202210836852.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-15
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2042-07-15
AI Technical Summary
In the PID parameter optimization algorithm, the existing particle swarm optimization algorithm has poor global optimization capabilities in the early stage and is prone to fall into local optimization in the later stage, and cannot effectively optimize the nonlinear and large-hysteresis control system.
By adjusting the inertia factor, the nonlinear decreasing and incremental formula based on sine and cosine adjustments are used to dynamically adjust the global and local optimization capabilities of the particle swarm to avoid local optimal traps.
The convergence speed and optimization performance of the particle swarm optimization algorithm are improved, ensuring that the output PID parameters are the global optimal solution, and improving the response rate, control accuracy, stability and security of the control system.
Smart Images

Figure CN115236969B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of automatic control technology, and particularly relates to a method for optimizing PID parameters by a particle swarm algorithm. Background Art
[0002] PID control is the earliest classical control technology and is one of the most widely used technologies in industrial process control. PID control has been widely applied in industrial control processes such as chemical industry, electric power, and machinery due to its advantages of simple structure, mature technology, good robustness, and easy optimization in practical applications. Although people have accumulated a large amount of experience in optimizing PID parameters, for some non-linear and large-lag control systems, the controller parameters cannot be optimized to the best state, the control system cannot achieve good control effects, and the safety and stability of the industrial production process are affected.
[0003] Therefore, in order to improve the performance of the PID controller, intelligent algorithms are widely applied to the optimization of PID parameters. The intelligent algorithms include genetic algorithms, particle swarm algorithms, population search algorithms, simulated annealing algorithms, etc. Among them, the particle swarm optimization algorithm (PSO) is an optimization algorithm based on swarm intelligence, which searches for the optimal solution of the optimization problem through the mutual cooperation, information sharing, and mutual competition mechanisms among particles. It has been widely applied in practical problems due to its easy implementation and fast convergence.
[0004] However, the existing technology is not perfect. During the convergence process of the particle swarm optimization algorithm, the activity range of the particle swarm is large and chaotic in the initial stage, which leads to the problem of poor global optimization ability in the initial stage. And all particles tend to be the same in the later stage, and the algorithm cannot continue to optimize when it converges to a certain accuracy, and it is easy to fall into the local optimum. Summary of the Invention
[0005] To overcome the deficiencies and problems of the existing technology, the present invention provides a method for optimizing PID parameters by a particle swarm algorithm.
[0006] To achieve the above object, the present invention adopts the following technical solutions:
[0007] A method for optimizing PID parameters by a particle swarm algorithm, wherein the PID controller uses the particle swarm optimization algorithm to optimize the PID parameters, specifically including the following steps:
[0008] S1: Initialize the particle swarm;
[0009] S2: Assign the PID parameters to the positions of the particles;
[0010] S3: Calculate the fitness value of the particles by using the following fitness function:
[0011]
[0012] Wherein, F is the fitness value of the particle, e(t) is the error between the PID parameters output by the PID controller and the state data detected by the sensor, u(t) is the control value, w1 is the first inertia factor, w2 is the second inertia factor, w3 is the third inertia factor, and w1 ∈ [0, 1], w2 ∈ [0, 1], w3 >> w1.
[0013] Find the individual optimal position of the particle and the global optimal position of the particle swarm according to the fitness value of the particle.
[0014] S4: Update the position and velocity of the particle using the following formula:
[0015]
[0016] Wherein, v[n] is the particle velocity at the current moment, V[n + 1] is the particle velocity at the next moment, X[n] is the particle position at the current moment, X[n + 1] is the particle position at the next moment, w is the inertia factor, c1 is the self-cognition factor, c2 is the social-cognition factor, rand is a custom number between 0 and 1, Pbest[n] is the individual optimal position of the particle, and gbest[n] is the global optimal position of the particle swarm.
[0017] S5: Determine whether the iteration times of S4 are less than one-third of the maximum iteration times. If so, update the inertia factor using the following formula:
[0018]
[0019] Wherein, w max is the maximum value of the inertia factor, w min is the minimum value of the inertia factor, t is the iteration times of S4, T max is the maximum iteration times, and update the global optimal position of the particle using the following formula:
[0020] gbest[n] = gbest[n] + c2 × rand × (gbest[n] - gbest[n + 1]) | (3),
[0021] Wherein, gbest[n + 1] is the global optimal position of the particle at the next moment. Update the obtained inertia factor and the global optimal position update formula (1) of the particle, and then continue to iterate the steps of S4. If not, perform the steps of S6.
[0022] S6: Determine whether the number of iterations in S4 is not less than one-third of the maximum number of iterations and less than two-thirds of the maximum number of iterations. If so, update the inertia factor using formula (2), update formula (1) with the updated inertia factor, and then continue to iterate the steps of S4. If not, proceed to the steps of S7;
[0023] S7: Determine whether the number of iterations in S4 is not less than two-thirds of the maximum number of iterations and less than the maximum number of iterations. If so, update the inertia factor using formula (2), update formula (1) with the updated inertia factor, and then continue to iterate the steps of S4. If not, output the position of the particle as the optimized PID parameters.
[0024] Preferably, in the steps of S1, it specifically includes:
[0025] Initialize the scale, dimension, maximum number of iterations, self-cognition factor, social-cognition factor, and particle velocity of the particle swarm.
[0026] Preferably, the maximum value of the inertia factor is 0.9.
[0027] Preferably, the minimum value of the inertia factor is 0.4.
[0028] The prominent and beneficial technical effects of the present invention compared with the prior art are:
[0029] (1) In the present invention, formula (2) adjusts the inertia factor according to the number of iterations in S4. When the particle swarm is in the initial stage of iteration, a non-linear decreasing formula based on sine adjustment is used to adjust the inertia factor, and the change rate of the inertia factor gradually becomes smaller. When the particle swarm is in the middle stage of iteration, a non-linear decreasing formula based on cosine adjustment is used to adjust the inertia factor, and the change rate of the inertia factor changes from large to small and then becomes larger. When the particle swarm is in the later stage of iteration, a non-linear increasing formula based on sine adjustment is used to adjust the inertia factor, and the change rate of the inertia factor gradually becomes smaller. Thus, throughout the iterative process, the particle swarm optimization algorithm can balance the local optimization ability and the global optimization ability, and also avoid the problem of local optimal solutions occurring in the later stage of iteration, which is beneficial to the final output of the PID parameters being the global optimal solution. Therefore, the optimization method of the PID parameters by this particle swarm algorithm has the advantages of fast convergence speed, good optimization performance, high efficiency, and good control effect.
[0030] (2) Apply the optimization method of the PID parameters by this particle swarm algorithm to the PID control system. The sensor collects the state parameters of the PID control system. The PID control generates the PID parameters according to the state parameters, and then optimizes the PID parameters according to the optimization method of the PID parameters by the particle swarm algorithm. The optimized PID parameters are used to control the actuator. The entire control process has the advantages of simple process, mature technology, and good robustness. The optimized PID parameters meet the actual required control effect, and also improve the response rate, control accuracy, stability, and safety of the PID control system.
[0031] (3) During the process of optimizing the PID parameters by the particle swarm optimization algorithm, it takes into account the global optimum value of the previous moment and the global optimum value of the next moment, and uses the method of mean calculation, which can better find the global optimum value in time series. Therefore, it further improves the optimization performance of the particle swarm optimization algorithm for the PID parameters.
[0032] (4) During actual testing, applying the optimization method of the PID parameters by this particle swarm algorithm to the attitude control of the unmanned aerial vehicle can avoid the problem of unstable flight of the unmanned aerial vehicle caused by problems such as roll angle, pitch angle, and heading angle deviation at the moment of takeoff. It can not only quickly respond to the attitude control of the unmanned aerial vehicle, but also avoid cumbersome simulation adjustment, ensuring the attitude stability of the unmanned aerial vehicle during operation. Brief Description of the Drawings
[0033] Figure 1 is the schematic structural diagram of the step flow of the present invention; Detailed Embodiments
[0034] For the convenience of understanding by those skilled in the art, the present invention will be further described below with reference to the drawings and specific embodiments.
[0035] The PID control system includes a PID controller, an actuator, and a sensor. The PID controller is communicatively connected to the actuator, and the sensor is communicatively connected to the PID controller, so that the PID control system forms a closed-loop feedback in terms of hardware. During the actual control process, the sensor detects the state data of the PID control system. The state data of the PID control system can include motion parameters, temperature parameters, humidity parameters, etc. The PID controller filters, denoises, and calculates the deviation value from the state data, and then calculates the PID parameters according to the deviation value, and controls the actuator to work according to the PID parameters.
[0036] In the prior art, in order to improve the control effects such as the response efficiency and accuracy of the PID control system, the PID controller uses the particle swarm optimization algorithm (PSO) to optimize the PID parameters. The existing particle swarm optimization algorithm applied to the PID controller has been widely used due to its fast convergence speed, few parameter settings, simplicity and ease of implementation. However, the prior art is not perfect enough. When the particle swarm optimization algorithm continuously iterates for PID control, it is easy to fall into a local optimal solution, thereby reducing the accuracy of the output result. Fundamentally speaking, the local optimization ability and the global optimization ability do not change with the number of iterations.
[0037] To solve the above technical problems, as shown in the figure, this embodiment provides a method for optimizing PID parameters by using the particle swarm algorithm. The PID controller uses the particle swarm optimization algorithm to optimize the PID parameters, which specifically includes the following steps:
[0038] S1: Initialize the particle swarm;
[0039] In the step of S1 above, it specifically includes: initializing the scale, dimension, maximum number of iterations, self-cognition factor, social cognition factor, particle velocity and the range of search positions of the particle swarm.
[0040] S2: Assign the PID parameters to the positions of the particle swarm;
[0041] In the step of S2 above, assigning the PID parameters to the positions of the particle swarm enables the particle swarm to adapt to the principles and laws of PID control. The PID parameters include the proportional Kp, integral Ki and derivative Kd. Assign the three parameters of proportional Kp, integral Ki and derivative Kd to the position of the particle, and the position of this particle is the starting position of the particle.
[0042] S3: Calculate the fitness value of the particle by using the following fitness function:
[0043]
[0044] In the formula, F is the fitness value of the particle, e(t) is the error between the PID parameters output by the PID controller and the state data detected by the sensor, u(t) is the control value, w1 is the first inertia factor, w2 is the second inertia factor, w3 is the third inertia factor, and w1 ∈ [0, 1], w2 ∈ [0, 1], w3 >> w1.
[0045] Find the individual optimal position of the particle and the global optimal position of the particle swarm according to the fitness value of the particle;
[0046] S4: Update the position and velocity of the particle by using the following formula:
[0047]
[0048] In the formula, v[n] is the particle velocity at the current moment, V[n + 1] is the particle velocity at the next moment, X[n] is the particle position at the current moment, X[n + 1] is the particle position at the next moment, w is the inertia factor, c1 is the self-cognition factor, c2 is the social-cognition factor, rand is a custom number between 0 and 1, Pbest[n] is the individual optimal position of the particle, and gbest[n] is the global optimal position of the particle group;
[0049] In the steps of S4 above, formula (1) is the iterative formula. By using formula (1) to iteratively update the position and velocity of the particle, the position and velocity of the particle can gradually approach the optimal value. The role of the inertia factor is to control the global optimization ability and local optimization ability of the particle swarm. When the inertia factor becomes larger, the global optimization ability becomes stronger, but the local optimization ability becomes weaker. When the inertia factor becomes smaller, the global optimization ability becomes weaker, but the local optimization ability becomes stronger. Therefore, the inertia factor plays a crucial role in the optimization ability of the particle swarm optimization algorithm.
[0050] S5: Determine whether the number of iterations of S4 is less than one-third of the maximum number of iterations. If so, update the inertia factor using the following formula:
[0051]
[0052] In the formula, w max is the maximum value of the inertia factor, w min is the minimum value of the inertia factor, t is the number of iterations of S4, T max is the maximum number of iterations, and update the global optimal position of the particle using the following formula:
[0053] gbest[n] = gbest[n] + c2 × rand × |gbest[n] - gbest[n + 1]| (3),
[0054] In the formula, gbest[n + 1] is the global optimal position of the particle at the next moment. Update the inertia factor and the global optimal position update formula (1) of the particle, and then continue to iterate the steps of S4. If not, perform the steps of S6;
[0055] In the steps of S5 above, when the number of iterations of S4 is less than one-third of the maximum number of iterations, the particle swarm is in the initial stage. The particle swarm in the initial stage shows the characteristics of a large and disordered movement range. At this time, the particle swarm optimization algorithm needs to have better global optimization ability, and it weakens as the number of iterations of S4 increases. Update the inertia factor using the following formula in formula (2):
[0056]
[0057] The above formula belongs to a non-linear decreasing formula based on sine adjustment. As the number of iterations of S4 increases, the inertia factor gradually becomes smaller. During the initial iteration process, the updated inertia factor continuously updates formula (1), thereby improving the accuracy of iterative convergence. However, as the number of iterations of S4 increases, the particle swarm optimization algorithm is prone to falling into the problem of local optimal solutions.
[0058] S6: Determine whether the number of iterations of S4 is not less than one-third of the maximum number of iterations and less than two-thirds of the maximum number of iterations. If so, update the inertia factor using formula (2), update formula (1) with the updated inertia factor, and then continue to iterate the steps of S4. If not, proceed to the steps of S7;
[0059] In the above steps of S6, when the number of iterations of S4 is not less than one-third of the maximum number of iterations and less than two-thirds of the maximum number of iterations, the particle swarm is in the middle stage. In the middle stage, the particle swarm has the problem of local convergence to the optimal solution but it is not very serious. To balance the local search ability and the global search ability of the particle swarm optimization algorithm, the following formula in formula (2) is used to update the inertia factor:
[0060]
[0061] The above formula belongs to a non-linear decreasing formula based on cosine adjustment. As the number of iterations of S4 increases, the inertia factor gradually becomes smaller, and the change rate of the inertia factor changes from large to small and then to large. During the middle iteration process, the updated inertia factor continuously updates formula (1), so that the particle swarm optimization algorithm can balance the local search ability and the global search ability during the middle iteration.
[0062] S7: Determine whether the number of iterations of S4 is not less than two-thirds of the maximum number of iterations and less than the maximum number of iterations. If so, update the inertia factor using formula (2), update formula (1) with the updated inertia factor, and then continue to iterate the steps of S4. If not, output the position of the particle as the optimized PID parameter.
[0063] In the above steps of S7, when the number of iterations of S4 is not less than two-thirds of the maximum number of iterations and less than the maximum number of iterations, the particle swarm is in the late stage. In the late stage, the local convergence problem of the particle swarm is very serious. Therefore, the following formula in formula (2) is used to update the inertia factor:
[0064]
[0065] The above formula belongs to a non-linear increasing formula with sine adjustment. As the number of iterations of S4 increases, the inertia factor gradually becomes larger, and the change rate of the inertia factor gradually becomes smaller. During the later iteration process, the updated inertia factor continuously updates formula (1), so that the particle swarm optimization algorithm can have a strong global optimization ability in the later iteration stage and avoid the problem of falling into local optimal solutions.
[0066] The maximum value of the inertia factor is 0.9, that is, w max = 0.9.
[0067] The minimum value of the inertia factor is 0.4, that is, w min = 0.4.
[0068] In order to verify the beneficial effects of the present invention, a test experiment was set up based on the present invention. The process of the test experiment is introduced in detail below:
[0069] The test experiment uses a DJI quadcopter drone, model Mavic3. Four high-precision MPU9250 gyroscopes are installed on the drone. The four MPU9250 gyroscopes are used to monitor the attitude of the drone. The size of the particle swarm is set to 50, the dimension is 20, the maximum number of iterations is 1000, the self-cognition factor is taken as 2, the social cognition factor is taken as 2, the maximum speed of the particle is taken as 200, and the maximum search algebra is 100. The test program runs in the MATLAB7.8 environment. An Intl i5 CPU computer with 128G of RAM and an operating system of Windows 10 Professional Edition are used, and the development environment is VS Code. During the actual test process, the flight success rate of the quadcopter drone is 100%, the deviation of the output optimal value is controlled within 14.93, and the structural singular value of the robust stability is controlled below 0.2. Compared with the prior art, the present invention shows better optimization performance in PID control, can avoid the problem of unstable flight of the drone caused by problems such as roll angle, pitch angle, and heading angle deviation at the moment of takeoff, can not only quickly respond to the attitude control of the drone, but also avoid cumbersome simulation adjustment, and ensure the attitude stability of the drone during operation.
[0070] The above embodiments are only preferred embodiments of the present invention, and do not limit the protection scope of the present invention accordingly. Therefore, all equivalent changes made according to the structure, shape, and principle of the present invention should be covered within the protection scope of the present invention.
Claims
1. An optimization method for PID parameters using a particle swarm algorithm, characterized in that, The PID controller uses the particle swarm optimization algorithm to optimize the PID parameters, which specifically includes the following steps: S1: Initialize the particle swarm; S2: Assign the PID parameters to the position of the particle; S3: Calculate the fitness value of the particle using the following fitness function: In the formula, F is the fitness value of the particle, e(t) is the error between the PID parameters output by the PID controller and the state data detected by the sensor, u(t) is the control value, w1 is the first inertia factor, w2 is the second inertia factor, w3 is the third inertia factor, and w1 ∈ [0, 1], w2 ∈ [0, 1], w3 >> w1. Find the individual optimal position of the particle and the global optimal position of the particle swarm according to the fitness value of the particle; S4: Update the position and velocity of the particle using the following formula: In the formula, v[n] is the particle velocity at the current moment, V[n + 1] is the particle velocity at the next moment, X[n] is the particle position at the current moment, X[n + 1] is the particle position at the next moment, w is the inertia factor, c1 is the self-cognition factor, c2 is the social cognition factor, rand is a custom number between 0 and 1, Pbest[n] is the individual optimal position of the particle, and gbest[n] is the global optimal position of the particle swarm; S5: Determine whether the number of iterations in S4 is less than one-third of the maximum number of iterations. If so, update the inertia factor using the following formula: where w max is the maximum value of the inertia factor, w min is the minimum value of the inertia factor, t is the iteration number of S4, T max is the maximum iteration number, and the global best position of the particles is updated using the following formula: gbest[n] = gbest[n] + c2 × rand × |gbest[n] - gbest[n + 1]| (3), In the formula, gbest[n + 1] is the global optimal position of the particle at the next moment. Update the updated inertia factor and the global optimal position formula of the particle swarm (1) and continue to iterate the steps of S4. If not, perform the steps of S6; S6: Determine whether the number of iterations in S4 is not less than one-third of the maximum number of iterations and less than two-thirds of the maximum number of iterations. If so, update the inertia factor using formula (2), update the updated inertia factor to formula (1) and continue to iterate the steps of S4. If not, perform the steps of S7; S7: Determine whether the number of iterations in S4 is not less than two-thirds of the maximum number of iterations and less than the maximum number of iterations. If so, update the inertia factor using formula (2), update the updated inertia factor to formula (1) and continue to iterate the steps of S4. If not, output the position of the particle as the optimized PID parameter.
2. The optimization method of PID parameters by a particle swarm algorithm according to claim 1, characterized in that In the steps of S1, it specifically includes: Initialize the scale, dimension, maximum number of iterations, self-cognition factor, social cognition factor, and particle velocity of the particle swarm.
3. The optimization method of PID parameters by using the particle swarm algorithm according to claim 1, characterized in that, The maximum value of the inertia factor is 0.
9.
4. The optimization method of PID parameters by a particle swarm algorithm according to claim 1, characterized in that The minimum value of the inertia factor is 0.4.
Citation Information
Patent Citations
Intelligent control system optimization algorithm based on transformation function and filled function
CN106406087A
PID parameter tuning method for particle swarm optimization based on inertia weight cosine adjustment
CN109696827A