CarND-Controls-PID
Self-Driving Car Engineer Nanodegree Program
PID Controller
A controller takes as input(s) sensor data and convert it/them into an output that is directly controlling an actuator to impact an object’s position or state in the physical world.
In this case, I’m controlling a car in a simulator. Here is a capture of it:
Input:
- Cross track error
cte
(distance of the car form the center of the road).
Output:
- Steering angle
st
A PID controller has 3 components/gains that will be taken into account to calculate the output steering angle:
- proportional
Kp
- differential
Kd
- integral
Ki
The formula is really simple:
st = - Kp * cte
- Kd * (cte - prev_cte)
- Ki * sum(cte)
Where prev_cte
is the cte at the previous iteration and sum is pseudo code for the sum of all the cte
observed since the beginning of the simulation.
Here is a visualization of the incremental addition of the differential and integral gains.
Parameter tuning
I started with similar values as in the Udacity lessons for the 3 different gains:
Kp = 0.3
Kd = 3
Ki = 0.004
I observed that even though the car would drive continuously, there was too much oscillation. By looking at the first figure, I concluded that the oscillation was due to a proportional gain being to high. Therefore I lowered it to 0.15
.
Then, I observed that the correction for an increase in the cross track error would overshoot and result on having the car bouncing on the other side of the road. I deduced that the integral component was the faulty one here. After a few tests, I obtained a value for the integral gain of 0.0008
.
I tried tweaking the differential gain without observable improvement.
Final parameters
Kp = 0.15 ///< proportional gain
Kd = 3 ///< differential gain
Ki = 0.0008 ///< integral gain
Dependencies
- 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.git clone https://github.com/uWebSockets/uWebSockets cd uWebSockets git checkout e94b6e1
Some function signatures have changed in v0.14.x. See this PR for more details.
- Run either
- Simulator. You can download these from the project intro page in the classroom.
There’s an experimental patch for windows in this PR
Basic Build Instructions
- 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