nturumel / CarND-PID-Control-Project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


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)

PID Controller

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.

  1. Proportional:

    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

    image-20200927142256390

  2. Integral:

    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.

    image-20200927142840938

  3. Differential:

    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.

    image-20200927143239757

Controllers used

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);

Manual Tuning

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

Results

Car can make it through the track above the minimum required speed of 30 MPH (avg).

PID_gif

Future Challenges

  1. Implement Twiddle to obtain most optimum values.
  2. Increase Speed

About

License:MIT License


Languages

Language:C++ 99.5%Language:Shell 0.3%Language:CMake 0.1%