The goal of this project is to control a vehicle driving on a road by keeping it as close to the center of the road as possible. We utilize the PID controller to achieve this goal. We use a simulator of a car driving on a road and real-time stream of its speed, cross-track error (CTE), and steering angle. The simulator allows the user to control the car using its throttle and steering angle values, which will be provided by our PID controllers.
The steering angle PID controller we use here attempts to minimize the error over time by adjusting the steering angle of the car, such as the location of the car, to a new value determined by a weighted sum of the control terms. The control terms of the PID controller are:
Steering angle = -P*CTE - I*CTEacc - D*(CTEt-CTEt-1)
- P is the proportional term to the error between the desired and actual location of the car (CTE). The higher the error, the larger the contribution of this term to the control signal.
- I helps eliminate any systematic drift the car may have from the desired location. The I parameter is multiplied by the accumulated CTE (over time) to remove the drift effect.
- D accounts for the rate of change of the error CTE. The higher the rate of change of error (CTEt-CTEt-1), the higher the damping effect.
In addition to the steering angle PID controller, we also use a throttle PID controller. It uses the magnitude of error (i.e., the abs value) to compute the control signal.
The challenge in this project is to carefully tune the parameters of the PID controllers (P, I, & D) such that the generated steering angle and throttle control signals keep the car inside the road all the time.
In this project, the controller parameters were initially manually selected and then automatically tuned using the twiddle algorithm to further decrease the overall CTE. The manual selection step through trial and error is necessary to make sure that the car is driving on the road and not trapped outside when we fine tune the parameters in the automated mode. Also, during the course of fine tuning, the proposed changes to the parameters should be small enough to ensure that the car continues driving on the road and large enough to quickly find the optimal values. The twiddle algorithm runs for 1000 steps of driving to test whether the proposed change is acceptable or not. If acceptable, the next change will be slightly larger (10% of the current change). Otherwise, we will reduce the change by 10% and try again.
After compiling the project (as outlined in the steps below), the project can be ran in the driving mode or driving & twiddling mode using the commands:
driving_mode_only$./pid diving_and_twiddling_mode$./pid twiddle
- cmake >= 3.5
- All OSes: click here for installation instructions
- make >= 4.1(mac, linux), 3.81(Windows)
- gcc/g++ >= 5.4
- Run either
- If you install from source, checkout to commit
Some function signatures have changed in v0.14.x. See this PR for more details.
git clone https://github.com/uWebSockets/uWebSockets cd uWebSockets git checkout e94b6e1
- Run either
- Simulator. You can download these from the project intro page in the classroom.
There's an experimental patch for windows in this PR
Basic Build Instructions
- Clone this repo.
- Make a build directory:
mkdir build && cd build
cmake .. && make
- Run it:
- in driving mode only:
- in driving and parameter tunning modes (twiddle):
- in driving mode only:
Tips for setting up your environment can be found here
The editor configuration files were kept out of this repo in order to keep it as simple and environment agnostic as possible. However, it is recommended to use the following settings:
- indent using spaces
- set tab width to 2 spaces (keeps the matrices in source code aligned)
Please (do your best to) stick to Google's C++ style guide.