Edited for clarity and organization: September 30, 2011

This discussion goes over the various tips I've picked up going over tuning PID and FLC (fuzzy logic) controllers for a quadrotor device.

**Controller Essentials:**

Regardless of which type of controller your using, you MUST use some sort of algorithm that will limit how fast the quad will turn! This will give the slower angle error controller a chance to stabelize the craft.

That being said, something like a PD can be used, or a combination PI + d(PI), in which another PI is used to control the angle rate. FLC's may be able to operate by claculating the difference between the current error signal and the previous error signal, but this has its own quirks...

**PID Tuning:**

After trying to help someone that goes by Chris here with his quad, I came across a tuning method for PID's:

- Set your quad up onto some sort of test rig, so that it can only tilt in one direction. Depending on the software used, you might be able to do this just once and be done with it, or you might have to change the orientation of the Quad and tune all three axiis.

- Determine a PD combination for Kp and Kd (with Ki zero'd) that gives you an acceptable rate to an abrupt change in angle. You can simulate this on your quad by giving it a sharp tap on one end (don't put alot of force into it, just enough to make it tilt quickly).

- Determine a PI combination (keep the same P used in PD) for Kp and Ki (with Kd zero'd) that gives you an acceptable steady state error. This error is basically the mathematical difference between the desired final value (0 degrees for our testing) and what the craft actually achieves.

- Combine the constants used for the PD and PI using the following math formulas:

Eq_PD * Eq_PI = P^2 * (s + D) * (s + I) / s

= P^2 * (s^2 + (I + D)s + (I * D) ) / s

comparing this to Eq_PID gives:

Kd = P^2;

Kp = P^2 * (I + D);

Ki = P^2 * I * D;

Where P is the Kp for your PD and PI combinations, I is the Ki for your PI combination, and D is the Kd for your PD combination. You'll have to disable the D and I terms (set 'em to zero) and find a P that will give you an underdamped response... in other words the oscillations will eventually die down.

The Kd, Kp, and Ki in the last three equations will be (or really close to) what values you need.

*NOTE: I haven't been able to verify these equations yet, so use at your own risk!!!1*

* *

* *

**Fuzzy Logic Controller Essentials:**

If you didn't know this already, there are two common type of FLC's: Mamdani and Sugeno.

Mamdani types are the "standard" FLC's, in which they have membership shapes for both their input and output. De-fuzzification of the output fuzzy variables are done by using a center-of gravity method.

Sugeno types are the "simplified" FLC's, in which they only have membership shapes for the input. The output fuzzy variables are represented as singletons, and defuzzification is done by a much simplier weighted average method.

- Sugeno types are less-intuitive than Mamdani types, since the output fuzzy variables are "partially" defuzzified to a degree.

- Sugeno output curves are very relient upon the input membership shapes. Piece-wise linear memberships (particularely trapazoids) leave "ledges" near their centroid, which can effect calculations. This can be partially mitigated by using non-linear memberships such as gaussian curves.

** **

**FLC Tuning:**

Depending on your setup, the FLC may be tuned just like a PID system by starting off with 3-triangles per compensator.

- Essentially, modifiy the output "gain" until the craft's oscillations no longer grows, but does not decay.

- Then, gradually transition from triangle functions to trapazoids (or gaussian if applicable) by keeping the outside shapes as triangles.

- Add more shapes to the functions as needed.

- If your using Sugeno type FLC's remember that your output shape is sensitive to ledges. Ideally, you'd want only one significant ledge around the 0 change area.

*NOTE: I'm in the process of verifying this method, so I'll let you know of any changes.*

## Replies

Original Post (July 26, 2011 at 10:05pm):

After a great deal of frustration, numerious "small modifications" to the operating code, and an improvement to the frame, I've managed to get it to stablize.

Code Problems:

Hardware Problems:

Currently, I've come up with a P gain of 0.1, which is the smallest I can go (for a range of -10 to +10 degrees, this means that the throttle range is -1 to 1us !). Suprisingly, the craft can slowly achieve stability given good conditions.

I'm going to take a break from working on the control system, and maybe work a bit on getting the communications to the ground station done.

I've got a bit more info about Fuzzy logic system design:

There are two main types of fuzzy logic control systems: Mamdani and Sugeno.

Sugeno systems differ from Mamdani in that they use singletons instead of shapes for their output variables. The defuzzification of the variables is simplified from finding the centroid of shapes to finding the weighted average of the singletons.

A rule of thumb for designing and tuning Sugeno systems (that I've come across so far) is to keep in mind what kind of curve your output should resemble and what order it is.

Straight lines (with a non-zero slope) are first-order, Parabolas are second-order, X^3 curves are third-order, etc.

The number of singletons should be 1 more than the order of the curve you want, so if you want a parabolic curve, then you'll need 3 singletons, if you want an X^3 curve then you'll need 4 singletons, etc.

You can have any number of singletons you wish, but keep in mind that if you have too many then you'll end up with an output curve that has "ledges" on them near the singleton positions.

Once you've figured out what the order of the curve you want to try out, you can then proceed to making the rules, since you've settled on the number of singletons/output variables.

--As always, if anyone feels I've mucked up somewhere or have some helpful advice, feel free to reply