This is a PID controller steering an autonomous vehicle across a racetrack. You can see it in action here.
A PID controller is a simple way to control the steering of a vehicle across a predefined trajectory. It uses three parameters to calculate the required steering angle:
- P, the proportional part of the equation. This component increases the steering more the further away the vehicle is from the trajectory, i.e. the higher its cross track error (CTE) is.
- I, the integral part of the equation. The integral is used to move the vehicle closer to the trajectory when both P and D combined let the car steer across a tangential path. It also influences how fast the car can approach its target trajectory.
- D is the derivative part of the equation. Its calculated by the difference of the current CTE and the previous CTE. The derivative component is used to keep a vehicle that has found the trajectory close to it by reducing the rate of change in the CTE.
For my final results i used:
- P: -0.2
- I: -0.01
- D: -30.0
I arrived at these values by starting at some values that successfully allowed the vehicle to complete a full round in the simulator (-0.25, 0.0 and -0.75) and then slowly altered them to make the round smoother and more reliable. Using the final parameters, the car can complete the course on full throttle. Driving on full throttle is unfortunately only possible on a strong computer, as I learned when recording the video, which required me to reduce the throttle to 50%. Aforementioned is due to lag caused by the recording and the program not being able to calculate the steering angle as often, which causes the vehicle to steer wildly across the course.
- cmake >= 3.5
- All OSes: click here for installation instructions
- make >= 4.1(mac, linux), 3.81(Windows)
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- Windows: Click here for installation instructions
- gcc/g
- Linux: gcc / g
- Mac: same deal as make - [install Xcode command line tools]((https://developer.apple.com/xcode/features/)
- Windows: recommend using MinGW
- uWebSockets
- Run either
./install-mac.sh
or./install-ubuntu.sh
. - If you install from source, checkout to commit
e94b6e1
, i.e.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
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./pid
.
Tips for setting up your environment can be found here
We've purposefully kept editor configuration files out of this repo in order to keep it as simple and environment agnostic as possible. However, we recommend using the following settings:
- indent using spaces
- set tab width to 2 spaces (keeps the matrices in source code aligned)
This project uses Google's C.