Skip to content

Commit

Permalink
fix(start_planner): publish stop path when goal is behind from ego
Browse files Browse the repository at this point in the history
Signed-off-by: Takamasa Horibe <horibe.takamasa@gmail.com>
  • Loading branch information
TakaHoribe committed Jul 10, 2023
1 parent 8c982e5 commit c5ae960
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ class StartPlannerModule : public SceneModuleInterface
bool isStopped();
bool hasFinishedCurrentPath();

// check if the goal is located behind the ego in the same route segment.
bool IsGoalBehindOfEgoInSameRouteSegment() const;

// generate BehaviorPathOutput with stopping path.
BehaviorModuleOutput generateStopOutput() const;

void setDebugData() const;
};
} // namespace behavior_path_planner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ ModuleStatus StartPlannerModule::updateState()

BehaviorModuleOutput StartPlannerModule::plan()
{
if (IsGoalBehindOfEgoInSameRouteSegment()) {
RCLCPP_WARN_THROTTLE(
getLogger(), *clock_, 5000, "Start plan for a backward goal is not supported now");
return generateStopOutput();
}

if (isWaitingApproval()) {
clearWaitingApproval();
resetPathCandidate();
Expand Down Expand Up @@ -296,6 +302,12 @@ BehaviorModuleOutput StartPlannerModule::planWaitingApproval()
updatePullOutStatus();
waitApproval();

if (IsGoalBehindOfEgoInSameRouteSegment()) {
RCLCPP_WARN_THROTTLE(
getLogger(), *clock_, 5000, "Start plan for a backward goal is not supported now");
return generateStopOutput();
}

BehaviorModuleOutput output;
if (!status_.is_safe) {
RCLCPP_WARN_THROTTLE(
Expand Down Expand Up @@ -841,6 +853,46 @@ TurnSignalInfo StartPlannerModule::calcTurnSignalInfo() const
return turn_signal;
}

bool StartPlannerModule::IsGoalBehindOfEgoInSameRouteSegment() const
{
const auto & rh = planner_data_->route_handler;

// Check if the goal and ego are in the same route segment. If not, this is out of scope of this
// function. Return false.
lanelet::ConstLanelet ego_lanelet;
rh->getClosestLaneletWithinRoute(getEgoPose(), &ego_lanelet);
const auto is_ego_in_goal_route_section = rh->isInGoalRouteSection(ego_lanelet);

if (!is_ego_in_goal_route_section) {
return false;
}

// If the goal and ego are in the same route segment, check the goal and ego pose relation.
// Return true when the goal is located behind of ego.
const auto ego_lane_path = rh->getCenterLinePath(
lanelet::ConstLanelets{ego_lanelet}, 0.0, std::numeric_limits<double>::max());
const auto dist_ego_to_goal = motion_utils::calcSignedArcLength(
ego_lane_path.points, getEgoPosition(), rh->getGoalPose().position);

const bool is_goal_behind_of_ego = (dist_ego_to_goal < 0.0);
return is_goal_behind_of_ego;
}

// NOTE: this must be called after updatePullOutStatus(). This must be fixed.
BehaviorModuleOutput StartPlannerModule::generateStopOutput() const
{
BehaviorModuleOutput output;
output.path = std::make_shared<PathWithLaneId>(generateStopPath());

DrivableAreaInfo current_drivable_area_info;
current_drivable_area_info.drivable_lanes = status_.lanes;
output.drivable_area_info = utils::combineDrivableAreaInfo(
current_drivable_area_info, getPreviousModuleOutput().drivable_area_info);

output.reference_path = getPreviousModuleOutput().reference_path;
return output;
}

void StartPlannerModule::setDebugData() const
{
using marker_utils::createPathMarkerArray;
Expand Down

0 comments on commit c5ae960

Please sign in to comment.