Skip to content

Commit ddb9da8

Browse files
committed
refactor(multi_object_tracker): add updateStatePoseVel method to BicycleMotionModel and update measurement logic in VehicleTracker
Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
1 parent 343689a commit ddb9da8

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

perception/autoware_multi_object_tracker/include/autoware/multi_object_tracker/tracker/motion_model/bicycle_motion_model.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class BicycleMotionModel : public MotionModel
9494
const double & x, const double & y, const double & yaw,
9595
const std::array<double, 36> & pose_cov);
9696

97+
bool updateStatePoseVel(
98+
const double & x, const double & y, const std::array<double, 36> & pose_cov, const double & vel,
99+
const std::array<double, 36> & twist_cov);
100+
97101
bool updateStatePoseHeadVel(
98102
const double & x, const double & y, const double & yaw, const std::array<double, 36> & pose_cov,
99103
const double & vel, const std::array<double, 36> & twist_cov);

perception/autoware_multi_object_tracker/lib/tracker/model/vehicle_tracker.cpp

+20-9
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,20 @@ VehicleTracker::VehicleTracker(
135135

136136
bool VehicleTracker::predict(const rclcpp::Time & time)
137137
{
138-
bool success = motion_model_.predictState(time);
139-
if (!success) {
140-
return false;
141-
}
142-
return true;
138+
return motion_model_.predictState(time);
143139
}
144140

145141
bool VehicleTracker::measureWithPose(const types::DynamicObject & object)
146142
{
147-
// current (predicted) state
148-
const double tracked_vel = motion_model_.getStateElement(IDX::VEL);
143+
// get measurement yaw angle to update
144+
bool is_yaw_available =
145+
object.kinematics.orientation_availability != types::OrientationAvailability::UNAVAILABLE;
149146

150147
// velocity capability is checked only when the object has velocity measurement
151148
// and the predicted velocity is close to the observed velocity
152149
bool is_velocity_available = false;
153150
if (object.kinematics.has_twist) {
151+
const double tracked_vel = motion_model_.getStateElement(IDX::VEL);
154152
const double & observed_vel = object.twist.linear.x;
155153
if (std::fabs(tracked_vel - observed_vel) < velocity_deviation_threshold_) {
156154
// Velocity deviation is small
@@ -166,11 +164,21 @@ bool VehicleTracker::measureWithPose(const types::DynamicObject & object)
166164
const double yaw = tf2::getYaw(object.pose.orientation);
167165
const double vel = object.twist.linear.x;
168166

169-
if (is_velocity_available) {
167+
if (is_yaw_available && is_velocity_available) {
168+
// update with yaw angle and velocity
170169
is_updated = motion_model_.updateStatePoseHeadVel(
171170
x, y, yaw, object.pose_covariance, vel, object.twist_covariance);
172-
} else {
171+
} else if (is_yaw_available && !is_velocity_available) {
172+
// update with yaw angle, but without velocity
173173
is_updated = motion_model_.updateStatePoseHead(x, y, yaw, object.pose_covariance);
174+
} else if (!is_yaw_available && is_velocity_available) {
175+
// update without yaw angle, but with velocity
176+
is_updated = motion_model_.updateStatePoseVel(
177+
x, y, object.pose_covariance, vel, object.twist_covariance);
178+
} else {
179+
// update without yaw angle and velocity
180+
is_updated = motion_model_.updateStatePose(
181+
x, y, object.pose_covariance); // update without yaw angle and velocity
174182
}
175183
motion_model_.limitStates();
176184
}
@@ -206,6 +214,9 @@ bool VehicleTracker::measureWithShape(const types::DynamicObject & object)
206214
object_extension.y = gain_inv * object_extension.y + gain * object.shape.dimensions.y;
207215
object_extension.z = gain_inv * object_extension.z + gain * object.shape.dimensions.z;
208216

217+
// set shape type, which is bounding box
218+
object_.shape.type = object.shape.type;
219+
209220
// set maximum and minimum size
210221
limitObjectExtension(object_model_);
211222

perception/autoware_multi_object_tracker/lib/tracker/motion_model/bicycle_motion_model.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,35 @@ bool BicycleMotionModel::updateStatePoseHead(
176176
return ekf_.update(Y, C, R);
177177
}
178178

179+
bool BicycleMotionModel::updateStatePoseVel(
180+
const double & x, const double & y, const std::array<double, 36> & pose_cov, const double & vel,
181+
const std::array<double, 36> & twist_cov)
182+
{
183+
// check if the state is initialized
184+
if (!checkInitialized()) return false;
185+
186+
// update state, with velocity
187+
constexpr int DIM_Y = 4;
188+
189+
// update state
190+
Eigen::MatrixXd Y(DIM_Y, 1);
191+
Y << x, y, vel;
192+
193+
Eigen::MatrixXd C = Eigen::MatrixXd::Zero(DIM_Y, DIM);
194+
C(0, IDX::X) = 1.0;
195+
C(1, IDX::Y) = 1.0;
196+
C(2, IDX::VEL) = 1.0;
197+
198+
Eigen::MatrixXd R = Eigen::MatrixXd::Zero(DIM_Y, DIM_Y);
199+
R(0, 0) = pose_cov[XYZRPY_COV_IDX::X_X];
200+
R(0, 1) = pose_cov[XYZRPY_COV_IDX::X_Y];
201+
R(1, 0) = pose_cov[XYZRPY_COV_IDX::Y_X];
202+
R(1, 1) = pose_cov[XYZRPY_COV_IDX::Y_Y];
203+
R(2, 2) = twist_cov[XYZRPY_COV_IDX::X_X];
204+
205+
return ekf_.update(Y, C, R);
206+
}
207+
179208
bool BicycleMotionModel::updateStatePoseHeadVel(
180209
const double & x, const double & y, const double & yaw, const std::array<double, 36> & pose_cov,
181210
const double & vel, const std::array<double, 36> & twist_cov)

0 commit comments

Comments
 (0)