RigidChips
Would you like to react to this message? Create an account in a few clicks or log in to continue.

PID Controllers

2 posters

Go down

PID Controllers Empty PID Controllers

Post by fredsmith Fri Jan 28, 2011 1:06 am

Would it be possible to have a tutorial explaining PID controllers, and how to use them in terms of RC (autopilot, hovers, etc)? In Lua, obviously. I got interested after I saw Juz talking about how he and Bwansy both use them regularly.

Fred
fredsmith
fredsmith
Hover
Hover

Posts : 109
Join date : 2011-01-19
Location : Nowhere and everywhere.

http://lmgtfy.com/?q=rigidchips

Back to top Go down

PID Controllers Empty Re: PID Controllers

Post by bwansy Sat Jan 29, 2011 10:32 am

PID stands for Proportional, Integral and Differential Controller. It is one of the most common and simple types of linear control systems. It's comprised of 3 elements, and yes, you've guessed it: the proportional term, the integral term, and the differential term. But what do they mean?

All control systems work according to an "error". Don't worry, it's not a programming error or something. This "error" is the difference between the actual and desired values of a state. This state can be position, velocity, or even temperature. The names of the three terms in the PID system simply describe their relationship with the error.

Let's take a one-dimensional hover, one that can only go up and down, as an example. We define the state to be its vertical position, hence the error would be the difference between the height at which we'd like it to hover at, and its current height. Let's call them Y0 and Y, and the error DY = Y-Y0. The first term, the proportional term, gives you a force proportional to DY. Numerically, we can express it as
Code:
P = -Kp*DY
where Kp is the "proportional constant. Looks familiar? Yes, it's the Hooke's law: F = -k*x. It acts exactly like a spring does: it gives a force proportional to, but in opposite direction as, the error.

But without friction, the spring would bounce up and down forever. To dampen the oscillation, we need the differential term. As the name suggests, it's proportional to the differential of the error. In this case, it would be the vertical velocity of the hover, VY. It tries to oppose the velocity to dissipate its energy. Therefore, we have:
Code:
D = -Kd*VY
where Kd is the "differential constant".

With these two terms combined, it's not hard to see that the output force would be zero when the hover is at the desired height while velocity is zero. It would say exactly there for ever and ever, right? Oh, am I missing something? Oh yes, it's gravity. It constantly tries to pull the hover down, so that the hover would always stay lower than our desired height. This is called "steady-state error", and it's obvious that it has a magnitude g/Kp. In the case of our hover, it's easy to eliminate this error by adding a constant force that negates gravity. But what if we're on a planet with unknown gravity? What if it's a more complex system where we don't know what other forces are there to bother us? In this case, we'd need the integral term. It is the integral of the error over time, and doesn't have much physical meaning. In a nutshell, it works like this: "Hmm, not quite there? Let me push a little harder. Not there yet? Just a little harder still." until the steady-state error becomes zero. Programming-wise, it looks something like this:
Code:
I = I+Ki*Dy
where Ki is the integral constant.

Finally, to combine all these terms together, we have
Code:
F = P+D+I

This system can be applied to any linear system, or those that are linear enough. This includes cruise control for cars and jets, and pitch/roll/yaw controls. In autopilot, you can either define the state be pitch/roll/yaw rates or elevation/bank angles. For jet cruise control, I found that it would work better if you do
Code:
JET = JET-Ki*(Kp*DV+Kd*AV)
, where DV is the difference in velocity and AV is the acceleration.

I hope this helps!


Last edited by bwansy on Sat Jan 29, 2011 11:08 pm; edited 1 time in total

bwansy
Admin

Posts : 170
Join date : 2010-07-15

https://rigidchips.forumotion.com

Back to top Go down

PID Controllers Empty Re: PID Controllers

Post by fredsmith Sat Jan 29, 2011 7:32 pm

Wow, thank you so much! That was very helpful, and now I understand it! Thanks again Wink

So... they're really useful in RC for different kinds of auto-control, I guess.
fredsmith
fredsmith
Hover
Hover

Posts : 109
Join date : 2011-01-19
Location : Nowhere and everywhere.

http://lmgtfy.com/?q=rigidchips

Back to top Go down

PID Controllers Empty Re: PID Controllers

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum