Offline
Newbie
Karma: 0
Posts: 6
|
 |
« on: November 29, 2012, 08:19:59 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Milton Keynes UK
Offline
Tesla Member
Karma: 88
Posts: 6287
-
|
 |
« Reply #1 on: November 29, 2012, 09:06:40 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #2 on: November 29, 2012, 09:23:31 am » |
I know that other strategies use PID algorithm, but I dont find well explanation or implementation.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 4
Posts: 1126
If you're not living on the Edge, you're taking up too much space!
|
 |
« Reply #3 on: November 29, 2012, 10:34:23 am » |
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.
|
|
|
|
|
Logged
|
If you fall... I'll be there for you! -Floor
Skype Brighteyes3333 (262) 696-9619
|
|
|
|
0
Offline
Faraday Member
Karma: 6
Posts: 2504
|
 |
« Reply #4 on: November 29, 2012, 10:48:21 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 4
Posts: 1126
If you're not living on the Edge, you're taking up too much space!
|
 |
« Reply #5 on: November 29, 2012, 05:30:21 pm » |
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.
|
|
|
|
|
Logged
|
If you fall... I'll be there for you! -Floor
Skype Brighteyes3333 (262) 696-9619
|
|
|
|
Milton Keynes UK
Offline
Tesla Member
Karma: 88
Posts: 6287
-
|
 |
« Reply #6 on: November 29, 2012, 06:46:14 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #7 on: November 29, 2012, 07:42:11 pm » |
Thank everybody for your answer.
Can you explain exactly how PID works or post some pseudo code please. Im a bit confused...
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 6
|
 |
« Reply #9 on: November 29, 2012, 07:57:54 pm » |
I have searched a long time for this kind of tutorial ... thank you so much !
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Faraday Member
Karma: 6
Posts: 2504
|
 |
« Reply #10 on: November 29, 2012, 10:46:00 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Phoenix, Arizona USA
Offline
Faraday Member
Karma: 27
Posts: 5077
Where's the beer?
|
 |
« Reply #11 on: November 29, 2012, 10:58:18 pm » |
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!)...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 4
Posts: 1126
If you're not living on the Edge, you're taking up too much space!
|
 |
« Reply #12 on: November 30, 2012, 12:48:18 pm » |
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.
|
|
|
|
« Last Edit: November 30, 2012, 01:04:07 pm by sbright33 »
|
Logged
|
If you fall... I'll be there for you! -Floor
Skype Brighteyes3333 (262) 696-9619
|
|
|
|
Offline
Edison Member
Karma: 4
Posts: 1126
If you're not living on the Edge, you're taking up too much space!
|
 |
« Reply #13 on: December 01, 2012, 11:27:37 am » |
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.
|
|
|
|
|
Logged
|
If you fall... I'll be there for you! -Floor
Skype Brighteyes3333 (262) 696-9619
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 46
|
 |
« Reply #14 on: December 01, 2012, 06:09:22 pm » |
Ideas for improvement? How are you measuring altitude, and what sort of accuracy in the altitude hold are you trying to achieve?
|
|
|
|
|
Logged
|
|
|
|
|
|