Justification of optimal parameters for quadcopter PID-controllers with frame sizes up to 150 mm

. Unmanned aerial vehicles with a frame of up to 150 mm are used in agriculture to solve problems in smart greenhouses. Calculating the values of PID-regulators when optimizing the drone operation allows to reduce the risks of flight controller misadjustment and increase the accuracy of its control in different flight conditions. The aim of the study is to calculate the optimal values` of the PID controllers of the UAV, develop an algorithm for coefficient calculation, and compute the proportional, integrating, and differentiating errors along the deviation axes. The authors have developed a quadcopter with a take-off weight of up to 150 g for monitoring an industrial greenhouse. The mathematical theory of optimal control and stabilization was applied. A research analysis on the optimization of quadcopter flight was carried out. Experimental research in mechanics on adjusting the stability and acceleration of the quadcopter prototype during flight was carried out. Based on the mathematical formula for calculating the control signal, an algorithm was developed to calculate the coefficients and to compute the proportional, integrating, and differentiating errors in the axes of control deviation of the quadcopter’s brushless motors. Optimized settings of the PID-regulator stabilization system in Betaflight Configurator program for stable flight of the quadcopter prototype are selected, taking into account design and technical characteristics. The optimal values of coefficients (Kp, Ki, Kd) on the roll, pitch and yaw axes for the quadcopter prototype under development were justified.


Introduction
Unmanned aerial vehicles with a frame of up to 150 mm are used in agriculture to solve problems in smart greenhouses.Calculating the values of PID-regulators when optimizing the drone operation allows to reduce the risks of flight controller misadjustment and increase the accuracy of its control in different flight conditions.The aim of the study is to calculate the optimal values` of the PID controllers of the UAV, develop an algorithm for coefficient calculation, and compute the proportional, integrating, and differentiating errors along the deviation axes.The authors have developed a quadcopter with a takeoff weight of up to 150 g for monitoring an industrial greenhouse.The mathematical theory of optimal control and stabilization was applied.A research analysis on the optimization of quadcopter flight was carried out.Experimental research in mechanics on adjusting the stability and acceleration of the quadcopter prototype during flight was carried out.Based on the mathematical formula for calculating the control signal, an algorithm was developed to calculate the coefficients and to compute the proportional, integrating, and differentiating errors in the axes of control deviation of the quadcopter's brushless motors.
A UAV with a frame of up to 150 mm can be used in agriculture for the following tasks: -Analyzing the microclimate in greenhouses.Smart greenhouses can be equipped with UAVs that capture images and collect data on temperature, humidity, and other microclimate parameters.This data is used to optimize growing conditions and increase yields.
-Disease and Pest Detection and control.UAVs are used to detect plant diseases and insect pests.This allows timely control measures to be taken and yield losses to be reduced.
-Optimizing the use of fertilizers and chemicals.UAVs are used to determine the level of soil contamination and optimize fertilizer and chemical doses in closed greenhouses.
-Monitoring of storage and agricultural facilities.UAVs are used to monitor the microclimate of the used space and the thermal assessment of agricultural products.
Thus, UAVs with a frame of up to 150 mm can be effectively used for monitoring and solving various tasks in agriculture.In the design of quadcopters, it is necessary to ensure stable flight.With the high diversity of quadcopter components, there is no unified element base and no standardized parameter values for adjusting the flight stabilization system.In this regard, the coefficients of PID controllers are adjusted empirically.To ensure the stability of quadcopter flight, a mathematical model for setting the algorithms of PID controllers is used.
The use of PID controllers is a common method of optimizing the operation of a UAV.PID controllers are widely used in industry and automation.In the context of UAV control, PID controllers are used to optimize flight parameters such as speed, altitude, and flight angle.[9].A PID controller consists of proportional, integrating, and differentiating coefficient signals.The proportional coefficient responds to the current error value (the difference between the desired value and the current value), the integrating coefficient considers the accumulated errors, and the differentiating coefficient considers the rate of change of the error.To ensure the stability of quadcopter flight, a mathematical model of PID controller setting algorithms is used to maintain a given roll, pitch, and yaw angle by controlling the rotation speed of each of the four motors [10].
There are other methods of controlling a UAV, such as optimal control, adaptive control, nonlinear control, etc.However, PID controllers are the easiest to use and customize and show high efficiency in controlling the UAV.The advantages of PID controllers include ease of use, the ability to be quickly configured and adapted to different flight conditions, and low cost and availability.They can also be easily integrated into other control systems, such as autopilot.However, there are some challenges to using PID controllers.For example, they may not provide sufficient control accuracy in some challenging situations, such as high speeds, unstable atmospheric conditions, etc.Also, PID controllers may have problems maintaining constant control accuracy as flight conditions change [11].
Applying the mathematical theory of optimal control and stabilization for adjusting UAV PID controllers will reduce the risks of controller incorrect settings and increase the accuracy of UAV control in various flight conditions [12].This can improve the efficiency and reliability of UAVs in areas such as monitoring industrial greenhouses, warehouses, industrial premises, etc.
The purpose of the study is to calculate the optimal values of UAV PID controllers and to develop an algorithm for calculating the coefficients and for computing the proportional, integrating, and differentiating errors along the deviation axes.

Specifications unmanned aerial vehicle
The research was conducted using a prototype designed based on a frame (∅ 135 mm) printed on a 3D printer.The total mass of the quadcopter is 136g.The main construction material of the frame is PETG-plastic (polyethylene terephthalate-glycol).BetaFlight Configurator was used to configure the system software and calculate mathematical algorithms for setting the PID regulation of the stabilization system.
When developing a UAV, compactness of elements is important, so integrated components placed on a single board are used to reduce the mass characteristics of the control electronics.The hardware of the quadcopter is shown in Figure 1.There are All-In-One (AIO) form factor flight controllers on the market, which often have the central processor, inertial navigation system, on-board power supply, motor speed controller, and radio receiver soldered on one board.
For a quadcopter with a frame size up to 150 mm, brushless motors with a stator diameter of 8-12 mm are used.This type of motor has acceptable dynamics and traction in combination with 3-inch propellers for quadcopter frames up to 150 mm.Peak current consumption of motors with a stator diameter of 8-12 mm varies from 3 A to 12 A.
A Wi-Fi AIO camera (NDVI) is used as a camera for monitoring because the camera has a small weight of 10 g, a high resolution for filming in greenhouses of 12 MP, and a wide viewing angle of 60°.The camera has been modified to replace the optical filters.
In order to ensure optimal mass-size characteristics and the minimum 7.2 V supply voltage of the AIO flight controller, a battery with a maximum voltage of 8.4 V, a capacity of 460 mAh, and a current output of 70 C is used.The battery applied will provide an average flight time of up to 20 minutes.Since the built-in AIO receiver of the flight controller has a CC 2500 chip and FRSkyX communication protocol, the Radio Master T8 Pro multi-protocol remote control is used for operation.This console enables connection to various receivers with FRSky, Spectrum, and Futaba protocols.The remote control has eight control channels: the first four channels are used to control the drone; the fifth channel is used to switch flight modes; the sixth channel is used to control the camera; the seventh channel is used to adjust or activate special modes of the flight controller; and the eighth channel is used for emergency stops of the propellers.These components combine well in the assembly, as together they give high manoeuvrability with the low weight and size of the quadcopter, which are the main factors for indoor monitoring.The quadcopter components and their main hardware specifications are presented in Table 1.A three-dimensional model of the general view of the quadcopter is shown in Figure 2. The main task assigned to the prototype is to monitor an industrial greenhouse (<100 m 2 ) to analyse plant samples.This task involves the detection of abiotic and biotic stresses in plants and the tracking of growth dynamics and plant vegetation phases.

