Quadrotor Attitude Tuning : Fuzzy Logic and PID

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.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

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

    Hi all,

     

    My pet project for the past couple of months was to build the "AirDragon," a quadrotor helicraft built from scratch here at the University and uses affordable (ahem... cheap) as possible components.

     

    Currently I'm focused on getting the thing to level out stabily. I currently have problems with it overcompensating and oscillating on the test rig. Just Monday I figured out that the way I have the test rig set up, it put the center of mass of the quad above the test rig thus making it an inverted pendulum (very unstable).

     

    Wising up, I spent most of today reconfiguring the thing so I can at least put a couple of deadweights to temporarily bring the center of mass to exactly at or slightly below the test rig's pivot point. Well... it wasn't enough so I'll have to spend more time tomorrow working on it.

     

    I'm hoping that this overcompensation problem will be solved by the test rig alone, but Murphy's law dictates that it probably won't. As such, I'm looking for pointers as to how I should go about configuring the thing.

     

    Since most quad's out there use a PID type attitude compensator, I'd thought I ask how do some of you go about setting your Kp, Ki, and Kd?

     

     

    Drone Info:

    MCU   : "MicroDragon" pinout board. Features the Freescale MC9S12DG256

    ESCs  : BP Hobbies 18A. Auto-ranging. (Current version) uses ATmega8L and has a 16 MHz external clock(?)

    BLDCs : BP Hobbies A2212-13, 150W 13 Pole

    Prop's  : 10 x 4.x7 (for indoor use)

    Power  : E-flite 2200mAh, 30C (x2) 

  • 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:

    • Initially, my professor had suggested to integrate the output of the controller so as to get a smooth response. This turned out to be a bad idea, because it effectively made the controller into an I type, without any P or D.
    • After numerous combinations of sampling rates vs. control loop rates, I've settled on running the control loop the same speed as the sampling rate (110Hz). This resolves some issues with coupling the data to the control loop.
    • I've maxed the ESC's PWM frame rate to 400Hz. I thinking however that the ESC's may be able to go up to 475Hz, which will need some testing in the future.

    Hardware Problems:

    • The previous clamp-style hub was not a good idea, and it made construction of the frame difficult to do. A new threaded hub along with threaded arms allows the arms to be securely attached together at the fraction of the time needed before.
    • The test rig still poses a bit of a problem, because the center of mass is above the test rig's pivot point without using the counter masses.

     

    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

This reply was deleted.

Activity