pierluigiferrari / PID_controller

A PID controller for 2D vehicle trajectories

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PID Controller

This is a simple PID controller implementation in C++. The program is for use with the simulator linked below.


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.

The PID Components

The controller computes scalar control commands using an observed scalar error based on the following three additive components:

  1. The proportional (P) component: Acts proportionally to the observed error value, i.e. the larger the error value, the larger the absolute control command value.
  2. The integral (I) component: Acts using the sum of all past observed errors, i.e. the greater the imbalance between negative and positive past observed errors, the larger the absolute control command value.
  3. The differential (D) component: Acts using the change rate of the error, i.e. the more the error changes between the last and the current time step, the larger the absolute control command value.

The PID Coefficients for the steering controller

The strength of the influence of each of the three components on the control command value (the steering angle in this case) is determined by its respective coefficient.

I tuned the coefficients manually according to the following reasoning and trial and error.

Initial coefficient values

  1. P-coefficient: The cross-track error is measured in meters and the maximum absolute steering value is 1. Using the heuristic that a deviation from the target path by 3 meters (which is a large deviation given the width of a normal lane) should result in a rather strong steering value of 0.6, I used an initial value of 0.2 for this coefficient.
  2. I-coefficient: Since the cross-track error is measured every 0.1 seconds, the integral error can get large very quickly. I started out with a somewhat arbitrary value of 0.0001 for this coefficient.
  3. D-coefficient: The change in the error within 0.1 seconds will be small in most situations, therefore I somewhat arbitrarily chose the initial value to be 10 times the P-coefficient to 2.0.

Tuning and final values

The initial coefficient values worked sufficiently well, but the car constantly slightly overshot the target path and the car corrected back to the target path to drastically.

In order to get the car to convert back to the target path more smoothly, I gradually decreased the proportional coefficient.

In order to reduce the overshooting, I gradually increased the differential coefficient.

Of course not only the the absolute P- and D-coefficients matter, but also their relation. I ended up with a P-coefficient of 0.08 and a D-coefficient of 2.5, i.e. with the differential component over 30 times larger than the proportional component. Increasing the integral coefficient by a factor of 10 to 0.001 had a minor effect.

The coefficients chosen above lead to a satisfactorily smooth behavior in the simulator, however, a to-do and next step is to fine-tune the coefficients systematically using an optimization algorithm.

The PID Coefficients for the throttle controller

For the throttle controller I used the same initial coefficients as for the steering controller and didn't experiment much with them afterwards. The car seems to accelerate and decelerate in a sensical way.

About

A PID controller for 2D vehicle trajectories


Languages

Language:C++ 89.9%Language:Makefile 4.1%Language:C 3.3%Language:CMake 2.5%Language:Shell 0.1%