Analysis, Mathematical Model and Simulation Tests of the Unmanned Aerial Vehicle Control System

. The subject of this paper is to analyze, create a dynamic mathematical model and, on this basis, conduct simulation tests of the control system used in unmanned aerial vehicles. The key objective of the work is to develop a mathematical model of a control system based on the conducted studies of P, PI and PID regulators. The summary of this article are selected simulation tests of the proposed unmanned aerial vehicle (UAV) control system based on the analysis performed, the mathematical model developed for the dynamic control system and based on them, drawing practical conclusions.


Introduction
Stabilizing the ceiling of unmanned aerial vehicle UAV is a key issue on the way to ensuring the safety of its operation in an autonomous mode. In the case of a vertical take-off and landing UAV, it allows for stable hovering and systematic execution of further tasks entrusted to it and autonomous take-off and landing. At the same time, ensuring a stable hover of an unmanned aircraft is a difficult matter, because from the point of view of control theory this process has a nonlinear character. An additional factor increasing the complexity of the issue is the fact that in most practical solutions, due primarily to low costs, the stabilization of the ceiling of the said class of aircraft is carried out with the aid of ultrasonic sensors. These, in turn, provide relatively low resolution of the measurement (about 1 cm), sampling frequency of 20 Hz and have a range of operation limited from the top up to -about 7 m -and from below -up to about 0.35 m. Therefore, it is impossible to accurately determine the ceiling, let alone due to the low resolution -the speed of climbing. The problem of determining the speed of climbing seems to be key, mainly due to the structural solution, the key importance is the accuracy of the derivation of the control error in the process of regulation in the scope of the PID controller (Proportional Integral Derivative) [1], [2], [3].

Analysis and a mathematical model of the proposed technological solution of a control system for an Unmanned Aerial Vehicle
The mathematical model used for the analysis of the proposed unmanned aerial vehicle control system was formulated for a flying platform, powered by four electric engines, which were located on the vertical axis. In specialist nomenclature, this kind of platform is called the quadcopter. The key function of the control system selected by the authors of the object is realized through power changes for individual engines. The preset changes will affect both the direction of the flight of the platform as well as its stabilization. In addition, the small dimensions of the selected construction model make it susceptible to sudden changes in atmospheric conditions. For example, the impact of strong wind will be a factor significantly affecting the stable flight of the platform. Based on the above, and whereas the mathematical equations of the UAV flight dynamics differ in a crucial way from the mathematical relationships for standard flying objects (aircraft, helicopter), preliminary assumptions have been introduced. The weight of an unmanned aircraft is 0.89 [kg], the equation is formulated using the Euler-Lagrange's equation, in addition, the platform is located in the global coordinate system. The frame arms are made of carbon fiber, their length is 45 [mm]. Brushless motors were used, performing 1600 revolutions per 1 [V] power, with engines of this type being used as the main platform drive [4], [5].

Basic mathematical model of Unmanned Aerial Vehicle control system
The figure below (Fig. 1) shows the distribution of the lift force generated by four engines located at the ends of the platform arms. From the illustrated distribution of forces it follows that the lift force will always have a positive value. In addition, it is easy to see that the direction of rotation of M 1 and M 3 engines is opposite to the direction of rotation of the M 2 and M 4 engines. Based on the above, the M 2 and M 4 engines rotate clockwise, while the M 1 and M 3 engines rotate in the opposite direction. Thanks to the presented arrangement of engines, both aerodynamic moments as well as the gyrostatic effects will be distributed evenly on the platform. The lifting force F n will be equal to the sum of the forces generated by all four engines [6], [7].

Fig. 1. Model of the UAV control system
With respect to the inclination plane of the UAV (pitch), the torques are designated as function f 1 -f 3 . Whereas the rotational moments in relation to the tilting plane of the platform (roll) will be determined in the form of the f 2f 4 function. In turn, the sum of the four rotational moments of the i-th engine ( 1 + 2 + 3 + 4 ) determines the deviation torque (yaw). In addition, it should be noted that the torque of each engine depends on the acceleration and air resistance , that the UAV may encounter during the flight [8], [9], [10].

Inertia moments characterizing an Unmanned Aerial Vehicle
The engine torque is determined based on the following relationship: where: -moment of inertia of the rotor around its own axis. The aerodynamic resistance was presented as: where: -air density; Athe structural surface of the object; -speed of the flying object relative to the air. The angular velocity is the quotient of the linear velocity to the radius of rotation [11], [12]: The aerodynamic resistance results from the dependence: where: > 0constant, influenced by air density, radius and platform shape.
Assuming a constant angular speed for quasistationary maneuvers, we get: Movement in the inclination plane (pitch) is obtained by increasing the speed of the M 3 engine ("rear"). The change in engine speed M 1 causes the platform to move in the opposite direction. The "side" movement is achieved analogously, using the M 2 and M 4 engines. At the same time, by increasing the torque 1 , 3 and reducing the torque of the M 2 and M 4 engines, movement in the yaw plane is developed. In addition, it should be noted that the behavior of the total thrust constant is necessary for platform movements (Fig. 1).

