Skip to content

Commit

Permalink
refactor(goal_planner): move decision_state implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Mamoru Sobue <[email protected]>
  • Loading branch information
soblin committed Dec 2, 2024
1 parent 815abd9 commit 3492839
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
src/util.cpp
src/goal_planner_module.cpp
src/manager.cpp
src/decision_state.cpp
)

if(BUILD_EXAMPLES)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Copyright 2024 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware/behavior_path_goal_planner_module/util.hpp"

#include <autoware/behavior_path_goal_planner_module/decision_state.hpp>
#include <autoware/motion_utils/trajectory/trajectory.hpp>

namespace autoware::behavior_path_planner
{

using autoware::motion_utils::calcSignedArcLength;

void PathDecisionStateController::transit_state(

Check warning on line 25 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L25

Added line #L25 was not covered by tests
const bool found_pull_over_path, const rclcpp::Time & now,
const PredictedObjects & static_target_objects, const PredictedObjects & dynamic_target_objects,
const std::optional<GoalCandidate> modified_goal_opt,
const std::shared_ptr<const PlannerData> planner_data,
const std::shared_ptr<OccupancyGridBasedCollisionDetector> occupancy_grid_map,
const bool is_current_safe, const GoalPlannerParameters & parameters,
const std::shared_ptr<GoalSearcherBase> goal_searcher, const bool is_activated,
const std::optional<PullOverPath> & pull_over_path,
std::vector<autoware::universe_utils::Polygon2d> & ego_polygons_expanded)
{
const auto next_state = get_next_state(
found_pull_over_path, now, static_target_objects, dynamic_target_objects, modified_goal_opt,
planner_data, occupancy_grid_map, is_current_safe, parameters, goal_searcher, is_activated,
pull_over_path, ego_polygons_expanded);
current_state_ = next_state;
}

Check warning on line 41 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Excess Number of Function Arguments

PathDecisionStateController::transit_state has 13 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.

Check warning on line 41 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L41

Added line #L41 was not covered by tests

PathDecisionState PathDecisionStateController::get_next_state(

Check warning on line 43 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L43

Added line #L43 was not covered by tests
const bool found_pull_over_path, const rclcpp::Time & now,
const PredictedObjects & static_target_objects, const PredictedObjects & dynamic_target_objects,
const std::optional<GoalCandidate> modified_goal_opt,
const std::shared_ptr<const PlannerData> planner_data,
const std::shared_ptr<OccupancyGridBasedCollisionDetector> occupancy_grid_map,
const bool is_current_safe, const GoalPlannerParameters & parameters,
const std::shared_ptr<GoalSearcherBase> goal_searcher, const bool is_activated,
const std::optional<PullOverPath> & pull_over_path_opt,
std::vector<autoware::universe_utils::Polygon2d> & ego_polygons_expanded) const
{
auto next_state = current_state_;

Check warning on line 54 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L54

Added line #L54 was not covered by tests

// update safety
if (!parameters.safety_check_params.enable_safety_check) {
next_state.is_stable_safe = true;

Check warning on line 58 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L58

Added line #L58 was not covered by tests
} else {
if (is_current_safe) {
if (!next_state.safe_start_time) {
next_state.safe_start_time = now;
next_state.is_stable_safe = false;

Check warning on line 63 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L63

Added line #L63 was not covered by tests
} else {
next_state.is_stable_safe =

Check warning on line 65 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L65

Added line #L65 was not covered by tests
((now - next_state.safe_start_time.value()).seconds() >
parameters.safety_check_params.keep_unsafe_time);

Check warning on line 67 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L67

Added line #L67 was not covered by tests
}
} else {
next_state.safe_start_time = std::nullopt;
next_state.is_stable_safe = false;

Check warning on line 71 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L71

Added line #L71 was not covered by tests
}
}

// Once this function returns true, it will continue to return true thereafter
if (next_state.state == PathDecisionState::DecisionKind::DECIDED) {
return next_state;
}

// if path is not safe, not decided
if (!found_pull_over_path || !pull_over_path_opt) {
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;

Check warning on line 82 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L82

Added line #L82 was not covered by tests
return next_state;
}

const auto & pull_over_path = pull_over_path_opt.value();
const bool enable_safety_check = parameters.safety_check_params.enable_safety_check;

Check warning on line 87 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L87

Added line #L87 was not covered by tests
// If it is dangerous against dynamic objects before approval, do not determine the path.
// This eliminates a unsafe path to be approved
if (enable_safety_check && !next_state.is_stable_safe && !is_activated) {

Check warning on line 90 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

PathDecisionStateController::get_next_state 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.
RCLCPP_DEBUG(
logger_,
"[DecidingPathStatus]: NOT_DECIDED. path is not safe against dynamic objects before "
"approval");
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;

Check warning on line 95 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L95

Added line #L95 was not covered by tests
return next_state;
}

const auto & current_path = pull_over_path.getCurrentPath();
if (current_state_.state == PathDecisionState::DecisionKind::DECIDING) {
const double hysteresis_factor = 0.9;

// check goal pose collision
if (

Check warning on line 104 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L104

Added line #L104 was not covered by tests
modified_goal_opt && !goal_searcher->isSafeGoalWithMarginScaleFactor(
modified_goal_opt.value(), hysteresis_factor, occupancy_grid_map,
planner_data, static_target_objects)) {
RCLCPP_DEBUG(logger_, "[DecidingPathStatus]: DECIDING->NOT_DECIDED. goal is not safe");
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;
next_state.deciding_start_time = std::nullopt;
return next_state;
}

// check current parking path collision
const auto & parking_path = pull_over_path.parking_path();
const auto & parking_path_curvatures = pull_over_path.parking_path_curvatures();
const double margin =
parameters.object_recognition_collision_check_hard_margins.back() * hysteresis_factor;

Check warning on line 118 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L118

Added line #L118 was not covered by tests
if (goal_planner_utils::checkObjectsCollision(
parking_path, parking_path_curvatures, static_target_objects, dynamic_target_objects,
planner_data->parameters, margin,
/*extract_static_objects=*/false, parameters.maximum_deceleration,

Check warning on line 122 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L122

Added line #L122 was not covered by tests
parameters.object_recognition_collision_check_max_extra_stopping_margin,
ego_polygons_expanded, true)) {
RCLCPP_DEBUG(
logger_, "[DecidingPathStatus]: DECIDING->NOT_DECIDED. path has collision with objects");
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;
next_state.deciding_start_time = std::nullopt;
return next_state;
}

if (enable_safety_check && !next_state.is_stable_safe) {
RCLCPP_DEBUG(
logger_,
"[DecidingPathStatus]: DECIDING->NOT_DECIDED. path is not safe against dynamic objects");
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;

Check warning on line 136 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L136

Added line #L136 was not covered by tests
return next_state;
}

// if enough time has passed since deciding status starts, transition to DECIDED
constexpr double check_collision_duration = 1.0;
const double elapsed_time_from_deciding =
(now - current_state_.deciding_start_time.value()).seconds();
if (elapsed_time_from_deciding > check_collision_duration) {
RCLCPP_DEBUG(logger_, "[DecidingPathStatus]: DECIDING->DECIDED. has enough safe time passed");
next_state.state = PathDecisionState::DecisionKind::DECIDED;
next_state.deciding_start_time = std::nullopt;
return next_state;
}

// if enough time has NOT passed since deciding status starts, keep DECIDING
RCLCPP_DEBUG(
logger_, "[DecidingPathStatus]: keep DECIDING. elapsed_time_from_deciding: %f",
elapsed_time_from_deciding);
return next_state;
}

Check warning on line 156 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L156

Added line #L156 was not covered by tests

// 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 =
autoware::motion_utils::findNearestSegmentIndex(current_path.points, current_pose.position);

const size_t start_pose_segment_idx = autoware::motion_utils::findNearestSegmentIndex(
current_path.points, pull_over_path.start_pose().position);
const double dist_to_parking_start_pose = calcSignedArcLength(
current_path.points, current_pose.position, ego_segment_idx,
pull_over_path.start_pose().position, start_pose_segment_idx);

Check warning on line 167 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L167

Added line #L167 was not covered by tests
if (dist_to_parking_start_pose > parameters.decide_path_distance) {
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;

Check warning on line 169 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L169

Added line #L169 was not covered by tests
return next_state;
}

// 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.
if (parameters.use_object_recognition) {
RCLCPP_DEBUG(
logger_,
"[DecidingPathStatus]: NOT_DECIDED->DECIDING. start checking collision for certain "
"period of time");
next_state.state = PathDecisionState::DecisionKind::DECIDING;

Check warning on line 180 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L180

Added line #L180 was not covered by tests
next_state.deciding_start_time = now;
return next_state;
}
return {PathDecisionState::DecisionKind::DECIDED, std::nullopt};
}

Check warning on line 185 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Method

PathDecisionStateController::get_next_state has a cyclomatic complexity of 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 185 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

PathDecisionStateController::get_next_state has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested 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 warning on line 185 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/decision_state.cpp#L184-L185

Added lines #L184 - L185 were not covered by tests

} // namespace autoware::behavior_path_planner
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "autoware/behavior_path_planner_common/utils/path_shifter/path_shifter.hpp"
#include "autoware/behavior_path_planner_common/utils/utils.hpp"
#include "autoware/universe_utils/geometry/boost_polygon_utils.hpp"
#include "autoware/universe_utils/math/unit_conversion.hpp"

