Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address all TODO-s in the code. #11

Open
ser94mor opened this issue Apr 21, 2019 · 1 comment
Open

Address all TODO-s in the code. #11

ser94mor opened this issue Apr 21, 2019 · 1 comment

Comments

@ser94mor
Copy link
Owner

No description provided.

@YayoYY
Copy link

YayoYY commented Oct 30, 2024

Here is a case to test CTRV process model + Lidar measurement model:

int main()
{
  using EKF = ExtendedKalmanFilter<CTRV::ProcessModel, Lidar::MeasurementModel<CTRV::ProcessModel>>;
  using BEL = Belief<CTRV::StateVector, CTRV::StateCovarianceMatrix>;

  float v = 2;
  float omega = 30 * M_PI / 180;
  float v_yaw_rate = v / omega;

  float x = 0;
  float y = 0;
  float theta = 0;
  CTRV::StateVector mu;
  mu << x, y, 0, 0, 0;
  CTRV::StateCovarianceMatrix Sigma = Eigen::MatrixXd::Zero(5, 5);
  Sigma.diagonal() << 1., 1., 1., 1., 1.;
  BEL belief{0, mu, Sigma};

  CTRV::ProcessModel pm;
  CTRV::ProcessNoiseCovarianceMatrix mtx;
  mtx << 1.0, 0,
          0, 1.0;
  pm.SetProcessNoiseCovarianceMatrix(mtx);

  CTRV::ControlVector control_vector{CTRV::ControlVector::Zero()};

  Lidar::MeasurementModel<CTRV::ProcessModel> lidar_mm;
  Lidar::MeasurementCovarianceMatrix lidar_mtx;
  lidar_mtx << 1.0, 0.,
               0., 1.;
  lidar_mm.SetMeasurementCovarianceMatrix(lidar_mtx);

  int dt = 1;
  for (int step = 1; step < 100; step += dt)
  {

      BEL belief_prior{belief}; //初始化

      if (step != 1)
      {
          belief_prior = EKF::Predict(belief, control_vector, dt, pm);
      }

      theta += omega * dt;
      x += v_yaw_rate * (std::sin(theta+omega*dt) - std::sin(theta));
      y += v_yaw_rate * (-std::cos(theta+omega*dt) + std::cos(theta));
      Lidar::MeasurementVector m;
      m << x, y;
      std::cout << x << " " << y << std::endl;
      Lidar::Measurement measurement{step, m};

      BEL belief_posterior{EKF::Update(belief_prior, measurement, lidar_mm)};
      belief = belief_posterior;

      std::cout << belief.mu()(0) << " " << belief.mu()(1) << " " << belief.mu()(2)
                << " " << belief.mu()(3) << " " << belief.mu()(4) << std::endl;

  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants