This project's goal consists of implementing a proportional-integral-derivative (PID) controller in C++ to manoeuvre the vehicle around a simulated track. The PID controller generates steering values to minimize the deviations from the expected trajectory coming from the path planning algorithm.
The following animation shows an example of vehicle being controlled by the resulting PID controller:
The project complies with Udacity's list of rubric points required to pass the project and Google's C++ style guide.
The PID controller (proportional–integral–derivative controller) continuously calculates an error value as the difference between a desired value and a measured process variable. In this project, the desired value would be the trajectory generated by the path planning algorithm, which would represent the centre of the lane. The error between the observed value and the desired one is known as the Cross Track Error (CTE) and the goal is to minimize this error avoiding unnecessary oscillations.
To minimize the error, the algorithm applies a correction to the steering value according to the PID terms, i.e., proportional, integral, and derivative terms. The proportional term (P) can be thought as the term with the most direct impact on the vehicle's behaviour. It is proportional to the CTE, and high values of the CTE are linked to high steering values. For example, if the car was moving to the right of the centre, this value would cause the vehicle to steer to the left. If we isolated this term, we would obtain an oscillations in the trajectory, something which is undesirable since it's related to uncomfortable driving.
The second term is introduced to avoid oscillations. This value is related to the resistance in the rate of change of the CTE. This value prevents the vehicle from oscillating as the CTE decreases. However high values of this term will still lead to harsh turns and low values will not produce a significant impact.
The third term tries to compensate the impact of the systematic bias in the trajectory. It is called the integral term since it takes into account the summation of the CTE values to avoid constant values of the error. In the project, it prevents from driving away of the centre of the lane towards the left or right side.
Finally, these terms are weighted and combined to generate the output of the controller. The final weights, also called hyperparameters or PID coefficients, can be chosen through different methods (e.g., manual tuning, twiddle, SGD). In this project, these values were chosen manually, starting with the values presented in the lectures (i.e., [0.2, 3.0, 0.004]) and then testing slight individual modifications in the simulator. As a result, the final hyperparameters were [0.15, 3.0, 0.0005].
- cmake >= 3.5
- All OSes: click here for installation instructions
- make >= 4.1(mac, linux), 3.81(Windows)
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- Windows: Click here for installation instructions
- gcc/g++ >= 5.4
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - [install Xcode command line tools]((https://developer.apple.com/xcode/features/)
- Windows: recommend using MinGW
- uWebSockets
- Run either
./install-mac.sh
or./install-ubuntu.sh
. - If you install from source, checkout to commit
e94b6e1
, i.e.Some function signatures have changed in v0.14.x. See this PR for more details.git clone https://github.com/uWebSockets/uWebSockets cd uWebSockets git checkout e94b6e1
- Run either
- Simulator. You can download these from the project intro page in the classroom.
Fellow students have put together a guide to Windows set-up for the project here if the environment you have set up for the Sensor Fusion projects does not work for this project. There's also an experimental patch for windows in this PR.
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./pid
.
Tips for setting up your environment can be found here
We've purposefully kept editor configuration files out of this repo in order to keep it as simple and environment agnostic as possible. However, we recommend using the following settings:
- indent using spaces
- set tab width to 2 spaces (keeps the matrices in source code aligned)