Skip to content

Commit

Permalink
fix bug by using the collision data keeper
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
  • Loading branch information
danielsanchezaran committed Aug 26, 2024
1 parent 43efc6f commit 6b5b72c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ class CollisionDataKeeper
* @brief Get the closest object data
* @return Object data of the closest object
*/
[[nodiscard]] ObjectData get() const
{
return (closest_object_.has_value()) ? closest_object_.value() : ObjectData();
}
[[nodiscard]] std::optional<ObjectData> get() const { return closest_object_; }

/**
* @brief Get the previous closest object data
Expand Down
25 changes: 15 additions & 10 deletions control/autoware_autonomous_emergency_braking/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,15 @@ void AEB::onCheckCollision(DiagnosticStatusWrapper & stat)
const auto diag_level = DiagnosticStatus::ERROR;
stat.summary(diag_level, error_msg);
const auto & data = collision_data_keeper_.get();
stat.addf("RSS", "%.2f", data.rss);
stat.addf("Distance", "%.2f", data.distance_to_object);
stat.addf("Object Speed", "%.2f", data.velocity);
if (publish_debug_markers_) {
addCollisionMarker(data, debug_markers);
if (data.has_value()) {
stat.addf("RSS", "%.2f", data.value().rss);
stat.addf("Distance", "%.2f", data.value().distance_to_object);
stat.addf("Object Speed", "%.2f", data.value().velocity);
if (publish_debug_markers_) {
addCollisionMarker(data.value(), debug_markers);
}
}

addVirtualStopWallMarker(info_markers);
} else {
const std::string error_msg = "[AEB]: No Collision";
Expand Down Expand Up @@ -476,17 +479,19 @@ bool AEB::checkCollision(MarkerArray & debug_markers)
return std::make_optional<ObjectData>(*closest_object_point_itr);
});

const bool has_collision = (closest_object_point.has_value())
? hasCollision(current_v, closest_object_point.value())
: false;

// Add debug markers
if (publish_debug_markers_) {
const auto [color_r, color_g, color_b, color_a] = debug_colors;
addMarker(
this->get_clock()->now(), path, ego_polys, objects, closest_object_point, color_r, color_g,
color_b, color_a, debug_ns, debug_markers);
this->get_clock()->now(), path, ego_polys, objects, collision_data_keeper_.get(), color_r,
color_g, color_b, color_a, debug_ns, debug_markers);
}
// check collision using rss distance
return (closest_object_point.has_value())
? hasCollision(current_v, closest_object_point.value())
: false;
return has_collision;

Check notice on line 494 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::checkCollision already has high cyclomatic complexity, and now it increases in Lines of Code from 92 to 93. 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.
};

// step3. make function to check collision with ego path created with sensor data
Expand Down

0 comments on commit 6b5b72c

Please sign in to comment.