Go Down

Topic: Quadcopter stabilization algorithm (Read 21905 times) previous topic - next topic

kakou19

Hello everybody,

Im doing a quadcopter using Arduino, but I am stuck at the stabilization part.

I know that I have to something like this :

Pd - Pv  * coef - which Pd is the desired angle (0 for me so) and Pv the actual angle. I got the Yaw and Pitch thanks to MPU6050 so I managed to get the actual angle. But now I dont know how to convert this result to a motor power value...

If you could help me with this !

Thank you

PeterH


Im doing a quadcopter using Arduino, but I am stuck at the stabilization part.


Have you researched the control strategies used on other drones? I very much doubt that the simple proportional feedback algorithm you described will be sufficient.
I only provide help via the forum - please do not contact me for private consultancy.

kakou19

I know that other strategies use PID algorithm, but I dont find well explanation or implementation.

sbright33

I have a real simple solution I'm working on.  Will post some uncompiled pseudocode here later today if you'd like.  PID algorithms in the manufacturing process can be quite complex.  I believe this problem is simpler to solve.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

kg4wsv

Quote
PID algorithms in the manufacturing process can be quite complex.  I believe this problem is simpler to solve.


Please elaborate.

Around here (university engineering department that teaches controls) the consensus seems to be that PID is less effective than other control algorithms, but it is used because it is simpler (to implement and understand).

-j

sbright33

I see where I have misled you.  I am already using the KK board to control pitch and roll.  It is only $12.  KK v2.0 includes accelerometers to keep it level.  I agree with your statement.  I assert that P and I are all that is needed.  Each is only a few lines of code combined with my existing assembly code in the KK board.  The job of the KK board is to keep it stable in pitch, roll, and yaw.  It does nothing for altitude.  My code will keep the yaw from drifting using a magnetic compass.  It will keep the altitude constant when you enable it.  It will keep it in one position using GPS on top of the KK v2.0 leveling which does not take into account wind.  In the end I may decide to modify the assembly code on KK, but for now I'm going to intercept the PWM between the receiver and KK, and modify it with a few short lines of C.  One step at a time.  Let's start with the altitude.  Standby.  I'm going to rip out the important part from my testing code.  It's a work in progress.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

PeterH


Around here (university engineering department that teaches controls) the consensus seems to be that PID is less effective than other control algorithms, but it is used because it is simpler (to implement and understand).


PID can be applied to a wide variety of systems, and is conceptually simple. What 'other control algorithms' are you thinking of? The P, I and D elements each have a distinct purpose and are each simple to understand. P alone and P+I each represents subsets of the full PID which might work OK in specific situations, but if you omit the Integral term it may not converge on zero error, and if you omit the Derivative term it is liable to suffer from oscillations.
I only provide help via the forum - please do not contact me for private consultancy.

kakou19

Thank everybody for your answer.

Can you explain exactly how PID works or post some pseudo code please. Im a bit confused...


wildbill

No need for pseudocode - the PID library has the real thing and you can read about it here: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

kakou19

I have searched a long time for this kind of tutorial ... thank you so much !

kg4wsv

Quote
What 'other control algorithms' are you thinking of?


I think it was suggested sliding mode would be superior, but I've slept quite a few times since that discussion so I don't remember for sure.

-j

cr0sh


Can you explain exactly how PID works or post some pseudo code please. Im a bit confused...


If you really want to understand PID - I suggest that you take Udacity's CS373 class; in it, PID is described and implemented (in Python) in a way that makes it very clear how it works and why. This is only one small portion of the course, though; you can't just jump to that part and hope to understand it (unless you have a good grounding in the earlier parts of the course). Depending on your skill levels, the course may be considered from "easy" to "very difficult" (the latter being true if your understanding of linear algebra and probability/statistics is low to non-existant) - but in the end is well worth the struggle.

On a similar note:

Udacity recently announced that they have brought back the original AI course that Stanford ran last fall/winter (I am contemplating enrolling in it - I was in it last fall, and had to drop out halfway through due to personal issues - I am so glad they brought it back!)...
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

sbright33

#12
Nov 30, 2012, 06:48 pm Last Edit: Nov 30, 2012, 07:04 pm by sbright33 Reason: 1
Here's how simple it can be using all 3 P,I,D:

loop
 error = setpoint - measured_value
 integral = integral + error*dt
 derivative = (error - previous_error)/dt
 output = Kp*error + Ki*integral + Kd*derivative
 delay(dt)

While experimenting you can assign dt,gain to the value of R/C channel 5,6.
Let's start by controlling altitude only using the throttle channel, P term only:

void loop()
ft=get_altitude();
set_throttle((wasft-ft)*gain+wasthrottle);  //gain is Kp
wasft=ft;
delay(dt);

A few more lines gives us I term:
const int NZEROSLOW=3;
const int NZEROSTOP=15;

ft=get_altitude();
chg=wasft-ft;
if last is in correct direction toward setpoint and j-lastj > NZEROSLOW then chg=0;
set_throttle(chg*gain+wasthrottle);
if chg then
  last=chg;
  lastj=j';
j++;
delay(dt);

It's not perfect, oversimplified a bit to make it easier to understand.
Another improvement in case it's moving too slow, not near the setpoint:

if ft-setpoint > 10ft and j-lastj > NZEROSTOP then chg= toward setpoint;

You can use the same method for pitch, roll, yaw using magnetic compass and GPS to correct towards setpoint.

Simple?  Questions?  Improvement?  It works!

PS- Oh great library BTW!  It's not needed for my solution here.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

sbright33

Can you tell me why it won't work properly before I make these changes?
Ideas for improvement?
Thanks for taking the time to read it.
If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

jabbado


Ideas for improvement?

How are you measuring altitude, and what sort of accuracy in the altitude hold are you trying to achieve?

Go Up