/pid_control

CarND-Controls-PID

Primary LanguageC++MIT LicenseMIT

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Dependencies

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.

There's 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.

Rubric points

Compilation

Your code should compile.

The code compiles without errors with cmake and make as described in Basic Build Instructions.

Implementation

The PID procedure follows what was taught in the lessons.

The base PID algorithm follows what's presented in the lessons. The only difference is adding a limiter to the integral part to prevent the controller windup.

Reflection

Describe the effect each of the P, I, D components had in your implementation.

P part effectively is sufficient to have the system reacting on the error and compensating for it. But the maximum result you can achieve is either understeering or oscillation.

D part helps to compensate for oversteering or for a sudden change of the error. Especially it is helpful on high speed when the error is growing quickly and suddenly, e.g., on sharp turns.

I part is normally required to compensate for the static state error. But in the case of long sharp turns it also helps to stay on track because the rate of the error change is close to zero, so D part is becoming inefficient.

Describe how the final hyperparameters were chosen.

There are two controllers that work together - the velocity and steering controllers. Tuning the velocity controller was the easiest task. I started with proportional part only reaching a satisfactory speed control with a static offset. Then I moved on to the differential part to reach a satisfactory behaviour in particular for braking. The last step was adding the integral part to compensate for the static offset.

The steering controller was tricky to tune especially for high speed. The submitted code works well for velocities in range 60 - 70 MPH and is sharply tuned. For lower velocities a different set of parameters is prefered to achieve a smooth motion. The steering controller hyperparameters were selected by hand following a simple approach:

  1. Tune the P part to have a satisfactory steering with a slight oscillation. Reduce the P part slightly after finding the P paramter around the oscillation point.
  2. Increase the D part till the car is capable of dealing with sharp turns without leaving the road.
  3. Add integral part to smoothen the steering and to be able to handle long curves. Integral part was in this case the most challenging part which required finding not only the I coefficient but also a proper integral limit. Having a large integral limit with a low I coefficient would introduce oscillations. Reducing the limit but increasing the I coefficient helped to achive the desirable result.

Dealing with long curves

Simulation

The vehicle must successfully drive a lap around the track.

Unfortunately simulator recording didn't work for me, so I had to perform a screen recording which introduced some lags into the performance. The video can be found here.