Skip to content

Commit

Permalink
feat(behavior_path_planner): external request lane change (autowarefo…
Browse files Browse the repository at this point in the history
…undation#2442)

* feature(behavior_path_planner): add external request lane change module

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feature(behavior_path_planner): fix for RTC

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feature(behavior_path_planner): fix decision logic

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): fix behavior_path_planner_tree.xml

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): fix for rebase

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): output multiple candidate paths

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): get path candidate in behavior tree manager

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): fix for multiple candidate path

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): separate external request lane change module

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feature(behavior_path_planner): add create publisher method

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feature(behavior_path_planner): move publishers to node

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feature(behavior_path_planner): remove unnecessary publisher

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): move reset path candidate function to behavior tree manager

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): add external request lane change path candidate publisher

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

feat(behavior_path_planner): apply abort lane change

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

* fix(behavior_path_planner): remove unnecessary change

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

* feat(behavior_path_planner): fix getLaneChangePaths()

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

* feat(behavior_path_planner): disable external request lane change in default tree

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

* Update rtc_auto_mode_manager.param.yaml

* fix(route_handler): remove redundant code

* fix(behavior_path_planner): fix for turn signal

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>

Signed-off-by: Fumiya Watanabe <rej55.g@gmail.com>
Signed-off-by: tomoya.kimura <tomoya.kimura@tier4.jp>
  • Loading branch information
