# 2. Intro to Extended Kalman Filter Project

1. 红色表示激光雷达测量值
2. 蓝色表示雷达测量值，有个小箭头表示方向
3. 绿色三角形表示更新后的估算值

# 3. Data File for EKF project

• sensor_type
• rho_measured
• phi_measured
• rhodot_measured
• timestamp
• x_groundtruth
• y_groundtruth
• vx_groundtruth
• vy_groundtruth
• yaw_groundtruth
• yawrate_groundtruth

lidar时，各个行分别表示：

• sensor_type
• x_measured
• y_measured
• timestamp
• x_groundtruth
• y_groundtruth
• vx_groundtruth
• vy_groundtruth
• yaw_groundtruth
• yawrate_groundtruth

main.cpp中：

``````MeasurementPackage meas_package;
meas_package.sensor_type_ = MeasurementPackage::LASER;
meas_package.raw_measurements_ = VectorXd(2);
meas_package.raw_measurements_ << px, py;
meas_package.timestamp_ = timestamp;
``````
``````vector<VectorXd> ground_truth;
VectorXd gt_values(4);
gt_values(0) = x_gt;
gt_values(1) = y_gt;
gt_values(2) = vx_gt;
gt_values(3) = vy_gt;
ground_truth.push_back(gt_values);
``````

# 4. File Structure

• 初始化卡尔曼滤波器的变量
• 预测：在经过△t时间后，物体的状态
• 更新：基于传感器的测量值，更新物体的状态值

1. `main.cpp`：从simulator方接受测量数据，调用函数实现卡尔曼滤波，最后评估计算RMSE
2. `FusionEKF.cpp`：初始化滤波器所需要参数，调用预测和更新函数
3. `kalman_filter.cpp`：实现预测和更新函数
4. `tools.cpp`：计算RMSE和Jacobian matrix

1. `Main.cpp`读取数据，并将传感器测量值发送给`FusionEKF.cpp`
2. `FusionEKF.cpp`接收传感器数据，初始化变量以及更新变量。这里有个变量叫`ekf_`，是KalmanFilter滤波器类的实例。`ekf_`中包含了各种矩阵和向量数据，最后使用`ekf_`来实现预测和更新操作。
3. `KalmanFilter`，包含了预测和更新函数。

# 5. Main.cpp

simulator是一个客户端，这个C++程序是个web server。` h.onMessage`接收客户端的输入并相应，将对应的数据保存到对应变量meas_package中。

# 6. Project Code

FusionEKF.cpp：

You will need to:

• initialize variables and matrices (x, F, H_laser, H_jacobian, P, etc.)
• initialize the Kalman filter position vector with the first sensor measurements
• modify the F and Q matrices prior to the prediction step based on the elapsed time between measurements
• call the update step for either the lidar or radar sensor measurement. Because the update step for lidar and radar are slightly different, there are different functions for updating lidar and radar.

``````  // initializing matrices
R_laser_ = MatrixXd(2, 2);
H_laser_ = MatrixXd(2, 4);
Hj_ = MatrixXd(3, 4);

//measurement covariance matrix - laser
R_laser_ << 0.0225, 0,
0, 0.0225;

0, 0.0009, 0,
0, 0, 0.09;

/**
* TODO: Finish initializing the FusionEKF.
* TODO: Set the process and measurement noises
*/
``````

``````  /**
* Initialization
*/
if (!is_initialized_) {
/**
* TODO: Initialize the state ekf_.x_ with the first measurement.
* TODO: Create the covariance matrix.
* You'll need to convert radar from polar to cartesian coordinates.
*/

// first measurement
cout << "EKF: " << endl;
ekf_.x_ = VectorXd(4);
ekf_.x_ << 1, 1, 1, 1;

// TODO: Convert radar from polar to cartesian coordinates
//         and initialize state.

}
else if (measurement_pack.sensor_type_ == MeasurementPackage::LASER) {
// TODO: Initialize state.

}

// done initializing, no need to predict or update
is_initialized_ = true;
return;
}
``````

FusionEKF.cpp中有个变量ekf_，它是KalmanFilter类的示例，存储了卡尔曼对应的系数，并利用它调用预测和更新函数。

KalmanFilter Class

1. Because lidar uses linear equations, the update step will use the basic Kalman filter equations.
2. radar uses non-linear equations, so the update step involves linearizing the equations with the Jacobian matrix.

Tools.cpp

# 7. Tips and Tricks

Summary of What Needs to Be Done：

1. `tools.cpp`: fill in the functions that calculate root mean squared error (RMSE) and the Jacobian matrix.
2. `FusionEKF.cpp`：You’ll need to initialize the Kalman Filter, prepare the Q and F matrices for the prediction step, and call the radar and lidar update functions.
3. `kalman_filter.cpp`：fill out the Predict(), Update(), and UpdateEKF() functions.

# 9. Project Instructions for workspaces

1. Navigate to the repository `CarND-Extended-Kalman-Filter-Project` using the file and directory menu on the left.
2. Run `./install-ubuntu.sh`(you may need to run `chmod u+x install-ubuntu.sh` to make the file executable)
3. Complete the code
4. `mkdir build && cd build` ( from the project top directory)
5. `cmake .. && make` ( build directory)
6. `./ExtendedKF` ( build directory)