Efficient model of PID controller of unmanned aerial vehicle

. The widespread use of digital signal processing distinguishes the modern stage of science and technology development. The use of digital processing for effective control of aircraft and other technical equipment remains relevant for many industries. The paper considers the problem of building a model of a digital PID regulator that can be used in unmanned aerial vehicles. It is proposed to base the regulator on the methods of digital filtering (realization of the differential component using a digital filter with a finite impulse response). The calculation of digital filter coefficients is performed using a genetic algorithm. This approach increases the model’s accuracy in calculating PID-regulator coefficients using classical PID-regulator methods. The Python programming language for realizing the proposed method has been developed. The effectiveness of the developed model is demonstrated in simulation.


Introduction
The task of effective control of technological processes, robotic systems, aircraft and other technical means remains relevant for many industries.Unmanned Aerial Vehicles (UAVs) or drones are gaining popularity, especially recently.They are autonomous or semi-autonomous aircraft without a pilot on board, which can perform various tasks.
UAVs have a wide range of applications.They are used for commercial purposes, such as: aerial photography, mapping, monitoring industrial and natural complexes, delivering goods and much more.Drones are also actively used for scientific and research purposes, in agriculture, in the military sphere of activity, to quickly obtain information about the consequences of emergencies, as well as for entertainment purposes.
The advantages of UAVs are their manoeuvrability, ability to operate in hard-to-reach places, low cost of operation compared to manned aircraft, and ability to solve tasks without threat to human life and health.
Overall, UAVs have great potential, and it is expected that their popularity will continue to increase in the future.Moreover, consequently, the drone flight environment is becoming increasingly complex.For example, it may involve various moving obstacles.A microcontroller plays the role of the central controlling device in a UAV.It is responsible for control and data processing.UAV control can be conditionally divided into three components: route planning, navigation, flight stabilisation, and data processing into two components: data of the performed task (photo, video, etc.), data for navigation and stabilisation of the UAV (accelerometer, gyroscope, GNSS, etc.).Microcontrollers usually have limited resources compared to more powerful computers.They have limited processing power and RAM for data storage.This limits the complexity of algorithms that can be executed on board unmanned aircraft and the processing of large amounts of data.
The use of cloud computing and cloud storage greatly enhances the UAV control and data processing capabilities.However, there are limitations in using cloud computing, such is the delay in UAV data transmission.In this regard, edge computing and efficient UAV control algorithms have become important.

Architecture overview
There are several scenarios for the application of UAVs in an edge-computing architecture (figure 1) [26].
The first scenario (figure 1a) is the most common.In this case, the UAV solves the task of a specific user, and edge computing and cloud computing are used to process the data obtained using the drone.This scenario is used when the UAV has insufficient RAM and computational resources to accomplish the task.Also, moving the computation to the servers reduces the battery power consumption, which increases the drone's flight time.The second (figure 1b) and third (figure 1c) scenario is used to organise the computation of ground-based users.In the second scenario, the UAV raises the MEC (mobile edge computing) server to a certain altitude.In the third scenario, the UAV serves as a central repeater to transmit data to the MEC servers.
Edge computing is a distributed computing paradigm that brings computation and data storage closer to the data source.This reduces response time and network bandwidth.
Edge computing infrastructure is placed between cloud computing and edge devices (M2M, IoT, CPS, etc.).There are many different types of edge devices that utilise edge computing, so the architecture of edge computing may vary slightly.However, in general, it can be visualised as follows (figure 2) [16].
According to this figure, it can be seen that the farther the computation occurs from the device, the longer the response time of the system.Modern flight controllers based on PX4 [21] and ArduPilot [1] firmware allow you to organise information exchange with external devices (ground control stations, servers, etc.).MavLink (Micro Air Vehicle Link) is used as an exchange protocol.The MavLink protocol is an open standard not bound to any specific data transmission medium.
Based on MavLink, an API is provided to create applications that can send requests to the flight controller to control the drone, get information about the flight status, capture data from sensors, and others.Figure 3 shows an example of organising complex computations in unmanned aviation systems based on the "Pixhawk" flight controller (PX4 autopilot) and Raspberry Pi single-board computer (SBC) [21].Thus, it can be noted that the computations required to solve a specific task are distributed between the flight controller, intermediate computer and cloud servers.
Let us briefly look at an example of using such an architecture.Many companies are responsible for the condition of power transmission networks.Inspection and maintenance of power lines are aimed at minimising the risk of blackouts; and extending the life of cables.Inspection is carried out in different ways: manual inspection; using a helicopter based on aerial photography.Recently, UAVs [24] have been used to inspect power transmission facilities.In this paper, a UAV scheme based on an open-source platform is proposed to ensure the autonomy of the drone for power line inspection.
Figure 4 shows the general view of the system (numbers indicate the technologies used) [24]: (1) cloud services provide the drone with geolocation data of nearby power transmission towers, which are used for navigation; (2) acquisition and processing of sensor data to pinpoint power lines for drone alignment and cable inspection; (3) trajectory planning for cable capture; (4) following the line for cable inspection using on-board sensors.As we can see, the architecture of this system corresponds to figure 3.
When solving such tasks using UAVs, there may be non-standard situations; for example, on the way may appear broken wires of power lines; birds, etc., so the UAV must be able to avoid such obstacles [7] and the reaction time should be as short as possible.Such data processing should be done on the UAV side, and efficient control algorithms should be used.One of them is the PID controller algorithm [17,19].

