WARNING! There have been reports of certain PID values over saturating the motor outputs possibly causing a crash if not adjusted properly. Read our forum thread here. Let’s dive into the special set of PIDs available in AutoQuad. Since AQ is relatively a complicated system, it uses multiple PID loops to control your vehicle. Some of these loops are separate, and some are nested inside each other. There are basically two separate sets of PIDs, one dedicated to the attitude and the other to the navigation.
|Be aware that default values are suitable for most “normal” frames; you’ll probably just need a little bit of fine tuning. If your frame, however, has different structure, weight distribution, or unusual features -even small ones- that will require appropriate PID tuning. In any case, when adjusting any PID parameter, start with small increments/decrements, a 20%-30% of the current value.
This page will cover the Attitude PID controller
This set of PIDs control how your AutoQuad behaves on each of yaw, pitch and roll axes. It consists of two nested PID loops: the rate PID and the angle PID. The first (inner) loop controls the rate (speed) of change of the gyro signal. Its goal is to keep this rate of change at 0 radian/sec. When the rate of change (which is a derivative) is zero, this means the change is constant. The rate PID here aims to keep any gyro signal in a constant state, i.e., the gyro is not tilting, which gives your AQ its incredibly stable behavior! Note that this doesn’t mean the gyro output should be zero. It can be anything, but it should be constant with time. This gives your AQ the ability to balance itself at any given angle. The tilt rate PID controls the AQ’s pitch and roll stability, while the yaw rate PID controls the AQ’s yaw stability. Since gyro is highly sensitive to small movements and the multi copter is, by definition, a highly vibrating system, the tilt rate D value is chosen quiet large, shown in the next figure, in order to compensate for those vibrations.
|The rate angle controller only operates with a D term because the controller set point (command) is set at zero and the system changes are quiet fast.
To respond quickly enough to these changes, the rate PID loop is run at 400 Hz. Gyro signals are used directly without any mathematical filtering or correction which enables the system to achieve a quick dynamic behavior (meaning that AQ responds very quickly and actively to the R/C or autopilot commands). To guarantee not to amplify the noise signals with this high D value, the ARM Cortex-M4 MCU applies a tremendous oversampling (262.4 KHz) to the gyro signals. The yaw rate PID is a typical PID controller which is responsible of your AQ’s yaw orientation. Since vibrations don’t affect the yaw orientation that much, a relatively small value of D is chosen. Appropriate P and I values are chosen to achieve accurate and quick yaw lock. AutoQuad PID config screen in QGroundControl
The attitude rate PID generates required PWM width (in microseconds) to control the motors in order to achieve stability. PM, IM and DM limits the output of each PID term so that it doesn’t burn the motors or saturate the system. The OM parameter defines the maximum output from the rate controller, thus no matter how much you set the PID limits, the output won’t exceed OM value.
The F term is used to smooth out the D term. Since we have relatively large D value, it’s not practical to apply all that output to the motors in a small time step (1/400Hz = 2.5 milliseconds). The F term regulates how much of the D term is applied at each time step. In the above example, a value of 0.25 means only 25% of the D term is applied to the motors at each time step.
Attitude Angle PID
The second (outer) loop in the attitude control regulates the angle (in degrees) at which the AQ rotates on each of yaw (yaw angle PID), pitch and roll axes (tilt angle PID). This loops is run at 200Hz. Once again, a relatively large D value is used for tilt angle control while no D term at all is used in the yaw angle. The set point (angle) is either commanded directly from the user’s R/C input or from the navigation PID controllers (autopilot) or a combination of both depending on the operating mode at the time. Again, the output of this stage is R/C PWM pulse lengths measured in microseconds. The output of this PID is mathematically added to the output of the inner rate PID and both are sent to the motors and added with the current throttle setting at each time step. (Please add default settings here) So to think of it simply, the outer PID is constantly fighting to maintain a given angular set point and the inner PID is fighting for a zero change in rotation rate (but not necessarily a zero rotation.) Sometimes they are pushing or pulling together and sometime they are fighting each other. The result is a very fine control over the controller output which leads to a very stable platform when paired with high performance ESC’s.
Maximum tilt and roll.
AutoQuad is designed for stable flight and not acrobatic flight. The angular movements are limited to provide maximum stability. The default behavior will limit the angle to around 37 degrees. The max tilt (pitch) and roll angle is controlled by the these two parameters: CTRL_FACT_PITC 0.05f // user pitch multiplier CTRL_FACT_ROLL 0.05f // user roll multiplier They are multiplied by the elevator and roll channel data from the radio. So if you’re radio produces -750 to 750 output, your max tilt range will be +-37.5 degrees.
|While there is room for more tilt, be careful as you get to much higher values. This theory of operation breaks down as you approach the 90 deg singularities. For any accuracy over 45 deg on more than one axis, you will need to ditch the PID controller and go with something quaternion based