Skip to content

Pid

PID Controller

The PID (Proportional-Integral-Derivative) controller is one of the most widely used feedback mechanisms in control systems and robotics. It operates based on the error, which is the difference between a desired setpoint and the actual output.

Equation

\(u(t) = K_p e(t) + K_i \int_{0}^{t} e(\tau) d\tau + K_d \frac{de(t)}{dt}\)

Where:

  • \(u(t)\) is the control input. This can be velocity, steering angle, etc.

  • \(e(t)\) is the error. For example, if you are controlling based on velocity, the error would be the difference between a desired velocity and the actual current velocity.

  • \(K_p\) is the proportional gain, \(K_i\) is the integral gain, and \(K_d\) is the derivative gain

Components:

  • Proportional Control (P): This component produces an output value that's proportional to the current error. If the error has been large for an extended period of time, it will adjust the control output in proportion to that error.

    • As an example, take the speed of a car attempting to reach a goal point in a straight line. The farther the car is, the faster the car will go, and it's speed will reduce as it gets closer. Using the proportional control, we can fine-tune how fast the car will respond to the change in distance.
  • Integral Control (I): This component concerns itself with the accumulation of past errors. If the error has been present for an extended period, it will accumulate (integral of the error).

  • Using the car example again, suppose the car has gotten close enough to the target but hasn't reached it. The proportional control has stopped producing a meaningful output value but we want the car to get closer. We can increase the integral component which will allow us to eliminate the residual error (make the car move the final distance to the object).

    • This is particularly useful if the car is on a hill or there is a large amount of friction. The integral control would allow the car to move closer and avoid rolling backwards in the former case or getting stuck in the latter.
  • Derivative Control (D): This predicts the future trend of the error, by determining its rate of change. It provides a control output to counteract the rate of error change.

  • Using the car example, consider a situation where the car is moving quickly and is closing in on the target at a high rate of speed, about to overshoot it. Increasing the derivative control would reduce the control input (speed) to avoid this.

Demo

The following Google Colab notebook demonstrates a simple PID controller implementation in Python. The controller is used to control the position and orientation of a point robot along a desired trajectory.

Open In Colab

The following Google Colab notebook implements a PID controller for a F1TENTH car:

Open In Colab

The following Google Colab notebook implements a PID controller for a differential drive Husky robot:

Open In Colab

The following link allows you to download a .exe file of Ackermann Racecar PID Control implementation in pybullet: https://ucsdcloud-my.sharepoint.com/:u:/g/personal/sbogdanov_ucsd_edu/ERkxOhN7gqJKmmbeMsQmdScB-3rXqon5yyBAB35GZrWVDA?e=O1Z7bZ

Video Demo - Ackermann Racecar PID Control

Racecar Ackermann Demo