Dynamic model of Unmanned Aerial Vehicle
The model of a four-armed platform was presented as a rigid body in 3D space. While maintaining the three main planes describing the UAV movement and phenomena occurring during the flight. Here we are speaking of deviation, tilting and deviation. At this point, we will go to the description of the BSP control system using the Euler-Lagrange's equations [13], [14].
The generalized definition of platform coordinates is presented in the following form: where: = ( , , ) ∈ 3 -the platform center of gravity vector determined in relation to the inertial system that is associated with UAV; = ( , , ) ∈ 3 -Euler's angles ( -yaw angle of tilting with respect to z axis,, -pitch angle with respect to y axis, -yaw angle with respect to x axis) in the form of . The presented coordinate system will be used to carry out mathematical considerations describing the UAV control system. The following was obtained from the definition of the Lagrange's function: where: = 2̇̇-kinetic energy; The center of the coordinate system in which the angular velocity vector distribution is considered coincides with the center of gravity of the platform. In addition, there is a connection between the system and the rotorcraft speed, which is located in the ̇ plane [15].
There is a following relationship between them: Defining the dependence: hence: Matrix Jrepresents the moments of inertia caused by the rotation of UAV propellers (simultaneously triggering the kinetic energy of the platform). The generalized coordinate system was used to express all quantities. Taking into account the influence of external forces, the UAV control system model is described using the Euler-Lagrange's differential equations.
Regarding previous dependencies, we obtained: where: =̇∈ ℝ 3 -external force shifted, coming from the platform in 3D space, ∈ ℝ 3 . This force is a matrix describing the moments of tilting, inclination and yaw angles during the flight of the platform [16], [17], [18].
The UAV orientation with respect to the selected inertial system is shown in the parameter ( , , ) ∈ (3). where: where: c => cos; s => sin.
The distribution of forces is as follows (according to Fig.  1): where: uthe main direction of movement outside the UAV, which can be written in the following form: where: i = 1,…, 4; -forces obtained from M i , assuming standard conditions = 2 (k = const).
Generalized moments of UAV start-up result from: where: l-distance between the engine and the center of gravity of the platform; -torque generated by the engine i, obtained on the axis representing the center of gravity of the UAV.
In addition, the influence of kinetic energy, which comes from ̇, ̇ oblique arms, has not been included in the equation. This fact results in the possibility of dividing the Eulera-Lagrange'a equation into both coordinates ( , ). This division will characterize the UAV control system, and the equation for coordinates is as follows: In contrast, the coordinate system control equations assume the following form: From the above dependencies was obtained [19], [20]: Taking into account the influence of Corolis's force: Taking into account the above equation, the relationship can be written as: ̈+ ̅ ( ,) = (25) Determination of ̅ ( ,) quantity: where: ( , ̇) − Coriolis's factors. Then: To simplify the solution of the equation, the following assumption was made [21], [22]: Thanks to this simplification, we obtained: x ̈= (sin sin + cos cos sin ) where: x, y, zcoordinates in the planes (x, yhorizontal, zvertical); ̃, ̃, ̃moments of tilting, yaw and pitch respectively, which are associated with generalized moments ( , , ).

Selected simulation tests of P, PI and PID controllers used in the proposed technological solution of an Unmanned Aerial Vehicle control system
In the preliminary stage, differential equations have been defined that describe the UAV control system. It should be noted that while modeling the platform in the Matlab/Simulink programming environment, it is also important to define the UAV based on the global coordinate system.
Another condition necessary for modeling a mathematical object in three-dimensional space is to present a model based on the space of the states. The main elements of the description in the space of the states is the form of differential equations, by means of which the control system of the quadcopter is determined, while the remaining quantities take the form of a matrix. These are quantities that occur both during take-off and in flight [23], [24].
Based on the above, the state space model can be written as: The presented model characterizes the platform in the state space using the linear function, while the analyzed UAV in non-linear form.
Therefore, the ̇ quantity change should be made. It is expressed as: In connection with the previously presented quantities, which change is as follows: = ( , , , ,̇,̇) , a change in ̇ quantity should be made. When modeling a platform, the coordinate system must be redefined.
The estimation of changes in inclination angles, tilts and deviations from the moment of UAV start, until the flight stabilization is the main factor necessary before performing the simulation in the Matlab/Simulink environment. After the simulations have been performed, the influence of the PID controller on the controllability of the platform was determined.
The following figures (Figs. 2-7) show the conducted computer simulations.

Conclusions
A platform with four engines called a quadcopter was used for the analysis. The mathematical model of the UAV control system has been simulated in the Matlab/Simulink environment.
The Euler-Lagrange's equations were used for the description. The PID controller helped stabilize the UAV position, while the trajectory of the flight was controlled using the implemented algorithm.
Thanks to this, an improvement in the response from the PID controller has been obtained.
The reflection of the platform control system has been developed using a mathematical model in Matlab/Simulink. Thanks to computer simulations, it can be seen that the PID controller had a significant influence on the dynamics and stabilization of the platform. Unfortunately, the PID controller has a negative effect on some quantities.
For example, the stabilization deviation for the x, y axes and the platform angles with respect to the global coordinate system. There were also slight changes in relation to the initial values.
Improved platform stabilization at a given height in three-dimensional space was found. Positive impact was obtained through the use of heuristic methods in tests. By using linear differential equations, with increasing acceleration, the values of thrust and tilt and inclination angles were obtained.
Thanks to the obtained parameters, the moments obtained from each platform engine were determined.
In addition, it should be remembered that the analysis made in a computer environment is also burdened with some errors.