Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding PID controller Chapter. #346

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Gathros
Copy link
Contributor

@Gathros Gathros commented Aug 8, 2018

No description provided.

@Gathros Gathros added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) Chapter This provides a new chapter. (md files are edited) labels Aug 8, 2018
#Proportional-Integral-Derivative Controller

You are a helmsmen keeping a vessel on course in various conditions, how do you do that.
A common way is to steer based on current course error, past error and the current rate of change.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going for an analogy, I would love to see this sentence expanded to a paragraph. Something like: you are aiming towards the lighthouse, but you are 4 degrees to the left, that is your current error and you need to correct that. You're been zig zagging left and right for the past 10 minutes, you should fix that too. You also notice that steering has become hard and harder, maybe you've hit a new current? Taking all this information into account, you can correct your course to have a smooth trip, just like you father taught you, just like his father taught him.

Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just my thoughts (and typos), not a real review. I would love to see graphs of the corrections with coefficients too big, too small and just right. I think that could help.


Where $K_{p}$ is a constant and $e(t)$ is the current error.
The performance of the controller improves with larger $K_{p}$;
if $K_{p}$ is too high then when the error is too high, the system becomes unstable, i.e. the rc car drives in a circle.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it zig zag out of control?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is also not clear to me. I would be expecting an instability like what we see with euler methods. Also: what if K is a function of the error? Is this common practice?


## The Algorithm

Luckily the algorithm is very simple, You just need to make the PID equation decrete.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decrete => discrete

$$ U = K_{p} e(t) + K_{i} \int_{0}^{t} e(x) dx + K_{d} \frac{de(t)}{dt} $$

To use a PID controller, you need to tune it, by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, and more.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to see one of those method expanded later, I've tried to make a PID controlled segway-type device using an arduino once, but I could never quite get the constants right manually.

To use a PID controller, you need to tune it, by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, and more.

The uses of PID controllers are thoreticaly any process which has mesurable output and a known ideal output,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoreticaly => theoretically

Copy link
Contributor

@zsparal zsparal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I caught all the grammatical errors, but I listed a few. I'm also a little unsure about the text itself: it sounds pretty foreign in places.

I mentioned it in a few cases but there are a bunch more where I didn't have the time to come up with a better sounding alternative.

The PID controller is in three parts proportional controller, integral controller, and derivative controller.

Before we get into how a PID controller works, we need a good example to use to explain how it work.
Imagine you are making a self driving rc car that drives on a line, how wuld make it work given that the car moves with a constent speed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self driving -> self-driving
rc -> RC
wuld -> would
constent -> constant

The proportional-integral-derivative controller (PID controller) is a control loop feedback mechanism, used for continuously modulated control.
The PID controller is in three parts proportional controller, integral controller, and derivative controller.

Before we get into how a PID controller works, we need a good example to use to explain how it work.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence sounds pretty strange. The repetition (how a PID controller works ... explain how it works) could use a little work.

#Proportional-Integral-Derivative Controller

The proportional-integral-derivative controller (PID controller) is a control loop feedback mechanism, used for continuously modulated control.
The PID controller is in three parts proportional controller, integral controller, and derivative controller.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would sounds better as: The PID controller is comprised of three parts: proportional controller, integral controller, and derivative controller


### Proportional Controller

If the car is too far to the right then you would turn left and visa versa.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visa versa -> vice versa

### Proportional Controller

If the car is too far to the right then you would turn left and visa versa.
Since there is a range of angles you can turn the wheel, you can turn with proportion to how far you are from the line.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the biggest fan of this sentence either. The Since there is a range of angles... part sets up an explanation that's pretty much never expanded on.

Something like You can turn the wheel proportional to how far you are from the line. In fact, this is exactly what the proportional controller does. The formula describing its behavior is given by: would sound better I think.

Even if you leave the current version:
with proportion to -> proportional to


$$ U = K_{p} e(t) + K_{i} \int_{0}^{t} e(x) dx + K_{d} \frac{de(t)}{dt} $$

