hashkanna / CarND-PID-Control-Project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Dependencies

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./pid.

Implementation

The PID Controller is implemented using the three variables P, I and D.

  • P = Proportional(P) value corresponding to the CrossTrackError which is the distance of the car from the reference trajectory. This is used to steer the car to the right trajectory
  • I = cumulative total of the errors seen so far
  • D = Correcting P so as to smoothen and reduce the overshooting/oscillating nature of P

The formula for updating the error correction is below
d_error = cte - p_error
p_error = cte
i_error = cte + i_error

The total error is calculated using the weighted sum using Kp, Ki and Kd coefficients -Kp * p_error - Ki * i_error - Kd * d_error;

Reflection

Effect of P, I, D controllers

  • The P controller adjusts the steering based on how far the car is from the reference trajectory. A large P gain made the car overshoot and oscillate out of the track. It pushed the steering value to the max and in the next step tried to correct it but instead of making the necessary correction, it overshot in the opposite direction. And the cycle continued.

  • The D controller helped in balancing the heavy oscillation of the P gain. It used the rate of change of the P gain to control the car from oscillating too much.

  • The I controller ensured that the car stayed closer to the track. A very small value of I was enough for this specific track.

Choosing Hyperparameters

  • The Hyperparameters were hand tuned by performing several experiments. Details in below table.
PID ValuesObservations
pid.Init(0.0, 0.0, 0.0);travels in a straight line and moves out of the track
pid.Init(10.0, 0.0, 0.0);extremely volatile steering angle oscillations because of high P value - stops as soon as it nears the curve
pid.Init(10.0, 0.0, 50.0);moves to a decent distance because of D's opposition to P - but gets out of track & stops
pid.Init(10.0, 5.0, 3.0);keeps circling around as soon as it starts
pid.Init(0.5, 0.001, 2.2);Works kind of ok but starts oscillating near the curve & stops in deep curves
pid.Init(0.2, 0.001, 2.0);Completes a lap but zigzags till the end and then fails in the next lap
pid.Init(0.1, 0.0001, 2.0);near perfect. completes several laps. touches the red lines occassionally
pid.Init(0.13, 0.0003, 2.0);Final choice. slightly oscillating but does the job

Images of some of the erroneous ones below 1 2 3

Simulation

Final Image
Final Image

About


Languages

Language:C++ 99.7%Language:Shell 0.1%Language:CMake 0.1%