Unmanned Aerial Vehicles Motion Control with Fuzzy Tuning of Cascaded-PID Gains †

.


Introduction
Recently, the use of autonomous vehicles and robotics technologies has increased significantly.Such systems are now being used to perform a great number of tasks in an optimized manner.Most traditional solutions demanded human resources, which may provide gaps and cause unsafe working places or human workers' depletion due to repetitive tasks.Human safety issues are taken into account in some autonomous unmanned vehicle-related tasks in [1][2][3][4].
The field of Unmanned Aerial Vehicles (UAVs) is gaining a growing interest over the past years due to the possibility of enabling new services that help modernize transportation tasks [5], inspection [6], supply chain support [7], search and rescue activities [8], change detection in water scenes [9], air quality assessment (e.g., by measurements of gaseous elemental mercury) [10], early wildfire detection [11], delivery goods tasks [12,13], information warfare [14], topographic surveys in active mines [15], plant genotyping [16], documentation and inspection of historical buildings [17], among others.The reason for using them in several applications can be explained by the UAV's ability to perform complex activities with low-cost flight operation and maneuvering flexibility [18,19].
Autonomous or semi-autonomous UAVs have been used to substitute human workers in different tasks in order to reduce maintenance costs and intervention times, especially in inspections [20,21].There are different ways of performing such inspections with a UAV.In these all different flying situations, the UAV can fly very close to the object with a slow speed, producing valuable and reliable information about the inspected area.According to [1], the use of UAV can help to reduce the the mission's complexity for data gathering due to its high versatility, and the possibility of attaching new technologies into it.In this work, this and some other aspects are also taken in place to use as work motivation.
The UAV should also be capable of performing these missions stably.Therefore, there is also great importance in controlling the UAV's movement itself.For example, the authors of [22] have used a self-tuned PID control method to deal with external disturbances in a quadrotor UAV.In [23], the authors have proposed a hybrid PID control strategy to overcome sensor noise and strong wind disturbances.Several works in the literature have been proposed to make UAVs more robust to disturbances, parametric uncertainties, among other problems.For example, the control method proposed in [24] is a fault-tolerant strategy that takes into account system uncertainties and actuator failures.In [25], the authors have proposed a flight control for a quadrotor UAV for hovering with a slung load attached to it.The mathematical model was simplified to several controllable linear subsystems via reasonable assumptions.A robust H ∞ controller was designed by utilizing the estimated states of a state observer.Other works have proposed robust control techniques for compensating for the effects of external disturbances and uncertainties in the UAV model parameters [26][27][28][29].
The physical instability of the UAV's platform causes motion in the acquired videos, which imposes harmful impacts on the accuracy of camera-based measurements [30].These issues, among others, motivate the adoption of flight stabilization techniques, which allow the adaptation to operational changes based on the knowledge of dynamical properties [31].They commonly use a navigation system to feed a classical PID controller, which has a simple structure, good stability, and less dependence on the exact system model.Although the PID controller has a simple structure to be implemented, the process of adjusting its parameters requires attention from the designer, particularly when nonlinearities are present.This is an issue that has been receiving growing attention.Such dynamical characteristics force the PID design and tuning to become even more complex, demanding an additional control approach.Computational Intelligence techniques can be used to optimize the PID gains, as seen in [32], where the PID gains were tuned by using Particle Swarm Optimization technique, and in [33], where Genetic Algorithm was used.The Fuzzy Logic Theory has also emerged as a solution for dealing with systems that are not easy to be modeled because of their nonlinearities and undetermined states.In this sense, many researchers have applied fuzzy controllers to obtain improved performance, and robustness properties compared to those that use pure classical control algorithms [34][35][36][37][38].
Note that the fuzzy-based control is considered as a control scheme that can improve the system's robustness and adaptability.This approach can be used to dynamically adjust the controller parameters in accordance with the output [39].The authors in [40], proposed the use of a fuzzy PID scheme to control the attitude of a UAV.They used the fuzzy to adjust the controller parameters by inference rules.A similar scheme was proposed in [41].The results showed that the UAV obtained better dynamics and stable performance.
In this work, a hybrid approach composed of a Cascaded-PID and a Fuzzy Logic controller is implemented.Due to the Cascaded-PID module, the proposed approach offers the system adaptive capabilities engendered by the Fuzzy Logic part and a robustness property against parametric uncertainties.
The focus of the devised approach is to propose a controller that has the robustness of a PID, but also that could be applied to many different scenarios.PIDs are widely used in the context of machine control and stabilization.However, the values of the Proportional, Integrative, and Derivative gains rely directly on the plant model.It can be very challenging to choose values that will fit the best way in all operational situations that this kind of robot can use.In order to amplify the range of use for those UAVs, the insertion of a fuzzy-based algorithm is implemented.In this case, the fuzzy would not control the movement speed and position itself, as usually is seen in state of the art, but would provide the adapted PID gains to the system and develop an optimized new PID controller to it.
Therefore, the main contributions of this work are: This paper is structured as follows.Section 2 described the advanced method, whereas Section 3 describes some promising results and Section 4 the discussion.At last, Section 5 concludes the paper by furnishing the final conclusions.

