Skip to content

Commit bc9d13c

Browse files
technolojinKhalilSelyan
authored and
KhalilSelyan
committed
feat(multi_object_tracker): object position update by size change (#7170)
* fix: update object position offset caused by size change Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp> * fix: update object size only by updating object size, do not memorize previous object size Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp> * fix: rename message package Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp> --------- Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
1 parent 64c8f02 commit bc9d13c

File tree

5 files changed

+37
-83
lines changed

5 files changed

+37
-83
lines changed

perception/multi_object_tracker/include/multi_object_tracker/tracker/model/big_vehicle_tracker.hpp

-12
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ class BigVehicleTracker : public Tracker
4949
double height;
5050
};
5151
BoundingBox bounding_box_;
52-
BoundingBox last_input_bounding_box_;
5352
Eigen::Vector2d tracking_offset_;
54-
int last_nearest_corner_index_;
5553

5654
private:
5755
BicycleMotionModel motion_model_;
@@ -77,16 +75,6 @@ class BigVehicleTracker : public Tracker
7775
const rclcpp::Time & time,
7876
autoware_perception_msgs::msg::TrackedObject & object) const override;
7977
virtual ~BigVehicleTracker() {}
80-
81-
private:
82-
void setNearestCornerOrSurfaceIndex(const geometry_msgs::msg::Transform & self_transform)
83-
{
84-
Eigen::MatrixXd X_t(DIM, 1);
85-
motion_model_.getStateVector(X_t);
86-
last_nearest_corner_index_ = utils::getNearestCornerOrSurface(
87-
X_t(IDX::X), X_t(IDX::Y), X_t(IDX::YAW), bounding_box_.width, bounding_box_.length,
88-
self_transform);
89-
}
9078
};
9179

9280
#endif // MULTI_OBJECT_TRACKER__TRACKER__MODEL__BIG_VEHICLE_TRACKER_HPP_

perception/multi_object_tracker/include/multi_object_tracker/tracker/model/normal_vehicle_tracker.hpp

-12
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ class NormalVehicleTracker : public Tracker
4949
double height;
5050
};
5151
BoundingBox bounding_box_;
52-
BoundingBox last_input_bounding_box_;
5352
Eigen::Vector2d tracking_offset_;
54-
int last_nearest_corner_index_;
5553

5654
private:
5755
BicycleMotionModel motion_model_;
@@ -77,16 +75,6 @@ class NormalVehicleTracker : public Tracker
7775
const rclcpp::Time & time,
7876
autoware_perception_msgs::msg::TrackedObject & object) const override;
7977
virtual ~NormalVehicleTracker() {}
80-
81-
private:
82-
void setNearestCornerOrSurfaceIndex(const geometry_msgs::msg::Transform & self_transform)
83-
{
84-
Eigen::MatrixXd X_t(DIM, 1);
85-
motion_model_.getStateVector(X_t);
86-
last_nearest_corner_index_ = utils::getNearestCornerOrSurface(
87-
X_t(IDX::X), X_t(IDX::Y), X_t(IDX::YAW), bounding_box_.width, bounding_box_.length,
88-
self_transform);
89-
}
9078
};
9179

9280
#endif // MULTI_OBJECT_TRACKER__TRACKER__MODEL__NORMAL_VEHICLE_TRACKER_HPP_

perception/multi_object_tracker/include/multi_object_tracker/utils/utils.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ inline void calcAnchorPointOffset(
280280

281281
// update offset
282282
const Eigen::Vector2d offset = calcOffsetVectorFromShapeChange(w_n - w, l_n - l, indx);
283-
tracking_offset += offset;
283+
tracking_offset = offset;
284284

285285
// offset input object
286286
const Eigen::Matrix2d R = Eigen::Rotation2Dd(yaw).toRotationMatrix();

perception/multi_object_tracker/src/tracker/model/big_vehicle_tracker.cpp

+18-29
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using Label = autoware_perception_msgs::msg::ObjectClassification;
4444

4545
BigVehicleTracker::BigVehicleTracker(
4646
const rclcpp::Time & time, const autoware_perception_msgs::msg::DetectedObject & object,
47-
const geometry_msgs::msg::Transform & self_transform, const size_t channel_size,
47+
const geometry_msgs::msg::Transform & /*self_transform*/, const size_t channel_size,
4848
const uint & channel_index)
4949
: Tracker(time, object.classification, channel_size),
5050
logger_(rclcpp::get_logger("BigVehicleTracker")),
@@ -76,7 +76,6 @@ BigVehicleTracker::BigVehicleTracker(
7676
if (object.shape.type == autoware_perception_msgs::msg::Shape::BOUNDING_BOX) {
7777
bounding_box_ = {
7878
object.shape.dimensions.x, object.shape.dimensions.y, object.shape.dimensions.z};
79-
last_input_bounding_box_ = bounding_box_;
8079
} else {
8180
autoware_perception_msgs::msg::DetectedObject bbox_object;
8281
if (!utils::convertConvexHullToBoundingBox(object, bbox_object)) {
@@ -89,7 +88,6 @@ BigVehicleTracker::BigVehicleTracker(
8988
bbox_object.shape.dimensions.x, bbox_object.shape.dimensions.y,
9089
bbox_object.shape.dimensions.z};
9190
}
92-
last_input_bounding_box_ = bounding_box_;
9391
}
9492
// set maximum and minimum size
9593
constexpr double max_size = 30.0;
@@ -178,9 +176,6 @@ BigVehicleTracker::BigVehicleTracker(
178176
// initialize motion model
179177
motion_model_.initialize(time, x, y, yaw, pose_cov, vel, vel_cov, slip, slip_cov, length);
180178
}
181-
182-
/* calc nearest corner index*/
183-
setNearestCornerOrSurfaceIndex(self_transform); // this index is used in next measure step
184179
}
185180

186181
bool BigVehicleTracker::predict(const rclcpp::Time & time)
@@ -214,11 +209,11 @@ autoware_perception_msgs::msg::DetectedObject BigVehicleTracker::getUpdatingObje
214209
}
215210

216211
// get offset measurement
217-
int nearest_corner_index = utils::getNearestCornerOrSurface(
212+
const int nearest_corner_index = utils::getNearestCornerOrSurface(
218213
tracked_x, tracked_y, tracked_yaw, bounding_box_.width, bounding_box_.length, self_transform);
219214
utils::calcAnchorPointOffset(
220-
last_input_bounding_box_.width, last_input_bounding_box_.length, nearest_corner_index,
221-
bbox_object, tracked_yaw, updating_object, tracking_offset_);
215+
bounding_box_.width, bounding_box_.length, nearest_corner_index, bbox_object, tracked_yaw,
216+
updating_object, tracking_offset_);
222217

223218
// UNCERTAINTY MODEL
224219
if (!object.kinematics.has_position_covariance) {
@@ -332,15 +327,13 @@ bool BigVehicleTracker::measureWithShape(
332327
return false;
333328
}
334329

335-
constexpr double gain = 0.1;
330+
constexpr double gain = 0.5;
336331
constexpr double gain_inv = 1.0 - gain;
337332

338333
// update object size
339334
bounding_box_.length = gain_inv * bounding_box_.length + gain * object.shape.dimensions.x;
340335
bounding_box_.width = gain_inv * bounding_box_.width + gain * object.shape.dimensions.y;
341336
bounding_box_.height = gain_inv * bounding_box_.height + gain * object.shape.dimensions.z;
342-
last_input_bounding_box_ = {
343-
object.shape.dimensions.x, object.shape.dimensions.y, object.shape.dimensions.z};
344337

345338
// set maximum and minimum size
346339
constexpr double max_size = 30.0;
@@ -352,11 +345,19 @@ bool BigVehicleTracker::measureWithShape(
352345
// update motion model
353346
motion_model_.updateExtendedState(bounding_box_.length);
354347

355-
// // update offset into object position
356-
// motion_model_.adjustPosition(gain * tracking_offset_.x(), gain * tracking_offset_.y());
357-
// // update offset
358-
// tracking_offset_.x() = gain_inv * tracking_offset_.x();
359-
// tracking_offset_.y() = gain_inv * tracking_offset_.y();
348+
// update offset into object position
349+
{
350+
// rotate back the offset vector from object coordinate to global coordinate
351+
const double yaw = motion_model_.getStateElement(IDX::YAW);
352+
const double offset_x_global =
353+
tracking_offset_.x() * std::cos(yaw) - tracking_offset_.y() * std::sin(yaw);
354+
const double offset_y_global =
355+
tracking_offset_.x() * std::sin(yaw) + tracking_offset_.y() * std::cos(yaw);
356+
motion_model_.adjustPosition(-gain * offset_x_global, -gain * offset_y_global);
357+
// update offset (object coordinate)
358+
tracking_offset_.x() = gain_inv * tracking_offset_.x();
359+
tracking_offset_.y() = gain_inv * tracking_offset_.y();
360+
}
360361

361362
return true;
362363
}
@@ -390,9 +391,6 @@ bool BigVehicleTracker::measure(
390391
measureWithPose(updating_object);
391392
measureWithShape(updating_object);
392393

393-
/* calc nearest corner index*/
394-
setNearestCornerOrSurfaceIndex(self_transform); // this index is used in next measure step
395-
396394
return true;
397395
}
398396

@@ -414,15 +412,6 @@ bool BigVehicleTracker::getTrackedObject(
414412
return false;
415413
}
416414

417-
// recover bounding box from tracking point
418-
const double dl = bounding_box_.length - last_input_bounding_box_.length;
419-
const double dw = bounding_box_.width - last_input_bounding_box_.width;
420-
const Eigen::Vector2d recovered_pose = utils::recoverFromTrackingPoint(
421-
pose_with_cov.pose.position.x, pose_with_cov.pose.position.y,
422-
motion_model_.getStateElement(IDX::YAW), dw, dl, last_nearest_corner_index_, tracking_offset_);
423-
pose_with_cov.pose.position.x = recovered_pose.x();
424-
pose_with_cov.pose.position.y = recovered_pose.y();
425-
426415
// position
427416
pose_with_cov.pose.position.z = z_;
428417

perception/multi_object_tracker/src/tracker/model/normal_vehicle_tracker.cpp

+18-29
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using Label = autoware_perception_msgs::msg::ObjectClassification;
4444

4545
NormalVehicleTracker::NormalVehicleTracker(
4646
const rclcpp::Time & time, const autoware_perception_msgs::msg::DetectedObject & object,
47-
const geometry_msgs::msg::Transform & self_transform, const size_t channel_size,
47+
const geometry_msgs::msg::Transform & /*self_transform*/, const size_t channel_size,
4848
const uint & channel_index)
4949
: Tracker(time, object.classification, channel_size),
5050
logger_(rclcpp::get_logger("NormalVehicleTracker")),
@@ -76,7 +76,6 @@ NormalVehicleTracker::NormalVehicleTracker(
7676
if (object.shape.type == autoware_perception_msgs::msg::Shape::BOUNDING_BOX) {
7777
bounding_box_ = {
7878
object.shape.dimensions.x, object.shape.dimensions.y, object.shape.dimensions.z};
79-
last_input_bounding_box_ = bounding_box_;
8079
} else {
8180
autoware_perception_msgs::msg::DetectedObject bbox_object;
8281
if (!utils::convertConvexHullToBoundingBox(object, bbox_object)) {
@@ -90,7 +89,6 @@ NormalVehicleTracker::NormalVehicleTracker(
9089
bbox_object.shape.dimensions.x, bbox_object.shape.dimensions.y,
9190
bbox_object.shape.dimensions.z};
9291
}
93-
last_input_bounding_box_ = bounding_box_;
9492
}
9593
// set maximum and minimum size
9694
constexpr double max_size = 20.0;
@@ -179,9 +177,6 @@ NormalVehicleTracker::NormalVehicleTracker(
179177
// initialize motion model
180178
motion_model_.initialize(time, x, y, yaw, pose_cov, vel, vel_cov, slip, slip_cov, length);
181179
}
182-
183-
/* calc nearest corner index*/
184-
setNearestCornerOrSurfaceIndex(self_transform); // this index is used in next measure step
185180
}
186181

187182
bool NormalVehicleTracker::predict(const rclcpp::Time & time)
@@ -216,11 +211,11 @@ autoware_perception_msgs::msg::DetectedObject NormalVehicleTracker::getUpdatingO
216211
}
217212

