Model predictive control project for combined longitudinal and lateral control of the autonomous vehicles. It uses udacity vehicle simulator. The simulator sends the reference trajectory and the MPC sends the steering angle and the throttle value to the simulator. They are communicated by uWebSockets. The data specification is written in DATA.md.
If you want to more information of this project, please visit this link. I summarized the project more detail to describe more deeply.
The kinematic model is used for vehicle model.
The reference path was fitted with 3-order polynomials
auto coeffs = polyfit(xvals, yvals, 3);
Three error states are used.
cte
is refers the cross track error which is lateral difference with reference path. epsi
means the orientation error like above picture. For velocity keeping, velocity error was used.
This MPC minimize error states, magnitude of inputs and derivative of inputs.
MPC can consider the latency of inputs. In real vehicle, there is latency of inputs. It means that steering command will not directly applied to the car because there are many delay terms such communication, and mechanic parts. MPC can compensate it easily by use the future reference path.
const double latency = 0.1; // 100ms latency
px = px + v * cos(psi) * latency;
py = py + v * sin(psi) * latency;
Prediction horizon (N*dt) needs to be optimized. I found the values with try and error
-
git lfs
-
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++ >= 5.4
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - [install Xcode command line tools]((https://developer.apple.com/xcode/features/)
- Windows: recommend using MinGW
-
- Run either
install-mac.sh
orinstall-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
-
Ipopt and CppAD: Please refer to this document for installation instructions.
-
Eigen. This is already part of the repo so you shouldn't have to worry about it.
-
Simulator. You can download these from the releases tab.
-
Not a dependency but read the DATA.md for a description of the data sent back from the simulator.
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./mpc
.
The docker-compose can run the project into a container and exposes the port required by the simulator to run.
- Clone this repo.
- Build image:
docker-compose build
- Run Container:
docker-compose up
- On code changes repeat steps 2 and 3.
On terminal
mkdir build && cd build
cmake .. && make
./mpc
Open the simulator
1. Open term2_sim_linux/term2_sim.x86_64
2. Select graphic quality
3. Select Project 5: MPC Controller