3.3 Quaternion Error Implementation
4.1.2 PID Gain Tuning
Control gain tuning for PID controllers is typically done using programs like Mat- lab and Simulink in order to ensure that the final controller design meets performance specifications like rise time, maximum overshoot and settling time requirements. How- ever, detailed knowledge of the plant is needed in order to do this type of analytical tuning. While this type of system identification and PID tuning has been used in previous transition-to-hover works, such as [14], to achieve good transitional and hover flight performance, the ArduPilot and ArduPlane firmware were designed for ”plug-and-play” style use with many different types of airframes without the need for advanced knowledge of the system dynamics. To honor the spirit of the ArduPilot project, and to hopefully make the newly created flight modes easy to use for the rest of the DIY Drones community, all gain tuning of the ArduPlane PID controllers was done based on flight tests and simulated flights using the trial and error method sug-
gested on the DIY Drones help site [12], which all ArduPilot users are encouraged to reference and is available to the general public. No system identification or analytical gain tuning methods were used to determine the any of the control gains used in the flights or simulations conducted for this thesis.
Thanks to the Mission Planner software and 3DR telemetry link that was installed on the plane, gain tuning could be done while the aircraft was still flying, that way the effects of gain changes could be seen immediately and compared to the original controller performance. The DIY Drones suggested gain tuning method is comprised of a few easy to follow steps, which are to be performed for each of the roll, pitch and yaw axes individually:
1. Before flight, set the derivative and integral gains for the desired axis to zero and set the proportional gain for that axis to a relatively low value like 0.10. 2. Once airborne and at a safe altitude, switch the autopilot into the STABILIZE
mode and use the transmitter to introduce small, quick disturbances to the control axis you are trying to tune and watch the response of the aircraft as it returns back to steady level flight.
3. Increase or decrease the proportional gain for the selected controller as needed until the aircraft responds to the pilot initiated disturbances quickly but with minimal overshoot and oscillations. It is acceptable for the airplane to not fully return to its initial attitude at this point so only increase the proportional gain to the point where a crisp response is created. The steady state error is addressed in the next step.
4. Increase the integral gain for the selected controller until the aircraft is able to recover from the user initiated disturbances and eliminates the steady state error in a timely manor (i.e. 0 degrees roll/pitch angle, or returns to the original
heading within one or two seconds). Typically the integrator gain value is no more than half the magnitude of the proportional gain. If the aircraft is never fully able to eliminate the steady state error is it because the default maximum integrator value of 5.0 is too low. Increase the Imax value until the steady state
error is eliminated completely.
5. Add small amounts of derivative gain to help smooth the control response and eliminate overshoot. Be cautious when adding derivative gain because too much can hurt the performance of the system since the discrete derivatives of the Euler angle errors can be affected by sensor noise. Typically a derivative gain value about 1/10 the magnitude of the proportional gain is sufficient.
During initial testing, this process was used to establish separate sets of control gains for level flight and hover flight. The reason for this was because the lack of airflow over the control surfaces during hover flight meant that the control surfaces needed much larger deflections to maintain the desired hover attitude compared to the deflections needed to maintain high speed level flight. While these separate sets of control gains did work well for their respective uses, they made using both level flight modes and hover flight modes in the same flight nearly impossible because uploading the lower magnitude flight gains meant that the controllers would not have enough control authority to maintain stable hover, while using the larger hover flight gains would cause large overshoot and oscillation problems when attempting to use the level flight modes like STABILIZE and FLY BY WIRE. As mentioned in the introduction, one of he main purposes of having a fixed-wing airplane that can hover is to take advantage of the increased speed and endurance while still having hover capabilities, so having an autopilot that can only autonomously control the airplane in either level or hover flight, and not both, defeats the purpose.
was to modify the ArduPlane firmware to have two instances of the PID controllers running: one with the smaller level flight gains, and one with the larger hover flight gains. These two PID controller sets would then hand off control of the airplane to one another depending on the current flight mode and aircraft orientation. This method would have required heavy modification of the ArduPlane firmware and would make the autopilot and Mission Planner setup process very difficult for normal users. Instead, a much simpler solution was found that produced comparable results to having two unique sets of control gains.
Upon further examination of the differences between the level flight gains and hover flight gains, it was discovered that the hover flight gains were all approximately proportional to their corresponding level flight gain values by the same scalar value. In other words, the proportional, integral and derivative gains used in hover flight were all about 5 times larger than their corresponding level flight gains. This made sense since the same tuning process was used to establish both sets of control gains. Since the speed scalar modification was already built in to the PID controllers to increase control surface deflections at lower speeds, it was easy to manually override the speed scalar value when the aircraft is hovering. The firmware was modified to increase the speed scalar to a value of 5.0, instead of its original maximum of 2.0 (as detailed in Section 4.1.1), once the aircraft reaches hover orientation (defined through testing as pitch ≥ 85 degrees). This modification made it so that the HOVER PID STEP and HOVER PID REF modes would start the transition-to-hover using the level flight control gains. As the airplane pitches up and slows down the speed scalar would gradually increase from 0.5 to 2.0. Then, once the pitch angle exceeded 85 degrees, the speed scalar would increase to 5.0 which gave the same effect as using the separately tuned set of hover flight control gains when hovering.
Using this method was especially effective for maintaining ease of use because it only requires that the pilot establish a single set of level flight gains when doing
the initial autopilot setup and calibration. Determining a unique set of hover flight gains that were capable of maintaining stable hover proved to be one of the most difficult parts of this thesis and required many flight tests to even reach a point where tuning for improved performance, instead of just tuning for successful hover, could even occur. In the event that another ArduPilot user attempts to use the new hover capabilities in a different airframe, the speed scalar override method will allow initial setup to only require establishing a set of level flight gains and then manually increasing the value of the hover speed scalar until stable hover can be maintained. Once that happens, small changes to the level flight gains can be made to improve both hover and level flight performance.
Level Flight Control Gains Control Axis kp ki kd Imax
Roll 0.15 0.02 0.01 10.0 Pitch 0.27 0.02 0.01 20.0 Yaw 0.35 0.04 0.01 20.0 Table 4.1: Level Flight PID Control Gains
Hover Flight Control Gains = Level Gains ∗ 5.0 Control Axis kss∗ kp kss∗ ki kss∗ kd Imax
Roll 0.75 0.10 0.05 10.0
Pitch 1.35 0.10 0.05 20.0
Yaw 1.75 0.20 0.05 20.0
Table 4.2: Hover Flight PID Control Gains
The final values of the level flight control gains used for the Carbon-Z Yak 54 airframe during all simulations and flight tests discussed in the results chapters of this thesis are presented in Table 4.1, and the equivalent hover flight control gains are presented in Table 4.2. It is important to note that only the proportional, integral and derivative gain values are affected by the speed scalar override. The integrator maximum values remain unchanged when in hover orientation.