Skip to content

Commit c753924

Browse files
committed
fix: prediction to use variable kalman filter
a bug was found on `predictStateStep` methods * intention: predict the future state of the variable kalman filter `ekf` * bug: using the member kalman filter `ekf_` * fix: get the state vector from the variable kalman filter `ekf` Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
1 parent d28afea commit c753924

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

perception/multi_object_tracker/src/tracker/motion_model/bicycle_motion_model.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ bool BicycleMotionModel::predictStateStep(const double dt, KalmanFilter & ekf) c
316316

317317
// Current state vector X t
318318
Eigen::MatrixXd X_t(DIM, 1);
319-
getStateVector(X_t);
319+
ekf.getX(X_t);
320320

321321
const double cos_yaw = std::cos(X_t(IDX::YAW) + X_t(IDX::SLIP));
322322
const double sin_yaw = std::sin(X_t(IDX::YAW) + X_t(IDX::SLIP));

perception/multi_object_tracker/src/tracker/motion_model/ctrv_motion_model.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ bool CTRVMotionModel::predictStateStep(const double dt, KalmanFilter & ekf) cons
272272

273273
// Current state vector X t
274274
Eigen::MatrixXd X_t(DIM, 1);
275-
getStateVector(X_t);
275+
ekf.getX(X_t);
276276

277277
const double cos_yaw = std::cos(X_t(IDX::YAW));
278278
const double sin_yaw = std::sin(X_t(IDX::YAW));

perception/multi_object_tracker/src/tracker/motion_model/cv_motion_model.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ bool CVMotionModel::predictStateStep(const double dt, KalmanFilter & ekf) const
209209

210210
// Current state vector X t
211211
Eigen::MatrixXd X_t(DIM, 1);
212-
getStateVector(X_t);
212+
ekf.getX(X_t);
213213

214214
// Predict state vector X t+1
215215
Eigen::MatrixXd X_next_t(DIM, 1); // predicted state

perception/multi_object_tracker/src/tracker/motion_model/motion_model_base.cpp

+23-11
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ bool MotionModel::predictState(const rclcpp::Time & time)
5050
return true;
5151
}
5252

53-
if (!predictStateStep(dt, ekf_)) return false;
54-
55-
// update last_update_time_
53+
// multi-step prediction
54+
// if dt is too large, shorten dt and repeat prediction
55+
const uint32_t repeat = std::floor(dt / dt_max_) + 1;
56+
const double dt_ = dt / repeat;
57+
for (uint32_t i = 0; i < repeat; ++i) {
58+
if (!predictStateStep(dt_, ekf_)) return false;
59+
last_update_time_ += rclcpp::Duration::from_seconds(dt_);
60+
}
61+
// reset the last_update_time_ to the prediction time
5662
last_update_time_ = time;
5763
return true;
5864
}
@@ -63,17 +69,23 @@ bool MotionModel::getPredictedState(
6369
// check if the state is initialized
6470
if (!checkInitialized()) return false;
6571

72+
const double dt = getDeltaTime(time);
73+
if (dt < 1e-6 /*1usec*/) {
74+
// no prediction, return the current state
75+
ekf_.getX(X);
76+
ekf_.getP(P);
77+
return true;
78+
}
79+
6680
// copy the predicted state and covariance
6781
KalmanFilter tmp_ekf_for_no_update = ekf_;
68-
69-
double dt = getDeltaTime(time);
70-
if (dt < 0.0) {
71-
// a naive way to handle the case when the required prediction time is in the past
72-
dt = 0.0;
82+
// multi-step prediction
83+
// if dt is too large, shorten dt and repeat prediction
84+
const uint32_t repeat = std::floor(dt / dt_max_) + 1;
85+
const double dt_ = dt / repeat;
86+
for (uint32_t i = 0; i < repeat; ++i) {
87+
if (!predictStateStep(dt_, tmp_ekf_for_no_update)) return false;
7388
}
74-
75-
if (!predictStateStep(dt, tmp_ekf_for_no_update)) return false;
76-
7789
tmp_ekf_for_no_update.getX(X);
7890
tmp_ekf_for_no_update.getP(P);
7991
return true;

0 commit comments

Comments
 (0)