Skip to content

bobondemon/PID_Control

Repository files navigation

CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Dependencies

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.

Maunaully tunning

The P.I.D parameters are first chosen by hand. I first try "Kp=0.4; Ki=0; Kd=2" and found that it had many wiggling effects. This is because the large Kp coefficient makes overshooting. Then I reduced the Kp value and set Kp=0.2 as the manual result.

In addition, I found that it is hard to tune Ki because the integral error is typically larger than proportional error in hundreds of magnitude. So I just set it to zero and left it be tuned by twiddling function.

Twiddle

In order to evaluate each "Kp,Ki,Kd" setting, we need to restart the simulator. By sending "42[\"reset\",{}]" to WebSocket, simulator is able to restart. The twiddling function can then test the performance of each setting and found the best results.

Each perforamnce evaluation is tested in time stamps 3000 (#define TWIDDLE_TIME_NUM 3000 in program), which is about 59 seconds. Then twiddling function will update the parameters and restart simulator.

The initial setting is found by manually tunning: "Kp=0.4; Ki=0; Kd=2", and I set the initial step size as:

twiddle_step_size[0] = 0.01; // pd[0] in course lecture
twiddle_step_size[1] = 0.0001; // pd[1] in course lecture
twiddle_step_size[2] = 0.01; // pd[2] in course lecture

Moreover, the tolerance, tol, is set to 0.01, and if "cur_tol<tol", the twiddling function converges. One thing that is different from the course is the calculation of cur_tol. Instead of using sum(pd) as in the course lecture, I used:

double cur_tol = twiddle_step_size[0]+twiddle_step_size[1]*100+twiddle_step_size[2];

I scaled 100 times of twiddle_step_size[1] (pd[1]). This is because the integral error is typically larger than proportional error in hundreds of magnitude.

As we can see in the following figure, cur_tol converges toward tol in the 84th iteration. (about 84 mins)

Results

The 84th iteration got the following results:

double Init_Kp = 0.211;
double Init_Ki = 0.0003189;
double Init_Kd = 2.00109;

It can successfully drive a lap around the track!

About

Udacity PID control project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages