szon0111 / CarND_P9-PID-Control

implement a PID controller in C++ to maneuver the vehicle around the simulator track

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project 9: PID Control

Udacity - Self-Driving Car NanoDegree


Implement a PID controller in C++ to maneuver the vehicle around a simulated track

The goals / steps of this project are the following:

  • Build a PID controller
  • Tune the PID hyperparameters by testing the model on the track
  • Make sure no tire leaves the drivable portion of the track

Project Deliverables

  • main.cpp for calling the model and communicating with the simulator
  • PID.cpp defines the PID class with code for initialization, updating error, and returning the total error


The components of PID

  • "P" for proportional makes the vehicle steer in proportion to the cross-track error(CTE). Basically, this makes the vehicle steer in the correct direction. However, a P value that is too high will result in an unstable oscillating driving behavior as the vehicle will constantly try to correct its trajectory and overshoot. The vehicle with just the "P" value alone will never converge and keep oscillating.
  • "D" for derivative helps compensate for the overshooting behavior caused by the "P" component by making the controller output proportional to the rate of change of CTE. This counters the oscillations, leading to a more stable driving behavior. However, too high of a "D" value will cause constant change of steering angle.
  • "I" for integral takes the integral of the CTE overtime to compensate for systematic bias. This allows the vehicle to head back towards the middle.

How I tuned the parameters

I started out by finding a reliable "P" value while keeping the other parameters to 0. Once I found a value that kept the vehicle on track for the most part(although very wobbly), I started tuning the "D" value to reduce the oscillating behavior. Interestingly, the "I" value had little effect in the simulation. This may be because the simulator does not account for systematic bias.

In the end, P = 0.3, I = 0.002, D = 3.0 were chosen as the final parameters.


ezoic increase your site revenue


implement a PID controller in C++ to maneuver the vehicle around the simulator track


Language:C++ 91.0%Language:C 3.3%Language:CMake 3.2%Language:Makefile 2.4%Language:Shell 0.1%