Udacity Self-Driving Car Engineer - Project8: PID Controller
This is the repository of the PID project of the Udacity Self-Driving Car Nanodegree. Here are some outputs of the project:
A PID controller (Proportional Integral Derivative controller) is a control loop mechanism employing feedback that continuously calculates an error value as the difference between a desired setpoint (SP) and a measured process variable (PV) and applies a correction based on proportional, integral, and derivative terms (denoted P, I, and D respectively). The contol function is:
where Kp, Ki and Kd are the coefficients for the proportional, integral, and derivative terms respectively.
The following describes the effect each of the P, I, D components had on the current steering controller implementation. In this case, the measured error is the cross track error (cte), which is the distance between the car position and the desired position the car should be driving through:
Proportional component (P): This component set the steer in a value proportional to the cte. The bigger the value of the cte, the greater the value of the P component. Keeping Ki and Kd at 0 and choosing a suitable value of Kp, the vehicle is able to drive following the road. However, this simple control usually has overshooting of the setpoint and that is shown in the oscillations that the vehicle has when driving on the road. Even more, if the value of Kp is very large the vehicle tends to lose control and roll off to the side of the road. On the other hand, if the value of Kp is small, the vehicle does not turn well enough.
Derivative component (D): This component is proportional to the difference between the current error and the error in the previous instant (Δcte). It eliminates the overshooting caused by P component and the value converges faster to the desired setpoint. This is shown in the vehicle's path as a decrease in oscillations, tracing a smoother path.
Integral component (I): This component is proportional to the cumulative sum of all previous cte values (the integral of cte). It eliminates the error known as systematic bias (for example steering drift).
The PID controller is implemented in PID
class. The function GetValue
updates the error and returns the new value of the controlled variable. PID initialization takes as parameter the maximum and minimum output value. If the controller output exceeds the limits, the control saturates at that limit.
Two PID controller were implemented in main.cpp
to control the steering and the speed. The parameters Kp, Ki and Kd were manually selected as follows:
- Set the throttle value in 0.25 and tune steering PID parameters in.
- First, set Ki and Kd to 0 and find the Kp value that let the vehicle navigate (probably with oscillations).
- Keeping Ki in 0, find the value of Kd that eliminates (or reduces) the oscillations.
- Adjust the Ki value to eliminate the drift error (systematic bias).
- Repeat the process with speed PID parameters.
The twiddle algorithm (or another) could be implemented in order to get the optimal parameters for PID controller.
- 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.
- 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)
Please (do your best to) stick to Google's C++ style guide.
Note: regardless of the changes you make, your project must be buildable using cmake and make!
More information is only accessible by people who are already enrolled in Term 2 of CarND. If you are enrolled, see the project page for instructions and the project rubric.