Skip to content

Commit

Permalink
refactor(goal_planner): add rss safety check function (#5620)
Browse files Browse the repository at this point in the history
* refactor(goal_planner): add rss safety check function

Signed-off-by: kosuke55 <[email protected]>

* has_collision

Signed-off-by: kosuke55 <[email protected]>

---------

Signed-off-by: kosuke55 <[email protected]>
  • Loading branch information
kosuke55 authored Nov 20, 2023
1 parent 7fe0b59 commit a395e72
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ using freespace_planning_algorithms::RRTStar;
using freespace_planning_algorithms::RRTStarParam;

using behavior_path_planner::utils::path_safety_checker::EgoPredictedPathParams;
using behavior_path_planner::utils::path_safety_checker::ExtendedPredictedObject;
using behavior_path_planner::utils::path_safety_checker::ObjectsFilteringParams;
using behavior_path_planner::utils::path_safety_checker::PoseWithVelocityStamped;
using behavior_path_planner::utils::path_safety_checker::SafetyCheckParams;
Expand Down Expand Up @@ -471,6 +472,10 @@ class GoalPlannerModule : public SceneModuleInterface
const PredictedObjects & filtered_objects, const TargetObjectsOnLane & target_objects_on_lane,
const std::vector<PoseWithVelocityStamped> & ego_predicted_path) const;
bool isSafePath() const;
bool checkSafetyWithRSS(
const PathWithLaneId & planned_path,
const std::vector<PoseWithVelocityStamped> & ego_predicted_path,
const std::vector<ExtendedPredictedObject> & objects, const double hysteresis_factor) const;

// debug
void setDebugData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,34 @@ void GoalPlannerModule::updateSafetyCheckTargetObjectsData(
goal_planner_data_.ego_predicted_path = ego_predicted_path;
}

bool GoalPlannerModule::checkSafetyWithRSS(
const PathWithLaneId & planned_path,
const std::vector<PoseWithVelocityStamped> & ego_predicted_path,
const std::vector<ExtendedPredictedObject> & objects, const double hysteresis_factor) const
{
// Check for collisions with each predicted path of the object
const bool is_safe = !std::any_of(objects.begin(), objects.end(), [&](const auto & object) {
auto current_debug_data = marker_utils::createObjectDebug(object);

const auto obj_predicted_paths = utils::path_safety_checker::getPredictedPathFromObj(
object, objects_filtering_params_->check_all_predicted_path);

return std::any_of(
obj_predicted_paths.begin(), obj_predicted_paths.end(), [&](const auto & obj_path) {
const bool has_collision = !utils::path_safety_checker::checkCollision(
planned_path, ego_predicted_path, object, obj_path, planner_data_->parameters,
safety_check_params_->rss_params, hysteresis_factor, current_debug_data.second);

marker_utils::updateCollisionCheckDebugMap(
goal_planner_data_.collision_check, current_debug_data, !has_collision);

return has_collision;
});
});

return is_safe;
}

bool GoalPlannerModule::isSafePath() const
{
const auto pull_over_path = thread_safe_data_.get_pull_over_path()->getCurrentPath();
Expand Down Expand Up @@ -1759,41 +1787,13 @@ bool GoalPlannerModule::isSafePath() const
const auto target_objects_on_lane = utils::path_safety_checker::createTargetObjectsOnLane(
pull_over_lanes, route_handler, filtered_objects, objects_filtering_params_);

const double hysteresis_factor =
prev_data_.is_safe ? 1.0 : parameters_->hysteresis_factor_expand_rate;

utils::start_goal_planner_common::updateSafetyCheckTargetObjectsData(
goal_planner_data_, filtered_objects, target_objects_on_lane, ego_predicted_path);

bool is_safe_dynamic_objects = true;
// Check for collisions with each predicted path of the object
for (const auto & object : target_objects_on_lane.on_current_lane) {
auto current_debug_data = marker_utils::createObjectDebug(object);

bool is_safe_dynamic_object = true;

const auto obj_predicted_paths = utils::path_safety_checker::getPredictedPathFromObj(
object, objects_filtering_params_->check_all_predicted_path);

// If a collision is detected, mark the object as unsafe and break the loop
for (const auto & obj_path : obj_predicted_paths) {
if (!utils::path_safety_checker::checkCollision(
pull_over_path, ego_predicted_path, object, obj_path, planner_data_->parameters,
safety_check_params_->rss_params, hysteresis_factor, current_debug_data.second)) {
marker_utils::updateCollisionCheckDebugMap(
goal_planner_data_.collision_check, current_debug_data, false);
is_safe_dynamic_objects = false;
is_safe_dynamic_object = false;
break;
}
}
if (is_safe_dynamic_object) {
marker_utils::updateCollisionCheckDebugMap(
goal_planner_data_.collision_check, current_debug_data, is_safe_dynamic_object);
}
}

return is_safe_dynamic_objects;
const double hysteresis_factor =
prev_data_.is_safe ? 1.0 : parameters_->hysteresis_factor_expand_rate;
return checkSafetyWithRSS(
pull_over_path, ego_predicted_path, target_objects_on_lane.on_current_lane, hysteresis_factor);
}

void GoalPlannerModule::setDebugData()
Expand Down

0 comments on commit a395e72

Please sign in to comment.