PID Controller

Udacity - Self-Driving Car NanoDegree

A proportional–integral–derivative (PID) controller is a commonly used algorithm on control loops. The controller takes a signal input and calculates the desired actuator output. The PID includes in the feedback loop the present error (P), past error memory (I), and future (D) to reduce overshooting, and base on these values apply correction. On this project we have implemented a PID controller in C++ to maneuver the vehicle around the simulator track.


Photo by Florin Kozma on Unsplash

The implementation of the algorithm is fairly straightforward. Every time we get an error, we stored the variables and compute a new value. We use two PID controllers one for steering and one for throttle control, each with its initial constants. Given the fact that in practice the integral error can get saturated we clamped the saturation to a max value, which provides us with smoother correction when the car started oscillating too much.

The Video result shows how the car goes around the track.

Although many algorithms can do the parameter adjustment, we choose to understand them manually. Tuning each parameter at a time by hand helps understand how each one of them works. Although throttle control uses PID, fixing parameters is not as evident as steering control.

The parameters correspond as follows for steering.

  • P constant value was setup to 0.05. The value defines how much correction is done. If the value is set to say 1, the car will continuously correct the direction making it oscillate heavily on a straight line.

  • I Constant value was set 0.001 with a max value of 200. This value was set to 0 initially, and when the other two values P and D were set, with put a very small value that helps the car driver a bit smoother.

  • D constant value was set to 3. Finally, the D value was set high since it helps to turn on the curves harder.

The parameters correspond as follows for throttle.

  • P constant value was setup to 0.09

  • I constant value was set 0.0001 with a max value of 500

  • D constant value was set to 0.5