rej55 authored and tkimura4 committed Jan 24, 2023
1 parent 980a84e commit c3e7f3c
Show file tree
Hide file tree
Showing 18 changed files with 1,164 additions and 62 deletions.
12 changes: 10 additions & 2 deletions common/rtc_manager_rviz_plugin/src/rtc_manager_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ std::string getModuleName(const uint8_t module_type)
case Module::LANE_CHANGE_RIGHT: {
return "lane_change_right";
}
case Module::EXT_REQUEST_LANE_CHANGE_LEFT: {
return "ext_request_lane_change_left";
}
case Module::EXT_REQUEST_LANE_CHANGE_RIGHT: {
return "ext_request_lane_change_right";
}
case Module::AVOIDANCE_LEFT: {
return "avoidance_left";
}
Expand Down Expand Up @@ -80,8 +86,10 @@ bool isPathChangeModule(const uint8_t module_type)
{
if (
module_type == Module::LANE_CHANGE_LEFT || module_type == Module::LANE_CHANGE_RIGHT ||
module_type == Module::AVOIDANCE_LEFT || module_type == Module::AVOIDANCE_RIGHT ||
module_type == Module::PULL_OVER || module_type == Module::PULL_OUT) {
module_type == Module::EXT_REQUEST_LANE_CHANGE_LEFT ||
module_type == Module::EXT_REQUEST_LANE_CHANGE_RIGHT || module_type == Module::AVOIDANCE_LEFT ||
module_type == Module::AVOIDANCE_RIGHT || module_type == Module::PULL_OVER ||
module_type == Module::PULL_OUT) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- "intersection"
- "no_stopping_area"
- "traffic_light"
- "ext_request_lane_change_left"
- "ext_request_lane_change_right"
- "lane_change_left"
- "lane_change_right"
- "avoidance_left"
Expand Down
1 change: 1 addition & 0 deletions planning/behavior_path_planner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ament_auto_add_library(behavior_path_planner_node SHARED
src/scene_module/avoidance/avoidance_utils.cpp
src/scene_module/avoidance/debug.cpp
src/scene_module/lane_following/lane_following_module.cpp
src/scene_module/lane_change/external_request_lane_change_module.cpp
src/scene_module/lane_change/lane_change_module.cpp
src/scene_module/lane_change/util.cpp
src/scene_module/lane_change/debug.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
<Condition ID="SideShift_Request"/>
<Action ID="SideShift_Plan" output="{output}"/>
</ReactiveSequence>
<!-- <ReactiveSequence>
<Condition ID="ExternalRequestLaneChangeRight_Request"/>
<Action ID="ExternalRequestLaneChangeRight_Plan" output="{output}"/>
</ReactiveSequence>
<ReactiveSequence>
<Condition ID="ExternalRequestLaneChangeLeft_Request"/>
<Action ID="ExternalRequestLaneChangeLeft_Plan" output="{output}"/>
</ReactiveSequence> -->
<ReactiveSequence>
<Condition ID="LaneChange_Request"/>
<Action ID="LaneChange_Plan" output="{output}"/>
Expand All @@ -27,48 +35,27 @@
</Fallback>
</BehaviorTree>
<!-- ////////// -->
<BehaviorTree ID="a">
<ReactiveFallback>
<Condition ID="LaneChange_CheckApproval"/>
<KeepRunningUntilFailure>
<Action ID="LaneChange_PlanCandidate" output="{output}"/>
</KeepRunningUntilFailure>
</ReactiveFallback>
</BehaviorTree>
<!-- ////////// -->
<BehaviorTree ID="b">
<ReactiveFallback>
<Condition ID="Avoidance_CheckApproval"/>
<KeepRunningUntilFailure>
<Action ID="Avoidance_PlanCandidate" output="{output}"/>
</KeepRunningUntilFailure>
</ReactiveFallback>
</BehaviorTree>
<!-- ////////// -->
<TreeNodesModel>
<Condition ID="Avoidance_CheckApproval"/>
<Action ID="Avoidance_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Action ID="Avoidance_PlanCandidate">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="Avoidance_Request"/>
<Condition ID="ExternalApproval"/>
<Condition ID="LaneChange_CheckApproval"/>
<Action ID="LaneChange_Plan">
<Action ID="ExternalRequestLaneChangeRight_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="ExternalRequestLaneChangeRight_Request"/>
<Action ID="ExternalRequestLaneChangeLeft_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Action ID="LaneChange_PlanCandidate">
<Condition ID="ExternalRequestLaneChangeLeft_Request"/>
<Action ID="LaneChange_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="LaneChange_Request"/>
<Action ID="LaneFollowing_Plan">
<output_port name="output" type="boost::optional&lt;tier4_planning_msgs::PathWithLaneId_&lt;std::allocator&lt;void&gt; &gt; &gt;">desc</output_port>
</Action>
<Action ID="LaneFollowing_PlanCandidate">
<output_port name="output_candidate" type="boost::optional&lt;tier4_planning_msgs::PathWithLaneId_&lt;std::allocator&lt;void&gt; &gt; &gt;">desc</output_port>
</Action>
<Condition ID="LaneFollowing_Request"/>
<Action ID="PullOut_Plan">
<output_port name="output"/>
Expand All @@ -78,17 +65,10 @@
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="PullOver_Request"/>
<Condition ID="SideShift_CheckApproval"/>
<Action ID="SideShift_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Action ID="SideShift_PlanCandidate">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="SideShift_Request"/>
<SubTree ID="SubTree"/>
<SubTree ID="a"/>
<SubTree ID="b"/>
</TreeNodesModel>
<!-- ////////// -->
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0"?>
<root main_tree_to_execute="BehaviorTree">
<!-- ////////// -->
<BehaviorTree ID="BehaviorTree">
<Fallback>
<ReactiveSequence>
<Condition ID="PullOver_Request"/>
<Action ID="PullOver_Plan" output="{output}"/>
</ReactiveSequence>
<ReactiveSequence>
<Condition ID="PullOut_Request"/>
<Action ID="PullOut_Plan" output="{output}"/>
</ReactiveSequence>
<ReactiveSequence>
<Condition ID="SideShift_Request"/>
<Action ID="SideShift_Plan" output="{output}"/>
</ReactiveSequence>
<ReactiveSequence>
<Condition ID="ExternalRequestLaneChangeRight_Request"/>
<Action ID="ExternalRequestLaneChangeRight_Plan" output="{output}"/>
</ReactiveSequence>
<ReactiveSequence>
<Condition ID="ExternalRequestLaneChangeLeft_Request"/>
<Action ID="ExternalRequestLaneChangeLeft_Plan" output="{output}"/>
</ReactiveSequence>
<ReactiveSequence>
<Condition ID="LaneChange_Request"/>
<Action ID="LaneChange_Plan" output="{output}"/>
</ReactiveSequence>
<ReactiveSequence>
<Condition ID="Avoidance_Request"/>
<Action ID="Avoidance_Plan" output="{output}"/>
</ReactiveSequence>
<Action ID="LaneFollowing_Plan" output="{output}"/>
</Fallback>
</BehaviorTree>
<!-- ////////// -->
<TreeNodesModel>
<Action ID="Avoidance_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="Avoidance_Request"/>
<Condition ID="ExternalApproval"/>
<Action ID="ExternalRequestLaneChangeRight_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="ExternalRequestLaneChangeRight_Request"/>
<Action ID="ExternalRequestLaneChangeLeft_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="ExternalRequestLaneChangeLeft_Request"/>
<Action ID="LaneChange_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="LaneChange_Request"/>
<Action ID="LaneFollowing_Plan">
<output_port name="output" type="boost::optional&lt;tier4_planning_msgs::PathWithLaneId_&lt;std::allocator&lt;void&gt; &gt; &gt;">desc</output_port>
</Action>
<Condition ID="LaneFollowing_Request"/>
<Action ID="PullOut_Plan">
<output_port name="output"/>
</Action>
<Condition ID="PullOut_Request"/>
<Action ID="PullOver_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="PullOver_Request"/>
<Action ID="SideShift_Plan">
<output_port name="output" type="behavior_path_planner::BehaviorModuleOutput">desc</output_port>
</Action>
<Condition ID="SideShift_Request"/>
</TreeNodesModel>
<!-- ////////// -->
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "behavior_path_planner/behavior_tree_manager.hpp"
#include "behavior_path_planner/data_manager.hpp"
#include "behavior_path_planner/scene_module/avoidance/avoidance_module_data.hpp"
#include "behavior_path_planner/scene_module/lane_change/external_request_lane_change_module.hpp"
#include "behavior_path_planner/scene_module/lane_change/lane_change_module.hpp"
#include "behavior_path_planner/scene_module/lane_following/lane_following_module.hpp"
#include "behavior_path_planner/scene_module/pull_out/pull_out_module.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// Copyright 2022 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.

#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__LANE_CHANGE__EXTERNAL_REQUEST_LANE_CHANGE_MODULE_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__LANE_CHANGE__EXTERNAL_REQUEST_LANE_CHANGE_MODULE_HPP_

#include "behavior_path_planner/scene_module/lane_change/debug.hpp"
#include "behavior_path_planner/scene_module/lane_change/lane_change_module_data.hpp"
#include "behavior_path_planner/scene_module/lane_change/lane_change_path.hpp"
#include "behavior_path_planner/scene_module/scene_module_interface.hpp"
#include "behavior_path_planner/turn_signal_decider.hpp"

#include <rclcpp/rclcpp.hpp>

#include "tier4_planning_msgs/msg/detail/lane_change_debug_msg_array__struct.hpp"
#include "tier4_planning_msgs/msg/lane_change_debug_msg.hpp"
#include "tier4_planning_msgs/msg/lane_change_debug_msg_array.hpp"
#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
#include <geometry_msgs/msg/pose.hpp>
#include <geometry_msgs/msg/twist.hpp>

#include <tf2/utils.h>

#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

namespace behavior_path_planner
{
using autoware_auto_planning_msgs::msg::PathWithLaneId;
using geometry_msgs::msg::Pose;
using geometry_msgs::msg::Twist;
using marker_utils::CollisionCheckDebug;
using tier4_planning_msgs::msg::LaneChangeDebugMsg;
using tier4_planning_msgs::msg::LaneChangeDebugMsgArray;

class ExternalRequestLaneChangeModule : public SceneModuleInterface
{
public:
enum class Direction {
RIGHT = 0,
LEFT,
};

ExternalRequestLaneChangeModule(
const std::string & name, rclcpp::Node & node, std::shared_ptr<LaneChangeParameters> parameters,
const Direction & direction);

bool isExecutionRequested() const override;
bool isExecutionReady() const override;
BT::NodeStatus updateState() override;
BehaviorModuleOutput plan() override;
BehaviorModuleOutput planWaitingApproval() override;
CandidateOutput planCandidate() const override;
void onEntry() override;
void onExit() override;

std::shared_ptr<LaneChangeDebugMsgArray> get_debug_msg_array() const;
void acceptVisitor(
[[maybe_unused]] const std::shared_ptr<SceneModuleVisitor> & visitor) const override;

protected:
std::shared_ptr<LaneChangeParameters> parameters_;
LaneChangeStatus status_;
PathShifter path_shifter_;
mutable LaneChangeDebugMsgArray lane_change_debug_msg_array_;
LaneChangeStates current_lane_change_state_;
std::shared_ptr<LaneChangePath> abort_path_;
PathWithLaneId prev_approved_path_;

Direction direction_;

double lane_change_lane_length_{200.0};
double check_distance_{100.0};
bool is_abort_path_approved_{false};
bool is_abort_approval_requested_{false};
bool is_abort_condition_satisfied_{false};
bool is_activated_ = false;

void resetParameters();
void resetPathIfAbort();

void waitApproval(const double start_distance, const double finish_distance)
{
updateRTCStatus(start_distance, finish_distance);
is_waiting_approval_ = true;
}

lanelet::ConstLanelets get_original_lanes() const;
PathWithLaneId getReferencePath() const;
lanelet::ConstLanelets getLaneChangeLanes(
const lanelet::ConstLanelets & current_lanes, const double lane_change_lane_length) const;
std::pair<bool, bool> getSafePath(
const lanelet::ConstLanelets & lane_change_lanes, const double check_distance,
LaneChangePath & safe_path) const;

void updateLaneChangeStatus();
void generateExtendedDrivableArea(PathWithLaneId & path);
void updateOutputTurnSignal(BehaviorModuleOutput & output);
void updateSteeringFactorPtr(const BehaviorModuleOutput & output);
void updateSteeringFactorPtr(
const CandidateOutput & output, const LaneChangePath & selected_path) const;
void calcTurnSignalInfo();

bool isSafe() const;
bool isValidPath(const PathWithLaneId & path) const;
bool isApprovedPathSafe(Pose & ego_pose_before_collision) const;
bool isNearEndOfLane() const;
bool isCurrentSpeedLow() const;
bool isAbortConditionSatisfied();
bool hasFinishedLaneChange() const;
bool isAbortState() const;

// getter
Pose getEgoPose() const;
Twist getEgoTwist() const;
std_msgs::msg::Header getRouteHeader() const;

// debug
mutable std::unordered_map<std::string, CollisionCheckDebug> object_debug_;
mutable std::vector<LaneChangePath> debug_valid_path_;

void setObjectDebugVisualization() const;
};

class ExternalRequestLaneChangeRightModule : public ExternalRequestLaneChangeModule
{
public:
ExternalRequestLaneChangeRightModule(
const std::string & name, rclcpp::Node & node,
std::shared_ptr<LaneChangeParameters> parameters);
};

class ExternalRequestLaneChangeLeftModule : public ExternalRequestLaneChangeModule
{
public:
ExternalRequestLaneChangeLeftModule(
const std::string & name, rclcpp::Node & node,
std::shared_ptr<LaneChangeParameters> parameters);
};

} // namespace behavior_path_planner
// clang-format off
#endif // BEHAVIOR_PATH_PLANNER__SCENE_MODULE__LANE_CHANGE__EXTERNAL_REQUEST_LANE_CHANGE_MODULE_HPP_ // NOLINT
// clang-format on
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ LaneChangePaths getLaneChangePaths(

LaneChangePaths selectValidPaths(
const LaneChangePaths & paths, const lanelet::ConstLanelets & current_lanes,
const lanelet::ConstLanelets & target_lanes,
const lanelet::routing::RoutingGraphContainer & overall_graphs, const Pose & current_pose,
const bool isInGoalRouteSection, const Pose & goal_pose);
const lanelet::ConstLanelets & target_lanes, const RouteHandler & route_handler,
const Pose & current_pose, const Pose & goal_pose, const double minimum_lane_change_length);

bool selectSafePath(
const LaneChangePaths & paths, const lanelet::ConstLanelets & current_lanes,
Expand All @@ -103,9 +102,8 @@ bool isLaneChangePathSafe(

bool hasEnoughDistance(
const LaneChangePath & path, const lanelet::ConstLanelets & current_lanes,
const lanelet::ConstLanelets & target_lanes, const Pose & current_pose,
const bool isInGoalRouteSection, const Pose & goal_pose,
const lanelet::routing::RoutingGraphContainer & overall_graphs);
const lanelet::ConstLanelets & target_lanes, const Pose & current_pose, const Pose & goal_pose,
const RouteHandler & route_handler, const double minimum_lane_change_length);

ShiftLine getLaneChangeShiftLine(
const PathWithLaneId & path1, const PathWithLaneId & path2,
Expand Down
Loading

0 comments on commit c3e7f3c

Please sign in to comment.