项目作者: overtane

项目描述 :
PID Controller
高级语言: C++
项目地址: git://github.com/overtane/udacity-carnd-p9.git
创建时间: 2017-04-01T08:31:21Z
项目社区:https://github.com/overtane/udacity-carnd-p9

开源协议:

下载


CarND-Controls-PID

Self-Driving Car Engineer Nanodegree Program


Code structure

  • src/Timestamp.h: simple timestamp class. Timestamp is taken at object instantiation time. diff() method exists for comparing timestamps.
  • PID.cpp, PID.h: PID controller code for calculating new steering wheel angle from the latest cross track error (CTE). Calculation takes into account the time difference of samples.
  • main.cpp: reading drive status values (CTE, speed) from the Udacity SDC simulator, and feeds back the calculated steering wheel angle and throttle values. In this version, throttle is always constant 0.6.

Running the Program

The program can take four arguments:

  • -p : proportional term coeffient
  • -d : derivative term coefficient
  • -i : integral term coefficient
  • -D: debug output, get more output from processing

After starting the pid-program, start the Udacity simulator and select autonomous mode. For each data sample, program outputs three values: cross track error, calculated steering wheel angle, and running average of the CTE. With -D argument one gets additional output.

About the Controller

Control is achieved using proportional (P), derivative (D) and integral (I) terms. The P term counteracts the current and latest measured error value. This easily leads to overshooting the setpoint and a plain P-controller typically oscillates. To mitigate this behavior we use the derivate term, which predicts the future trend of the error and minimizes it over the time. The integral term sums up the past trends of the error, and can detect and correct possible constant drift in streering.

The behavior of different controllers can be easily tested by zeroing program arguments. For example:

  • PID-controller: ./pid -p 0.2 -d 0.1 -i 0.1
  • P-controller: ./pid -p 0.2 -d 0 -i 0
  • PD-controller: ./pid -p 0.2 -d 0.1 -i 0
  • PI-controller: ./pid -p 0.2 -d 0 -i 0.1

Default values for coefficients are p == 0.2, d == 0.1 and i == 0.1. Car passes the test track when these values are used. The values have been found by manual tuning with the SDC simulator. The car passes the track equally well without the integral factor, but the average CTE remains rather high. When using the I-term, the average CTE goes close to zero.

Experimenting

One can use PIDControl.ipynb jupyter notebook for experimenting with the controller. The notebook also contains a twiddle algorithm for finding optimal values for coeffients. This image. generated with the notebook code, illustrates error values from different kind of controllers:

PID

Dependencies

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./pid.