#include <autoware_lanelet2_extension/utility/message_conversion.hpp>
#include <autoware_lanelet2_extension/utility/query.hpp>
Expand Down Expand Up @@ -2605,166 +2604,4 @@ void GoalPlannerModule::GoalPlannerData::update(
goal_candidates = goal_candidates_;
}

Check notice on line 2606 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Method

PathDecisionStateController::get_next_state is no longer above the threshold for cyclomatic complexity. 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 2606 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Conditional

PathDecisionStateController::get_next_state 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 2606 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Bumpy Road Ahead

PathDecisionStateController::get_next_state 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 2606 in planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/goal_planner_module.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Excess Number of Function Arguments

PathDecisionStateController::transit_state is no longer above the threshold for number of arguments. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.
void PathDecisionStateController::transit_state(
const bool found_pull_over_path, const rclcpp::Time & now,
const PredictedObjects & static_target_objects, const PredictedObjects & dynamic_target_objects,
const std::optional<GoalCandidate> modified_goal_opt,
const std::shared_ptr<const PlannerData> planner_data,
const std::shared_ptr<OccupancyGridBasedCollisionDetector> occupancy_grid_map,
const bool is_current_safe, const GoalPlannerParameters & parameters,
const std::shared_ptr<GoalSearcherBase> goal_searcher, const bool is_activated,
const std::optional<PullOverPath> & pull_over_path,
std::vector<Polygon2d> & ego_polygons_expanded)
{
const auto next_state = get_next_state(
found_pull_over_path, now, static_target_objects, dynamic_target_objects, modified_goal_opt,
planner_data, occupancy_grid_map, is_current_safe, parameters, goal_searcher, is_activated,
pull_over_path, ego_polygons_expanded);
current_state_ = next_state;
}

