# PID Controllers

RigidChips :: Rigid-Chips :: Tutorials :: Request a Tutorial

## PID Controllers

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

Fred

**fredsmith**- Hover
- Posts : 109

Join date : 2011-01-19

Location : Nowhere and everywhere.

## Re: PID Controllers

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

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

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:

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

Finally, to combine all these terms together, we have

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

I hope this helps!

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`

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`

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`

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)`

I hope this helps!

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

_________________

A.K.A. Bernard

**bwansy**- Admin
- Posts : 170

Join date : 2010-07-15

## Re: PID Controllers

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

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

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

**fredsmith**- Hover
- Posts : 109

Join date : 2011-01-19

Location : Nowhere and everywhere.

Similar topics

» All these controllers! to play MH3U

» Scuf Custom Controllers

» Introducing the Dual Shock 4!

» Using a controller to play Crusade

» Day/Night Controller

» Scuf Custom Controllers

» Introducing the Dual Shock 4!

» Using a controller to play Crusade

» Day/Night Controller

RigidChips :: Rigid-Chips :: Tutorials :: Request a Tutorial

Page

**1**of**1****Permissions in this forum:**

**cannot**reply to topics in this forum