Methodology
The study analyzed literary sources by applying the calculative-analytical method.Scientific works on the subject by domestic and foreign authors have been analyzed: scientific studies, articles, monographs, reports of research institutions, scientific journals, and conference materials.Methods of mathematical modeling, theoretical mechanics, and optimal design in CAD "KOMPAS-3D" are applied to create a prototype quadcopter.
One of the main factors affecting the flight stability of a quadcopter is its design.A welldesigned quadcopter with evenly distributed weight and an optimally configured flight controller provides stable flight and precise control [13].The default settings of the flight controller ensure take-off and altitude hold with a large deviation from the specified pitch and positioning in space.To achieve stable flight of the quadcopter, it is necessary to precisely adjust the parameters of the PID function in the flight controller.A mathematical model of PID control algorithms is used to adjust PID controllers.It controls the speed of the stabilization system's response to external influence and maintains a given tilt angle in the X, Y, and Z axes by adjusting the rotation speed of each of the four rotors.The PID controllers operate on a feedback basis, using the current position and velocity information of the quadcopter to calculate the correction signal [14].For each controller, the P, I, and D coefficients are customized according to the characteristics of the particular quadcopter and the tasks assigned to it.In the context of quadcopter control, the angle to be held is the roll, pitch, or yaw angle, and it is measured by a gyroscope or accelerometer [15].The desired angle is set by the user through a control signal, such as a joystick on a remote control.
Mathematical formula for calculating the control output signal of quadcopter PID controllers: () =  +  +  (1) where u(t) is the control output signal for a given tilt angle (s -1 );  =   () is the proportional component of the signal adjusted for the coefficient Kp.It is used to respond directly to an angle error.The greater the roll of the quadcopter, the greater the control signal will be given and the greater the rotation speed of the quadcopter motors to stabilize the tilt angle;  =   ∫ ()  0 is the integrating component of the signal adjusted for the coefficient Ki.Used to eliminate the residual error.It compensates for the statistical error over time and adds it to the control signal to compensate for the constant angle error; is the differentiating component of the signal adjusted for the Kd coefficient.It is used to prevent overshoot and fluctuations.It measures the rate of change of the oscillation error and adds the corresponding value to the control signal to reduce the rate of change of rotation of the quadcopter motors; e(t) is a proportional component that produces an output signal counteracting the deviation of the regulated variable from the set value.The component is calculated as the difference between the desired angle and the current angle (in radians); ∫ ()  0 is an integrating component, which is proportional to the integral over time of the deviation of the regulated quantity.It takes into account the accumulated errors for the whole time of system operation.It allows the system to compensate for the static error (s -1 );   is the differentiating component, which is proportional to the rate of change of the deviation of the regulated variable and is intended to counteract deviations from the target value, determines the rate of change of the error.This component allows the system to react quickly to the change in the error (s -1 ).
The Kp, Ki, and Kd coefficients are adjusted to achieve optimal PID controller settings depending on the quadcopter's characteristics and operating conditions [16].They ensure the stability of the quadcopter flight by considering external factors such as wind, mass change, or weight distribution [17].
The principle of operation of PID controllers is presented in the scheme (Figure 3).The feedback system controls the value of the output control signal y(t), i.e., corrects the value of y(t) relative to the set value of the input control signal r(t) using the PID function.The error e(t) is fed to the input of the PID controllers.Then the combination of the three PID components allows for the creation of a control signal that corrects the deviation of the quadcopter.The output of the PID controllers produces a common control signal, u(t), for the flight controller.The flight controller maintains the received value of the output control signal y(t) according to the conditions of angle correction.Adjustment of PID-controller parameters is interrelated, and changing one parameter affects the behavior of others.Determining the optimal values of the Kp, Ki, and Kd coefficients requires a series of flights.Adjustment of PID-regulation is an iterative process with analysis of results and subsequent parameter corrections after each test flight.This algorithm is used to calculate the optimal values of the parameters of quadcopter PID regulators and to calculate the proportional, integrating, and differentiating errors along the deviation axes.The algorithm of PID-regulation calculation allows for adaptability to different flight conditions and load changes, as well as simplifying the process of setting PID controllers.This algorithm for calculating PID-regulation of the control signal is universal and can be applied to various models of quadcopters without the need for detailed knowledge and modeling of the system dynamics.
The graph was constructed based on the results obtained using the algorithm for calculating the coefficients of the control signal and proportional, integrating, and differentiating errors along the deviation axes (Figure 5).This graph represents the mathematical dependence of the optimal parameters of the control signal of the PID controller and reflects the approximate to ideal values of the flight of the prototype.When adjusting the PID controller, it is necessary to set the optimal values of the deflection angle.Obtaining the optimal values of the PID controller's parameters enables the quadcopter control system to be adjusted and ensure stable control in real time.These values are used to form a control signal, which will be calculated on the basis of current measurements and provide the necessary dynamics for the quadcopter's flight.PID control helps the quadcopter respond to disturbances and adjust its position to keep it in the air and maintain stable flight.During flight, there are external disturbances that affect the response of the control signal of the quadcopter [18].Some of the possible interferences affecting the operation of the PID controller in a quadcopter include: 1. Wind: gusts and speeds greater than 5 m/s can change the direction of the quadcopter's flight, requiring correction of the PID controller's coefficient.
2. Change the mass of the quadcopter: when installing a payload or the loss of an additional battery, change the mass and dimensional characteristics of the UAV, which also leads to adjusting the parameters of PID controllers.
3. Electromagnetic interference: radio interference from other drones, transformers, or wireless devices with identical radio frequencies.
The polling/action frequency in quadcopter PID control plays an important role in flight stabilization and control accuracy.The polling or action frequency depends on the required accuracy and responsiveness of the system to changes in input parameters.For quadcopters, polling and action frequencies in the range of 100 to 1000 Hz are used.The higher the interrogation or action frequency, the more accurate and faster the system's response to changes in input parameters.However, as the frequency increases, the load on the computing system and sensors also increases, which can lead to performance and stability problems.The selection of interrogation or interaction frequency in PID control for quadcopters requires a balance between accuracy, system response speed, performance, and stability of the system [19].
Using the results of the coefficient calculation algorithm (Figure 2), the proportional, integrating, and differentiating errors along the deviation axes were calculated.From the data, a graph was plotted to represent the adjustable parameters that depict the effect of each coefficient on the control of the object and to optimize the settings of the PID controllers.
The graph is used to analyze the effect of changing each parameter on the quality of control and select optimal values for each of them.Thus, using these results, we optimized the settings of PID controllers and provided effective control.Using the obtained data, the optimal settings of the PID controller software in the Betaflight Configurator flight controller configuration program are selected (Table 2).Using the obtained PID control software, the flight stability of the prototype UAV was improved, and its control accuracy and battery consumption were optimized.

Conclusion
The flight stability of a quadcopter depends on several factors, including the quality of the flight controller, quadcopter design, environmental conditions, and others.A properly designed and configured quadcopter with sufficient power and speed can provide stable flight and precise control.However, to ensure stable quadcopter flight, it is also necessary to consider the weight of the quadcopter, conduct proper calibration, and select appropriate components.Quadcopters have become indispensable for a variety of tasks, and ensuring their flight stability is a key factor for efficient and safe use.
Using the data from the calculation algorithm and graph, as well as selecting the optimal settings of the PID controller firmware profile, are important steps when setting up the quadcopter control and stabilization system.This can lead to improving its performance and flight stability.Thus, an algorithm was developed to calculate the optimal values of coefficients for calculating the proportional, integrating and differentiating errors along the deviation axes of PID controllers.

Fig. 3 .
Fig. 3. Scheme of operation of PID: quadcopter control signal regulation: r(t)-setpoint value of input control signal; e(t)-mismatch, regulation error; u(t)-controlling influence on the signal; y(t)-supported value of output control signal; P, I, and D: proportional, integrating, and differentiating components of the input signal, accordingly.

Fig. 4 .
Fig. 4. Algorithm for calculation of PID -regulation of quadcopter control signals by deviation axes

E3SFig. 5 .
Fig. 5. Parameters of customizable coefficients close to ideal values for the flight prototype

Table 1 .
Technical characteristics of the hardware

Table 2 .
Optimal software settings for PID controllers in the Betaflight Configurator program