218213
// get offset measurement
219-
int nearest_corner_index = utils::getNearestCornerOrSurface(
214+
const int nearest_corner_index = utils::getNearestCornerOrSurface(
220215
tracked_x, tracked_y, tracked_yaw, bounding_box_.width, bounding_box_.length, self_transform);
221216
utils::calcAnchorPointOffset(
222-
last_input_bounding_box_.width, last_input_bounding_box_.length, nearest_corner_index,
223-
bbox_object, tracked_yaw, updating_object, tracking_offset_);
217+
bounding_box_.width, bounding_box_.length, nearest_corner_index, bbox_object, tracked_yaw,
218+
updating_object, tracking_offset_);
224219

225220
// UNCERTAINTY MODEL
226221
if (!object.kinematics.has_position_covariance) {
@@ -334,15 +329,13 @@ bool NormalVehicleTracker::measureWithShape(
334329
return false;
335330
}
336331

337-
constexpr double gain = 0.1;
332+
constexpr double gain = 0.5;
338333
constexpr double gain_inv = 1.0 - gain;
339334

340335
// update object size
341336
bounding_box_.length = gain_inv * bounding_box_.length + gain * object.shape.dimensions.x;
342337
bounding_box_.width = gain_inv * bounding_box_.width + gain * object.shape.dimensions.y;
343338
bounding_box_.height = gain_inv * bounding_box_.height + gain * object.shape.dimensions.z;
344-
last_input_bounding_box_ = {
345-
object.shape.dimensions.x, object.shape.dimensions.y, object.shape.dimensions.z};
346339

347340
// set maximum and minimum size
348341
constexpr double max_size = 20.0;
@@ -354,11 +347,19 @@ bool NormalVehicleTracker::measureWithShape(
354347
// update motion model
355348
motion_model_.updateExtendedState(bounding_box_.length);
356349

357-
// // update offset into object position
358-
// motion_model_.adjustPosition(gain * tracking_offset_.x(), gain * tracking_offset_.y());
359-
// // update offset
360-
// tracking_offset_.x() = gain_inv * tracking_offset_.x();
361-
// tracking_offset_.y() = gain_inv * tracking_offset_.y();
350+
// update offset into object position
351+
{
352+
// rotate back the offset vector from object coordinate to global coordinate
353+
const double yaw = motion_model_.getStateElement(IDX::YAW);
354+
const double offset_x_global =
355+
tracking_offset_.x() * std::cos(yaw) - tracking_offset_.y() * std::sin(yaw);
356+
const double offset_y_global =
357+
tracking_offset_.x() * std::sin(yaw) + tracking_offset_.y() * std::cos(yaw);
358+
motion_model_.adjustPosition(-gain * offset_x_global, -gain * offset_y_global);
359+
// update offset (object coordinate)
360+
tracking_offset_.x() = gain_inv * tracking_offset_.x();
361+
tracking_offset_.y() = gain_inv * tracking_offset_.y();
362+
}
362363

363364
return true;
364365
}
@@ -392,9 +393,6 @@ bool NormalVehicleTracker::measure(
392393
measureWithPose(updating_object);
393394
measureWithShape(updating_object);
394395

395-
/* calc nearest corner index*/
396-
setNearestCornerOrSurfaceIndex(self_transform); // this index is used in next measure step
397-
398396
return true;
399397
}
400398

@@ -416,15 +414,6 @@ bool NormalVehicleTracker::getTrackedObject(
416414
return false;
417415
}
418416

419-
// recover bounding box from tracking point
420-
const double dl = bounding_box_.length - last_input_bounding_box_.length;
421-
const double dw = bounding_box_.width - last_input_bounding_box_.width;
422-
const Eigen::Vector2d recovered_pose = utils::recoverFromTrackingPoint(
423-
pose_with_cov.pose.position.x, pose_with_cov.pose.position.y,
424-
motion_model_.getStateElement(IDX::YAW), dw, dl, last_nearest_corner_index_, tracking_offset_);
425-
pose_with_cov.pose.position.x = recovered_pose.x();
426-
pose_with_cov.pose.position.y = recovered_pose.y();
427-
428417
// position
429418
pose_with_cov.pose.position.z = z_;
430419

0 commit comments

Comments
 (0)