How are you??

Last year, i design a stabilization system for a 3d helicopter, using neuro-fuzzy systems, it worked great!!!

now, im designing a quadcopter, just like everyone else, hehehe, but with the same difference, its going to use fuzzy logic to stabilize itself...

My hardware is the next:

- Leaflabs Maple, Arm Cortex @ 72 mhz
- IMU razor 9DOF with the onboard atmega
- Hobbyking motors 30amps
- Hobbyking ESC 30amps
- Xbee pro 900mhz
- Aluminum for the chasis

My plan is to first stabilize one axis, and then go the other, thats why in the picture you can see "something" that is holding down the quad, in the other pic you can see the proud owner, hehehehe

Im using a sugeno inference system, because it requires less computation power than a mandami.

I got 5 membership functions, gaussians for more precise control.

Its a simple one input (angle) two outputs (motors) system.

Yesterday i started to test the stabilization system, but its not working nice... its oscillating, when i move the quad to angles more than -20 or 20 degrees, the control cant stabilize and the system oscillates...

Im using the Maple analogwrite feature for writing the pwm to the 2 motors, also im using the 400hz update rate, so it supose to be very fast and smooth...

You can see the videos in the next page:


You can see how it oscilates...

Im a little stuck, im thinking to implement a PID system to check is not the maple or the 400hz or another stuff, when i discart the hardware, then i will know that the problem is the fuzzy system, but im almost sure that the 5membership functions of the system is more than capable to do the stabilization task with no problems... so i dont really know what im doing wrong...

Anyone has a idea???



Views: 4052


Reply to This

Replies to This Discussion


Sorry if I fail to follow some of the social graces of posting stuff ..... I don't post very often.

I can't see the video .... all I get is single frames in the avi(s).

What do you have by the way of fuzzy logic?????

Sounds like you need more of something like this. (a fuzzy suggestion)

If the rotation around the axis is high towards the target and the target is close then slow the rotation down.


My guess is that the output for the "over 20 degrees" range is too much, and when the quad approaches the "Stable" area, the quad does not attempt to slow itself down and instead perpetuates.


How are you treating the output of the fuzzy compensator? are you saving the differences to an accumulator (think of a capacitor) first, or are you directly changing the output?


You may also need to add another set of input membership functions to handle rate error, or the rate the sensed angle is moving away or toward the desired angle.


I'm actually having a similar problem myself using fuzzy logic... but with a more 16-bit solution. Found out my test rig wanted to make the quad an inverted pendulum, so I can't tell if my problem is due to that or what your having (...or had).

Hi Allen,
Do you want to post some code or pseudo code?

Hey Lew,


Had a successful test run just a few minutes ago, the new deadweights moved the center of mass close enough to the test rig's pivot so that the controller can work now. Had a few moments where the thing got itself nice and level, but more tweaking is needed to make the operation smooth and steady.


As for the pseudo code.. well, the rule table itself is pretty straight forward, problem is adjusting the input and output membership distributions.


          EN2    EN1    EZ    EP1   EP2

ERN:  TP3     TP1    TP1    TZ    TN2

ERZ:   TP3    TP1     TZ     TN1   TN3

ERP:   TP2    TZ      TN1    TN1   TN3 


Uh, one of these days I need to learn how to do HTML tables..


Anyway, this form of a rule table is read by going through the rows and columns to find the output. All letters on the top row and leftmost column are accronyms for the membership names . For example, EN2 is Error Negative level 2, ERZ is Error Rate Zero, and EP2 is Error Positive level 2


The output fuzzy variables are in a similar fashaion, ex: TP2 is adjust Thrust by Positive level 2.


This is an And table, so you read it by doing so: If (error level) AND (error rate level) THEN (Output). Example:

    If EP2 And ERN Then output is TP3.


For those of you wondering "why the fudge would anybody want to do THAT??" I say, Fuzzy Logic controllers are far more mathmatically simpler and have the potential to execute far faster than traditional controllers such as PID, PD^2, and robust controllers. Additionally, they are "guess and check" friendly for any unknown system, and can control very high order systems with ease (and with fewer math).


Downside is... the membership functions can take a while to get properly set up, also some of the nicer membership functions (gausian) are too CPU hungry to use in formula form... but you can use a tabulation method if you really wanted gausian (trapazoid's and triangles do just fine).



Anyway, back to the rule table... my partner was the one who came up with that awhile back and I haven't had a chance till today to really test it out. And yes, the rule matrix should probably be a 5x5 square...



thanks for the replies!!

my stabilization system now works!! i add the angular rate to the equation... i have now a sugeno fuzzy system, with 2 inputs and 2 outputs, the inputs are the angle and the angular rate, with 25 rules... ill post a video as quickly as i can...


Hi Allen,

That all sounds right.

I am sure that a 5x5 matrix will do the trick.

Looks like Aldo has it sorted.

May I ask what board you are using?

I will be starting with a KK multicopter board (hobbyking version).


I am currently finishing an FPV plane.

Hi Aldo,

That's fantastic!

Can't wait to see the video.



Glad you got it to work! Any wobbles?

I'm using the MicroDragon board from EVBplus.com. It's just a pinout board for the Freescale MC9S12DG256 along with a crystal and other basic components to get it running. It doesn't have a voltage regulator... which is a good thing because you can make your own power board and use it off of almost any battery.


I chose the 9S12 chip because I knew a good portion of the assembler language for that chip, plus it has built-in support for fuzzy logic.

Why not use the BEC on your speed controller?

Your board needs a 5V VCC line so that should be a good fit.

If your going to add FPV later, just get a 5V camera and transmitter and you can run the whole lot from your BEC.

eg. TURNIGY Plush 12amp (2A BEC) BESC

The original MiniDragon board that I was using needed an input of 9 to 12V because its onboard regulator needed it. I didn't see any good way of bypassing it, so I just used a seperate 9V regulator to pass power to it.


When the new MicroDragon board was installed on the new quadrotor, I had forgotten that the ESC's can provide up to 2A with 5V. Since we're using 4 ESC's, the maximum 5V ampherage we can use would be 8A... way plenty for anything.


I'll have to look at that sometime later, thanks Lew!



Are your ESC's anything special?

I saw a video on youtube with a quad where the guy re-programed the esc's to have really fast responses. This helped with stability.

Reply to Discussion


© 2020   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service