Materials and Methods
The proposed scheme combines a Cascaded-PID with a Fuzzy algorithm that is responsible for calculating the PID gains.In the so-called fuzzy controller, the control strategy is described through linguistic rules that imprecisely connect various situations with the actions taken.Different from the traditional PID controller, a formal mathematical model of the plant is not necessary.Approximately knowing the UAV's behavior when exposed to different inputs is enough for defining the fuzzy rules, which is a feasible task to UAV specialists.Therefore, these linguistic rules that define the control strategy represent the linguistic model of the plant.Note that Fuzzy and the PID can provide an effective solution to the system's non-linearity.As a result, the system can accurately converge to the desired position in fewer iterations.
In the beginning, suitable PID values may be defined for the PID controller.As time goes by, such gains are updated dynamically by the Fuzzy algorithm, whose rules are only dependent on the position error and its derivative.
Figure 1 depicts the designed iterative learning control algorithm, along with the real-time management of Fuzzy gain computation.The UAV Desired Position is the commanded waypoint that the UAV should go to.The desired position can be changed at any time during the process, allowing the system to follow a moving goal or a trajectory, for example.
It is important to note that one independent Fuzzy Logic controller must be set for each control axis (x, y and z).In this work, the methods, figures and tables will be only relative to the x-axis to avoid unnecessary repetition.

Cascaded-PID
The cascade strategy is a well-known scheme in control system design.It basically consists of the interaction between two control loops: an external one that is responsible for generating a reference signal and an internal, fed by the latter, which is responsible for computing the signals to drive the actuators.
The block diagram in Figure 2 illustrates the proposed simplified Cascaded-PID controller scheme.The external loop uses the position error to generate a setpoint reference value for the internal loop.Concerning the diagram, the internal control loop is responsible for controlling the UAV motors.The rotors ' velocities are calculated after demonstrating that both roll and pitch angles converge to their (generated) reference values.As can be seen in the diagram of Figure 2, the proposed scheme uses the altitude and position errors for generating and sending the velocity commands to the flight control unit controller.

ROS Integration
The general idea of the proposed methodology is illustrated in Figure 3.It consists of using a companion computer to perform the control of the UAV.This strategy allows a more straightforward implementation and testing tasks that are benefited from more advanced sensors, such as light detection and ranging and waypoint control integration.The Flight Management Unit (FMU) is responsible for acquiring information from the peripheral sensors and modifying these values in the actuators to which it has access.The primary sensor data are fed through the FMU to a specific ROS driver, the MAVROS.The data are then forwarded to a ROS node, in which the controller is implemented.The reverse-path takes place to perform motor driving at the end of the control loop.
The ROS interface with the UAV works as follows.The companion computer has the ROS core processing data in each of the code's pre-configured nodes.The computer receives the UAV state information from Ethernet using the MAVLink communication protocol.The UAV state is made available as a ROS topic by the MAVROS ROS driver.The calculations that enable the Cascaded-PID controller are performed in the main ROS node, which publishes the current PID gains and the errors to a topic that is used by the fuzzy logic module.The same ROS node subscribes to the messages with the new PID gains sent by the fuzzy logic module.When it receives a message, it makes the PID calculations and transmits the target velocities to the FMU by publishing a MAVROS message.The gains are changed at a rate of 10 Hz, which is the best possible MAVLink rate.

Fuzzy Logic PID Tuner
In Figure 4, the MATLAB/Simulink block diagram with the Fuzzy Logic and the connection between Simulink and ROS are presented.It is shown, on the left side of the diagram, the subscription block that reads the information from the topics sent by ROS.The messages are divided in five variables, so they can be individually read by Simulink.The variable of the error derivative was suppressed, as it can be directly calculated from the error variable using Simulink, which guarantees that both have the same rate.Some displays are added only to keep track of evaluation during the tests.The the error and it's calculated derivative are sent to the Fuzzy Logic Controller With Ruleviewer block.This particular block is responsible for reading the fuzzy controller file and performing the fuzzy logic calculations.After that, the values from the fuzzy controller are sent to ROS, on the publish block on the bottom of the figure.The ROS messages of "fuzzy_values" and "defuzzy_values" were created for this work.The Membership Functions types were chosen as Gaussian for the inputs and triangular for the outputs.This is the setup present in most of the literature cited by this work when it comes to PID gains tuning with fuzzy logic.The existing works were followed as a start point regarding the rules, and the rules were defined according to the UAV's desired behavior.For instance, if the position error X-error and its time derivative X-error-D are sufficiently small in the present approach, there is no need for large PID gain values.Since no "crisp functions" were used, final gains regularly tend to be slightly different from those in the center of the membership function.The fuzzy inference technique adopted in this work is based on the classical Mamdani [42] inference method and on the centroid defuzzification method.
The fuzzy rule Table 1 can be seen as the following.The symbol 'B' represents 'Big', 'M' for 'Medium', and 'L' for 'Low.'The outputs should be interpreted as K P , K D , and Alpha gains.Hence, the output notation 'LMB' should mean that the proportional (K P ) gain is Low, the derivative (K D ) gain is Medium, and Alpha gain is Big.For the integrative (K I ) gain, the formula below is used [43].As the desired behavior of the controller is the same for when the position error is positive or negative, the absolute value of the error was used.Regarding the derivative, it was the derivative of the absolute value of the error.The methodology to define the range of each of the PID gains for the horizontal motion control (x and y axis) followed [44], and [43] with a modification proposed by this work.
First, the ultimate gain (K u ) and the oscillation period (T u ) [45] are obtained.This is done by removing the derivative and integral parts of the PID and increasing the proportional gain until the point that the output of the control loop has stable and consistent oscillations.In this work, the measured ultimate gain was of 2.2 and the oscillation period of 4 s.
With the measured values of K u and T u , the Zhao/Larson gains K P ,min , K P ,max , K D ,min and K D ,max were calculated: Provided that the traditional Ziegler-Nichols exhibits a high overshoot and that the overshoot is reduced but not removed by the above described method, this work proposes the following modification.The modification is to use a compression factor to reduce the fuzzy range of the PID gains, which will smooth the control signal and make it more suitable for UAV applications, where a fast convergence is desired but without a very high overshoot.
Therefore, the actual adopted gains K P,min , K P ,max , K D ,min and K D,max are obtained as follows: K P,min = K P ,min − K P ,min 7 , K P,max = K P ,min + K P ,max 7 , (4) Finally, the summary of the limits can be seen in Figure 5, where the left shows the two inputs and the right shows the three outputs.

Horizontal Motion Control Tests in the Simulation Environment
The proposed solution was tested in a simulation environment and compared with other solutions.The other solutions adopted for comparisons are: • ArduPilot built-in GUIDED mode controller.• Cascaded-PID solution tuned by the Ziegler-Nichols method.• Cascaded-PID solution tuned by the methods in [44], which were detailed in [43].
The tests were performed in a simulation environment (Figure 6) that runs in Windows operating system with Windows Subsystem for Linux (WSL) Ubuntu 18.04.5 LTS 64 bits.The computer has an Intel i9-9900K 3600 MHz processor with an NVIDIA GeForce RTX 2080Ti graphics card and 48 GB RAM.The software Unreal Engine 4 (UE4) with the AirSim plugin [46] was used for the simulations trials.AirSim was developed by Microsoft, and is an abbreviation for Aerial Informatics and Robotics Simulation.This plugin program provided some important resources for this work, especially with regard to input/output signals, corresponding to the behavior of sensors and actuators, sent to and received from the UAV flight controllers.In the tests, the UAV was commanded to go from position 2 m at East from takeoff position to −2 m.Therefore, a total movement of 4 m was performed.The command to move was sent around 1.6 s after starting recording the logs and building the graphs.

