PID Controller
Self-Driving Car Engineer Nanodegree Program
The program can take four arguments:
After starting the pid-program, start the Udacity simulator and select autonomous mode. For each data sample, program outputs three values: cross track error, calculated steering wheel angle, and running average of the CTE. With -D argument one gets additional output.
Control is achieved using proportional (P), derivative (D) and integral (I) terms. The P term counteracts the current and latest measured error value. This easily leads to overshooting the setpoint and a plain P-controller typically oscillates. To mitigate this behavior we use the derivate term, which predicts the future trend of the error and minimizes it over the time. The integral term sums up the past trends of the error, and can detect and correct possible constant drift in streering.
The behavior of different controllers can be easily tested by zeroing program arguments. For example:
./pid -p 0.2 -d 0.1 -i 0.1
./pid -p 0.2 -d 0 -i 0
./pid -p 0.2 -d 0.1 -i 0
./pid -p 0.2 -d 0 -i 0.1
Default values for coefficients are p == 0.2, d == 0.1 and i == 0.1. Car passes the test track when these values are used. The values have been found by manual tuning with the SDC simulator. The car passes the track equally well without the integral factor, but the average CTE remains rather high. When using the I-term, the average CTE goes close to zero.
One can use PIDControl.ipynb
jupyter notebook for experimenting with the controller. The notebook also contains a twiddle algorithm for finding optimal values for coeffients. This image. generated with the notebook code, illustrates error values from different kind of controllers:
mkdir build && cd build
cmake .. && make
./pid
.