An unmanned aerial vehicle PID parameter automatic adjustment method, terminal, medium and product

By employing an intelligent sampling optimization strategy that combines simulation and actual flight testing, the Metropolis-Hastings algorithm is used to automatically adjust the PID parameters of the UAV, solving the problem of traditional adjustment relying on human experience. This achieves efficient and accurate PID parameter tuning, thereby improving the flight control performance of the UAV.

CN122194608APending Publication Date: 2026-06-12CHANGSHA MYSTICAL BOW INFORMATION SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610167069.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-05
Publication Date
2026-06-12

Smart Images

  • Figure CN122194608A_ABST
    Figure CN122194608A_ABST
Patent Text Reader

Abstract

The application discloses a kind of unmanned aerial vehicle PID parameter automatic adjustment method, belong to unmanned aerial vehicle technical field.The method includes: in simulation environment, unmanned aerial vehicle model and PID controller model are constructed, PID parameter sample set is obtained based on MetropolisHastings algorithm sampling, optimal parameter A is selected;Based on A, adjacent and relatively optimal sample is selected, and its covariance matrix H is calculated;In actual flight, A is used as initial parameter, based on H, continue sampling optimization, finally select the parameter of best performance as final PID parameter.The application realizes PID parameter automatic setting by two-stage optimization of simulation and actual flight, improves the efficiency of parameter adjustment and flight control precision, avoids local optimum, and has higher practicality and reliability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of unmanned aerial vehicle (UAV) technology, and in particular to a method, terminal, medium, and product for automatically adjusting PID parameters of UAVs. Background Technology

[0002] Multi-rotor drones, with their advantages of low cost, ease of operation, high maneuverability, and unmanned operation, have been widely used in aerial photography, agricultural plant protection, power and energy inspection, and topographic mapping. In drones using PID controllers, the settings of the proportional, integral, and derivative parameters directly determine the dynamic response quality of the drone system and are key parameters affecting the stability and handling performance of the drone.

[0003] The attitude control system of multi-rotor UAVs is a typical nonlinear, multivariable coupled system. The adjustment of its PID controller parameters is often done through empirical methods. The quality of parameter selection is limited by the experience of engineers, resulting in a large workload for PID parameter tuning and difficulty in parameter adjustment. Summary of the Invention

[0004] To address the above problems, this invention provides an automatic PID parameter adjustment method for unmanned aerial vehicles (UAVs). It aims to solve the problems of traditional UAV PID parameter adjustment relying on manual experience, low efficiency, and difficulty in obtaining the global optimal solution. Through an intelligent sampling optimization strategy that combines simulation and actual flight, the method achieves automated, efficient, and accurate tuning of PID parameters.

[0005] In a first aspect, the present invention provides a method for automatically adjusting the PID parameters of a UAV, comprising:

[0006] Construct a nonlinear dynamics model and a PID controller model for a UAV in a simulation environment; Set the flight path, PID parameter range and flight performance evaluation index, and sample based on the Metropolis-Hastings algorithm to obtain the PID parameter sample set under the simulation environment; Select the PID parameter A with the best flight performance from the sample set; Based on parameter A, neighboring samples are selected, and from the neighboring samples, a sample set with the highest flight performance by a first preset percentage is selected, and its covariance matrix H is calculated. In actual flight environments, with parameter A as the initial PID parameter, the Metropolis-Hastings algorithm is used for sampling optimization based on the covariance matrix. Record the flight performance corresponding to each sampling parameter, and select the PID parameter with the best performance as the final PID parameter used by the UAV.

[0007] Furthermore, the specific process for selecting neighboring samples is as follows: Calculate the Euclidean distance between all sampling points and parameter A; Based on the Euclidean distance, the sampling points are sorted from smallest to largest, and the top second-preset percentage of sampling points are selected as neighboring sampling points.

[0008] By calculating the Euclidean distance between all sampling points and the optimal parameter A, and then sorting and selecting neighboring sampling points accordingly, samples that are geometrically close to the optimal parameter in the parameter space can be effectively screened, thereby improving the representativeness and effectiveness of the neighboring sample set. This sorting mechanism ensures that the subsequent calculation of the covariance matrix is ​​based on real neighborhood data of the optimal parameter, enhancing the reliability and convergence efficiency of the algorithm's sampling direction in real-world environments.

[0009] Furthermore, the flight performance evaluation index is the cumulative value of the absolute value of the tracking error.

[0010] Defining the flight performance evaluation index as the cumulative absolute value of tracking error provides an objective and quantifiable evaluation standard. This index directly reflects the accuracy and stability of UAV flight trajectory tracking, accurately distinguishes the impact of different PID parameters on flight control performance, thus providing a clear objective function for parameter optimization and enhancing the scientific rigor and reliability of parameter selection.

[0011] Furthermore, repeat the following process to obtain the optimal PID parameters: Obtain the actual flight performance E corresponding to the new sampling parameter B. B Actual flight performance E corresponding to current parameter A A ; Calculate the acceptance probability c = min(1, exp(-E)). B ) / exp(-E A )); Generate a random number d that is uniformly distributed in the interval [0,1]. If d≤c, then update parameter A to parameter B; otherwise, keep the current parameter A unchanged. Sampling ends when the maximum number of samples is reached.

[0012] The specific steps for parameter updating in the algorithm are clarified, including the calculation of acceptance probability and the random acceptance mechanism. This ensures that the sampling process follows the steady-state distribution of a Markov chain, thus theoretically guaranteeing that the algorithm can escape local optima with a certain probability and gradually converge to the global optimum. This process enhances the robustness and adaptability of the algorithm in real flight environments, avoiding parameter oscillations or non-convergence problems caused by random errors or noise.

[0013] Furthermore, using the current parameter A as the mean and β²H as the covariance, a multivariate normal distribution is constructed, where β is an adjustable scaling factor, and a new parameter B is obtained by sampling from the multivariate normal distribution.

[0014] By constructing a multivariate normal distribution with the current parameters as the mean and the covariance matrix adjusted by the scaling factor for sampling new parameters, adaptive adjustment of the sampling step size is achieved. The introduction of the scaling factor β allows for dynamic adjustment of the exploration range based on the actual convergence situation, maintaining a large exploration capability in the early stages while fine-tuning the parameters when approaching the optimum, thus improving optimization efficiency and stability.

[0015] Furthermore, the nonlinear dynamics model and PID controller model of the UAV were built using the Matlab / Simulink platform.

[0016] The guidelines specify the use of the Matlab / Simulink platform to build the UAV nonlinear dynamics model and PID controller model, making full use of the platform's mature toolchain and rich library functions in control system modeling, simulation and algorithm verification, which significantly reduces the development difficulty and cycle.

[0017] Secondly, the present invention also provides a computer terminal, comprising: Memory, which stores executable programs; A processor is used to run the program, wherein the program executes the method for automatically adjusting PID parameters of a UAV during runtime.

[0018] Thirdly, the present invention also provides a computer-readable storage medium comprising a stored executable program, wherein, when the executable program is executed, it controls the device where the computer-readable storage medium is located to execute the aforementioned method for automatically adjusting PID parameters of a UAV.

[0019] Fourthly, the present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the aforementioned method for automatically adjusting PID parameters of a UAV.

[0020] Compared with existing technologies, the beneficial effects of this invention are as follows: By adopting a two-stage strategy combining simulation and actual flight, and using the Metropolis-Hastings algorithm for intelligent sampling and optimization, the entire process of PID parameter adjustment is automated, significantly improving the efficiency of parameter tuning and reducing labor costs; the simulation stage obtains better initial parameters, ensuring the safety and reliability of actual flight parameter tuning; by extracting and transmitting the covariance information of the excellent parameter region in the simulation, the actual flight sampling is guided to conduct directional and targeted intelligent exploration, effectively avoiding getting trapped in local optima, thereby approaching the global optimal solution, and significantly improving the trajectory tracking accuracy and stability of flight control. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of this drawing or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this drawing. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.

[0022] Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a schematic diagram of the surface formed in the simulation environment as a function of PID parameters and trajectory tracking error. Figure 3 A schematic diagram of the surface formed by the function of PID parameters and trajectory tracking error in a real flight environment; Figure 4 This is a distribution diagram of the initial sampling results in the simulation environment; Figure 5 This is a distribution map of sample points in sample set K; Figure 6 This is a distribution map of sample points in sample set M; Figure 7 This is a distribution map of sampling results in a real flight environment. Detailed Implementation

[0023] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. All other embodiments obtained by those skilled in the art based on the embodiments provided by this invention without inventive effort are within the scope of protection of this invention.

[0024] This invention provides a method for automatically adjusting the PID parameters of a drone, such as... Figure 1 As shown, it specifically includes: A nonlinear dynamics model and a PID controller model for an unmanned aerial vehicle (UAV) were built using the Matlab / Simulink programming and simulation platform.

