Skip to content

Commit 61b98ba

Browse files
committed
initialize student code
1 parent 5d1cd06 commit 61b98ba

15 files changed

+2016
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
# build files
55
build/
6+
7+
# editor config
8+
.vscode/

Docs/Data_Flow_Doc.txt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Data Flow:
2+
1) The measuremennt processor/matlab simulator is generating the FUSION .txt file:
3+
"data/obj_pose-laser-radar-synthetic-ukf-input.txt";
4+
OR
5+
"../matlab_examples/obj_pose-laser-radar-synthetic-ukf-input.txt";
6+
7+
The Input file format is:
8+
#L(for laser) meas_px meas_py timestamp gt_px gt_py gt_vx gt_vy
9+
#R(for radar) meas_rho meas_phi meas_rho_dot timestamp gt_px gt_py gt_vx gt_vy
10+
11+
Example:
12+
R 8.60363 0.0290616 -2.99903 1477010443399637 8.6 0.25 -3.00029 0
13+
L 8.45 0.25 1477010443349642 8.45 0.25 -3.00027 0
14+
15+
2) The EKF Algorithm reads form file reads all the lines and generates measurement structures
16+
3) The MeasurementProcessor() is called with individual measurements (one by one). The results are saved
17+
(Attention: no file processing rutines are used inside MeasurementProcessor() all the file processing rutines are in the main function
18+
So the data read/wirte is decoupled from the algorithm
19+
4) The results are saved in an output file:
20+
"data/obj_pose-laser-radar-ekf-output.txt"
21+
22+
Output file format:
23+
est_px est_py est_vx est_vy meas_px meas_py gt_px gt_py gt_vx gt_vy
24+
25+
Example:
26+
4.53271 0.279 -0.842172 53.1339 4.29136 0.215312 2.28434 0.226323
27+
43.2222 2.65959 0.931181 23.2469 4.29136 0.215312 2.28434 0.226323
28+
29+

Docs/Input_Output File Format.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#L(for laser) meas_px meas_py timestamp gt_px gt_py gt_vx gt_vy
2+
#R(for radar) meas_rho meas_phi meas_rho_dot timestamp gt_px gt_py gt_vx gt_vy
3+
-----------------------------
4+
Example
5+
-----------------------------
6+
R 8.60363 0.0290616 -2.99903 1477010443399637 8.6 0.25 -3.00029 0
7+
L 8.45 0.25 1477010443349642 8.45 0.25 -3.00027 0
8+
9+
#Output file format:
10+
est_px est_py est_vx est_vy meas_px meas_py gt_px gt_py gt_vx gt_vy

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Self-Driving Car Engineer Nanodegree Program
33

44
---
5+
56
## Dependencies
67

78
* cmake >= v3.5
@@ -17,6 +18,19 @@ Self-Driving Car Engineer Nanodegree Program
1718
some sample inputs in 'data/'.
1819
- eg. `./ExtendedKF ../data/obj_pose-laser-radar-ekf-input.txt output.txt`
1920

