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

chore(crosswalk): port the same direction ignore block #9983

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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2023 Tier IV, Inc.

Check notice on line 1 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Lines of Code in a Single File

The lines of code decreases from 1089 to 1074, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 5.97 to 5.81, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -335,36 +335,18 @@
dist_default_stop, sparse_resample_path, crosswalk_attention_range, attention_area);

// Check pedestrian for stop
// NOTE: first stop point and its minimum distance from ego to stop
auto isVehicleType = [](const uint8_t label) {
return label == ObjectClassification::MOTORCYCLE || label == ObjectClassification::BICYCLE;
};
std::optional<double> dist_nearest_cp;
std::vector<geometry_msgs::msg::Point> stop_factor_points;
const std::optional<double> ego_crosswalk_passage_direction =
findEgoPassageDirectionAlongPath(sparse_resample_path);
for (const auto & object : object_info_manager_.getObject()) {
const auto & collision_point_opt = object.collision_point;
if (collision_point_opt) {
const auto & collision_point = collision_point_opt.value();
const auto & collision_state = object.collision_state;
if (collision_state != CollisionState::YIELD) {
continue;
}

Check notice on line 349 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Complex Method

CrosswalkModule::checkStopForCrosswalkUsers decreases in cyclomatic complexity from 16 to 10, 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 notice on line 349 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Conditional

CrosswalkModule::checkStopForCrosswalkUsers 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.

Check notice on line 349 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Bumpy Road Ahead

CrosswalkModule::checkStopForCrosswalkUsers is no longer above the threshold for logical blocks with deeply nested code. 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 349 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Deep, Nested Complexity

CrosswalkModule::checkStopForCrosswalkUsers is no longer above the threshold for nested complexity depth. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.
if (
isVehicleType(object.classification) && ego_crosswalk_passage_direction &&
collision_point.crosswalk_passage_direction) {
double direction_diff = std::abs(std::fmod(
collision_point.crosswalk_passage_direction.value() -
ego_crosswalk_passage_direction.value(),
M_PI_2));
direction_diff = std::min(direction_diff, M_PI_2 - direction_diff);
if (direction_diff < planner_param_.vehicle_object_cross_angle_threshold) {
continue;
}
}

stop_factor_points.push_back(object.position);

const auto dist_ego2cp =
Expand Down Expand Up @@ -1165,10 +1147,12 @@

const auto collision_point =
getCollisionPoint(sparse_resample_path, object, crosswalk_attention_range, attention_area);
const std::optional<double> ego_crosswalk_passage_direction =
findEgoPassageDirectionAlongPath(sparse_resample_path);
object_info_manager_.update(
obj_uuid, obj_pos, std::hypot(obj_vel.x, obj_vel.y), clock_->now(), is_ego_yielding,
has_traffic_light, collision_point, object.classification.front().label, planner_param_,
crosswalk_.polygon2d().basicPolygon(), attention_area);
crosswalk_.polygon2d().basicPolygon(), attention_area, ego_crosswalk_passage_direction);

const auto collision_state = object_info_manager_.getCollisionState(obj_uuid);
if (collision_point) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@
const rclcpp::Time & now, const geometry_msgs::msg::Point & position, const double vel,
const bool is_ego_yielding, const std::optional<CollisionPoint> & collision_point,
const PlannerParam & planner_param, const lanelet::BasicPolygon2d & crosswalk_polygon,
const bool is_object_away_from_path)
const bool is_object_away_from_path,
const std::optional<double> & ego_crosswalk_passage_direction)
{
const bool is_stopped = vel < planner_param.stop_object_velocity;

Expand Down Expand Up @@ -224,6 +225,24 @@

// Compare time to collision and vehicle
if (collision_point) {
auto isVehicleType = [](const uint8_t label) {
return label == ObjectClassification::MOTORCYCLE ||

Check warning on line 229 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.hpp#L229

Added line #L229 was not covered by tests
label == ObjectClassification::BICYCLE;
};
if (
isVehicleType(classification) && ego_crosswalk_passage_direction &&
collision_point->crosswalk_passage_direction) {
double direction_diff = std::abs(std::fmod(
collision_point->crosswalk_passage_direction.value() -

Check warning on line 236 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.hpp#L235-L236

Added lines #L235 - L236 were not covered by tests
ego_crosswalk_passage_direction.value(),
M_PI_2));

Check warning on line 238 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.hpp#L238

Added line #L238 was not covered by tests
direction_diff = std::min(direction_diff, M_PI_2 - direction_diff);
if (direction_diff < planner_param.vehicle_object_cross_angle_threshold) {
collision_state = CollisionState::IGNORE;
return;

Check warning on line 242 in planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_planner/autoware_behavior_velocity_crosswalk_module/src/scene_crosswalk.hpp#L241-L242

Added lines #L241 - L242 were not covered by tests
}
}

// Check if ego will pass first
const double ego_pass_first_additional_margin =
collision_state == CollisionState::EGO_PASS_FIRST
Expand Down Expand Up @@ -268,7 +287,8 @@
const rclcpp::Time & now, const bool is_ego_yielding, const bool has_traffic_light,
const std::optional<CollisionPoint> & collision_point, const uint8_t classification,
const PlannerParam & planner_param, const lanelet::BasicPolygon2d & crosswalk_polygon,
const Polygon2d & attention_area)
const Polygon2d & attention_area,
const std::optional<double> & ego_crosswalk_passage_direction)
{
// update current uuids
current_uuids_.push_back(uuid);
Expand All @@ -292,7 +312,7 @@
// update object state
objects.at(uuid).transitState(
now, position, vel, is_ego_yielding, collision_point, planner_param, crosswalk_polygon,
is_object_away_from_path);
is_object_away_from_path, ego_crosswalk_passage_direction);
objects.at(uuid).collision_point = collision_point;
objects.at(uuid).position = position;
objects.at(uuid).classification = classification;
Expand Down
Loading