[0025] In the simulation environment, set the flight conditions, flight path, PID parameter value range, maximum number of samplings, and flight performance evaluation indicators (such as the cumulative value of the absolute value of tracking error).

[0026] In a simulation environment, Metropolis-Hastings is used to sample the PID parameters of the UAV PID controller, evaluate the flight performance of the UAV when flying along the route under different sampling parameters, and save the corresponding PID parameters. Sampling stops when the maximum number of samplings is reached.

[0027] In the above sampling, the PID parameter A with the best flight performance is selected, and the Euclidean distance between each sampling point and sampling point A is calculated. All samples are sorted according to the Euclidean distance from smallest to largest, and the sample set K with the second-to-last preset percentage is selected.

[0028] Based on the flight performance corresponding to the samples in the selected sample set K, select the sample set M of the first preset percentage data, and calculate the covariance matrix H of the samples in the sample set M.

[0029] Implement the Metropolis-Hastings algorithm in the UAV flight control code, set the actual flight conditions and flight path, and use the PID parameter A with the best flight performance obtained in the above simulation environment as the initial PID parameter for the actual flight of the UAV to execute a flight path.

[0030] In a real-world environment, the Metropolis-Hastings algorithm is used to sample the PID parameters of the UAV's PID controller, recording the UAV's flight performance under different sampling parameters. Sampling stops when the maximum number of samplings is reached, and the PID parameters with the best flight performance during the sampling process are used as the final PID parameters for the UAV.

[0031] Specifically, using parameter A as the initial sampling mean and β²H as the covariance, a multivariate normal distribution is constructed, i.e.: ; Where β is an adjustable scaling factor; i Number of samples; X 0 represents the initial sampling parameter. X i≠0 For subsequent sampling parameters; X current The sampled values ​​received in the previous iteration; With A as the mean, It is a multivariate normal distribution of covariance.

[0032] To obtain a new parameter B by sampling from a multivariate normal distribution, repeat the following process to obtain the optimal PID parameters: Obtain the actual flight performance E corresponding to the new sampling parameter B. B Actual flight performance E corresponding to current parameter A A ; Calculate the acceptance probability c = min(1, exp(-E)). B ) / exp(-E A )); Generate a random number d that is uniformly distributed in the interval [0,1]. If d≤c, then update parameter A to parameter B; otherwise, keep the current parameter A unchanged. Sampling ends when the maximum number of samples is reached.

[0033] The implementation process of the algorithm of this invention will be illustrated below through a specific example. This example uses the adjustment of the proportional parameter (kp) and derivative parameter (kd) of the roll axis angular velocity loop of the UAV attitude controller as an example to demonstrate how to optimize the PID parameters using the method of this invention and obtain better flight trajectory tracking performance.

[0034] In the simulation environment, the following functional relationship is established between kp, kd, and the trajectory tracking error (TrackErrors): z1 = -20exp(-((kp-2) 2 +(kd-2) 2 )); z2 = -17exp(-((kp-4) 2 +(kd-4) 2 )); z3 = -18exp(-((kp-4) 2 +(kd-2) 2 )); z4 = -12exp(-((kp-2) 2 +(kd-4) 2 )); TrackErrors = z1 + z2 + z3 + z4 + 30; Where z1 is a two-dimensional Gaussian function with a peak center at (2, 2) and a peak height of -20; z2 is a two-dimensional Gaussian function with a peak center at (4, 4) and a peak height of -17; z3 is a two-dimensional Gaussian function with a peak center at (4, 2) and a peak height of -18; z4 is a two-dimensional Gaussian function with a peak center at (2, 4) and a peak height of -12.

[0035] The surface diagram generated by this function in the simulation environment is shown below. Figure 2 As shown.

[0036] In a real flight environment, to simulate the impact of actual noise, Gaussian noise with a mean of 0 and a variance of 1 is added to the above function, as shown in the schematic diagram below. Figure 3 As shown.

[0037] Based on the simulation environment and real flight environment model described above, the implementation process of the algorithm is explained: (1) In the simulation environment, the initial values ​​of kp and kd are both set to 3, the sampling range of kp and kd parameters is set to [0, 6] and [0, 6] respectively, and the sampling covariance matrix is ​​set to Using the Metropolis-Hastings algorithm, 1000 points were sampled, and the distribution of the sampling results is as follows: Figure 4 As shown.

[0038] (2) The minimum tracking error is 9.41, and the corresponding optimal parameters A are: kp=2.054, kd=2.033; calculate the Euclidean distance between all sample points and A, and select the nearest 30% of the samples to form the nearest neighbor sample set K, the distribution of which is as follows. Figure 5 As shown.