To use a PID controller, you need to tune it, by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tune it, -> tune it (it doesn't need the comma)

To use a PID controller, you need to tune it, by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, and more.

The uses of PID controllers are theoretically any process which has mesurable output and a known ideal output,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mesurable -> measurable

There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, and more.

The uses of PID controllers are theoretically any process which has mesurable output and a known ideal output,
but controllers are used mainly for regulating temperature, pressure, force, flow rate, feed rate, speed, and more.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speed, and more -> speed and more


## The Algorithm

Luckily the algorithm is very simple, You just need to make the PID equation discrete.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You -> you

## The Algorithm

Luckily the algorithm is very simple, You just need to make the PID equation discrete.
Thus, the equation looks like this,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this, -> this:

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noted everything I thought was odd about the text, but haven't yet gotten to the code. Overall, I am happy with its addition to the AAA.

After these revisions are done, there will be at least one more review. The car analogy works, well, but it's a bit there's a sentence missing somewhere that I cannot quite figure out to make it flow with the rest of the text.

@@ -0,0 +1,84 @@
#Proportional-Integral-Derivative Controller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does there need to be a space here?

# Proportional-Integral-Derivative Controller

@@ -0,0 +1,84 @@
#Proportional-Integral-Derivative Controller

The proportional-integral-derivative controller (PID controller) is a control loop feedback mechanism, used for continuously modulated control.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Proportional-Integral-Derivative controller (PID controller)

capitalize PID because the acronym follows


### Proportional Controller

If the car is too far to the right then you would turn left and vice versa.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would -> should

### Proportional Controller

If the car is too far to the right then you would turn left and vice versa.
But there are a range of angles you can turn the wheel, so you can turn proportional to how far you are from the line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is a bit unclear to me and I don't like starting sentences with But. I think it might be clearer to say:

In this case, the amount of turning should be proportional to your distance from the line


$$ P = K_{p} e(t), $$

Where $K_{p}$ is a constant and $e(t)$ is the current error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the error defined? Is it the distance from the line?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$$e(t)$$ is canonically defined as $$setpoint(t) − measured_value(t)$$

### Integral Controller

I looks like we are done, we start driving but if some wind starts pushing the car then we get a constant error.
We need to know if we are spending too long on one side and account for that.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To correct this error, we need...

The way to do that is to sum up all the errors and multiply it by a constant.
This is what the integral controller (I controller) does, which is given by,

$$ I = K_{i} \int_{0}^{t} e(x) dx, $$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a different e? Its dependent on position instead of time. Maybe it would be nice to create three separate errors e_P, e_D and e_I so we can differentiate?

Also, is the integral going from 0 -> t but in terms of dx?


### Proportional-Integral-Derivative Controller

The PID controller is just a sum of all there three constrollers, of the form,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PID controller is just a sum of all three controllers and is of the form,


To use a PID controller, you need to tune it by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
If you choose the parameters for your PID controller incorrectly, the output will be unstable, i.e., the output diverges.
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, and Åström-Hägglund.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these be covered? If so, leave a note.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't algorithms it's just done by hand so I don't imagine there being a chapter on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, then for completeness we might want to differentiate these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are mentioned, they should be described. You can add a simple list with all of them and how they are differentiated from each other.

It might be worth adding a separate heading for tuning and discussing these in-turn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, it would be nice to have citations for all of these with bibtex-cite

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you cite?

Copy link
Member

@leios leios Dec 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the appropriate bibtex citation in the literature.bib file at the start of the directory, then put {{ "ct1965" | cite } where you want to cite it and add a

### Bibliography

{% references %} {% endreferences %}

at the bottom

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, Thanks.

If you choose the parameters for your PID controller incorrectly, the output will be unstable, i.e., the output diverges.
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, and Åström-Hägglund.

The uses of PID controllers are theoretically any process which has measurable output and a known ideal output,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theoretically, PID controllers can be used for any process with a measurable output and a known ideal output,

@leios
Copy link
Member

leios commented Aug 21, 2018

I am sorry it's taking me so long to get to this. It's mostly there. I'll look over the text once more and check out the code next.

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall positive changes. There is still some work to do, though. The code is readable and there are only a few minor corrections to the text, mainly a differentiation between Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, and Åström-Hägglund tuning methods.

The PID controller is comprised of three parts: proportional controller, integral controller, and derivative controller.

Before we get into how a PID controller works, we need a good example to explain things.
Imagine you are making a self-driving RC car that drives on a line, how would make it work given that the car moves with a constant speed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean "how would make it work"? Do you mean: "how would we keep the car on the line"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I mean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant this as a fix. The sentence doesn't currently make sense.

### Proportional Controller

If the car is too far to the right then you should turn left and vice versa.
Since there are a range of angles you can turn the wheel, so you should turn proportional to the distance from the line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are a range of angles you can turn the wheel, so you should turn proportional to the distance from the line.

contents/pid_controller/pid_controller.md Show resolved Hide resolved
Where $K_{p}$ is a constant and $e(t)$ is the current distance from the line, which is called the error.
The performance of the controller improves with larger $K_{p}$;
if $K_{p}$ is too high then when the error is too high, the system becomes unstable.
In this case, the car would turn in circles, since there is a maximum angle the wheel can turn, else it would zig zag around the line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence feels weird. Maybe:

In this case, the car would turn in circles because there is a maximum angle the wheel can turn, otherwise it would zig zag around the line.

Where $K_{d}$ is a constant.
If $K_{d}$ is too high then the system is overdamped, i.e. the car takes too long to get back on track.
If it's too low the system is underdamped, i.e. the car oscillates around the line.
When the car is getting back on track quickly with little to no oscillations then the system is called critically damped.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the car returns to the track quickly...

### Integral Controller

The Proportional and Derivative controllers are robust enough to get the on course.
We start driving, but then some wind starts pushing the car which introduces a constant error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe combine these two sentences?

The Proportional and Derivative controllers are robust enough to get the on course, but what if some wind starts pushing the car and introduces a constant error?

The Proportional and Derivative controllers are robust enough to get the on course.
We start driving, but then some wind starts pushing the car which introduces a constant error.
We need to know if we are spending too long on one side and account for that.
The way to do that is to sum up all the errors and multiply it by a constant.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

Well, we would need to know if we are spending too long on one side and account for that, and we can figure that out by summing up all the errors and multiply it by a constant.


## Example Code

This example is not calculating the time elapsed, instead it is setting a value called dt.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear from the code what this example is supposed to output or do, in general.

I just need a clear description of what this example code is trying to do. I am having a little trouble figuring out what the code is supposed to be doing, but I think it's a 1D analog to the car example, right? We are trying to keep the car on setpoint?

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more suggestions

The PID controller is comprised of three parts: proportional controller, integral controller, and derivative controller.

Before we get into how a PID controller works, we need a good example to explain things.
Imagine you are making a self-driving RC car that drives on a line, how would make the car stay on track given that it moves with a constant speed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence still doesn't make sense. Maybe:

Imagine you are making a self-driving RC car that drives on a line, how could we keep the car on track if it moves with a constant speed?


Before we get into how a PID controller works, we need a good example to explain things.
Imagine you are making a self-driving RC car that drives on a line, how would make the car stay on track given that it moves with a constant speed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a sentence here like:

This could be done with a PID controller, which is a combination of Proportional, Integral, and Derivative (PID) controllers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer introducing it over time, to make it easier to follow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My argument was that it was not followable without a transitional sentence.


### Proportional Controller

If the car is too far to the right then you should turn left and vice versa.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think sticking to "we" instead of "you" makes sense, but that's personal preference. Maybe something like:

Imagine our RC car is moving too far to the right, in this case it makes sense to turn left.


### Derivative Controller

The P controller works well but it has the added problem of overshooting a lot, we need to dampen these oscillations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the P controller really provide an oscillation? It seems like just an overshooting, right? If that's the case, it makes more sense to say "dampen this motion" then "dampen these oscillations"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P controllers may over shoot then it will start to oscillate around the track. So you're dampening this oscillation not the motion of the car.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me how we can model the error in the P controller as an oscillation. Again, an animation or some depiction could help here.

### Integral Controller

The Proportional and Derivative controllers are robust enough to keep on course, but what if some wind starts pushing the car and introducing a constant error?
Well, we would need to know if we are spending too long on one side and account for it, we can figure it out by summing up all the errors and multiply it by a constant.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we would need to know if we are spending too long on one side to account for it, and we can figure it out by summing up all the errors and multiply it by a constant.


To use a PID controller, you need to tune it by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
If you choose the parameters for your PID controller incorrectly, the output will be unstable, i.e., the output diverges.
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, and Åström-Hägglund.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are mentioned, they should be described. You can add a simple list with all of them and how they are differentiated from each other.

It might be worth adding a separate heading for tuning and discussing these in-turn.

## Example Code

The example code is of a 1-dimensional RC car that is trying to change from the first lane to the second lane, where the numbers represent the center of the lane.
This example is we can't calculate the time elapsed, instead we are setting a value called dt for time elapsed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is unclear. Did you mean:

In this example, we can't calculate the time elapsed, so we are instead setting a value called dt for time elapsed.

In this case, why are we using dt instead of time or some other parameter? dt always describes the size of a timestep, not the time, itself.

If the normal case is to calculate time, as indicated in line 10 of the code, why do we provide an example that doesn't do this? What is the point in the time parameter to begin with? Is it for dynamic timestepping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The I and D controllers use the time parameter for calculating integration and differentiation.


## Example Code

The example code is of a 1-dimensional RC car that is trying to change from the first lane to the second lane, where the numbers represent the center of the lane.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need some more information here or in the code because it's unclear. What does setpoint mean? "where the numbers represent the center of the lane" is really vague. What does that mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you want me to write there, I can't make it more clear.

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We need to add in the license at the bottom of the chapter:
## License
The text of this of this chapter is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode) with attribution to Gathros.
The code examples are licensed under the MIT license (found in LICENSE.md).

[<p><img  class="center" src="../cc/CC-BY-SA_icon.svg" /></p>](https://creativecommons.org/licenses/by-sa/4.0/)

I cannot approve this fully until until #560 is merged

  1. For each of the 3 controllers, it makes sense to have a quick animation of a car moving on a dotted line to show what the controllers are actually doing. I can make these, if you want.

Ultimately, it's pretty close to being completed, just a few graphics and citations.

@@ -0,0 +1,86 @@
# Proportional-Integral-Derivative Controller
Written by Gathros
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want to remove this now that we have the license at the bottom? I 'm actually not sure about this, though, so I'm happy leaving a note on authorship at the top too.

Written by Gathros

The Proportional-Integral-Derivative controller (PID controller) is a control loop feedback mechanism, used for continuously modulated control.
The PID controller is comprised of three parts: proportional controller, integral controller, and derivative controller.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I might do something like this:

The PID controller has three components:

  1. proportional controller: quick description
  2. integral controler: quick description
  3. derivative controller: quick description

The PID controller is comprised of three parts: proportional controller, integral controller, and derivative controller.

Before we get into how a PID controller works, we need a good example to explain things.
Imagine you are making a self-driving RC car that drives on a line, how could we keep the car on track if it moves with a constant speed?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add

For the following sections, imagine you are designing a self-driving RC car that tries to remain on a line...

(or something similar)


### Proportional Controller

Imagine our RC car is moving too far to the right, in this case it makes sense to turn left.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine our RC car is moving too far to the right of the line, in this case it makes sense to turn left.

Where $K_{p}$ is a constant and $e(t)$ is the current distance from the line, which is called the error.
The performance of the controller improves with larger $K_{p}$;
if $K_{p}$ is too high then when the error is too high, the system becomes unstable.
In this example, the car would turn in circles, since there is a maximum angle the wheel can turn, else it would zig zag around the line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have an animation to show these.

$$ I = K_{i} \int_{0}^{t} e(\uptau) d\uptau, $$

Where $K_{i}$ is a constant.
The peformance of the controller is better with higher $K_{i}$; but with higher $K_{i}$ it can introduce oscillations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, a side-by-side animation would do well here


The Proportional and Derivative controllers are robust enough to keep on course, but what if some wind starts pushing the car and introducing a constant error?
Well, we would need to know if we are spending too long on one side to account for it, and we can figure it out by summing up all the errors and multiply it by a constant.
This is what the integral controller (I controller) does, which is described by,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, no comma (I think)


### Proportional-Integral-Derivative Controller

The PID controller is just a sum of all three controllers and is of the form,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again no comma (I think)


To use a PID controller, you need to tune it by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
If you choose the parameters for your PID controller incorrectly, the output will be unstable, i.e., the output diverges.
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, and Åström-Hägglund.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, it would be nice to have citations for all of these with bibtex-cite

contents/pid_controller/pid_controller.md Show resolved Hide resolved
@Gathros Gathros changed the title Adding PID controller Chapter. Adding PID controller Chapter. WIP Dec 26, 2018
@Gathros Gathros changed the title Adding PID controller Chapter. WIP Adding PID controller Chapter. Dec 30, 2018
@Gathros
Copy link
Contributor Author

Gathros commented Dec 30, 2018

I, Gathros, the copyright holder of this work, irrevocably grant anyone the right to use this work, including derivatives created during the review process, under the Creative Commons Attribution ShareAlike 4.0 license (legal code).

(Anyone may use, share or remix this work, as long as they credit me and share any derivative work under this license.)

Copy link
Member

@leios leios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, good. Some of the suggestions were nitpicks, but others still need to be addressed from before.

The PID controller has three components: proportional controller, integral controller, and derivative controller.

Before we get into how a PID controller works, we need a good example to explain things.
For the following sections, imagine you are designing a self driving RC car that tries to remain on a line as it is moving with a constant speed. How would you keep it on course.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For the following sections, imagine you are designing a self driving RC car that tries to remain on a line as it is moving with a constant speed. How would you keep it on course.
For the following sections, imagine you are designing a self-driving RC car that tries to remain on a line as it is moving with a constant speed. How would you keep it on course?

### Proportional Controller

Imagine our RC car is too far to the right of the line, in this case it makes sense to turn left.
Since there are a range of angles you can turn the wheel, you should turn proportional to the distance from the line.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Since there are a range of angles you can turn the wheel, you should turn proportional to the distance from the line.
Since there are a range of angles you could turn the wheel by, it is unclear what strategy would work best to return the RC car to the line; however, it is clear that if the angle chosen is proportional to the distance from the line, the car will always be moving towards it.


$$ P = K_{p} e(t), $$

Where $K_{p}$ is a constant and $e(t)$ is the current distance from the line, which is called the error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Where $K_{p}$ is a constant and $e(t)$ is the current distance from the line, which is called the error.
Where $$K_{p}$$ is an arbitrary constant and $$e(t)$$ is the current distance from the line, which is called the error.

$$ P = K_{p} e(t), $$

Where $K_{p}$ is a constant and $e(t)$ is the current distance from the line, which is called the error.
The performance of the controller improves with larger $K_{p}$;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The performance of the controller improves with larger $K_{p}$;
The performance of the controller improves with larger $$K_{p}$$;


Where $K_{p}$ is a constant and $e(t)$ is the current distance from the line, which is called the error.
The performance of the controller improves with larger $K_{p}$;
if $K_{p}$ is too high then when the error is too high, the system becomes unstable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if $K_{p}$ is too high then when the error is too high, the system becomes unstable.
however, if $$K_{p}$$ and $$e(t)$$ are too high then the system becomes unstable.

Well, we would need to know if we are spending too long on one side to account for it, and we can figure it out by summing up all the displacements, usually refered to as errors, and multiply it by a constant.
This is what the integral controller (I controller) does, which is described by

$$ I = K_{i} \int_{0}^{t} e(\uptau) d\uptau, $$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\uptau doesn't seem to exist in mathjax, can we use tau?


$$ U = K_{p} e(t) + K_{i} \int_{0}^{t} e(x) dx + K_{d} \frac{de(t)}{dt} $$

To use a PID controller, you need to tune it by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To use a PID controller, you need to tune it by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
To use a PID controller, you need to tune it by setting the constants, $$K_{p}$$, $$K_{i}$$, and $$K_{d}$$.


To use a PID controller, you need to tune it by setting the constants, $K_{p}$, $K_{i}$, and $K_{d}$.
If you choose the parameters for your PID controller incorrectly, the output will be unstable, i.e., the output diverges.
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, and Åström-Hägglund.{{ "wikipid" | cite }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
There are multiple methods of tuning like, manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, and Åström-Hägglund.{{ "wikipid" | cite }}
There are multiple methods of tuning like manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, and Åström-Hägglund.{{ "wikipid" | cite }}
``

Comment on lines 73 to 75
### Bibliography

{% references %} {% endreferences %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to after the example code


{% references %} {% endreferences %}

## The Algorithm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## The Algorithm
## Putting it all together

@ntindle
Copy link
Member

ntindle commented Aug 28, 2021

[lang: c]

@github-actions github-actions bot added the lang: c C programming language label Aug 28, 2021
@leios
Copy link
Member

leios commented Nov 7, 2021

@Gathros It's been years. I really dropped the ball on chapter reviews, but I am making it a priority now and I promised you that your chapter would be the first one in, so would you mind either:

  1. Continuing with the PR
  2. Allowing me to either push to this branch or create a separate PR from this one with my own changes. Obviously, if I need to create a second PR, you will still be in the git history.

If I don't get a response, I will go ahead and start with 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Chapter This provides a new chapter. (md files are edited) Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) lang: c C programming language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants