Skip to content

Commit

Permalink
Add option to ignore crosswalk with traffic light + apply max decel/jerk
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime CLEMENT <[email protected]>
  • Loading branch information
maxime-clem committed Jan 22, 2024
1 parent ffc64c5 commit 0ea75dc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@
min_size: 0.5 # [m] minimum size of an occlusion (square side size)
free_space_max: 43 # [-] maximum value of a free space cell in the occupancy grid
occupied_min: 58 # [-] minimum value of an occupied cell in the occupancy grid
ignore_with_traffic_light: true # [-] if true, occlusions at crosswalks with traffic lights are ignored
4 changes: 3 additions & 1 deletion planning/behavior_velocity_crosswalk_module/src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ CrosswalkModuleManager::CrosswalkModuleManager(rclcpp::Node & node)
cp.occlusion_occluded_object_velocity =
getOrDeclareParameter<double>(node, ns + ".occlusion.occluded_object_velocity");
cp.occlusion_slow_down_velocity =
getOrDeclareParameter<double>(node, ns + ".occlusion.slow_down_velocity");
getOrDeclareParameter<float>(node, ns + ".occlusion.slow_down_velocity");
cp.occlusion_time_buffer = getOrDeclareParameter<double>(node, ns + ".occlusion.time_buffer");
cp.occlusion_min_size = getOrDeclareParameter<double>(node, ns + ".occlusion.min_size");
cp.occlusion_free_space_max = getOrDeclareParameter<int>(node, ns + ".occlusion.free_space_max");
cp.occlusion_occupied_min = getOrDeclareParameter<int>(node, ns + ".occlusion.occupied_min");
cp.occlusion_ignore_with_traffic_light =
getOrDeclareParameter<bool>(node, ns + ".occlusion.ignore_with_traffic_light");
}

void CrosswalkModuleManager::launchNewModules(const PathWithLaneId & path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ lanelet::BasicPoint2d interpolate_point(
return segment.second + extra_distance * direction_vector;

Check warning on line 51 in planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp#L50-L51

Added lines #L50 - L51 were not covered by tests
}

bool is_crosswalk_ignored(

Check warning on line 54 in planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp#L54

Added line #L54 was not covered by tests
const lanelet::ConstLanelet & crosswalk_lanelet, const bool ignore_with_traffic_light)
{
const auto traffic_lights_reg_elems =
crosswalk_lanelet.regulatoryElementsAs<const lanelet::TrafficLight>();
const bool has_traffic_light = !traffic_lights_reg_elems.empty();

Check warning on line 59 in planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp#L59

Added line #L59 was not covered by tests
const bool has_skip_attribute = crosswalk_lanelet.hasAttribute("skip_occluded_slowdown");
return (ignore_with_traffic_light && has_traffic_light) || has_skip_attribute;
}

Check warning on line 62 in planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp#L62

Added line #L62 was not covered by tests

bool is_crosswalk_occluded(

Check warning on line 64 in planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp#L64

Added line #L64 was not covered by tests
const lanelet::ConstLanelet & crosswalk_lanelet,
const nav_msgs::msg::OccupancyGrid & occupancy_grid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ bool is_occluded(
lanelet::BasicPoint2d interpolate_point(
const lanelet::BasicSegment2d & segment, const double extra_distance);

/// @brief check if the crosswalk should be ignored
/// @param crosswalk_lanelet lanelet of the crosswalk
/// @param ignore_with_traffic_light if true, ignore the crosswalk if it has a traffic light
/// @return true if the crosswalk should be ignored
bool is_crosswalk_ignored(
const lanelet::ConstLanelet & crosswalk_lanelet, const bool ignore_with_traffic_light);

/// @brief check if the crosswalk is occluded
/// @param crosswalk_lanelet lanelet of the crosswalk
/// @param occupancy_grid occupancy grid with the occlusion information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ bool CrosswalkModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
static_cast<float>(crosswalk_.attribute("safety_slow_down_speed").asDouble().get()));
}
// Apply safety slow down speed if the crosswalk is occluded
if (planner_param_.occlusion_enable && !path_intersects.empty()) {
if (
planner_param_.occlusion_enable && !path_intersects.empty() &&

Check warning on line 239 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: Complex Conditional

CrosswalkModule::modifyPathVelocity has 1 complex conditionals with 2 branches, threshold = 2. 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.
!is_crosswalk_ignored(crosswalk_, planner_param_.occlusion_ignore_with_traffic_light)) {
const auto dist_ego_to_crosswalk =
calcSignedArcLength(path->points, ego_pos, path_intersects.front());
const auto detection_range = calculate_detection_range(
Expand All @@ -256,9 +258,12 @@ bool CrosswalkModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
const auto is_last_occlusion_within_time_buffer =
most_recent_occlusion_time_ && (clock_->now() - *most_recent_occlusion_time_).seconds() <=
planner_param_.occlusion_time_buffer;
if (is_last_occlusion_within_time_buffer)
if (is_last_occlusion_within_time_buffer) {
const auto target_velocity = calcTargetVelocity(path_intersects.front(), *path);
applySafetySlowDownSpeed(
*path, path_intersects, planner_param_.occlusion_slow_down_velocity);
*path, path_intersects,
std::max(target_velocity, planner_param_.occlusion_slow_down_velocity));
}
}

Check warning on line 267 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: Complex Method

CrosswalkModule::modifyPathVelocity has a cyclomatic complexity of 13, 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.
}
recordTime(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ class CrosswalkModule : public SceneModuleInterface
// param for occlusions
bool occlusion_enable;
double occlusion_occluded_object_velocity;
double occlusion_slow_down_velocity;
float occlusion_slow_down_velocity;
double occlusion_time_buffer;
double occlusion_min_size;
int occlusion_free_space_max;
int occlusion_occupied_min;
bool occlusion_ignore_with_traffic_light;
};

struct ObjectInfo
Expand Down

0 comments on commit 0ea75dc

Please sign in to comment.