In this project you'll implement model predictive controller to drive the car around the track. You will need to extract the data and calculate the cross track error then compute the appropriate steering angle and acceleration and feed them back to the simulator to drive the vehicle around the track. Besides that, you can also plot your predicted trajectory in front of the vehicle to see how well your model is working. Remember, there is a 100 millisecond latency between actuations commands on top of the connection latency so you will need to handle that latency in your code.
There is a simulator provided by Udacity (Term 2 Simulator Release) which will generate the state and actuator data. And you will be using those data to calculate the cross track error (CTE) then compute the appropriate control inputs then feed them back to the simulator to drive the vehicle.
Here is the link to the orginal repository provided by Udaciy. This repository contains all the code needed to complete the final project for the Model Predictive Control course in Udacity's Self-Driving Car Nanodegree.
- 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
- 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
- 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.
- Meet the
Prerequisites/Dependencies
- Intall
uWebSocketIO
on your system
2.1 Windows Installation
2.1.1 Use latest version of Ubuntu Bash 16.04 on Windows 10, here is the step-by-step guide for setting up the utility.
2.1.2 (Optional) Check your version of Ubuntu Bash here. - Open Ubuntu Bash and clone the project repository
- On the command line execute
./install-ubuntu.sh
- Build and run your code.
Tips for setting up your environment can be found here
- main.cpp:Reads in data, calls a function to initialize and run the model predictive controller on steering angle, acceleration pedal and brake. Besides that, it will also handle the 100 millisecond connection latency and retrieve the predicted trajectory from the model predictive controller and propagate the line in front of the vehicle.
- MPC.cpp: Initializes the model predictive controller, define the cost calculation, set the contraints, process data and return actuator commands and predicted trajectory. Defines
FG_eval()
andSolve()
. - README.md: Writeup for this project, including setup, running instructions and project rubric addressing.
- CMakeLists.txt:
CMakeLists.txt
file that will be used when compiling your code (you do not need to change this file)
- Clone this respository
- At the top level of the project repository, create a build directory:
mkdir build && cd build
- In
/build
directory, compile yoru code withcmake .. && make
- Launch the simulator from Windows
- Execute the run command for the project
./mpc
(Make sure you also run the simulator on the Windows host machine) If you see * * this message, it is workingListening to port 4567 Connected!!!
- It's recommended to test the MPC on basic examples to see if your implementation behaves as desired. One possible example is the vehicle starting offset of a straight line (reference). If the MPC implementation is correct, after some number of timesteps (not too many) it should find and track the reference line.
- The
lake_track_waypoints.csv
file has the waypoints of the lake track. You could use this to fit polynomials and points and see of how well your model tracks curve. NOTE: This file might be not completely in sync with the simulator so your solution should NOT depend on it. - For visualization this C++ matplotlib wrapper could be helpful.)
- Tips for setting up your environment are available here
- VM Latency: Some students have reported differences in behavior using VM's ostensibly a result of latency. Please let us know if issues arise as a result of a VM environment.
Please (do your best to) stick to Google's C++ style guide.
Yes, it does.
Please see my notes/comments/documentation in MPC.cpp
.
The number of points(N) and the time step (dt) define the prediction horizon.
Larger N
will consume more computational time which will affect the controller performance with no doubt.
Smaller N
will have less computational time but the model will generate less points which might not suitable for high speed vehicle.
Larger dt
will lower the accuracy of the predicition or mislead the prediction horizon.
Smaller dt
will have higher solution but it mighy not necessary on a low speed vehicle.
Larger time horizon N * dt
will generate a longer predicted path.
Smaller time horizon N * dt
will genertate a shorter predicted path.
In conclusion, we will need to balance N
and dt
value for different purposes/metrics on our vehicle.
Our vehicle is assumed running as 50~80 mph for regular US high way speed limit.
Start with N = 25, dt = 0.05 then tried with different combinations.
Finally, I picked N = 10, dt = 0.1 to have a better result at MPC.cpp
Line8-10.
Polynomial fitting was called at main.cpp
Line120-124.
Polynomial fitting was implemented at main.cpp
Line44-66.
MPC preprocessing was implemented at main.cpp
Line104-118.
The model will transform the waypoints from map coordinates to car coordinates before polynomial fitting. main.cpp
Line107.
The latency was handled at main.cpp
Line126-151.
Also, one line changed at main.cpp
Line228.
The connectivity has a 100 millisecond latency.
Here, I defined the delay time as 0.1 second and 100 millisecond for different functions use. main.cpp
Line129-132.
Then the state vector was initialized with the generated polynomial fitting coefficients. main.cpp
Line134-140.
Next, the new state vector will be computed with the delay time. main.cpp
Line142-148.
Finally, the new state vector was fed into the mpc.Solve()
to get the new control inputs. main.cpp
Line157.
Yes, it does. Please see the videos below.
Video recordings for success cases.
Success case for smooth driving.
Success case for highest speed driving with around 57 mph.