aranga81 / PID-Controller

PID controller in C++ - unity/udacity simulator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PID control Project

Introduction:

Main objective of this project was to design a PID controller & tune the gains so that car follows the track in the provided simulator. The simulator provides CTE (cross track error = current car positition - set point), speed, steering angle data as inputs.

Effect of Proportional / Derivative & Integral gains..!!

The proportional gain (P) - 'Kp' in the code has an apparent affect on the car in the simulator. Steering angle adjustment scales linearly with the gain and system or the car reaches marginal stability - hence oscillating heavily.

Differential gain (kd) reduces the oscillations or overshoot as it exerts control action looking at the rate of change of error or cte in our case. The greater the cte error change more is the affect of Kd.

Integral component tries to reduce the steady state error to zero. The bias in CTE which restricts the car from reaching the set point or the middle of the road is compensated using Integral component.

Describe how the final hyperparameters were chosen:

I started off with manual tuning. First with a Kp = 0.1, Kd & ki = 0. The car in the simulator oscillates heavily about the center of the the track as CTE error starts to increase. Next step was tuning Kd to eliminate overshoot and oscillations - using kd = 3.0 worked best. Just using PD controller the car could easily navigate on the track without oscillations and overshoot. Just to make sure the car follows middle of the track and hence to reduce CTE during turns a small Ki gain of 0.0003 was applied. Also the PID controller gains can be tuned using optimization techniques like twiddling, SGD.

Apart from PID controller that was implemented to compensate CTE and adjust steering angle, a throttle controller was implemented. Car needs to slow down and acceralate as the steering angle input is large and respectively small. Hence the input to throttle controller is (1 - absolute(steering angle)) and I used a gain and offset to scale the throttle input.

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.

About

PID controller in C++ - unity/udacity simulator


Languages

Language:C++ 99.7%Language:Shell 0.2%Language:CMake 0.1%