Skip to content

Commit

Permalink
perf(map_based_prediction): improve world to map transform calculation
Browse files Browse the repository at this point in the history
1. remove unused transforms
2. make transform loading late as possible

Signed-off-by: Taekjin LEE <taekjin.lee@tier4.jp>
  • Loading branch information
technolojin committed Aug 8, 2024
1 parent 147403f commit cab8307
Showing 1 changed file with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -971,23 +971,6 @@ void MapBasedPredictionNode::objectsCallback(const TrackedObjects::ConstSharedPt
return;
}

Check notice on line 973 in perception/autoware_map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Conditional

MapBasedPredictionNode::objectsCallback no longer has a complex conditional. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
auto world2map_transform = transform_listener_.getTransform(
"map", // target
in_objects->header.frame_id, // src
in_objects->header.stamp, rclcpp::Duration::from_seconds(0.1));
auto map2world_transform = transform_listener_.getTransform(
in_objects->header.frame_id, // target
"map", // src
in_objects->header.stamp, rclcpp::Duration::from_seconds(0.1));
auto debug_map2lidar_transform = transform_listener_.getTransform(
"base_link", // target
"map", // src
rclcpp::Time(), rclcpp::Duration::from_seconds(0.1));

if (!world2map_transform || !map2world_transform || !debug_map2lidar_transform) {
return;
}

// Remove old objects information in object history
const double objects_detected_time = rclcpp::Time(in_objects->header.stamp).seconds();
removeOldObjectsHistory(objects_detected_time, object_buffer_time_length_, road_users_history);
Expand Down Expand Up @@ -1026,6 +1009,12 @@ void MapBasedPredictionNode::objectsCallback(const TrackedObjects::ConstSharedPt
}
std::unordered_set<std::string> predicted_crosswalk_users_ids;

// get world to map transform
auto world2map_transform = transform_listener_.getTransform(
"map", // target
in_objects->header.frame_id, // src
in_objects->header.stamp, rclcpp::Duration::from_seconds(0.1));

Check notice on line 1017 in perception/autoware_map_based_prediction/src/map_based_prediction_node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Complex Method

MapBasedPredictionNode::objectsCallback decreases in cyclomatic complexity from 46 to 43, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
for (const auto & object : in_objects->objects) {
TrackedObject transformed_object = object;

Expand Down

0 comments on commit cab8307

Please sign in to comment.