Skip to content

Commit

Permalink
refactor(multi_object_tracker): update calcAnchorPointOffset function…
Browse files Browse the repository at this point in the history
… signature and streamline object handling
  • Loading branch information
technolojin committed Mar 10, 2025
1 parent a97ab6b commit cfcdbca
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ void getNearestCornerOrSurface(
const geometry_msgs::msg::Transform & self_transform, types::DynamicObject & object);

void calcAnchorPointOffset(
const types::DynamicObject & this_object, const types::DynamicObject & input_object,
Eigen::Vector2d & tracking_offset, types::DynamicObject & offset_object);
const types::DynamicObject & this_object, Eigen::Vector2d & tracking_offset,
types::DynamicObject & offset_object);
} // namespace shapes
} // namespace autoware::multi_object_tracker

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,16 @@ void getNearestCornerOrSurface(
}

void calcAnchorPointOffset(
const types::DynamicObject & this_object, const types::DynamicObject & input_object,
Eigen::Vector2d & tracking_offset, types::DynamicObject & offset_object)
const types::DynamicObject & this_object, Eigen::Vector2d & tracking_offset,
types::DynamicObject & updating_object)
{
// copy value
offset_object = input_object;
const geometry_msgs::msg::Point anchor_vector = input_object.anchor_point;
const geometry_msgs::msg::Point anchor_vector = updating_object.anchor_point;
// invalid anchor
if (anchor_vector.x <= 1e-6 && anchor_vector.y <= 1e-6) {
return;
}
double input_yaw = tf2::getYaw(input_object.pose.orientation);
double input_yaw = tf2::getYaw(updating_object.pose.orientation);

// current object width and height
const double length = this_object.shape.dimensions.x;
Expand All @@ -250,8 +249,8 @@ void calcAnchorPointOffset(
// offset input object
const Eigen::Matrix2d R = Eigen::Rotation2Dd(input_yaw).toRotationMatrix();
const Eigen::Vector2d rotated_offset = R * tracking_offset;
offset_object.pose.position.x += rotated_offset.x();
offset_object.pose.position.y += rotated_offset.y();
updating_object.pose.position.x += rotated_offset.x();
updating_object.pose.position.y += rotated_offset.y();

Check notice on line 253 in perception/autoware_multi_object_tracker/lib/object_model/shapes.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Excess Number of Function Arguments

calcAnchorPointOffset is no longer above the threshold for number of arguments
}

} // namespace shapes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ bool BicycleTracker::getTrackedObject(
const rclcpp::Time & time, types::DynamicObject & object) const
{
object = object_;

// predict from motion model
auto & pose = object.pose;
auto & pose_cov = object.pose_covariance;
auto & twist = object.twist;
auto & twist_cov = object.twist_covariance;

// predict from motion model
if (!motion_model_.getPredictedState(time, pose, pose_cov, twist, twist_cov)) {
RCLCPP_WARN(logger_, "BicycleTracker::getTrackedObject: Failed to get predicted state.");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ bool PedestrianTracker::measureWithShape(const types::DynamicObject & object)

bool PedestrianTracker::measure(const types::DynamicObject & object, const rclcpp::Time & time)
{
// keep the latest input object
object_ = object;

// check time gap
const double dt = motion_model_.getDeltaTime(time);
if (0.01 /*10msec*/ < dt) {
Expand All @@ -192,12 +189,12 @@ bool PedestrianTracker::getTrackedObject(
const rclcpp::Time & time, types::DynamicObject & object) const
{
object = object_;

// predict from motion model
auto & pose = object.pose;
auto & pose_cov = object.pose_covariance;
auto & twist = object.twist;
auto & twist_cov = object.twist_covariance;

// predict from motion model
if (!motion_model_.getPredictedState(time, pose, pose_cov, twist, twist_cov)) {
RCLCPP_WARN(logger_, "PedestrianTracker::getTrackedObject: Failed to get predicted state.");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ bool UnknownTracker::measureWithPose(const types::DynamicObject & object)

bool UnknownTracker::measure(const types::DynamicObject & object, const rclcpp::Time & time)
{
// keep the latest input object
object_ = object;
// update object shape
object_.shape = object.shape;

// check time gap
const double dt = motion_model_.getDeltaTime(time);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,8 @@ bool VehicleTracker::measureWithShape(const types::DynamicObject & object)
return true;
}

bool VehicleTracker::measure(const types::DynamicObject & object, const rclcpp::Time & time)
bool VehicleTracker::measure(const types::DynamicObject & in_object, const rclcpp::Time & time)
{
// keep the latest input object
object_ = object;

// check time gap
const double dt = motion_model_.getDeltaTime(time);
if (0.01 /*10msec*/ < dt) {
Expand All @@ -243,8 +240,8 @@ bool VehicleTracker::measure(const types::DynamicObject & object, const rclcpp::
}

// update object
types::DynamicObject updating_object = object;
shapes::calcAnchorPointOffset(object_, object, tracking_offset_, updating_object);
types::DynamicObject updating_object = in_object;
shapes::calcAnchorPointOffset(object_, tracking_offset_, updating_object);
measureWithPose(updating_object);
measureWithShape(updating_object);

Expand All @@ -255,12 +252,12 @@ bool VehicleTracker::getTrackedObject(
const rclcpp::Time & time, types::DynamicObject & object) const
{
object = object_;

// predict from motion model
auto & pose = object.pose;
auto & pose_cov = object.pose_covariance;
auto & twist = object.twist;
auto & twist_cov = object.twist_covariance;

// predict from motion model
if (!motion_model_.getPredictedState(time, pose, pose_cov, twist, twist_cov)) {
RCLCPP_WARN(logger_, "VehicleTracker::getTrackedObject: Failed to get predicted state.");
return false;
Expand Down

0 comments on commit cfcdbca

Please sign in to comment.