PathDecisionState PathDecisionStateController::get_next_state(
const bool found_pull_over_path, const rclcpp::Time & now,
const PredictedObjects & static_target_objects, const PredictedObjects & dynamic_target_objects,
const std::optional<GoalCandidate> modified_goal_opt,
const std::shared_ptr<const PlannerData> planner_data,
const std::shared_ptr<OccupancyGridBasedCollisionDetector> occupancy_grid_map,
const bool is_current_safe, const GoalPlannerParameters & parameters,
const std::shared_ptr<GoalSearcherBase> goal_searcher, const bool is_activated,
const std::optional<PullOverPath> & pull_over_path_opt,
std::vector<Polygon2d> & ego_polygons_expanded) const
{
auto next_state = current_state_;

// update safety
if (!parameters.safety_check_params.enable_safety_check) {
next_state.is_stable_safe = true;
} else {
if (is_current_safe) {
if (!next_state.safe_start_time) {
next_state.safe_start_time = now;
next_state.is_stable_safe = false;
} else {
next_state.is_stable_safe =
((now - next_state.safe_start_time.value()).seconds() >
parameters.safety_check_params.keep_unsafe_time);
}
} else {
next_state.safe_start_time = std::nullopt;
next_state.is_stable_safe = false;
}
}

// Once this function returns true, it will continue to return true thereafter
if (next_state.state == PathDecisionState::DecisionKind::DECIDED) {
return next_state;
}

// if path is not safe, not decided
if (!found_pull_over_path || !pull_over_path_opt) {
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;
return next_state;
}

const auto & pull_over_path = pull_over_path_opt.value();
const bool enable_safety_check = parameters.safety_check_params.enable_safety_check;
// If it is dangerous against dynamic objects before approval, do not determine the path.
// This eliminates a unsafe path to be approved
if (enable_safety_check && !next_state.is_stable_safe && !is_activated) {
RCLCPP_DEBUG(
logger_,
"[DecidingPathStatus]: NOT_DECIDED. path is not safe against dynamic objects before "
"approval");
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;
return next_state;
}

const auto & current_path = pull_over_path.getCurrentPath();
if (current_state_.state == PathDecisionState::DecisionKind::DECIDING) {
const double hysteresis_factor = 0.9;

// check goal pose collision
if (
modified_goal_opt && !goal_searcher->isSafeGoalWithMarginScaleFactor(
modified_goal_opt.value(), hysteresis_factor, occupancy_grid_map,
planner_data, static_target_objects)) {
RCLCPP_DEBUG(logger_, "[DecidingPathStatus]: DECIDING->NOT_DECIDED. goal is not safe");
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;
next_state.deciding_start_time = std::nullopt;
return next_state;
}

// check current parking path collision
const auto & parking_path = pull_over_path.parking_path();
const auto & parking_path_curvatures = pull_over_path.parking_path_curvatures();
const double margin =
parameters.object_recognition_collision_check_hard_margins.back() * hysteresis_factor;
if (goal_planner_utils::checkObjectsCollision(
parking_path, parking_path_curvatures, static_target_objects, dynamic_target_objects,
planner_data->parameters, margin,
/*extract_static_objects=*/false, parameters.maximum_deceleration,
parameters.object_recognition_collision_check_max_extra_stopping_margin,
ego_polygons_expanded, true)) {
RCLCPP_DEBUG(
logger_, "[DecidingPathStatus]: DECIDING->NOT_DECIDED. path has collision with objects");
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;
next_state.deciding_start_time = std::nullopt;
return next_state;
}

if (enable_safety_check && !next_state.is_stable_safe) {
RCLCPP_DEBUG(
logger_,
"[DecidingPathStatus]: DECIDING->NOT_DECIDED. path is not safe against dynamic objects");
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;
return next_state;
}

// if enough time has passed since deciding status starts, transition to DECIDED
constexpr double check_collision_duration = 1.0;
const double elapsed_time_from_deciding =
(now - current_state_.deciding_start_time.value()).seconds();
if (elapsed_time_from_deciding > check_collision_duration) {
RCLCPP_DEBUG(logger_, "[DecidingPathStatus]: DECIDING->DECIDED. has enough safe time passed");
next_state.state = PathDecisionState::DecisionKind::DECIDED;
next_state.deciding_start_time = std::nullopt;
return next_state;
}

// if enough time has NOT passed since deciding status starts, keep DECIDING
RCLCPP_DEBUG(
logger_, "[DecidingPathStatus]: keep DECIDING. elapsed_time_from_deciding: %f",
elapsed_time_from_deciding);
return next_state;
}

// 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 =
autoware::motion_utils::findNearestSegmentIndex(current_path.points, current_pose.position);

const size_t start_pose_segment_idx = autoware::motion_utils::findNearestSegmentIndex(
current_path.points, pull_over_path.start_pose().position);
const double dist_to_parking_start_pose = calcSignedArcLength(
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) {
next_state.state = PathDecisionState::DecisionKind::NOT_DECIDED;
return next_state;
}

// 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.
if (parameters.use_object_recognition) {
RCLCPP_DEBUG(
logger_,
"[DecidingPathStatus]: NOT_DECIDED->DECIDING. start checking collision for certain "
"period of time");
next_state.state = PathDecisionState::DecisionKind::DECIDING;
next_state.deciding_start_time = now;
return next_state;
}
return {PathDecisionState::DecisionKind::DECIDED, std::nullopt};
}

} // namespace autoware::behavior_path_planner

0 comments on commit 3492839

Please sign in to comment.