The project implements a PID controller in C++ to maneuver the vehicle around the track.
PID controller generates a steering value (actuating signal) to input "SYSTEM", which is a simulator in the project. in feedback control, The simulator will provide the cross-track error (CTE) and so on to simulate Senser data. So I can find how far off the vehicle is from where I want it to be. So the cross-track Error (CTE) is an error term that is the distance between vehicle position and centerline position. If the steering value is accurate. the error term would be zero. So the target is how do I take this CTE and convert it into a suitable steering value.
Using the CTE at the present moment to decide How much "α" are going to rotate . For example If the CTE is 10m and I set P-controller τ as 0.1 . then I can get the steer speed is 1 rad/s. So A second later, the steering value would be 1 rad , So I can get
α = 1 * 180 / π
So the "α" is proportional to The CTE. In the project, I directly design P-Controller as Kp * p_error
But here a problem. the Vehicle does not stop when it reaches the centerline. The speed of a vehicle can be decomposed into horizontal and vertical speeds.
So the vehicle is overshoot. When the vehicle tried to fix the overshoot, it would create a Vy in the opposite direction. So the Vy is never to be zero.
We need a controller to respond to how fast the Vehicle's closing in on the goal. So a derivative is a better way to measure the rate of change of the error that is how fast the error is growing or shrinking.
For example, if the vehicle is running quickly and fast approaching the centerline. this means that the error is quickly decreasing, That decreasing error has a negative rate of change, which will produce a negative value. That negative value will be added to our controller's output. Therefore lowering the steering value. preventing the Vehicle from overshooting. In the project, I take current CTE minus the Prevouise CTE Kd *(cte - p_error)
When there was a bias in the system, we had better use past CTE data to correct the system bias. So the Integral controller will do calculate all the CTE Subtract from the steering value. In the project, I took Ki * ∑ cte.
There are three branches each contribute some amount to the overall output of the controller and there are three parameters to weigh each controller contribution. So the finial controller output is -Kp *p_error - Ki* i_error - Kd * d_error
The next step is tuning the parameters Kp Ki Kd
-
step 1: pid_a.Init(0.1, 0.001, 1); First I set initial value as Kp = 0.1 Ki = 0.01 Kd = 1. Because Kp, Ki, Kd is inversely proportional to T. The vehicle ran out of the left lane . So I increased Kp to decrease T-rise.
-
step 2: pid_a.Init(0.2, 0.001, 1) The T-rise is better then before. So I increased a small value.
-
step 3: pid_a.Init(0.25, 0.001, 2) The vehicle oscillated , I increased Kd to decrease overshoot.
-
step 4: pid_a.Init(0.25, 0.001, 3) The Oscillating situation is not better, I need to continue to increase the Kd.
-
step 5: pid_a.Init(0.25, 0.001, 4) When the vehicle runs through a fast curve lane, goes out of the lane. I increased Kd to deal with strong changes in future data
-
step 6: pid_a.Init(0.25,0.001, 5);
The vehicle oscillate wiht weakening intensity, I increased Kd to decrease overshoot -
step 7: pid_a.Init(0.25, 0.001, 5.5); The vehicle was slightly overshooting. I increased Kd to a small value.
-
step 8: pid_a.Init(0.25, 0.001, 5.75); The vehicle went off the track on the second lap, I increased Kd to decrease overshoot.
-
step 9: pid_a.Init(0.25, 0.001, 6.0); The controller works well with these parameters. No further Twiddle algorithm was required, and the Twiddle algorithm was not very efficient in this project.
- Clone this repo.
- Make a build directory:
mkdir build && cd build - Compile:
cmake .. && make - Run it:
./pid.
The environment can be found here
- 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.shor./install-ubuntu.sh. - If you install from source, checkout to commit
e94b6e1, i.e.
- Run either
- We use SemVer for versioning. For the versions available, see the tags on this repository.
- Tom Ge - Self-Driving Car egineer - github profile
- This project is licensed under the MIT License




