Skip to content

Commit

Permalink
feat(crosswalk): ignore predicted path going across the crosswalk
Browse files Browse the repository at this point in the history
Signed-off-by: Mamoru Sobue <[email protected]>
  • Loading branch information
soblin committed Dec 12, 2023
1 parent 91290a3 commit 4d162cc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
# param for target object filtering
object_filtering:
crosswalk_attention_range: 1.0 # [m] the detection area is defined as -X meters before the crosswalk to +X meters behind the crosswalk
vehicle_object_cross_angle_threshold: 0.785 # [rad] threshold judging object is crossing walkway as a pedestrian or passing over as a vehicle
target_object:
unknown: true # [-] whether to look and stop by UNKNOWN objects
bicycle: true # [-] whether to look and stop by BICYCLE objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum class CollisionState { YIELD, EGO_PASS_FIRST, EGO_PASS_LATER, IGNORE };
struct CollisionPoint
{
geometry_msgs::msg::Point collision_point{};
double crosswalk_passage_direction;
double time_to_collision{};
double time_to_vehicle{};
};
Expand Down
2 changes: 2 additions & 0 deletions planning/behavior_velocity_crosswalk_module/src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ CrosswalkModuleManager::CrosswalkModuleManager(rclcpp::Node & node)
// param for target area & object
cp.crosswalk_attention_range =
getOrDeclareParameter<double>(node, ns + ".object_filtering.crosswalk_attention_range");
cp.vehicle_object_cross_angle_threshold = getOrDeclareParameter<double>(
node, ns + ".object_filtering.vehicle_object_cross_angle_threshold");
cp.look_unknown =
getOrDeclareParameter<bool>(node, ns + ".object_filtering.target_object.unknown");
cp.look_bicycle =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ std::optional<StopFactor> CrosswalkModule::checkStopForCrosswalkUsers(
const double ego_vel = planner_data_->current_velocity->twist.linear.x;
const double ego_acc = planner_data_->current_acceleration->accel.accel.linear.x;

const std::optional<double> ego_crosswalk_passage_direction = [&]() -> std::optional<double> {
if (path_intersects.size() < 2) {
return std::nullopt;
}
const auto & front = path_intersects.front();
const auto & back = path_intersects.back();
return std::atan2(back.y - front.y, back.x - front.x);
}();
const auto base_link2front = planner_data_->vehicle_info_.max_longitudinal_offset_m;
const auto dist_ego_to_stop =
calcSignedArcLength(ego_path.points, ego_pos, p_stop_line->first) + p_stop_line->second;
Expand Down Expand Up @@ -358,6 +366,14 @@ std::optional<StopFactor> CrosswalkModule::checkStopForCrosswalkUsers(
if (collision_state != CollisionState::YIELD) {
continue;
}
if (ego_crosswalk_passage_direction) {
const double direction_diff = tier4_autoware_utils::normalizeRadian(
collision_point.value().crosswalk_passage_direction -
ego_crosswalk_passage_direction.value());
if (direction_diff < planner_param_.vehicle_object_cross_angle_threshold) {
continue;
}
}

Check warning on line 376 in planning/behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Brain Method

CrosswalkModule::checkStopForCrosswalkUsers is a brain method. A Brain Method -- aka a God Function -- is a large and complex function that centralizes the behavior of a module. Brain Methods are detected using a combination of the following code smells: Deeply Nested Logic + High Cyclomatic Complexity + Many Lines of Code + Many Function Arguments.

Check warning on line 376 in planning/behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

CrosswalkModule::checkStopForCrosswalkUsers increases in cyclomatic complexity from 15 to 19, 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.

Check warning on line 376 in planning/behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Bumpy Road Ahead

CrosswalkModule::checkStopForCrosswalkUsers increases from 4 to 5 logical blocks with deeply nested code, threshold is one single block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check notice on line 376 in planning/behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ New issue: Deep, Nested Complexity

CrosswalkModule::checkStopForCrosswalkUsers has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.

stop_factor_points.push_back(object.position);

Expand Down Expand Up @@ -625,6 +641,10 @@ std::optional<CollisionPoint> CrosswalkModule::getCollisionPoint(
// Calculate multi-step object polygon, and reset start_idx
const size_t start_idx_with_margin = std::max(static_cast<int>(start_idx) - 1, 0);
const size_t end_idx_with_margin = std::min(i + 1, obj_path.path.size() - 1);
const auto &start_idx_point = obj_path.path.at(start_idx_with_margin).position,
end_idx_point = obj_path.path.at(end_idx_with_margin).position;
const double object_crosswalk_passage_direction =
std::atan2(end_idx_point.y - start_idx_point.y, end_idx_point.x - start_idx_point.x);
const auto obj_multi_step_polygon = createMultiStepPolygon(
obj_path.path, obj_polygon, start_idx_with_margin, end_idx_with_margin);
is_start_idx_initialized = false;
Expand Down Expand Up @@ -660,7 +680,8 @@ std::optional<CollisionPoint> CrosswalkModule::getCollisionPoint(
if (dist_ego2cp < minimum_stop_dist) {
minimum_stop_dist = dist_ego2cp;
nearest_collision_point = createCollisionPoint(
intersection_center_point, dist_ego2cp, dist_obj2cp, ego_vel, obj_vel);
intersection_center_point, dist_ego2cp, dist_obj2cp, ego_vel, obj_vel,
object_crosswalk_passage_direction);

Check warning on line 684 in planning/behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

CrosswalkModule::getCollisionPoint already has high cyclomatic complexity, and now it increases in Lines of Code from 73 to 78. 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.
debug_data_.obj_polygons.push_back(
toGeometryPointVector(obj_multi_step_polygon, ego_pos.z));
}
Expand All @@ -679,7 +700,8 @@ std::optional<CollisionPoint> CrosswalkModule::getCollisionPoint(
CollisionPoint CrosswalkModule::createCollisionPoint(
const geometry_msgs::msg::Point & nearest_collision_point, const double dist_ego2cp,
const double dist_obj2cp, const geometry_msgs::msg::Vector3 & ego_vel,
const geometry_msgs::msg::Vector3 & obj_vel) const
const geometry_msgs::msg::Vector3 & obj_vel,
const double object_crosswalk_passage_direction) const
{
constexpr double min_ego_velocity = 1.38; // [m/s]

Expand All @@ -690,6 +712,7 @@ CollisionPoint CrosswalkModule::createCollisionPoint(

CollisionPoint collision_point{};
collision_point.collision_point = nearest_collision_point;
collision_point.crosswalk_passage_direction = object_crosswalk_passage_direction;
collision_point.time_to_collision =
std::max(0.0, dist_ego2cp - planner_param_.stop_distance_from_object - base_link2front) /
std::max(ego_vel.x, min_ego_velocity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class CrosswalkModule : public SceneModuleInterface
double traffic_light_state_timeout;
// param for target area & object
double crosswalk_attention_range;
double vehicle_object_cross_angle_threshold;
bool look_unknown;
bool look_bicycle;
bool look_motorcycle;
Expand Down Expand Up @@ -366,7 +367,8 @@ class CrosswalkModule : public SceneModuleInterface
CollisionPoint createCollisionPoint(
const geometry_msgs::msg::Point & nearest_collision_point, const double dist_ego2cp,
const double dist_obj2cp, const geometry_msgs::msg::Vector3 & ego_vel,
const geometry_msgs::msg::Vector3 & obj_vel) const;
const geometry_msgs::msg::Vector3 & obj_vel,
const double object_crosswalk_passage_direction) const;

float calcTargetVelocity(
const geometry_msgs::msg::Point & stop_point, const PathWithLaneId & ego_path) const;
Expand Down

0 comments on commit 4d162cc

Please sign in to comment.