Skip to content

Commit

Permalink
refactor(start_planner): add rss safety check function (#5623)
Browse files Browse the repository at this point in the history
* Refactor safety check method in StartPlannerModule

Signed-off-by: kyoichi-sugahara <[email protected]>

* Remove unused function checkSafetyWithRSS

Signed-off-by: kyoichi-sugahara <[email protected]>

---------

Signed-off-by: kyoichi-sugahara <[email protected]>
  • Loading branch information
kyoichi-sugahara authored Nov 30, 2023
1 parent c180bf6 commit 6c85af4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ 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 @@ -489,11 +488,6 @@ class GoalPlannerModule : public SceneModuleInterface
*/
std::pair<bool, 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();
void printParkingPositionError() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ ExtendedPredictedObject filterObjectPredictedPathByTimeHorizon(
ExtendedPredictedObjects filterObjectPredictedPathByTimeHorizon(
const ExtendedPredictedObjects & objects, const double time_horizon,
const bool check_all_predicted_path);

bool checkSafetyWithRSS(
const PathWithLaneId & planned_path,
const std::vector<PoseWithVelocityStamped> & ego_predicted_path,
const std::vector<ExtendedPredictedObject> & objects, CollisionCheckDebugMap & debug_map,
const BehaviorPathPlannerParameters & parameters, const RSSparams & rss_params,
const bool check_all_predicted_path, const double hysteresis_factor);

/**
* @brief Iterate the points in the ego and target's predicted path and
* perform safety check for each of the iterated points.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1742,34 +1742,6 @@ 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 = utils::path_safety_checker::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);

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

return has_collision;
});
});

return is_safe;
}

std::pair<bool, bool> GoalPlannerModule::isSafePath() const
{
const auto pull_over_path = thread_safe_data_.get_pull_over_path()->getCurrentPath();
Expand Down Expand Up @@ -1821,8 +1793,10 @@ std::pair<bool, bool> GoalPlannerModule::isSafePath() const

const bool current_is_safe = std::invoke([&]() {
if (parameters_->safety_check_params.method == "RSS") {
return checkSafetyWithRSS(
return behavior_path_planner::utils::path_safety_checker::checkSafetyWithRSS(
pull_over_path, ego_predicted_path, target_objects_on_lane.on_current_lane,
goal_planner_data_.collision_check, planner_data_->parameters,
safety_check_params_->rss_params, objects_filtering_params_->use_all_predicted_path,
hysteresis_factor);
} else if (parameters_->safety_check_params.method == "integral_predicted_polygon") {
return utils::path_safety_checker::checkSafetyWithIntegralPredictedPolygon(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,35 +1091,11 @@ bool StartPlannerModule::isSafePath() const
utils::start_goal_planner_common::updateSafetyCheckTargetObjectsData(
start_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 = utils::path_safety_checker::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_out_path, ego_predicted_path, object, obj_path, planner_data_->parameters,
safety_check_params_->rss_params, hysteresis_factor, current_debug_data.second)) {
utils::path_safety_checker::updateCollisionCheckDebugMap(
start_planner_data_.collision_check, current_debug_data, false);
is_safe_dynamic_objects = false;
is_safe_dynamic_object = false;
break;
}
}
if (is_safe_dynamic_object) {
utils::path_safety_checker::updateCollisionCheckDebugMap(
start_planner_data_.collision_check, current_debug_data, is_safe_dynamic_object);
}
}

return is_safe_dynamic_objects;
return behavior_path_planner::utils::path_safety_checker::checkSafetyWithRSS(
pull_out_path, ego_predicted_path, target_objects_on_lane.on_current_lane,
start_planner_data_.collision_check, planner_data_->parameters,
safety_check_params_->rss_params, objects_filtering_params_->use_all_predicted_path,
hysteresis_factor);
}

bool StartPlannerModule::isGoalBehindOfEgoInSameRouteSegment() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,36 @@ ExtendedPredictedObjects filterObjectPredictedPathByTimeHorizon(
return filtered_objects;
}

bool checkSafetyWithRSS(
const PathWithLaneId & planned_path,
const std::vector<PoseWithVelocityStamped> & ego_predicted_path,
const std::vector<ExtendedPredictedObject> & objects, CollisionCheckDebugMap & debug_map,
const BehaviorPathPlannerParameters & parameters, const RSSparams & rss_params,
const bool check_all_predicted_path, const double hysteresis_factor)
{
// 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 = utils::path_safety_checker::createObjectDebug(object);

const auto obj_predicted_paths =
utils::path_safety_checker::getPredictedPathFromObj(object, 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, parameters, rss_params,
hysteresis_factor, current_debug_data.second);

utils::path_safety_checker::updateCollisionCheckDebugMap(
debug_map, current_debug_data, !has_collision);

return has_collision;
});
});

return is_safe;
}

bool checkSafetyWithIntegralPredictedPolygon(
const std::vector<PoseWithVelocityStamped> & ego_predicted_path, const VehicleInfo & vehicle_info,
const ExtendedPredictedObjects & objects, const bool check_all_predicted_path,
Expand Down

0 comments on commit 6c85af4

Please sign in to comment.