src/ukf.cpp
/**
 * Updates the state and the state covariance matrix using a laser measurement.
 * @param {MeasurementPackage} meas_package
 */
Updates the state and the state covariance matrix using a laser measurement.
Updates the state and the state covariance matrix using a laser measurement .
void UKF::UpdateLidar(MeasurementPackage meas_package) {
  int n_z = 2;
  MatrixXd Zsig = MatrixXd(n_z, 2 * n_aug_ + 1);
  VectorXd z = VectorXd(n_z);
  z(0) = meas_package.raw_measurements_(0);
  z(1) = meas_package.raw_measurements_(1);
  for (int i = 0; i < 2*n_aug_+1; i++) {
    double px  = Xsig_pred_(0,i);
    double py  = Xsig_pred_(1,i);
    Zsig(0, i) = px;
    Zsig(1, i) = py;
  }
  VectorXd z_pred = VectorXd(n_z);
  z_pred.fill(0.0);
  for (int i = 0; i < 2*n_aug_+1; i++) {
      z_pred = z_pred + weights_(i) * Zsig.col(i);
  }
  MatrixXd S = MatrixXd(n_z, n_z);
  S.fill(0.0);
  for (int i = 0; i < 2*n_aug_+1; i++) {
    VectorXd z_diff = Zsig.col(i) - z_pred;
    S = S + weights_(i) * z_diff * z_diff.transpose();
  }
  MatrixXd R = MatrixXd(n_z, n_z);
  R <<    std_laspx_*std_laspx_, 0,
          0, std_laspy_*std_laspy_;
  S = S + R;
  MatrixXd Tc = MatrixXd(n_x_, n_z);
  Tc.fill(0.0);
  for (int i = 0; i < 2*n_aug_+1; i++) {  
    VectorXd z_diff = Zsig.col(i) - z_pred;
    VectorXd x_diff = Xsig_pred_.col(i) - x_;
    Tc = Tc + weights_(i) * x_diff * z_diff.transpose();
  }
  MatrixXd K = Tc * S.inverse();
  VectorXd z_diff = z - z_pred;
  lidar_nis_ = z_diff.transpose() * S.inverse() * z_diff;
  x_ = x_ + K * z_diff;
  P_ = P_ - K * S * K.transpose();
}
void UKF :: UpdateLidar ( MeasurementPackage meas_package ) { int n_z = 2 ; MatrixXd Zsig = MatrixXd ( n_z , 2 * n_aug_ + 1 ) ; VectorXd z = VectorXd ( n_z ) ; z ( 0 ) = meas_package . raw_measurements_ ( 0 ) ; z ( 1 ) = meas_package . raw_measurements_ ( 1 ) ; for ( int i = 0 ; i < 2 * n_aug_ + 1 ; i ++ ) { double px = Xsig_pred_ ( 0 , i ) ; double py = Xsig_pred_ ( 1 , i ) ; Zsig ( 0 , i ) = px ; Zsig ( 1 , i ) = py ; } VectorXd z_pred = VectorXd ( n_z ) ; z_pred . fill ( 0.0 ) ; for ( int i = 0 ; i < 2 * n_aug_ + 1 ; i ++ ) { z_pred = z_pred + weights_ ( i ) * Zsig . col ( i ) ; } MatrixXd S = MatrixXd ( n_z , n_z ) ; S . fill ( 0.0 ) ; for ( int i = 0 ; i < 2 * n_aug_ + 1 ; i ++ ) { VectorXd z_diff = Zsig . col ( i ) - z_pred ; S = S + weights_ ( i ) * z_diff * z_diff . transpose ( ) ; } MatrixXd R = MatrixXd ( n_z , n_z ) ; R << std_laspx_ * std_laspx_ , 0 , 0 , std_laspy_ * std_laspy_ ; S = S + R ; MatrixXd Tc = MatrixXd ( n_x_ , n_z ) ; Tc . fill ( 0.0 ) ; for ( int i = 0 ; i < 2 * n_aug_ + 1 ; i ++ ) { VectorXd z_diff = Zsig . col ( i ) - z_pred ; VectorXd x_diff = Xsig_pred_ . col ( i ) - x_ ; Tc = Tc + weights_ ( i ) * x_diff * z_diff . transpose ( ) ; } MatrixXd K = Tc * S . inverse ( ) ; VectorXd z_diff = z - z_pred ; lidar_nis_ = z_diff . transpose ( ) * S . inverse ( ) * z_diff ; x_ = x_ + K * z_diff ; P_ = P_ - K * S * K . transpose ( ) ; }
Updates the state and the state covariance matrix using a laser measurement.
Updates the state and the state covariance matrix using a laser measurement .
/**
  TODO:

  Complete this function! Use lidar data to update the belief about the object's
  position. Modify the state vector, x_, and covariance, P_.

  You'll also need to calculate the lidar NIS.
  */ // Convert sigma points into measurement space /// extract values /// measurement model: px, py // Calculate mean predicted measurement // Calculate innovation covariance matrix S // Add measurement noise covariance matrix //calculate cross correlation matrix //2n+1 simga points //Kalman gain K; //update state mean and covariance matrix