Skip to content

Commit

Permalink
use wrapper instead of std::optional
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 committed Sep 26, 2023
1 parent 47ce8dd commit d5b99a3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ boost::optional<PoseWithVelocityAndPolygonStamped> getInterpolatedPoseWithVeloci
const std::vector<PoseWithVelocityStamped> & pred_path, const double current_time,
const VehicleInfo & ego_info);

/**
* @brief Iterate the points in the ego and target's predicted path and
* perform safety check for each of the iterated points.
* @param planned_path The predicted path of the ego vehicle.
* @param predicted_ego_path Ego vehicle's predicted path
* @param ego_current_velocity Current velocity of the ego vehicle.
* @param target_object The predicted object to check collision with.
* @param target_object_path The predicted path of the target object.
* @param common_parameters The common parameters used in behavior path planner.
* @param front_object_deceleration The deceleration of the object in the front.(used in RSS)
* @param rear_object_deceleration The deceleration of the object in the rear.(used in RSS)
* @param debug The debug information for collision checking.
* @return a list of polygon when collision is expected.
*/
std::vector<Polygon2d> getCollidedPolygons(
const PathWithLaneId & planned_path,
const std::vector<PoseWithVelocityStamped> & predicted_ego_path,
const ExtendedPredictedObject & target_object,
const PredictedPathWithPolygon & target_object_path,
const BehaviorPathPlannerParameters & common_parameters, const RSSparams & rss_parameters,
const double hysteresis_factor, CollisionCheckDebug & debug);

/**
* @brief Iterate the points in the ego and target's predicted path and
* perform safety check for each of the iterated points.
Expand All @@ -103,7 +125,7 @@ boost::optional<PoseWithVelocityAndPolygonStamped> getInterpolatedPoseWithVeloci
* @param debug The debug information for collision checking.
* @return true if distance is safe.
*/
std::optional<std::vector<Polygon2d>> checkCollision(
bool checkCollision(
const PathWithLaneId & planned_path,
const std::vector<PoseWithVelocityStamped> & predicted_ego_path,
const ExtendedPredictedObject & target_object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ bool AvoidanceModule::isSafePath(
: ego_predicted_path_for_rear_object;

for (const auto & obj_path : obj_predicted_paths) {
if (utils::path_safety_checker::checkCollision(
if (!utils::path_safety_checker::checkCollision(
shifted_path.path, ego_predicted_path, object, obj_path, p, parameters_->rss_params,
hysteresis_factor, current_debug_data.second)) {
marker_utils::updateCollisionCheckDebugMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ bool GoalPlannerModule::isSafePath() const

// 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(
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1443,15 +1443,14 @@ PathSafetyStatus NormalLaneChange::isLaneChangePathSafe(
const auto obj_predicted_paths = utils::path_safety_checker::getPredictedPathFromObj(
obj, lane_change_parameters_->use_all_predicted_path);
for (const auto & obj_path : obj_predicted_paths) {
const auto have_collision = utils::path_safety_checker::checkCollision(
const auto collided_polygons = utils::path_safety_checker::getCollidedPolygons(
path, ego_predicted_path, obj, obj_path, common_parameters, rss_params, 1.0,
current_debug_data.second);

if (!have_collision) {
if (collided_polygons.empty()) {
continue;
}

const auto & collided_polygons = *have_collision;
const auto collision_in_current_lanes = utils::lane_change::isCollidedPolygonsInLanelet(
collided_polygons, lane_change_path.info.current_lanes);
const auto collision_in_target_lanes = utils::lane_change::isCollidedPolygonsInLanelet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ bool StartPlannerModule::isSafePath() const

// 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(
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)) {
marker_utils::updateCollisionCheckDebugMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ boost::optional<PoseWithVelocityAndPolygonStamped> getInterpolatedPoseWithVeloci
return PoseWithVelocityAndPolygonStamped{current_time, pose, velocity, ego_polygon};
}

std::optional<std::vector<Polygon2d>> checkCollision(
std::vector<Polygon2d> getCollidedPolygons(
[[maybe_unused]] const PathWithLaneId & planned_path,
const std::vector<PoseWithVelocityStamped> & predicted_ego_path,
const ExtendedPredictedObject & target_object,
Expand Down Expand Up @@ -348,11 +348,21 @@ std::optional<std::vector<Polygon2d>> checkCollision(
}
}

if (!collided_polygons.empty()) {
return collided_polygons;
}
return collided_polygons;
}

return std::nullopt;
bool checkCollision(
const PathWithLaneId & planned_path,
const std::vector<PoseWithVelocityStamped> & predicted_ego_path,
const ExtendedPredictedObject & target_object,
const PredictedPathWithPolygon & target_object_path,
const BehaviorPathPlannerParameters & common_parameters, const RSSparams & rss_parameters,
const double hysteresis_factor, CollisionCheckDebug & debug)
{
const auto collided_polygons = getCollidedPolygons(
planned_path, predicted_ego_path, target_object, target_object_path, common_parameters,
rss_parameters, hysteresis_factor, debug);
return collided_polygons.empty();
}

bool checkCollisionWithExtraStoppingMargin(
Expand Down

0 comments on commit d5b99a3

Please sign in to comment.