Skip to content

Manoeuvre a vehicle around a simulated track using a PID controller.

License

Notifications You must be signed in to change notification settings

lmasello/CarND-PID-Control-Project

 
 

Repository files navigation

CarND-Controls-PID

Udacity - Self-Driving Car NanoDegree

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:

Video of the vehicle driving on the simulated track

Project implementation

The project complies with Udacity's list of rubric points required to pass the project and Google's C++ style guide.

Reflection

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].


Dependencies

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.

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

Editor Settings

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)

About

Manoeuvre a vehicle around a simulated track using a PID controller.

Topics

Resources

License

Stars

Watchers

Forks

Languages

  • C++ 99.6%
  • Other 0.4%