Theoretical background
In general, the control system for any object has the form shown in figure 5. where   () -PID control transfer function,   () -control object transfer function,  () ,  () ,  () , () -input action, output signal, error signal, control signal, respectively.
The time-domain control algorithm is implemented by the expression (1) [17]:  where   ,   ,   -proportional factor, constant of integration and constant of derivation of the controller, respectively.In some cases, the following expression is used (2): where   ,   ,   -PID controller coefficients.Thus, the PID controller includes three components: proportional, integral and differential.The proportional component generates a control signal counteracting the deviation (mismatch) of the output signal from the set value.The greater the mismatch, the greater the impact on the control object.If the output signal is equal to the set value, then the error signal is zero, and therefore, the control action of the proportional component is zero.The integrator is used to eliminate the static error.The differentiating component takes into account the rate of change of the output signal, which allows you to get better control of the object by predicting the output value of the signal [17].
There are several groups for assessing the quality indicators of object management: direct, root, frequency, and integral.In practice, direct quality indicators have found the greatest application.This is because direct indicators of the quality of object management are determined directly by the transient characteristic [17].The following quality indicators can be distinguished: • steady-state output value; • static error; • regulation time; • overshoot; • attenuation rate; • etc.The choice of control quality indicators depends on the task in which the PID controller is used.
To ensure the required performance of regulation, it is necessary to calculate the coefficients of the PID controller.
There are many methods for calculating quality indicators.One of the first methods for calculating the parameters of PID controllers was proposed by Ziegler J. and Nichols N. [22].This technique does not give excellent results, but it is elementary.Therefore, it is still often used in practice.After calculating the parameters of the regulator, manual adjustment is required to improve the quality of regulation.
In [22], other methods for calculating the parameters of PID controllers are also considered, namely Chien-Hrones-Reswickand Kuhn.Relay methods are also widely used [5,8].
If the methods considered were developed relatively long ago, then the methods below are quite recent.
In [10,27], methods for optimising the parameters of a PID controller using a genetic algorithm are considered.In these works, the choice is analysed: fitness functions, the main operators of the genetic algorithm, and quality indicators.
In [11], the possibility of using neural networks to optimise the PID controller coefficients was considered.The main focus of the article is on the analysis of the stability of such systems.
Many works are related to determining the optimal parameters of the PID controller for specific control objects [10,11,23,25].
A large number of jobs linked to the development of the digital PID [2-4, 9, 12-14].However, in fact, all the articles cited can be divided into two groups.
The first group of works [2,3,9,14] is based on expression (3) given in [4]: where   -sampling period,   =     ,   =   /  . https://doi.org/10.55056/jec.593 Expression (3) is often written in a recurrent form to reduce computational costs (4): The second group of works [12,13] is based on the expression (5): where The analysis showed that expressions (4) and ( 5) are practically identical (the control signal () depends on the last three readings of the error signal).The main difference between them is that expression (4) allows you to determine the coefficients of a digital PID controller based on an analogue prototype.For expression (5), the coefficients  1 ,  2 ,  3 must be selected when manually adjusting the control system.It may seem that these coefficients depend on the controller coefficients   ,   ,   so that they can be calculated, but this is not the case.This is easy to see if you pay attention to the fact that these coefficients  1 ,  2 ,  3 do not consider the sampling rate.
Considering the above, digital and analogue PID controllers are not considered different entities.Therefore, methods for calculating the controller coefficients are considered regardless of whether digital or analogue.However, as the analysis has shown, there are at least two implementations of a digital PID controller, so the calculation methods must take into account the structure of the controller.In addition, as will be shown later, the digital controller ( 4) is not a complete analogue of the classic analogue PID controller.Thus, the problem of the algorithm for optimising the digital PID controller is relevant.

