Skip to content

Commit

Permalink
feat(goal_planner): add deciding status to check collision for for a …
Browse files Browse the repository at this point in the history
…certain period of time

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
  • Loading branch information
kosuke55 committed Jan 21, 2024
1 parent 38f1f88 commit d66d632
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ struct LastApprovalData
Pose pose{};
};

enum class DecidingPathStatus {
NOT_DECIDED,
DECIDING,
DECIDED,
};
using DecidingPathStatusWithStamp = std::pair<DecidingPathStatus, rclcpp::Time>;

struct PreviousPullOverData
{
struct SafetyStatus
Expand All @@ -242,12 +249,13 @@ struct PreviousPullOverData
{
found_path = false;
safety_status = SafetyStatus{};
has_decided_path = false;
deciding_path_status = DecidingPathStatusWithStamp{};

Check warning on line 252 in planning/behavior_path_goal_planner_module/include/behavior_path_goal_planner_module/goal_planner_module.hpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/include/behavior_path_goal_planner_module/goal_planner_module.hpp#L252

Added line #L252 was not covered by tests
}

bool found_path{false};
SafetyStatus safety_status{};
bool has_decided_path{false};
// bool has_decided_path{false};
DecidingPathStatusWithStamp deciding_path_status{};
};

// store stop_pose_ pointer with reason string
Expand Down Expand Up @@ -439,6 +447,8 @@ class GoalPlannerModule : public SceneModuleInterface
bool needPathUpdate(const double path_update_duration) const;
bool isStuck();
bool hasDecidedPath() const;
bool hasNotDecidedPath() const;
DecidingPathStatusWithStamp checkDecidingPathStatus() const;
void decideVelocity();
bool foundPullOverPath() const;
void updateStatus(const BehaviorModuleOutput & output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,36 +903,74 @@ void GoalPlannerModule::updateSteeringFactor(

bool GoalPlannerModule::hasDecidedPath() const
{
return checkDecidingPathStatus().first == DecidingPathStatus::DECIDED;

Check warning on line 906 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L906

Added line #L906 was not covered by tests
}

bool GoalPlannerModule::hasNotDecidedPath() const

Check warning on line 909 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L909

Added line #L909 was not covered by tests
{
return checkDecidingPathStatus().first == DecidingPathStatus::NOT_DECIDED;

Check warning on line 911 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L911

Added line #L911 was not covered by tests
}

DecidingPathStatusWithStamp GoalPlannerModule::checkDecidingPathStatus() const

Check warning on line 914 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L914

Added line #L914 was not covered by tests
{
const auto & prev_status = prev_data_.deciding_path_status;

// Once this function returns true, it will continue to return true thereafter
if (prev_data_.has_decided_path) {
return true;
if (prev_status.first == DecidingPathStatus::DECIDED) {

Check warning on line 919 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L919

Added line #L919 was not covered by tests
return prev_status;
}

// if path is not safe, not decided
if (!thread_safe_data_.foundPullOverPath()) {
return false;
return {DecidingPathStatus::NOT_DECIDED, clock_->now()};

Check warning on line 925 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L925

Added line #L925 was not covered by tests
}

// If it is dangerous before approval, do not determine the path.
// If it is dangerous against dynamic objects before approval, do not determine the path.
// This eliminates a unsafe path to be approved
if (
parameters_->safety_check_params.enable_safety_check && !isSafePath().first && !isActivated()) {
return false;
return {DecidingPathStatus::NOT_DECIDED, clock_->now()};

Check warning on line 932 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L932

Added line #L932 was not covered by tests
}

const auto pull_over_path = thread_safe_data_.get_pull_over_path();
const auto current_path = pull_over_path->getCurrentPath();
if (prev_status.first == DecidingPathStatus::DECIDING) {

Check warning on line 937 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L935-L937

Added lines #L935 - L937 were not covered by tests
// if object recognition for path collision check is enabled, transition to DECIDED after
// DECIDING for a certain period of time if there is no collision.
if (checkObjectsCollision(

Check warning on line 940 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L940

Added line #L940 was not covered by tests
current_path, parameters_->object_recognition_collision_check_margin,
true /*update_debug_data*/)) {
return {DecidingPathStatus::NOT_DECIDED, clock_->now()};

Check warning on line 943 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L943

Added line #L943 was not covered by tests
}

constexpr double check_collision_duration = 1.0;
if ((clock_->now() - prev_status.second).seconds() > check_collision_duration) {
return {DecidingPathStatus::DECIDED, clock_->now()};

Check warning on line 948 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L947-L948

Added lines #L947 - L948 were not covered by tests
}

return prev_status;
}

// if ego is sufficiently close to the start of the nearest candidate path, the path is decided
const auto & current_pose = planner_data_->self_odometry->pose.pose;
const size_t ego_segment_idx = motion_utils::findNearestSegmentIndex(
thread_safe_data_.get_pull_over_path()->getCurrentPath().points, current_pose.position);
const size_t ego_segment_idx =
motion_utils::findNearestSegmentIndex(current_path.points, current_pose.position);

Check warning on line 957 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L957

Added line #L957 was not covered by tests

const size_t start_pose_segment_idx = motion_utils::findNearestSegmentIndex(
thread_safe_data_.get_pull_over_path()->getCurrentPath().points,
thread_safe_data_.get_pull_over_path()->start_pose.position);
const size_t start_pose_segment_idx =
motion_utils::findNearestSegmentIndex(current_path.points, pull_over_path->start_pose.position);

Check warning on line 960 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L960

Added line #L960 was not covered by tests
const double dist_to_parking_start_pose = calcSignedArcLength(
thread_safe_data_.get_pull_over_path()->getCurrentPath().points, current_pose.position,
ego_segment_idx, thread_safe_data_.get_pull_over_path()->start_pose.position,
start_pose_segment_idx);
return dist_to_parking_start_pose < parameters_->decide_path_distance;
current_path.points, current_pose.position, ego_segment_idx,
pull_over_path->start_pose.position, start_pose_segment_idx);
if (dist_to_parking_start_pose > parameters_->decide_path_distance) {
return {DecidingPathStatus::NOT_DECIDED, clock_->now()};

Check warning on line 965 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L963-L965

Added lines #L963 - L965 were not covered by tests
}

// if object recognition for path collision check is enabled, transition to DECIDING to check
// collision for a certain period of time. Otherwise, transition to DECIDED directly.
return {
parameters_->use_object_recognition ? DecidingPathStatus::DECIDING

Check warning on line 971 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L971

Added line #L971 was not covered by tests
: DecidingPathStatus::DECIDED,
clock_->now()};

Check notice on line 973 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ New issue: Complex Method

GoalPlannerModule::checkDecidingPathStatus has a cyclomatic complexity of 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.

Check warning on line 973 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L973

Added line #L973 was not covered by tests
}

void GoalPlannerModule::decideVelocity()
Expand Down Expand Up @@ -993,7 +1031,7 @@ BehaviorModuleOutput GoalPlannerModule::planPullOverAsOutput()
return getPreviousModuleOutput();
}

if (!hasDecidedPath() && needPathUpdate(1.0 /*path_update_duration*/)) {
if (hasNotDecidedPath() && needPathUpdate(1.0 /*path_update_duration*/)) {

Check warning on line 1034 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L1034

Added line #L1034 was not covered by tests
// if the final path is not decided and enough time has passed since last path update,
// select safe path from lane parking pull over path candidates
// and set it to thread_safe_data_
Expand Down Expand Up @@ -1083,7 +1121,7 @@ void GoalPlannerModule::updatePreviousData()
// this is used to determine whether to generate a new stop path or keep the current stop path.
prev_data_.found_path = thread_safe_data_.foundPullOverPath();

prev_data_.has_decided_path = hasDecidedPath();
prev_data_.deciding_path_status = checkDecidingPathStatus();

Check warning on line 1124 in planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_goal_planner_module/src/goal_planner_module.cpp#L1124

Added line #L1124 was not covered by tests

// This is related to safety check, so if it is disabled, return here.
if (!parameters_->safety_check_params.enable_safety_check) {
Expand Down

0 comments on commit d66d632

Please sign in to comment.