# PID Controller

For the purpose of completeness, we provide a brief description of PID Controller.&#x20;

In the time domain, a PID controller has the following equation:

$$
u(t) = K\_pe(t) +K\_I\int\_0^{t}e(\tau)d\tau + K\_D\dot{e}(t)
$$

where $$K\_p$$, $$K\_I$$, and $$K\_D$$ are parameters for proportional control, integral control, and derivative control respectively.

In the state domain, a PID controller has the following transfer function:

$$
H(s) = K\_P+\frac{K\_I}{s} + K\_D s
$$

This is a direct application of the Laplace transform&#x20;

The integral control helps to remove the steady state error; the combination of integral and derivative control helps to reduce the overshoot and improve the transient response to make it faster. There is a very nice video (<https://www.youtube.com/watch?v=XfAt6hNV8XM>) that explains the intuition behind these terms.

The general idea is the following: suppose we want to track a variable, say a car. By tracking, it means we drive side-by-side with the tracked car. Initially, we are behind, in this case, the error is the distance between our car and the tracked car. The proportional term means if the distance is long, we should make more effort (i.e. press the gas pedal more). Imaging we are able to reduce the distance. This means our car is driving faster than the tracked car. At the moment when we catch up the tracked car, the distance is zero, which means the error is zero. At this particular moment, we are not making effort. However, during the catch-up process, our car drives faster. The speed of the car is continuouse so even if we stop making efforts anymore, our car is still faster than the tracked car, which means it will go beyond the tracked car. This is overshoot. To deal with the overshot, a derivative term is added as an offset. In our case, as the distance is reduced, we should make less efforts. The integral term is used to improve the control in steady state. For example, based on the distance, we apply the proportional control, this may make our car drive at the exact same speed as the tracked car. In this case, there is no change in the distance between the two cars so the derivative term is zero and the two-car system is in a steady state and the distance will remain the same forever. The intergral control term represents the accumulation of the error. In our example, the distance and the error remain constant and the error is accumulated. Thus the integral term will instruct the car to be faster and make it escape the steady state.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.learnros2.com/control-of-dynamic-systems/pid-controller.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