Simulation Results
First, the three tuning methods for the Cascaded-PID were evaluated (Figure 7).It is possible to notice that, as already shown in [43,44], the Zhao/Larson method achieves the same convergence time as the Ziegler-Nichols but with lower overshoot and faster accommodation profile.In UAV applications, fast convergence is desirable, but the accommodation property is more important, as the UAV usually needs to acquire data with onboard sensors.Therefore, the solution proposed in this work is better suited for UAVs as it can achieve accommodation in a faster way with significantly less overshoot.By considering an acceptable error of 1 cm, the proposed solution reaches accommodation in 6.7 s, against 10.8 s achieved by using the Zhao/Larson tuning approach and more than 20 s achieved with the Ziegler-Nichols tuning method.
The proposed method was also compared with ArduPilot's built-in controller in GUIDED mode, in which ArduPilot accepts target position commands and updates the velocity control at a rate of 50 Hz.A ROS message of the target position was sent using MAVROS.The result is presented in Figure 8. From the curve, it is possible to conclude that the ArduPilot achieves a shorter time of accommodation.However, the proposed method performed very well to reach the desired position, being 1.5 s faster than the ArduPilot, with a small overshoot of less than 0.5 m (Figure 9).It is important to note that the ArduPilot controller is very advanced and has been developed for many years, counting with a big team of developers and contributors.
Furthermore, in comparison with ArduPilot's results, in Figure 10 the accumulated error can be analyzed.The accumulated error is a measure that shows how much the UAV was away from the desired position over time.The upper line shows the ArduPilot's accumulated error in terms of position in X axis, while the lower line represents the results of this proposed method.Both have crescent errors before two seconds, but it is shown that the ArduPilot stabilizes this error almost in 6 s, while the proposed method takes more than that to be a fairly horizontal line.However, the most meaningful information in this comparison is that the difference between both methods at the end of the experimentation is almost 25 m.This means that counting on every small error that both had on the trajectory tests, the proposed method shows itself significantly more accurate in terms of position in x.Regarding the Fuzzy Logic PID gains used in the proposed method, they can be observed in Figure 11, by the side of a graph with the calculated error and error time derivative.The peak of the derivative error, in the beginning, is due to discontinuity generated by variable initialization and should not be considered.As explained in the previous section, the error curve is shown in absolute value.
The behavior of the PID gains variations shows that the Fuzzy Logic was properly configured as in the beginning when the error exhibits large values, the derivative gain has lower values but increases every time the error is approaching the setpoint.In addition, the derivative gain tends to reduce even more if the derivative of the error is negative, meaning that the UAV is progressing correctly.The integral gain tended to increase if there is an error for a long time, being smoothly reduced if the UAV is around the setpoint for some time.Regarding the proportional gain, it is possible to observe that it is basically directly following the error.
A fact that deserves to be highlighted in the graphs in Figure 11b are the oscillatory behaviors of the P, I and D gain estimates.These behaviors are probably caused by the measurement of the error derivative illustrated in Figure 12a, and are also propagated to the velocity command represented in Figure 12a.Although this type of oscillatory behavior is undesirable, it did not affect the actual measured velocity (Figure 12b).However, the issue regarding the chattering mitigation needs to be further investigated in future work.Finally, the commanded velocity and the measured velocity can be compared in Figure 12.The sample times are different because the commands are sent at a rate 2.5 times superior than the measurements.Therefore, the graphs have the same time range in seconds.
It can be observed that the actual measured velocity of the UAV does not reach the commanded velocity.That happens because new commanded velocities are sent before the UAV can reach the previously sent one.In addition, the UAV has a limited maximum velocity, which was set to 3 m/s.Therefore, if the Fuzzy logic Cascaded-PID calculates a commanded velocity larger than 3 m/s, as it happened in the beginning as the UAV was steady and the error was big, the UAV is not able to immediately reach that velocity because of inertia.
In another perspective, in Figure 13, the proposed method is compared to fixed PID gains using the mean values of the Fuzzy Logic gains.This clarifies the importance of the adaptive controller for such purposes, while the mean values of fuzzy gains present still reasonable results, the variation of the fuzzy gains shows a smaller overshoot on the first attempt to stabilize, oscillates less than the mean-gains approach, and achieve the desired position in X axis before than the mean-values method.Still compared to a the method using fuzzy gains' mean values, the accumulated position error in X axis is slightly smaller for the proposed method at the end of the experimentation in Figure 14.The accumulated error from the proposed method is greater than the mean-values method only near 7 s, where it is trying to stabilize for the last time, with no further oscillations, while the mean-values method oscillates and thus briefly achieves the objective position.Finally, a last simulation was performed, when a wind of 15 m per second was introduced.The results can be seen in Figure 15.It is possible to observe that the proposed method has a better performance than the approach using only the mean values.In addition, it achieves nearly the same time of accommodation than the Ardupilot solution, with faster convergence.

Altitude Control Tests in Real Flight
In the real implementation, the multirotor Parot bebop 2 was used.This UAV is shown in Figure 16.Its system provides a compatible network interface for ROS, by furnishing the required sensor information as well as the control interface.Any other compatible UAV can also be used, replacing only the proper interfaces.
Only height control is used in the test, while the original FMU algorithm still handles stabilization and position control.This ensures safety once the UAV is stable and locked into position.Figure 17 shows the UAV flight on a blue screen room during the test.In order to avoid discontinuous movements, the method was tested using ramp profiles from one altitude setpoint to the next one.Figure 18 shows the control signal and the error measurements.The dotted line represents the overall behavior of the control signal that is applied in discrete time instants.Note that the error has a well-behaved time profile.The slightly oscillatory behavior is due to the effects of environmental conditions.The control PID gains estimated by the proposed fuzzy algorithm are shown in Figure 19.Their performances are within the expected patterns.It is also noticeable that the derivative estimation changes were more aggressive than the other two.

Discussion
In the literature, most of the Fuzzy Logic tuning solutions have rules defining the PID gains (K P , K D , and K I ) based on the output error and its time derivative.In this work, however, the absolute value of the output error is used to generate the Fuzzy rules.With this strategy, the deviation between the desired and current UAV position always assumes positive or null values, which facilitates the definition of "low", "medium" and "high" levels for the fuzzy algorithm.In the literature, it is common to find the same definitions of such levels for both the positive and negative excursions of the error time derivative, which is the same strategy adopted in fuzzy rules proposed in this work.Based on the observations made on the results obtained, we emphasize that the definition of different rules for the negative and positive excursions of the error derivative seems to influence the performance of the closed-loop and that, therefore, it should be an issue to be investigated in a future work.
In addition, one of the main challenges when using Fuzzy Logic for PID online tuning is to define a proper range of K P , K D , and K I values.This work presents a method for defining a proper range for the horizontal motion PID gains specifically applied to UAVs based on the existing literature and with a novel modification that smooths the behavior.Regarding the altitude controller, the range of PID gains was chosen empirically.Similar tuning methods could have been used for this purpose, such as the Ziegler-Nichols ultimate gain and oscillation period method, or some variant tuning scheme as fast as the Zhao/Larson method, but with better settling time.
Regarding the results, some oscillations were verified on the commanded PID gains, which may be due to different rates among the different systems (ROS, FMU, MAT-LAB/Simulink).This affected the commanded velocity but did not affect the actual measured velocity.The MATLAB/Simulink was used for this solution's proof of concept version, and the Fuzzy Logic algorithm should be embedded in the ROS Python or C++ scripts in future work.By doing so, we expect to achieve a faster and more synchronized system.
In terms of evaluation, this research work opens up several future possibilities.For instance, it is expected the deployment of this method in a real UAV inspection mission.

Figure 1 .
Figure 1.Scheme of fuzzy addition to the PID controller.

Figure 4 .
Figure 4. Simulink model for the fuzzy controller.

Figure 6 .
Figure 6.Simulation Environment provided by the software Unreal Engine 4 with AirSim.

Figure 9 .
Figure 9. Absolute Error comparison between ArduPilot and the proposed method.

Figure 10 .
Figure 10.Accumulated Error comparison between ArduPilot and the proposed method.

Figure 13 .
Figure 13.Comparison between the proposed method and using the mean values of the fuzzy logic gains.

Figure 14 .
Figure 14.Accumulated Error comparison between the proposed method and using the mean values of the fuzzy logic gains.

Figure 15 .
Figure 15.Comparison among different methods in the presence of 15 m/s wind to the West.

Figure 17 .
Figure 17.The UAV height control flight test.

Figure 18 .
Figure 18.Control signal and error during the experimental trial.

Figure 19 .
Figure 19.Individual control response during the experiment.