Skip to content

Commit 86aaa08

Browse files
committed
fix(multi_object_tracker): mot multi-step prediction is not work as intended (autowarefoundation#6611)
* bugfix: mot multi-step prediction is not work as intended. back to one-step prediction. Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp> * fix: remove comment-out codes Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp> * 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> --------- Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
1 parent 3f8c721 commit 86aaa08

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

perception/multi_object_tracker/include/multi_object_tracker/multi_object_tracker_core.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class MultiObjectTracker : public rclcpp::Node
124124
const autoware_auto_perception_msgs::msg::DetectedObject & object, const rclcpp::Time & time,
125125
const geometry_msgs::msg::Transform & self_transform) const;
126126

127-
void publish(const rclcpp::Time & time);
127+
void publish(const rclcpp::Time & time) const;
128128
inline bool shouldTrackerPublish(const std::shared_ptr<const Tracker> tracker) const;
129129
};
130130

perception/multi_object_tracker/src/multi_object_tracker_core.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ inline bool MultiObjectTracker::shouldTrackerPublish(
441441
return true;
442442
}
443443

444-
void MultiObjectTracker::publish(const rclcpp::Time & time)
444+
void MultiObjectTracker::publish(const rclcpp::Time & time) const
445445
{
446446
const auto subscriber_count = tracked_objects_pub_->get_subscription_count() +
447447
tracked_objects_pub_->get_intra_process_subscription_count();

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

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

318318
// Current state vector X t
319319
Eigen::MatrixXd X_t(DIM, 1);
320-
getStateVector(X_t);
320+
ekf.getX(X_t);
321321

322322
const double cos_yaw = std::cos(X_t(IDX::YAW) + X_t(IDX::SLIP));
323323
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

+22-23
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ bool MotionModel::predictState(const rclcpp::Time & time)
4646
if (dt < 0.0) {
4747
return false;
4848
}
49+
if (dt < 1e-6 /*1usec*/) {
50+
return true;
51+
}
52+
53+
// multi-step prediction
4954
// if dt is too large, shorten dt and repeat prediction
50-
const uint32_t repeat = std::ceil(dt / dt_max_);
55+
const uint32_t repeat = std::floor(dt / dt_max_) + 1;
5156
const double dt_ = dt / repeat;
5257
for (uint32_t i = 0; i < repeat; ++i) {
53-
if (!predictStateStep(dt_, ekf_)) {
54-
return false;
55-
}
56-
// add interval to last_update_time_
58+
if (!predictStateStep(dt_, ekf_)) return false;
5759
last_update_time_ += rclcpp::Duration::from_seconds(dt_);
5860
}
59-
// update last_update_time_ to the estimation time
61+
// reset the last_update_time_ to the prediction time
6062
last_update_time_ = time;
6163
return true;
6264
}
@@ -67,25 +69,22 @@ bool MotionModel::getPredictedState(
6769
// check if the state is initialized
6870
if (!checkInitialized()) return false;
6971

70-
// copy the predicted state and covariance
71-
KalmanFilter tmp_ekf_for_no_update = ekf_;
72-
73-
double dt = getDeltaTime(time);
74-
if (dt < 0.0) {
75-
// a naive way to handle the case when the required prediction time is in the past
76-
dt = 0.0;
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;
7778
}
7879

79-
// predict only when dt is small enough
80-
if (0.001 /*1msec*/ < dt) {
81-
// if dt is too large, shorten dt and repeat prediction
82-
const uint32_t repeat = std::ceil(dt / dt_max_);
83-
const double dt_ = dt / repeat;
84-
for (uint32_t i = 0; i < repeat; ++i) {
85-
if (!predictStateStep(dt_, tmp_ekf_for_no_update)) {
86-
return false;
87-
}
88-
}
80+
// copy the predicted state and covariance
81+
KalmanFilter tmp_ekf_for_no_update = ekf_;
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;
8988
}
9089
tmp_ekf_for_no_update.getX(X);
9190
tmp_ekf_for_no_update.getP(P);

0 commit comments

Comments
 (0)