Results
This section will discuss the implementation of a digital PID controller.The controller will be based on a digital filter [20].The method for calculating the filter coefficients will be performed using a genetic algorithm [6,15].
The purpose of the work is to refine the digital PID controller model by using a digital filter.
To achieve the goal in the work, the following tasks must be solved: to analyse digital filters; suggest a filter type for the PID controller; choose a fitness function to optimise the filter coefficients; calculate the filter coefficients for the PID controller model; draw conclusions from the results.

Digital filter
Digital signal processing is used wherever necessary to perform tasks such as filtering, compressing, recovering, controlling, and measuring a signal: audio, video, or any signal from any source.
Filtering is the most common digital processing task, implemented using digital filters: filters with a finite impulse response (FIR filters); filters with infinite impulse response (IIR filters).In general, a digital filter is understood as a hardware or software implementation of a mathematical algorithm, the input of which is a digital signal, and the output is another digital signal modified by the filter.
The primary operations of information filtering include noise suppression, smoothing, prediction, differentiation, signal separation, etc.
The main advantages of digital filters over analogue filters: • may have parameters that are impossible to implement in analogue filters, for example, linear phase response; • does not require calibration because its performance does not depend on the destabilising factors of the external environment, for example, temperature; • input and output data can be saved for later processing; • accuracy of digital filters is limited by the capacity of the filter coefficients.
• can be easily rearranged to filter a different frequency range, for example, by changing the data sampling rate.
In general, the digital filter is described by the following expression (6): where   ,   -filter coefficients;  () , () -input and output signal; ,  -number of filter coefficients   ,   respectively.Expression ( 6) is also called IIR filter.Such a filter is often used when you must filter with a minimum number of arithmetic operations.If all the coefficients   are equal to zero, then such a filter is called an FIR filter.In this case, the digital filter will be described by the following difference expression (7): where ℎ () =   -impulse response of an FIR filter.The amplitude-frequency response (AFR) of such a filter will have the following form (8): where  -circular frequency.In many digital signal processing applications, the use of FIR filters is preferable because they have the following advantages: • filter group delay constant (linear phase FIR filters); • FIR filters are always stable.

Table 1
Types of linear phase filters and their characteristics.For FIR filters to be a linear phase, the impulse response must be symmetric or antisymmetric [20].In this case, four types of FIR filters are possible (table 1).
In this case . An example of an antisymmetric FIR filter with an even number of coefficients is a differentiating filter, the AFR of which corresponds to figure 6.

Development of a PID controller model
Let us define the transfer function of the analogue PID controller.For this, it is necessary to perform the Laplace transform of formula (2) with zero initial conditions  (0) = 0.As a result, we get the following expression: where  -Laplace operator.
If in expression ( 9) we substitute  = , then we obtain an expression for the frequency response of the analogue PID controller (10): Let us look at the frequency response of the regulator at   = 10,   = 1,   = 1 (figure 7).The AFR of the analogue PID controller shows that the integrating component has an effect in the low-frequency range and the differentiating component in the high-frequency range.Now, let us compare the AFR of the differentiating components of the analogue and digital PID controllers.
First, let us write the frequency response of the derivative component of the analogue PID controller.It can be seen from formula (10) that its frequency response is determined by the expression (11): Now, let us determine the AFR of the differentiating component of the digital PID controller.From expression (3), it can be seen that in the time domain, the differentiating component has the following form (12): In the brackets of expression (12), there is a digital filter of the first order.Therefore, the frequency response can be determined from the formula (8).As a result, we will have the following expression (13): Figure 8 shows the AFR of both regulators.For convenience of comparison, the frequencies are normalised (the sampling rate is taken equal to one), and the coefficients are taken equal to   = 1,   = 1.The AFR of the differentiating component of the analogue PID controller corresponds to figure 6, but the digital one does not.Such a term works as a differentiating one only for 1/3 of the initial interval.However, in this area, its influence is minimal because the integrating and proportional components prevail there.Figure 9 shows the relative error.As you can see from the figure, the maximum error is more than 35%.
To eliminate this drawback, it is necessary to set a new model of the differentiating component.One of the options is using digital processing methods, namely, using the previously mentioned FIR filter with a linear phase.
From table 1, it follows that there are four types of such filters.Filters of types III and IV have an imaginary part of the AFR.However, the type III filter cannot always be used as such.The reason is that the value of the transmission coefficient at the maximum frequency will be equal to zero  (  ) = 0 regardless of the filter coefficients (table 1).Such a filter can be used as a differentiating filter only in the initial section.We need to use the entire range, so for our task, the best solution would be to use a type IV filter.
From expression (7) and table 1, it follows that the differentiating component for a digital PID controller can be represented in the form of expression ( 14): https://doi.org/10.55056/jec.593where  -number of independent coefficients.In this case, taking into account expression (3), the algorithm for implementing a digital PID controller will be described by the expression (15): For simplicity, we call it PPID.By analogy, we can write an expression similar to the recurrence formula (4) or recurrently record only an integrating part (this will reduce the likelihood of overflow and reduce the number of arithmetic operations) in the following way (16): where  () =  ( − 1) +    () -integrating component.
To synthesise the filter ( 14), a fitness function is required.The synthesis of the filter with the best uniform approximation will be performed in the form of the problem of minimising the weighted Chebyshev norm (17): where  (), ̂︀ () -AFR of the approximated and approximating filters, respectively,  ()weight function.

Experiments
To test the model of the digital PPID controller, we will carry out some experiments.Let us synthesise a digital FIR filter (14).There are many methods for their design in the scientific literature [20].The most widely used are the classical methods for calculating FIR filters: weighing method; frequency sampling method; least squares method; and best uniform approximation method.The first two are not optimisation methods, but are fairly easy to use.The third and fourth methods are referred to as optimisation methods.The fourth method allows obtaining the best results, but, as a rule, it is impossible to determine analytically the function of the best uniform approximation.However, in this case, the synthesis of the FIR filter will be carried out using the genetic algorithm [18], which will allow us to obtain some advantages; for example, when searching for the values of the filter coefficients, we will take into account the effect of quantisation.
A genetic algorithm is a heuristic algorithm, a kind of evolutionary algorithm, with the help of which optimisation problems are solved using methods of natural evolution, similar to natural selection in nature [6,15].
When solving a problem with a genetic algorithm, it is necessary to isolate the phenotype that determines the real object.In our case, the filter coefficients forming an species will act as a phenotype (figure 10).The fitness function will be described by expression (17).The AFR of the differentiating part of the analogue PID filter (11) at   = 1 (figure 8, graph 1) will act as the AFR of the approximated filter.The AFR of the approximating filter will be determined by a type IV filter (table 1).
The simulation was carried out using the Python programming language.To implement the genetic algorithm, it is necessary to tune the hyperparameters.In our case, they will have the following form: POPULATION = 100 # number of individuals in the population SURVIVOR = 0.2 # survival probability MUTATION = 0.1 # possibility of mutating of an individual GENERATIONS = 250 # maximum number of generations Below is the fitness function code in the Python programming language, which corresponds to the expression (17), where prototype is an instance of the PrototypeFIR class of the filter being approximated (figure 6); fir -an instance of the Fir1T class approximating the filter (7).if e > emax: emax = e return emax, Figure 11 shows the synthesis of a differentiating component PPID controller.Table 2 shows the calculated coefficients of filters of different orders and also indicates the approximation error of the differentiating component of the PPID controller.
If we compare the proposed model of the PPID controller with the original digital PID controller (3) at  = 1, we can see that the expressions differ only by the factor ℎ(0) (table 2).However, due to him, the error was reduced by 15%. Figure 12 shows the relative error of this PPID controller.
Figure 13 shows the tendency of decreasing the error with an increase in the number of coefficients ℎ().
Let us compare the number of arithmetic operations (number of addition and multiplication operations) for the classical PID model and the developed PPID model.When calculating, we will consider that the subtraction operation is equivalent to the addition operation because the addition operation can replace the subtraction operation with some opposite sign, and the division operation is equivalent to the multiplication operation.Expression (3) cannot be realised directly using a microprocessor (microcontroller), so it is converted into expression (4) but for adequate comparison with the developed PPID model, expression (3) is better written in this way: where  () =  ( − 1) +    () -integrating component.Now, the classical model ( 18) has a form that is similar to the developed PPID model ( 16), but this is not enough for comparison because it is obvious that the original model is more straightforward, but has a significant error.The question arises: Can the error of the classical PID model be reduced?The answer is unambiguous -yes, it is possible.If you look at Figure 8, you can see that the initial section of the curve of the D-component is close to linear, and the error is less than 5%.For the PID controller to satisfy this requirement, it is necessary to lower the sampling period   (increase the sampling frequency) by 3-5 times.Figure 14 shows an example of increasing the sampling rate by a factor of 4.
This approach is used in many digital systems to reduce the error caused by the sampling step.Figure 15 shows the architecture of the control node in the PX4 autopilot [21].The documentation states: "Most of the IMU drivers sample the data at 1kHz, integrate it and publish with 250Hz" [21], so the sampling and processing rate is four times higher than necessary.
Table 3 compares the number of arithmetic operations of the classical PID controller model (18) and the developed PPID controller model ( 16) for three cases.The results in the table show that with comparable errors of the D-component, the number of multiplication operations of the developed PPID regulator is almost two times less, and the number of addition operations is one and a half times less.
Another disadvantage of the classical PID controller model is the noise amplification at the output of the D-component.The reason for this effect is explained in figure 8.This effect is absent in the developed model of the PID regulator.It can be verified by using the following diagram (figure 16).
The input is the original signal () and noise   (), and the output is noise   (), after passing through the differentiating component.
Thus, it can be noted that 3 ≤  ≤ 6 is sufficient for UAV control in the developed PPID controller model.
In a classic digital PID controller, the amplitude-frequency response of the differential component is nonlinear.Because the initial section of the characteristic is quite linear, they try to  use this part of the characteristic in the PID controller, increasing the sampling frequency by 3-5 times.In this case, the error will not exceed 5%.However, this approach leads to additional costs of computing resources and increased noise levels.
In this paper, we propose another approach to eliminate the nonlinearity of the characteristic.The differential component is considered a nonrecursive digital filter, increasing the order of which reduces the nonlinearity of the amplitude-frequency response.

