Self-Driving Car Engineer Nanodegree Program
- 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)
Taken from https://en.wikipedia.org/wiki/PID_controller
PID stands for Proportional, Integral, Differential controller. It calculates an error value, the difference between the current value of process variable and the desired value. $$ {\displaystyle u(t)=K_{\text{p}}e(t)+K_{\text{i}}\int {0}^{t}e(t'),dt'+K{\text{d}}{\frac {de(t)}{dt}},}{\displaystyle u(t)=K_{\text{p}}e(t)+K_{\text{i}}\int {0}^{t}e(t'),dt'+K{\text{d}}{\frac {de(t)}{dt}},} $$ where the K's are the constants for the different parts.
Let us look at the three components individually.
-
As the name suggests, proportional control applies a correction directly proportional to the offest of the process variable from the desired variable. Higher values lead to faster convergence, however it also leads to higher oscillations. Basically think of a spring mass system with a high stiffness... Same behavior
-
Sometimes, there may be a constant error in the process intrinsic to the devices, this error is called steady state error. To counter this problem, we can introduce a correction, that is proportional to the total accumulation of error. In a spring mass system, think that this correction solves the problem of a spring that has a permanent stretch in it.
-
In a spring mass system, this would be the damping term, this dampens the oscillations and gets you to a steady state.
The magnitude of correction is directly proportional to the slope of the error.
There are two controllers used in this project, one for speed and one for angle.
The speed controller tries to get the car to the desired speed and the angle controller steers the car.
The error for the steer controller is obtained from the simulator.
The error for the speed controller is obtained by taking the difference between the current speed and the desired speed.
The desired speed is:
double desiredSpeed = 40 - (10) * fabs(steer_value);
Initially, I fixed the throttle at 0.3 and started with K values for steering controller is [0.2, 0.0003, 3.0].
I noticed that greater the proportional value, the greater the swing. The differential term basically dampens the swing. The integral term is probably least influential, as there is not much steady state error.
I initially started with K values for speed controller is [0.12, 0, 1.2] and fixed the desired speed of 40. This was a problem as the speed needs to reflect the sharpness of the turn.
Then the speed reflected the sharpness.
The proportional term impacts how fast or soft the car slows down.
The differential term is not useful as the desired speed changes really rapidly, so we need rapid oscillations of the speed. The integral term maintains the average speed to a greater value.
We end with obtained the following weights (P, I, D):
Angle PID -->(0.3, 0.008, 3.5)
Speed PID --> (0.15, 0.0, 1.5)
We also limit the range of throttle and steer angle, the corrections, to values between -1 and 1
Car can make it through the track above the minimum required speed of 30 MPH (avg).
- Implement Twiddle to obtain most optimum values.
- Increase Speed