Skip to content

Use a PID controller to control the steering angle and throttle for driving a car in a car game simulator.

Notifications You must be signed in to change notification settings

JunshengFu/PID-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autonomous driving with PID controllers

1. Objective

This project is to use PID controllers to control the steering angle and the throttle for driving a car in a game simulator. The simulator provides cross-track error (CTE) via websocket. The PID (proportional-integral-differential) controllers give steering and throttle commands to drive the car reliably around the simulator track.

Demo 1: Steady drive with constant throttle (click to see the full video)

demo_gif1

2. Parameters of PID controller

Description of PID values in PID control

  • P (proportional) accounts for present values of the error. For example, if the error is large and positive, the control output will also be large and positive.

  • I (integral) accounts for all past values of the error. For example, if the current output is not sufficiently strong, the integral of the error will accumulate over time, and the controller will respond by applying a stronger action.

  • D (differential) accounts for possible future trends of the error, based on its current rate of change.

Finally parameters

  • PID parameters used for steering angles:

    • p value: 0.1
    • i value: 0.001
    • d value: 2.8
  • PID parameters used for throttle:

    • p value: 0.45
    • i value: 0.000
    • d value: 0.5

How to tune the parameters

The parameters are tuned manually with the order of: p, d, i. The d and i are first setted to be zeros, and 0.2 is used for the p value. I adjust the p value up and down till it could drive around the first corner and hard to imporve more. Then I keep the p value as it is, and increase the d value. Use the same approach for d value and i value.

In order to automatically fine tune the parameters, an optimization algorithm twiddle can be used, which is exampled as follows:

Demo 2: speedy drive, which is targeting for dirivng the car as fast as possible, but as a side effect, the car starts to swing. In order to make the car drive fast as well as steady, further joint parameter tuning for both PID controllers need to be carried out.


Code & Files

1. Dependencies & environment

  • cmake >= 3.5
  • make >= 4.1
  • gcc/g++ >= 5.4
  • uWebSockets: used for communication between the main code and the simulator.

2. How to run the code

  1. Clone this repo.
  2. Clean the project: $./clean.sh
  3. Build the project: $./build.sh
  4. Run the project: $./run.sh
  5. Start the simulator v1.45, select the PID Controller.

3. My project files

4. Code Style

5. Release History

  • 0.1.1

    • First proper release
    • Date 14 July 2017
  • 0.1.0

    • Create the repo
    • Date 13 July 2017

About

Use a PID controller to control the steering angle and throttle for driving a car in a car game simulator.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages