|
| 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 | +} |
0 commit comments