Skip to content

Commit

Permalink
use the motion utils isDrivingForward function
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Sanchez <[email protected]>
  • Loading branch information
danielsanchezaran committed Oct 24, 2024
1 parent 32e0c92 commit 2ff5ca6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ class AEB : public rclcpp::Node
*/
void getClosestObjectsOnPath(
const Path & ego_path, const rclcpp::Time & stamp,
const PointCloud::Ptr points_belonging_to_cluster_hulls, std::vector<ObjectData> & objects,
const bool ego_moves_forward);
const PointCloud::Ptr points_belonging_to_cluster_hulls, std::vector<ObjectData> & objects);

/**
* @brief Create object data using point cloud clusters
Expand Down
17 changes: 9 additions & 8 deletions control/autoware_autonomous_emergency_braking/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <autoware/autonomous_emergency_braking/node.hpp>
#include <autoware/autonomous_emergency_braking/utils.hpp>
#include <autoware/motion_utils/marker/marker_helper.hpp>
#include <autoware/motion_utils/trajectory/trajectory.hpp>
#include <autoware/universe_utils/geometry/boost_geometry.hpp>
#include <autoware/universe_utils/geometry/boost_polygon_utils.hpp>
#include <autoware/universe_utils/geometry/geometry.hpp>
Expand Down Expand Up @@ -467,9 +468,7 @@ bool AEB::checkCollision(MarkerArray & debug_markers)
use_pointcloud_data_ && points_belonging_to_cluster_hulls &&
!points_belonging_to_cluster_hulls->empty()) {
const auto current_time = obstacle_ros_pointcloud_ptr_->header.stamp;
const bool ego_moves_forward = current_v > 0.0;
getClosestObjectsOnPath(
path, current_time, points_belonging_to_cluster_hulls, objects, ego_moves_forward);
getClosestObjectsOnPath(path, current_time, points_belonging_to_cluster_hulls, objects);
}
if (use_predicted_object_data_) {
createObjectDataUsingPredictedObjects(path, ego_polys, objects);
Expand Down Expand Up @@ -882,15 +881,18 @@ void AEB::getPointsBelongingToClusterHulls(

void AEB::getClosestObjectsOnPath(
const Path & ego_path, const rclcpp::Time & stamp,
const PointCloud::Ptr points_belonging_to_cluster_hulls, std::vector<ObjectData> & objects,
const bool ego_moves_forward)
const PointCloud::Ptr points_belonging_to_cluster_hulls, std::vector<ObjectData> & objects)
{
autoware::universe_utils::ScopedTimeTrack st(__func__, *time_keeper_);
// check if the predicted path has a valid number of points
if (ego_path.size() < 2 || points_belonging_to_cluster_hulls->empty()) {
return;
}

const auto ego_is_driving_forward_opt = autoware::motion_utils::isDrivingForward(ego_path);
if (!ego_is_driving_forward_opt.has_value()) {
return;
}
const bool ego_is_driving_forward = ego_is_driving_forward_opt.value();
// select points inside the ego footprint path
const auto current_p = [&]() {
const auto & first_point_of_path = ego_path.front();
Expand Down Expand Up @@ -919,10 +921,9 @@ void AEB::getClosestObjectsOnPath(

// If the object is behind the ego, we need to use the backward long offset. The distance should
// be a positive number in any case
const double dist_ego_to_object = (ego_moves_forward)
const double dist_ego_to_object = (ego_is_driving_forward)
? obj_arc_length - vehicle_info_.max_longitudinal_offset_m
: obj_arc_length + vehicle_info_.min_longitudinal_offset_m;

Check warning on line 926 in control/autoware_autonomous_emergency_braking/src/node.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

AEB::getClosestObjectsOnPath increases in cyclomatic complexity from 11 to 12, 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.

ObjectData obj;
obj.stamp = stamp;
obj.position = obj_position;
Expand Down
3 changes: 1 addition & 2 deletions control/autoware_autonomous_emergency_braking/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ TEST_F(TestAEB, checkImuPathGeneration)
aeb_node_->getPointsBelongingToClusterHulls(
obstacle_points_ptr, points_belonging_to_cluster_hulls, debug_markers);
std::vector<ObjectData> objects;
aeb_node_->getClosestObjectsOnPath(
imu_path, stamp, points_belonging_to_cluster_hulls, objects, true);
aeb_node_->getClosestObjectsOnPath(imu_path, stamp, points_belonging_to_cluster_hulls, objects);
ASSERT_FALSE(objects.empty());
}

Expand Down

0 comments on commit 2ff5ca6

Please sign in to comment.