CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


PID Controller

A controller takes as input(s) sensor data and convert it/them into an output that is directly controlling an actuator to impact an object’s position or state in the physical world.

In this case, I’m controlling a car in a simulator. Here is a capture of it:

alt text

Input:

Output:

A PID controller has 3 components/gains that will be taken into account to calculate the output steering angle:

The formula is really simple:

st = - Kp * cte
     - Kd * (cte - prev_cte)
     - Ki * sum(cte)

Where prev_cte is the cte at the previous iteration and sum is pseudo code for the sum of all the cteobserved since the beginning of the simulation.

Here is a visualization of the incremental addition of the differential and integral gains.

alt text

Parameter tuning

I started with similar values as in the Udacity lessons for the 3 different gains:

Kp = 0.3
Kd = 3
Ki = 0.004

I observed that even though the car would drive continuously, there was too much oscillation. By looking at the first figure, I concluded that the oscillation was due to a proportional gain being to high. Therefore I lowered it to 0.15.

Then, I observed that the correction for an increase in the cross track error would overshoot and result on having the car bouncing on the other side of the road. I deduced that the integral component was the faulty one here. After a few tests, I obtained a value for the integral gain of 0.0008.

I tried tweaking the differential gain without observable improvement.

Final parameters

Kp = 0.15       ///< proportional gain
Kd = 3          ///< differential gain
Ki = 0.0008     ///< integral gain

Dependencies

There’s an experimental patch for windows in this PR

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./pid.

Tips for setting up your environment can be found here