Conclusions
The problem of building a model of a digital PID controller that can be used in unmanned aerial vehicles is considered.The regulator is based on digital filtering methods.It is proposed to use an FIR filter with a linear phase of the IV type as a filtering device.This made it possible to fairly accurately approximate the differentiating component.So, for a classic digital PID controller, the introduction of one coefficient has reduced the relative frequency response error by 15%.In addition, the PID controller model was developed with the ability to use ready-made methods for calculating the PID controller coefficients.
The digital filter coefficients are calculated using a genetic algorithm.The phenotype is the filter coefficients.The Chebyshev norm was used as a fitness function.
The simulation results were carried out using the Python programming language.Data for all filters up to 21 orders (up to 11 independent coefficients) has been analysed.As shown in the work, for most control problems in robotic systems, it is sufficient to use filters with 3-6 independent coefficients.Also, the analysis showed that with the same errors of the classical PID controller and the developed PPID controller, the cost of computational resources is approximately two times less.
Perspectives for further research consist of testing the proposed methods on a wider range of problems, studying the effects of finite bit depth, and analysing the structure of the PID controller.

Figure 1 :
Figure 1: UAV-enabled edge computing architecture: a) The scenario UAVs have computation task; b) The scenario UAVs as a MEC; c) The scenario UAVs as a Relay.

Figure 4 :
Figure 4: Conceptual overview of the proposed framework.

Figure 6 :
Figure 6: AFR of the differentiating term.

Figure 7 :
Figure 7: AFR of the PID controller.

Figure 9 :
Figure 9: Relative error of the differentiating component of AFR of the digital PID controller.

Figure 10 :
Figure 10: The structure of the individual.

Figure 13 :
Figure 13: Changing error differentiating component with increasing  of PPID controller.

Figure 14 :
Figure 14: Frequency response of PID controller at four times increase of sampling frequency.

Figure 16 :
Figure 16: Testing the noise level at the output of the D-component.

Table 2
FIR filter coefficients for the developed model of a digital PID controller.

Table 3
Comparison of the number of arithmetic operations in PID regulators.