Skip to content

Commit 17cac69

Browse files
committed
chore: align tracker format
Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
1 parent eda2b3c commit 17cac69

File tree

4 files changed

+92
-89
lines changed

4 files changed

+92
-89
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class NormalVehicleTracker : public Tracker
9090
const rclcpp::Time & time,
9191
autoware_auto_perception_msgs::msg::TrackedObject & object) const override;
9292
void setNearestCornerOrSurfaceIndex(const geometry_msgs::msg::Transform & self_transform);
93+
double getMeasurementYaw(const autoware_auto_perception_msgs::msg::DetectedObject & object);
9394
virtual ~NormalVehicleTracker() {}
9495
};
9596

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

+22-17
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//
1818

1919
#include "multi_object_tracker/tracker/model/bicycle_tracker.hpp"
20-
2120
#include "multi_object_tracker/utils/utils.hpp"
2221

2322
#include <tier4_autoware_utils/geometry/boost_polygon_utils.hpp>
@@ -94,16 +93,15 @@ BicycleTracker::BicycleTracker(
9493
X(IDX::X) = object.kinematics.pose_with_covariance.pose.position.x;
9594
X(IDX::Y) = object.kinematics.pose_with_covariance.pose.position.y;
9695
X(IDX::YAW) = tf2::getYaw(object.kinematics.pose_with_covariance.pose.orientation);
96+
X(IDX::SLIP) = 0.0;
9797
if (object.kinematics.has_twist) {
9898
X(IDX::VEL) = object.kinematics.twist_with_covariance.twist.linear.x;
9999
} else {
100100
X(IDX::VEL) = 0.0;
101101
}
102-
X(IDX::SLIP) = 0.0;
103102

104103
// initialize state covariance matrix P
105104
Eigen::MatrixXd P = Eigen::MatrixXd::Zero(ekf_params_.dim_x, ekf_params_.dim_x);
106-
107105
if (!object.kinematics.has_position_covariance) {
108106
const double cos_yaw = std::cos(X(IDX::YAW));
109107
const double sin_yaw = std::sin(X(IDX::YAW));
@@ -250,16 +248,15 @@ bool BicycleTracker::predict(const double dt, KalmanFilter & ekf) const
250248
q_stddev_yaw_rate = std::min(q_stddev_yaw_rate, ekf_params_.q_stddev_yaw_rate_max);
251249
q_stddev_yaw_rate = std::max(q_stddev_yaw_rate, ekf_params_.q_stddev_yaw_rate_min);
252250
}
253-
float q_cov_slip_rate{0.0};
251+
float q_cov_slip_rate{0.0f};
254252
if (vel <= 0.01) {
255253
q_cov_slip_rate = ekf_params_.q_cov_slip_rate_min;
256254
} else {
255+
// The slip angle rate uncertainty is modeled as follows:
256+
// d(slip)/dt ~ - sin(slip)/v * d(v)/dt + l_r/v * d(w)/dt
257257
// where sin(slip) = w * l_r / v
258-
// uncertainty of the slip angle rate is modeled as
259-
// d(slip)/dt ~ - w*l_r/v^2 * d(v)/dt + l_r/v * d(w)/dt
260-
// = - sin(slip)/v * d(v)/dt + l_r/v * d(w)/dt
261-
// d(w)/dt is modeled as proportional to w (more uncertain when slip is large)
262-
// d(v)/dt and d(w)/t is considered that those are not correlated
258+
// d(w)/dt is assumed to be proportional to w (more uncertain when slip is large)
259+
// d(v)/dt and d(w)/t are considered to be uncorrelated
263260
q_cov_slip_rate =
264261
std::pow(ekf_params_.q_stddev_acc_lat * sin_slip / vel, 2) + std::pow(sin_slip * 1.5, 2);
265262
q_cov_slip_rate = std::min(q_cov_slip_rate, ekf_params_.q_cov_slip_rate_max);
@@ -378,12 +375,12 @@ bool BicycleTracker::measureWithPose(
378375
}
379376
}
380377

381-
// update with ekf
378+
// ekf update
382379
if (!ekf_.update(Y, C, R)) {
383380
RCLCPP_WARN(logger_, "Cannot update");
384381
}
385382

386-
// normalize yaw and limit vel, wz
383+
// normalize yaw and limit vel, slip
387384
{
388385
Eigen::MatrixXd X_t(ekf_params_.dim_x, 1);
389386
Eigen::MatrixXd P_t(ekf_params_.dim_x, ekf_params_.dim_x);
@@ -409,14 +406,22 @@ bool BicycleTracker::measureWithPose(
409406
bool BicycleTracker::measureWithShape(
410407
const autoware_auto_perception_msgs::msg::DetectedObject & object)
411408
{
409+
// if the input shape is convex type, convert it to bbox type
410+
autoware_auto_perception_msgs::msg::DetectedObject bbox_object;
412411
if (object.shape.type != autoware_auto_perception_msgs::msg::Shape::BOUNDING_BOX) {
413-
return false;
412+
utils::convertConvexHullToBoundingBox(object, bbox_object);
413+
} else {
414+
bbox_object = object;
414415
}
415-
constexpr float gain = 0.9;
416416

417-
bounding_box_.length = gain * bounding_box_.length + (1.0 - gain) * object.shape.dimensions.x;
418-
bounding_box_.width = gain * bounding_box_.width + (1.0 - gain) * object.shape.dimensions.y;
419-
bounding_box_.height = gain * bounding_box_.height + (1.0 - gain) * object.shape.dimensions.z;
417+
constexpr float gain = 0.9;
418+
bounding_box_.length =
419+
gain * bounding_box_.length + (1.0 - gain) * bbox_object.shape.dimensions.x;
420+
bounding_box_.width = gain * bounding_box_.width + (1.0 - gain) * bbox_object.shape.dimensions.y;
421+
bounding_box_.height =
422+
gain * bounding_box_.height + (1.0 - gain) * bbox_object.shape.dimensions.z;
423+
last_input_bounding_box_ = {
424+
bbox_object.shape.dimensions.x, bbox_object.shape.dimensions.y, bbox_object.shape.dimensions.z};
420425

421426
// update lf, lr
422427
lf_ = bounding_box_.length * 0.3; // 30% front from the center
@@ -454,7 +459,7 @@ bool BicycleTracker::getTrackedObject(
454459
object.object_id = getUUID();
455460
object.classification = getClassification();
456461

457-
// predict kinematics
462+
// predict state
458463
KalmanFilter tmp_ekf_for_no_update = ekf_;
459464
const double dt = (time - last_update_time_).seconds();
460465
if (0.001 /*1msec*/ < dt) {

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

+23-26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
// Author: v1.0 Yukihiro Saito
1717
//
1818

19+
#include "multi_object_tracker/tracker/model/big_vehicle_tracker.hpp"
20+
#include "multi_object_tracker/utils/utils.hpp"
21+
22+
#include <tier4_autoware_utils/geometry/boost_polygon_utils.hpp>
23+
#include <tier4_autoware_utils/math/normalization.hpp>
24+
#include <tier4_autoware_utils/math/unit_conversion.hpp>
25+
1926
#include <bits/stdc++.h>
2027
#include <tf2/LinearMath/Matrix3x3.h>
2128
#include <tf2/LinearMath/Quaternion.h>
@@ -26,17 +33,11 @@
2633
#else
2734
#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
2835
#endif
29-
30-
#define EIGEN_MPL2_ONLY
31-
#include "multi_object_tracker/tracker/model/big_vehicle_tracker.hpp"
32-
#include "multi_object_tracker/utils/utils.hpp"
3336
#include "object_recognition_utils/object_recognition_utils.hpp"
3437

38+
#define EIGEN_MPL2_ONLY
3539
#include <Eigen/Core>
3640
#include <Eigen/Geometry>
37-
#include <tier4_autoware_utils/geometry/boost_polygon_utils.hpp>
38-
#include <tier4_autoware_utils/math/normalization.hpp>
39-
#include <tier4_autoware_utils/math/unit_conversion.hpp>
4041

4142
using Label = autoware_auto_perception_msgs::msg::ObjectClassification;
4243

@@ -99,7 +100,6 @@ BigVehicleTracker::BigVehicleTracker(
99100
X(IDX::SLIP) = 0.0;
100101
if (object.kinematics.has_twist) {
101102
X(IDX::VEL) = object.kinematics.twist_with_covariance.twist.linear.x;
102-
// X(IDX::YAW) = object.kinematics.twist_with_covariance.twist.angular.z;
103103
} else {
104104
X(IDX::VEL) = 0.0;
105105
}
@@ -149,9 +149,7 @@ BigVehicleTracker::BigVehicleTracker(
149149
bounding_box_ = {
150150
bbox_object.shape.dimensions.x, bbox_object.shape.dimensions.y,
151151
bbox_object.shape.dimensions.z};
152-
last_input_bounding_box_ = {
153-
bbox_object.shape.dimensions.x, bbox_object.shape.dimensions.y,
154-
bbox_object.shape.dimensions.z};
152+
last_input_bounding_box_ = bounding_box_;
155153
}
156154
ekf_.init(X, P);
157155

@@ -265,16 +263,15 @@ bool BigVehicleTracker::predict(const double dt, KalmanFilter & ekf) const
265263
q_stddev_yaw_rate = std::min(q_stddev_yaw_rate, ekf_params_.q_stddev_yaw_rate_max);
266264
q_stddev_yaw_rate = std::max(q_stddev_yaw_rate, ekf_params_.q_stddev_yaw_rate_min);
267265
}
268-
float q_cov_slip_rate{0.0};
266+
float q_cov_slip_rate{0.0f};
269267
if (vel <= 0.01) {
270268
q_cov_slip_rate = ekf_params_.q_cov_slip_rate_min;
271269
} else {
270+
// The slip angle rate uncertainty is modeled as follows:
271+
// d(slip)/dt ~ - sin(slip)/v * d(v)/dt + l_r/v * d(w)/dt
272272
// where sin(slip) = w * l_r / v
273-
// uncertainty of the slip angle rate is modeled as
274-
// d(slip)/dt ~ - w*l_r/v^2 * d(v)/dt + l_r/v * d(w)/dt
275-
// = - sin(slip)/v * d(v)/dt + l_r/v * d(w)/dt
276-
// d(w)/dt is modeled as proportional to w (more uncertain when slip is large)
277-
// d(v)/dt and d(w)/t is considered that those are not correlated
273+
// d(w)/dt is assumed to be proportional to w (more uncertain when slip is large)
274+
// d(v)/dt and d(w)/t are considered to be uncorrelated
278275
q_cov_slip_rate =
279276
std::pow(ekf_params_.q_stddev_acc_lat * sin_slip / vel, 2) + std::pow(sin_slip * 1.5, 2);
280277
q_cov_slip_rate = std::min(q_cov_slip_rate, ekf_params_.q_cov_slip_rate_max);
@@ -317,14 +314,14 @@ bool BigVehicleTracker::measureWithPose(
317314
float r_cov_y;
318315
const uint8_t label = object_recognition_utils::getHighestProbLabel(object.classification);
319316

320-
if (label == Label::CAR) {
317+
if (utils::isLargeVehicleLabel(label)) {
318+
r_cov_x = ekf_params_.r_cov_x;
319+
r_cov_y = ekf_params_.r_cov_y;
320+
} else if (label == Label::CAR) {
321321
constexpr float r_stddev_x = 2.0; // [m]
322322
constexpr float r_stddev_y = 2.0; // [m]
323323
r_cov_x = std::pow(r_stddev_x, 2.0);
324324
r_cov_y = std::pow(r_stddev_y, 2.0);
325-
} else if (utils::isLargeVehicleLabel(label)) {
326-
r_cov_x = ekf_params_.r_cov_x;
327-
r_cov_y = ekf_params_.r_cov_y;
328325
} else {
329326
r_cov_x = ekf_params_.r_cov_x;
330327
r_cov_y = ekf_params_.r_cov_y;
@@ -364,7 +361,7 @@ bool BigVehicleTracker::measureWithPose(
364361
last_input_bounding_box_.width, last_input_bounding_box_.length, last_nearest_corner_index_,
365362
bbox_object, X_t(IDX::YAW), offset_object, tracking_offset_);
366363

367-
/* Set measurement matrix */
364+
/* Set measurement matrix and noise covariance*/
368365
Eigen::MatrixXd Y(dim_y, 1);
369366
Eigen::MatrixXd C = Eigen::MatrixXd::Zero(dim_y, ekf_params_.dim_x);
370367
Eigen::MatrixXd R = Eigen::MatrixXd::Zero(dim_y, dim_y);
@@ -398,6 +395,7 @@ bool BigVehicleTracker::measureWithPose(
398395
R(2, 2) = object.kinematics.pose_with_covariance.covariance[utils::MSG_COV_IDX::YAW_YAW];
399396
}
400397

398+
// Update the velocity when necessary
401399
if (dim_y == 4) {
402400
Y(IDX::VEL, 0) = object.kinematics.twist_with_covariance.twist.linear.x;
403401
C(3, IDX::VEL) = 1.0; // for vel
@@ -409,7 +407,7 @@ bool BigVehicleTracker::measureWithPose(
409407
}
410408
}
411409

412-
/* ekf tracks constant tracking point */
410+
// ekf update
413411
if (!ekf_.update(Y, C, R)) {
414412
RCLCPP_WARN(logger_, "Cannot update");
415413
}
@@ -440,9 +438,8 @@ bool BigVehicleTracker::measureWithPose(
440438
bool BigVehicleTracker::measureWithShape(
441439
const autoware_auto_perception_msgs::msg::DetectedObject & object)
442440
{
441+
// if the input shape is convex type, convert it to bbox type
443442
autoware_auto_perception_msgs::msg::DetectedObject bbox_object;
444-
445-
// if input is convex shape convert it to bbox shape
446443
if (object.shape.type != autoware_auto_perception_msgs::msg::Shape::BOUNDING_BOX) {
447444
utils::convertConvexHullToBoundingBox(object, bbox_object);
448445
} else {
@@ -565,6 +562,7 @@ bool BigVehicleTracker::getTrackedObject(
565562
* wz = vel * sin(slip) / l_r = vy / l_r
566563
*
567564
*/
565+
568566
constexpr double vz_cov = 0.1 * 0.1; // TODO(yukkysaito) Currently tentative
569567
constexpr double wx_cov = 0.1 * 0.1; // TODO(yukkysaito) Currently tentative
570568
constexpr double wy_cov = 0.1 * 0.1; // TODO(yukkysaito) Currently tentative
@@ -599,7 +597,6 @@ bool BigVehicleTracker::getTrackedObject(
599597
const auto ekf_pose_yaw = tf2::getYaw(pose_with_cov.pose.orientation);
600598
object.shape.footprint =
601599
tier4_autoware_utils::rotatePolygon(object.shape.footprint, origin_yaw - ekf_pose_yaw);
602-
603600
return true;
604601
}
605602

0 commit comments

Comments
 (0)