# Optimal Control for a Three-Rotor Unmanned Aerial Vehicle in Programmed Flights
## 5 Conclusions  
The paper describes methods for selecting PID controller gains for controlling the height of a tricopter. A comparison of the IAE criterion shows that each of the four methods used: _fmincon_, _fminimax_, _lsqonlin_, _fminsearch_ selected better coefficients than the dedicated PID Tuner function [18]. The best function is _fminsearch_, and for further experiments, this method was used. The regulation was carried out for a larger number of controllers, gradually reaching the control of the tricopter flight, for real tasks that are often performed by unmanned aerial vehicles.  
A universal procedure for selecting PID controller gains using optimization methods, which can also be used for other mobile objects, has been presented. The weights were arbitrarily chosen to be able to compare the obtained gains resulting from optimization for both considered trajectories. This highlighted the discrepancies in the optimization of tricopter gains.  
The paper demonstrates that by knowing the conditions and trajectory, it is possible to select PID controller coefficients for a specific task using known optimization methods. The optimal coefficients differ depending on the established trajectory, and if the UAV is to be used for a repetitive mission, it is worth selecting specific controller gains for this task. It can also be noted that the UAV does not have to be launched precisely at the starting point of the trajectory, but when planning the trajectory, a reserve of engine power should be left. It is worth selecting weights appropriately for UAV parameters based on experience in flights on the object. The results were compared with analogous experiments obtained for ArduPilot flight controller settings. The settings were downloaded from the controller. Based on the individual simulation experiments, it was shown that better ones can replace the default settings. Updating them from the technical side of the controller only requires connecting it to a computer and saving the new settings. Optimizing the trajectory to the maximum exorbitant results involves operating close to the narrow stability margin. Care must be taken to set boundary conditions well, such as maximum swing angles. As shown, if the planned trajectory is changed, new coefficients should be adjusted so that the stability margin is not exceeded.  
This paper can be used by other researchers to select optimal PID controller gains for tricopter objects or by people using other types of UAVs for repetitive, programmed tasks.  
Figure 30: Tilt angle response.  
**Author Contributions:** Conceptualization, I.K.; methodology, I.K.; software, M.S.; validation, I.K. and M.S.; formal analysis, M.S. and I.K.; investigation, M.S.; resources, M.S. and I.K.; data curation, I.K. and M.S.; writing--original draft preparation, M.S.; writing--review and editing, I.K.; visualization, M.S.; supervision, I.K. All authors have read and agreed to the published version of the manuscript.  
**Funding:** This research received no external funding.  
**Institutional Review Board Statement:** Not applicable.  
**Informed Consent Statement:** Not applicable.  
**Data Availability Statement:** The datasets used and analyzed in this study are available from the corresponding author upon reasonable request. The data are not publicly available due to privacy.  
**Conflicts of Interest:** The authors declare no conflict of interest.