Self-Driving Car Engineer Nanodegree Program
In this project you will utilize a kalman filter to estimate the state of a moving object of interest with noisy lidar and radar measurements. Passing the project requires obtaining RMSE values that are lower than the tolerance outlined in the project rubric.
This project involves the Term 2 Simulator which can be downloaded here.
This repository includes two files that can be used to set up and install uWebSocketIO for either Linux or Mac systems. For windows you can use either Docker, VMware, or even Windows 10 Bash on Ubuntu to install uWebSocketIO. Please see the uWebSocketIO Starter Guide page in the classroom within the EKF Project lesson for the required version and installation scripts.
Once the install for uWebSocketIO is complete, the main program can be built and run by doing the following from the project top directory.
- mkdir build
- cd build
- cmake ..
- make
- ./ExtendedKF
Tips for setting up your environment can be found in the classroom lesson for this project.
Note that the programs that need to be written to accomplish the project are src/FusionEKF.cpp, src/FusionEKF.h, kalman_filter.cpp, kalman_filter.h, tools.cpp, and tools.h
The program main.cpp has already been filled out, but feel free to modify it.
Here is the main protocol that main.cpp uses for uWebSocketIO in communicating with the simulator.
INPUT: values provided by the simulator to the c++ program
["sensor_measurement"] => the measurement that the simulator observed (either lidar or radar)
OUTPUT: values provided by the c++ program to the simulator
["estimate_x"] <= kalman filter estimated position x
["estimate_y"] <= kalman filter estimated position y
["rmse_x"]
["rmse_y"]
["rmse_vx"]
["rmse_vy"]
- cmake >= 3.5
- All OSes: click here for installation instructions
- make >= 4.1 (Linux, Mac), 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
- Windows: recommend using MinGW
- Clone this repo.
- Make a build directory:
mkdir build && cd build
- Compile:
cmake .. && make
- On windows, you may need to run:
cmake .. -G "Unix Makefiles" && make
- On windows, you may need to run:
- Run it:
./ExtendedKF
-
Initialization
is_initialized_ = false; previous_timestamp_ = 0; // initializing matrices R_laser_ = MatrixXd(2, 2); R_radar_ = MatrixXd(3, 3); H_laser_ = MatrixXd(2, 4); Hj_ = MatrixXd(3, 4); //measurement covariance matrix - laser R_laser_ << 0.0225, 0, 0, 0.0225; //measurement covariance matrix - radar R_radar_ << 0.09, 0, 0, 0, 0.0009, 0, 0, 0, 0.09; // Initialize P ekf_.P_ = MatrixXd(4, 4); ekf_.P_ << 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1000, 0, 0, 0, 0, 1000; H_laser_ << 1, 0, 0, 0, 0, 1, 0, 0;
-
Prediction
x_ = F_ * x_; MatrixXd Ft = F_.transpose(); P_ = F_ * P_ * Ft + Q_;
-
Radar Measurement update
void KalmanFilter::UpdateEKF(const VectorXd &z) { /** * TODO: update the state by using Extended Kalman Filter equations */ double px = x_(0); double py = x_(1); double vx = x_(2); double vy = x_(3); // Coordinate conversion from Cartesian coordinates to Polar coordinates double rho = sqrt(px*px + py*py); double theta = atan2(py, px); double rho_dot = (px*vx + py*vy) / rho; VectorXd h = VectorXd(3); h << rho, theta, rho_dot; VectorXd y = z - h; // Nominalization of angle while (y(1)>M_PI) y(1)-=2*M_PI; while (y(1)<-M_PI) y(1)+=2*M_PI; MatrixXd Ht = H_.transpose(); MatrixXd S = H_ * P_ * Ht + R_; MatrixXd Si = S.inverse(); MatrixXd K = P_ * Ht * Si; x_ = x_ + (K * y); int x_size = x_.size(); MatrixXd I = MatrixXd::Identity(x_size, x_size); P_ = (I - K * H_) * P_; }
-
Lidar Measurement update
void KalmanFilter::Update(const VectorXd &z) { /** * TODO: update the state by using Kalman Filter equations */ VectorXd z_pred = H_ * x_; VectorXd y = z - z_pred;; MatrixXd Ht = H_.transpose(); MatrixXd S = H_ * P_ * Ht + R_; MatrixXd Si = S.inverse(); MatrixXd K = P_ * Ht * Si; x_ = x_ + K * y; int x_size = x_.size(); MatrixXd I = MatrixXd::Identity(x_size, x_size); P_ = (I - K * H_) * P_; }
-
Evaluation Kalman Filter Performance
MatrixXd Tools::CalculateJacobian(const VectorXd& x_state) { /** * TODO: * Calculate a Jacobian here. */ MatrixXd Hj(3,4); // state parameters double px = x_state(0); double py = x_state(1); double vx = x_state(2); double vy = x_state(3); // preparation of Jacobian terms double c1 = px*px+py*py; double c2 = sqrt(c1); double c3 = (c1*c2); if(fabs(c1) < 0.0001){ cout << "ERROR - Division by Zero" << endl; return Hj; } // compute jacobian matrix Hj << (px/c2), (py/c2), 0, 0, -(py/c1), (px/c1), 0, 0, py*(vx*py - vy*px)/c3, px*(px*vy - py*vx)/c3, px/c2, py/c2; return Hj; }
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)
Please (do your best to) stick to Google's C++ style guide.
This is optional!
If you'd like to generate your own radar and lidar data, see the utilities repo for Matlab scripts that can generate additional data.
Note: regardless of the changes you make, your project must be buildable using cmake and make!
More information is only accessible by people who are already enrolled in Term 2 (three-term version) or Term 1 (two-term version) of CarND. If you are enrolled, see the Project Resources page in the classroom for instructions and the project rubric.
-
You don't have to follow this directory structure, but if you do, your work will span all of the .cpp files here. Keep an eye out for TODOs.
-
Students have reported rapid expansion of log files when using the term 2 simulator. This appears to be associated with not being connected to uWebSockets. If this does occur, please make sure you are conneted to uWebSockets. The following workaround may also be effective at preventing large log files.
- create an empty log file
- remove write permissions so that the simulator can't write to log
-
Please note that the
Eigen
library does not initializeVectorXd
orMatrixXd
objects with zeros upon creation.
Help your fellow students!
We decided to create Makefiles with cmake to keep this project as platform agnostic as possible. Similarly, we omitted IDE profiles in order to ensure that students don't feel pressured to use one IDE or another.
However! We'd love to help people get up and running with their IDEs of choice. If you've created a profile for an IDE that you think other students would appreciate, we'd love to have you add the requisite profile files and instructions to ide_profiles/. For example if you wanted to add a VS Code profile, you'd add:
- /ide_profiles/vscode/.vscode
- /ide_profiles/vscode/README.md
The README should explain what the profile does, how to take advantage of it, and how to install it.
Regardless of the IDE used, every submitted project must still be compilable with cmake and make.
A well written README file can enhance your project and portfolio. Develop your abilities to create professional README files by completing this free course.