Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(behavior_velocity_run_out): ignore momentary detection caused by false positive #5359

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions planning/behavior_velocity_run_out_module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ You can choose whether to use this feature by parameter of `slow_down_limit.enab
| `max_jerk` | double | [m/s^3] minimum jerk deceleration for safe brake. |
| `max_acc` | double | [m/s^2] minimum accel deceleration for safe brake. |

| Parameter /ignore_momentary_detection | Type | Description |
| ------------------------------------- | ------ | ----------------------------------------------------------------- |
| `enable` | bool | [-] whether to ignore momentary detection |
| `time_threshold` | double | [sec] ignores detections that persist for less than this duration |

### Future extensions / Unimplemented parts

- Calculate obstacle's min velocity and max velocity from covariance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@
enable: true
max_jerk: -0.7 # [m/s^3] minimum jerk deceleration for safe brake.
max_acc : -2.0 # [m/s^2] minimum accel deceleration for safe brake.

# prevent abrupt stops caused by false positives in perception
ignore_momentary_detection:
enable: true
time_threshold: 0.15 # [sec] ignores detections that persist for less than this duration
7 changes: 7 additions & 0 deletions planning/behavior_velocity_run_out_module/src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@
p.max_acc = getOrDeclareParameter<double>(node, ns_m + ".max_acc");
}

{
auto & p = planner_param_.ignore_momentary_detection;
const std::string ns_param = ns + ".ignore_momentary_detection";
p.enable = getOrDeclareParameter<bool>(node, ns_param + ".enable");
p.time_threshold = getOrDeclareParameter<double>(node, ns_param + ".time_threshold");

Check warning on line 126 in planning/behavior_velocity_run_out_module/src/manager.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_run_out_module/src/manager.cpp#L124-L126

Added lines #L124 - L126 were not covered by tests
}

debug_ptr_ = std::make_shared<RunOutDebug>(node);
setDynamicObstacleCreator(node, debug_ptr_);
}
Expand Down
25 changes: 24 additions & 1 deletion planning/behavior_velocity_run_out_module/src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,57 +137,63 @@
}

boost::optional<DynamicObstacle> RunOutModule::detectCollision(
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path) const
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path)
{
if (path.points.size() < 2) {
RCLCPP_WARN_STREAM(logger_, "path doesn't have enough points.");
return {};
}

// detect collision with obstacles from the nearest path point to the end
// ignore the travel time from current pose to nearest path point?
float travel_time = 0.0;
float dist_sum = 0.0;
for (size_t idx = 1; idx < path.points.size(); idx++) {
const auto & p1 = path.points.at(idx - 1).point;
const auto & p2 = path.points.at(idx).point;
const float prev_vel =
std::max(p1.longitudinal_velocity_mps, planner_param_.run_out.min_vel_ego_kmph / 3.6f);
const float ds = tier4_autoware_utils::calcDistance2d(p1, p2);

// calculate travel time from nearest point to p2
travel_time += ds / prev_vel;
dist_sum += ds;

// skip collision detection to reduce calculation time
if (idx != 1 && dist_sum < planner_param_.run_out.detection_span) {
continue;
}
dist_sum = 0.0;

const auto vehicle_poly = createVehiclePolygon(p2.pose);

debug_ptr_->pushPredictedVehiclePolygons(vehicle_poly);
debug_ptr_->pushTravelTimeTexts(travel_time, p2.pose, /* lateral_offset */ 3.0);

auto obstacles_collision =
checkCollisionWithObstacles(dynamic_obstacles, vehicle_poly, travel_time);
if (obstacles_collision.empty()) {
continue;
}

const auto obstacle_selected = findNearestCollisionObstacle(path, p2.pose, obstacles_collision);
if (!obstacle_selected) {
continue;
}

// ignore momentary obstacle detection to avoid sudden stopping by false positive
if (isMomentaryDetection()) {

Check warning on line 185 in planning/behavior_velocity_run_out_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_run_out_module/src/scene.cpp#L185

Added line #L185 was not covered by tests
return {};
}

debug_ptr_->pushCollisionPoints(obstacle_selected->collision_points);
debug_ptr_->pushNearestCollisionPoint(obstacle_selected->nearest_collision_point);

return obstacle_selected;
}

// no collision detected
first_detected_time_.reset();

Check warning on line 196 in planning/behavior_velocity_run_out_module/src/scene.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

RunOutModule::detectCollision increases in cyclomatic complexity from 10 to 11, 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.
return {};
}

Expand Down Expand Up @@ -812,4 +818,21 @@
debug_ptr_->publishDebugValue();
}

bool RunOutModule::isMomentaryDetection()

Check warning on line 821 in planning/behavior_velocity_run_out_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_run_out_module/src/scene.cpp#L821

Added line #L821 was not covered by tests
{
if (!planner_param_.ignore_momentary_detection.enable) {

Check warning on line 823 in planning/behavior_velocity_run_out_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_run_out_module/src/scene.cpp#L823

Added line #L823 was not covered by tests
return false;
}

if (!first_detected_time_) {
first_detected_time_ = std::make_shared<rclcpp::Time>(clock_->now());
return true;

Check warning on line 829 in planning/behavior_velocity_run_out_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_run_out_module/src/scene.cpp#L827-L829

Added lines #L827 - L829 were not covered by tests
}

const auto now = clock_->now();
const double elapsed_time_since_detection = (now - *first_detected_time_).seconds();
RCLCPP_DEBUG_STREAM(logger_, "elapsed_time_since_detection: " << elapsed_time_since_detection);

Check warning on line 834 in planning/behavior_velocity_run_out_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_run_out_module/src/scene.cpp#L832-L834

Added lines #L832 - L834 were not covered by tests

return elapsed_time_since_detection < planner_param_.ignore_momentary_detection.time_threshold;
}

Check warning on line 837 in planning/behavior_velocity_run_out_module/src/scene.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_run_out_module/src/scene.cpp#L836-L837

Added lines #L836 - L837 were not covered by tests
} // namespace behavior_velocity_planner
6 changes: 4 additions & 2 deletions planning/behavior_velocity_run_out_module/src/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ class RunOutModule : public SceneModuleInterface
std::unique_ptr<DynamicObstacleCreator> dynamic_obstacle_creator_;
std::shared_ptr<RunOutDebug> debug_ptr_;
std::unique_ptr<run_out_utils::StateMachine> state_machine_;
std::shared_ptr<rclcpp::Time> first_detected_time_;

// Function
Polygons2d createDetectionAreaPolygon(const PathWithLaneId & smoothed_path) const;

boost::optional<DynamicObstacle> detectCollision(
const std::vector<DynamicObstacle> & dynamic_obstacles,
const PathWithLaneId & path_points) const;
const std::vector<DynamicObstacle> & dynamic_obstacles, const PathWithLaneId & path_points);

float calcCollisionPositionOfVehicleSide(
const geometry_msgs::msg::Point & point, const geometry_msgs::msg::Pose & base_pose) const;
Expand Down Expand Up @@ -141,6 +141,8 @@ class RunOutModule : public SceneModuleInterface
const PathWithLaneId & path, const std::vector<DynamicObstacle> extracted_obstacles,
const boost::optional<DynamicObstacle> & dynamic_obstacle,
const geometry_msgs::msg::Pose & current_pose) const;

bool isMomentaryDetection();
};
} // namespace behavior_velocity_planner

Expand Down
7 changes: 7 additions & 0 deletions planning/behavior_velocity_run_out_module/src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ struct DynamicObstacleParam
float points_interval; // [m]
};

struct IgnoreMomentaryDetection
{
bool enable;
double time_threshold;
};

struct PlannerParam
{
CommonParam common;
Expand All @@ -138,6 +144,7 @@ struct PlannerParam
DynamicObstacleParam dynamic_obstacle;
SlowDownLimit slow_down_limit;
Smoother smoother;
IgnoreMomentaryDetection ignore_momentary_detection;
};

enum class DetectionMethod {
Expand Down
Loading