21+
## Editor Settings
22+
23+
We've purposefully kept editor configuration files out of this repo in order to
24+
keep it as simple and environment agnostic as possible. However, we recommend
25+
using the following settings:
26+
27+
* indent using spaces
28+
* set tab width to 2 spaces (keeps the matrices in source code aligned)
29+
30+
## Code Style
31+
32+
Please (do your best to) stick to [Google's C++ style guide](https://google.github.io/styleguide/cppguide.html).
33+
2034
## Generating Additional Data
2135

2236
This is optional!
@@ -30,3 +44,8 @@ Matlab scripts that can generate additional data.
3044
This information is only accessible by people who are already enrolled in Term 2
3145
of CarND. If you are enrolled, see [the project page](https://classroom.udacity.com/nanodegrees/nd013/parts/40f38239-66b6-46ec-ae68-03afd8a601c8/modules/0949fca6-b379-42af-a919-ee50aa304e6a/lessons/f758c44c-5e40-4e01-93b5-1a82aa4e044f/concepts/12dd29d8-2755-4b1b-8e03-e8f16796bea8)
3246
for instructions and the project rubric.
47+
48+
## Hints!
49+
50+
* You don't have to follow this directory structure, but if you do, your work
51+
will span all of the .cpp files here. Keep an eye out for TODOs.

data/sample-laser-radar-measurement-data-1.txt

+1,224
Large diffs are not rendered by default.

data/sample-laser-radar-measurement-data-2.txt

+200
Large diffs are not rendered by default.

src/FusionEKF.cpp

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include "FusionEKF.h"
2+
#include "tools.h"
3+
#include "Eigen/Dense"
4+
#include <iostream>
5+
6+
using namespace std;
7+
using Eigen::MatrixXd;
8+
using Eigen::VectorXd;
9+
using std::vector;
10+
11+
/*
12+
* Constructor.
13+
*/
14+
FusionEKF::FusionEKF() {
15+
is_initialized_ = false;
16+
17+
previous_timestamp_ = 0;
18+
19+
// initializing matrices
20+
R_laser_ = MatrixXd(2, 2);
21+
R_radar_ = MatrixXd(3, 3);
22+
H_laser_ = MatrixXd(2, 4);
23+
Hj_ = MatrixXd(3, 4);
24+
25+
/**
26+
TODO:
27+
* Finish initializing the FusionEKF.
28+
*/
29+
}
30+
31+
/**
32+
* Destructor.
33+
*/
34+
FusionEKF::~FusionEKF() {}
35+
36+
void FusionEKF::ProcessMeasurement(const MeasurementPackage &measurement_pack) {
37+
/*****************************************************************************
38+
* Initialization
39+
****************************************************************************/
40+
if (!is_initialized_) {
41+
/**
42+
TODO:
43+
* Initialize the state ekf_.x_ with the first measurement.
44+
* Create the covariance matrix.
45+
* Remember: you'll need to convert radar from polar to cartesian coordinates.
46+
*/
47+
// first measurement
48+
cout << "EKF: " << endl;
49+
ekf_.x_ = VectorXd(4);
50+
ekf_.x_ << 1, 1, 1, 1;
51+
52+
if (measurement_pack.sensor_type_ == MeasurementPackage::RADAR) {
53+
/**
54+
Convert radar from polar to cartesian coordinates and initialize state.
55+
*/
56+
}
57+
else if (measurement_pack.sensor_type_ == MeasurementPackage::LASER) {
58+
/**
59+
Initialize state.
60+
*/
61+
}
62+
63+
// done initializing, no need to predict or update
64+
is_initialized_ = true;
65+
return;
66+
}
67+
68+
/*****************************************************************************
69+
* Prediction
70+
****************************************************************************/
71+
72+
/**
73+
TODO:
74+
* Update the state transition matrix F according to the new elapsed time.
75+
- Time is measured in seconds.
76+
* Update the process noise covariance matrix.
77+
*/
78+
79+
ekf_.Predict();
80+
81+
/*****************************************************************************
82+
* Update
83+
****************************************************************************/
84+
85+
/**
86+
TODO:
87+
* Use the sensor type to perform the update step.
88+
* Update the state and covariance matrices.
89+
*/
90+
91+
if (measurement_pack.sensor_type_ == MeasurementPackage::RADAR) {
92+
// Radar updates
93+
} else {
94+
// Laser updates
95+
}
96+
97+
// print the output
98+
cout << "x_ = " << ekf_.x_ << endl;
99+
cout << "P_ = " << ekf_.P_ << endl;
100+
}

src/FusionEKF.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#ifndef FusionEKF_H_
2+
#define FusionEKF_H_
3+
4+
#include "measurement_package.h"
5+
#include <vector>
6+
#include <string>
7+
#include <fstream>
8+
#include "kalman_filter.h"
9+
#include "tools.h"
10+
11+
class FusionEKF {
12+
public:
13+
/**
14+
* Constructor.
15+
*/
16+
FusionEKF();
17+
18+
/**
19+
* Destructor.
20+
*/
21+
virtual ~FusionEKF();
22+
23+
/**
24+
* Run the whole flow of the Kalman Filter from here.
25+
*/
26+
void ProcessMeasurement(const MeasurementPackage &measurement_pack);
27+
28+
/**
29+
* Kalman Filter update and prediction math lives in here.
30+
*/
31+
KalmanFilter ekf_;
32+
33+
private:
34+
// check whether the tracking toolbox was initiallized or not (first measurement)
35+
bool is_initialized_;
36+
37+
// previous timestamp
38+
long previous_timestamp_;
39+
40+
// tool object used to compute Jacobian and RMSE
41+
Tools tools;
42+
MatrixXd R_laser_;
43+
MatrixXd R_radar_;
44+
MatrixXd H_laser_;
45+
MatrixXd Hj_;
46+
};
47+
48+
#endif /* FusionEKF_H_ */

src/ground_truth_package.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef GROUND_TRUTH_PACKAGE_H_
2+
#define GROUND_TRUTH_PACKAGE_H_
3+
4+
#include "Eigen/Dense"
5+
6+
class GroundTruthPackage {
7+
public:
8+
long timestamp_;
9+
10+
enum SensorType{
11+
LASER,
12+
RADAR
13+
} sensor_type_;
14+
15+
Eigen::VectorXd gt_values_;
16+
17+
};
18+
19+
#endif /* MEASUREMENT_PACKAGE_H_ */

src/kalman_filter.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "kalman_filter.h"
2+
3+
KalmanFilter::KalmanFilter() {}
4+
5+
KalmanFilter::~KalmanFilter() {}
6+
7+
void KalmanFilter::Init(VectorXd &x_in, MatrixXd &P_in, MatrixXd &F_in,
8+
MatrixXd &H_in, MatrixXd &R_in, MatrixXd &Q_in) {
9+
x_ = x_in;
10+
P_ = P_in;
11+
F_ = F_in;
12+
H_ = H_in;
13+
R_ = R_in;
14+
Q_ = Q_in;
15+
}
16+
17+
void KalmanFilter::Predict() {
18+
/**
19+
TODO:
20+
* predict the state
21+
*/
22+
}
23+
24+
void KalmanFilter::Update(const VectorXd &z) {
25+
/**
26+
TODO:
27+
* update the state
28+
*/
29+
}
30+
31+
void KalmanFilter::UpdateWithAlreadyPredictedMeasurements(const VectorXd& z, const VectorXd& z_pred) {
32+
/**
33+
TODO:
34+
* update after predicting
35+
*/
36+
}

src/kalman_filter.h

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#ifndef KALMAN_FILTER_H_
2+
#define KALMAN_FILTER_H_
3+
#include "Eigen/Dense"
4+
5+
using Eigen::MatrixXd;
6+
using Eigen::VectorXd;
7+
8+
class KalmanFilter {
9+
public:
10+
11+
// state vector
12+
VectorXd x_;
13+
14+
// state covariance matrix
15+
MatrixXd P_;
16+
17+
// state transistion matrix
18+
MatrixXd F_;
19+
20+
// process covariance matrix
21+
MatrixXd Q_;
22+
23+
// measurement matrix
24+
MatrixXd H_;
25+
26+
// measurement covariance matrix
27+
MatrixXd R_;
28+
29+
/**
30+
* Constructor
31+
*/
32+
KalmanFilter();
33+
34+
/**
35+
* Destructor
36+
*/
37+
virtual ~KalmanFilter();
38+
39+
/**
40+
* Init Initializes Kalman filter
41+
* @param x_in Initial state
42+
* @param P_in Initial state covariance
43+
* @param F_in Transition matrix
44+
* @param H_in Measurement matrix
45+
* @param R_in Measurement covariance matrix
46+
* @param Q_in Process covariance matrix
47+
*/
48+
void Init(VectorXd &x_in, MatrixXd &P_in, MatrixXd &F_in,
49+
MatrixXd &H_in, MatrixXd &R_in, MatrixXd &Q_in);
50+
51+
/**
52+
* Prediction Predicts the state and the state covariance
53+
* using the process model
54+
* @param delta_T Time between k and k+1 in s
55+
*/
56+
void Predict();
57+
58+
/**
59+
* Updates the state and
60+
* @param z The measurement at k+1
61+
*/
62+
void Update(const VectorXd &z);
63+
64+
/**
65+
* @param z The measurement at k+1
66+
* @param z_pred The predicted measurements at k+1
67+
*/
68+
void UpdateWithAlreadyPredictedMeasurements(const VectorXd &z, const VectorXd &z_pred);
69+
70+
};
71+
72+
#endif /* KALMAN_FILTER_H_ */

0 commit comments

Comments
 (0)