[0039] (3) Select the top 50% of the samples with the highest tracking errors from the sample set K to form the sample set M, and calculate the covariance matrix of M: The distribution of sample set M is as follows Figure 6 As shown.

[0040] (4) Set the simulation optimal parameters A (kp=2.054, kd=2.033) as the initial PID parameters for actual flight; perform one flight along the flight path and measure the tracking error E. A =10.1212.

[0041] (5) Set the maximum number of samplings for the real flight environment model to 30 times and the scaling factor β=1; construct a multivariate normal distribution with A as the mean and β²H as the covariance, and obtain new parameters B by sampling: kp=1.999, kd=2.123.

[0042] (6) Perform flight using parameter B and measure the tracking error E. B =8.4024; Calculate the acceptance probability: c = min(1, exp(-8.4024) / exp(-10.1212)) = 1; Generate random numbers d=0.7164 from a uniform distribution U(0,1); Since d≤c, parameter B is accepted, that is, the parameters kp and kd are updated to 1.999 and 2.123 respectively; Repeat the above sampling and acceptance process until the maximum number of samples is reached. After sampling, the distribution of the actual flight environment sampling results is as follows: Figure 7 As shown.

[0043] (7) After sampling, the minimum tracking error was 7.7682, and the corresponding optimal PID parameters were: kp=2.1478, kd=2.1478.

[0044] It should be noted that the present invention is not limited to the above-described embodiments. The above embodiments are merely examples, and any embodiments that have the same structure and perform the same effects as the technical concept within the scope of the present invention are included within the scope of the present invention. Furthermore, various modifications that can be conceived by those skilled in the art to the embodiments, and other ways of constructing by combining some of the constituent elements of the embodiments, without departing from the spirit of the present invention, are also included within the scope of the present invention.

Claims

1. A method for automatically adjusting PID parameters of an unmanned aerial vehicle (UAV), characterized in that, include: Construct a nonlinear dynamics model and a PID controller model for a UAV in a simulation environment; Set the flight path, PID parameter range and flight performance evaluation index, and sample based on the Metropolis-Hastings algorithm to obtain the PID parameter sample set under the simulation environment; Select the PID parameter A with the best flight performance from the sample set; Based on parameter A, neighboring samples are selected, and from the neighboring samples, a sample set with the highest flight performance by a first preset percentage is selected, and its covariance matrix H is calculated. In actual flight environments, with parameter A as the initial PID parameter, the Metropolis-Hastings algorithm is used for sampling optimization based on the covariance matrix. Record the flight performance corresponding to each sampling parameter, and select the PID parameter with the best performance as the final PID parameter used by the UAV.

2. The method for automatically adjusting PID parameters of a UAV as described in claim 1, characterized in that, The specific process for selecting neighboring samples is as follows: Calculate the Euclidean distance between all sampling points and parameter A; Based on the Euclidean distance, the sampling points are sorted from smallest to largest, and the top second-preset percentage of sampling points are selected as neighboring sampling points.

3. The method for automatically adjusting PID parameters of a UAV as described in claim 1, characterized in that, The flight performance evaluation index is the cumulative value of the absolute value of the tracking error.

4. The method for automatically adjusting PID parameters of a UAV as described in claim 1, characterized in that, Repeat the following process to obtain the optimal PID parameters: Obtain the actual flight performance E corresponding to the new sampling parameter B. B Actual flight performance E corresponding to current parameter A A ; Calculate the acceptance probability c = min(1, exp(-E)). B ) / exp(-E A )); Generate a random number d that is uniformly distributed in the interval [0,1]. If d ≤ c, then update parameter A to parameter B; otherwise, keep the current parameter A unchanged. Sampling ends when the maximum number of samples is reached.

5. The method for automatically adjusting PID parameters of a UAV as described in claim 4, characterized in that, Using the current parameter A as the mean and β²H as the covariance, construct a multivariate normal distribution, where β is an adjustable scaling factor, and sample the new parameter B from the multivariate normal distribution.

6. The method for automatically adjusting PID parameters of a UAV as described in claim 1, characterized in that, The nonlinear dynamics model and PID controller model of the UAV were built using the Matlab / Simulink platform.

7. A computer terminal, characterized in that, include: Memory, which stores executable programs; A processor for running the program, wherein the program, when running, performs the method according to any one of claims 1 to 6.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored executable program, wherein, when the executable program is executed, it controls the device on which the computer-readable storage medium is located to perform the method according to any one of claims 1 to 6.

9. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 6.