Skip to content

Commit

Permalink
feat(avoidance_by_lc): add new module to avoid obstacle by lane change (
Browse files Browse the repository at this point in the history
#3125)

* feat(rtc_interface): add new module avoidance by lc

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>

* feat(launch): add new param files

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>

* feat(avoidance_by_lc): add avoidance by lane change module

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>

* feat(behavior_path_planner): integrate avoidance by lc

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>

* fix(avoidance_by_lc): apply refactor

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>

* fix(avoidance_by_lc): use found_safe_path for ready check

* fix request condition

* fix build error

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>

---------

Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
  • Loading branch information
satoshi-ota authored Apr 6, 2023
1 parent 5257ae7 commit c8e97e0
Show file tree
Hide file tree
Showing 14 changed files with 1,818 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def launch_setup(context, *args, **kwargs):
side_shift_param = yaml.safe_load(f)["/**"]["ros__parameters"]
with open(LaunchConfiguration("avoidance_param_path").perform(context), "r") as f:
avoidance_param = yaml.safe_load(f)["/**"]["ros__parameters"]
with open(LaunchConfiguration("avoidance_by_lc_param_path").perform(context), "r") as f:
avoidance_by_lc_param = yaml.safe_load(f)["/**"]["ros__parameters"]
with open(LaunchConfiguration("lane_change_param_path").perform(context), "r") as f:
lane_change_param = yaml.safe_load(f)["/**"]["ros__parameters"]
with open(LaunchConfiguration("lane_following_param_path").perform(context), "r") as f:
Expand Down Expand Up @@ -85,6 +87,7 @@ def launch_setup(context, *args, **kwargs):
nearest_search_param,
side_shift_param,
avoidance_param,
avoidance_by_lc_param,
lane_change_param,
lane_following_param,
pull_over_param,
Expand Down
2 changes: 2 additions & 0 deletions planning/behavior_path_planner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(common_src
src/behavior_path_planner_node.cpp
src/scene_module/scene_module_visitor.cpp
src/scene_module/avoidance/avoidance_module.cpp
src/scene_module/avoidance_by_lc/module.cpp
src/scene_module/pull_out/pull_out_module.cpp
src/scene_module/pull_over/pull_over_module.cpp
src/scene_module/side_shift/side_shift_module.cpp
Expand Down Expand Up @@ -62,6 +63,7 @@ else()
ament_auto_add_library(behavior_path_planner_node SHARED
src/planner_manager.cpp
src/scene_module/avoidance/manager.cpp
src/scene_module/avoidance_by_lc/manager.cpp
src/scene_module/pull_out/manager.cpp
src/scene_module/pull_over/manager.cpp
src/scene_module/side_shift/manager.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**:
ros__parameters:
avoidance_by_lane_change:
execute_object_num: 1
execute_object_longitudinal_margin: 0.0
execute_only_when_lane_change_finish_before_object: true
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
lane_change_right:
enable_module: true
enable_simultaneous_execution: false
priority: 4
priority: 5
max_module_size: 1

pull_out:
Expand All @@ -48,5 +48,11 @@
avoidance:
enable_module: true
enable_simultaneous_execution: false
priority: 4
max_module_size: 1

avoidance_by_lc:
enable_module: false
enable_simultaneous_execution: false
priority: 3
max_module_size: 1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#else
#include "behavior_path_planner/planner_manager.hpp"
#include "behavior_path_planner/scene_module/avoidance/manager.hpp"
#include "behavior_path_planner/scene_module/avoidance_by_lc/manager.hpp"
#include "behavior_path_planner/scene_module/lane_change/manager.hpp"
#include "behavior_path_planner/scene_module/pull_out/manager.hpp"
#include "behavior_path_planner/scene_module/pull_over/manager.hpp"
Expand All @@ -39,6 +40,7 @@
#include "behavior_path_planner/steering_factor_interface.hpp"
#include "behavior_path_planner/turn_signal_decider.hpp"
#include "behavior_path_planner/util/avoidance/avoidance_module_data.hpp"
#include "behavior_path_planner/util/avoidance_by_lc/module_data.hpp"
#include "behavior_path_planner/util/lane_change/lane_change_module_data.hpp"
#include "behavior_path_planner/util/lane_following/module_data.hpp"
#include "behavior_path_planner/util/pull_out/pull_out_parameters.hpp"
Expand Down Expand Up @@ -159,6 +161,7 @@ class BehaviorPathPlannerNode : public rclcpp::Node

// parameters
std::shared_ptr<AvoidanceParameters> avoidance_param_ptr_;
std::shared_ptr<AvoidanceByLCParameters> avoidance_by_lc_param_ptr_;
std::shared_ptr<SideShiftParameters> side_shift_param_ptr_;
std::shared_ptr<LaneChangeParameters> lane_change_param_ptr_;
std::shared_ptr<LaneFollowingParameters> lane_following_param_ptr_;
Expand All @@ -177,6 +180,9 @@ class BehaviorPathPlannerNode : public rclcpp::Node
SideShiftParameters getSideShiftParam();
PullOverParameters getPullOverParam();
PullOutParameters getPullOutParam();
AvoidanceByLCParameters getAvoidanceByLCParam(
const std::shared_ptr<AvoidanceParameters> & avoidance_param,
const std::shared_ptr<LaneChangeParameters> & lane_change_param);

// callback
void onOdometry(const Odometry::ConstSharedPtr msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct BehaviorPathPlannerParameters
bool verbose;

ModuleConfigParameters config_avoidance;
ModuleConfigParameters config_avoidance_by_lc;
ModuleConfigParameters config_pull_out;
ModuleConfigParameters config_pull_over;
ModuleConfigParameters config_side_shift;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2023 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__AVOIDANCE_BY_LC__MANAGER_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE_BY_LC__MANAGER_HPP_

#include "behavior_path_planner/scene_module/avoidance_by_lc/module.hpp"
#include "behavior_path_planner/scene_module/scene_module_manager_interface.hpp"
#include "behavior_path_planner/util/avoidance_by_lc/module_data.hpp"

#include <rclcpp/rclcpp.hpp>

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

namespace behavior_path_planner
{

class AvoidanceByLCModuleManager : public SceneModuleManagerInterface
{
public:
AvoidanceByLCModuleManager(
rclcpp::Node * node, const std::string & name, const ModuleConfigParameters & config,
const std::shared_ptr<AvoidanceByLCParameters> & parameters);

std::shared_ptr<SceneModuleInterface> createNewSceneModuleInstance() override
{
return std::make_shared<AvoidanceByLCModule>(
name_, *node_, parameters_, rtc_interface_ptr_map_);
}

void updateModuleParams(const std::vector<rclcpp::Parameter> & parameters) override;

private:
std::shared_ptr<AvoidanceByLCParameters> parameters_;

std::vector<std::shared_ptr<AvoidanceByLCModule>> registered_modules_;
};

} // namespace behavior_path_planner

#endif // BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE_BY_LC__MANAGER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// Copyright 2023 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__AVOIDANCE_BY_LC__MODULE_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE_BY_LC__MODULE_HPP_

#include "behavior_path_planner/marker_util/lane_change/debug.hpp"
#include "behavior_path_planner/scene_module/scene_module_interface.hpp"
#include "behavior_path_planner/turn_signal_decider.hpp"
#include "behavior_path_planner/util/avoidance/avoidance_module_data.hpp"
#include "behavior_path_planner/util/avoidance_by_lc/module_data.hpp"
#include "behavior_path_planner/util/lane_change/lane_change_module_data.hpp"
#include "behavior_path_planner/util/lane_change/lane_change_path.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 route_handler::Direction;
using tier4_planning_msgs::msg::LaneChangeDebugMsg;
using tier4_planning_msgs::msg::LaneChangeDebugMsgArray;

class AvoidanceByLCModule : public SceneModuleInterface
{
public:
AvoidanceByLCModule(
const std::string & name, rclcpp::Node & node,
const std::shared_ptr<AvoidanceByLCParameters> parameters,
const std::unordered_map<std::string, std::shared_ptr<RTCInterface>> & rtc_interface_ptr_map);

bool isExecutionRequested() const override;
bool isExecutionReady() const override;
ModuleStatus updateState() override;
BehaviorModuleOutput plan() override;
BehaviorModuleOutput planWaitingApproval() override;
CandidateOutput planCandidate() const override;
void processOnEntry() override;
void processOnExit() override;
void updateData() override;

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

#ifndef USE_OLD_ARCHITECTURE
void updateModuleParams(const std::shared_ptr<AvoidanceByLCParameters> & parameters)
{
parameters_ = parameters;
}
#endif

private:
std::shared_ptr<AvoidanceByLCParameters> 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_;

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 waitApprovalLeft(const double start_distance, const double finish_distance)
{
rtc_interface_ptr_map_.at("left")->updateCooperateStatus(
uuid_map_.at("left"), isExecutionReady(), start_distance, finish_distance, clock_->now());
is_waiting_approval_ = true;
}

void waitApprovalRight(const double start_distance, const double finish_distance)
{
rtc_interface_ptr_map_.at("right")->updateCooperateStatus(
uuid_map_.at("right"), isExecutionReady(), start_distance, finish_distance, clock_->now());
is_waiting_approval_ = true;
}

void updateRTCStatus(const CandidateOutput & candidate)
{
if (candidate.lateral_shift > 0.0) {
rtc_interface_ptr_map_.at("left")->updateCooperateStatus(
uuid_map_.at("left"), isExecutionReady(), candidate.start_distance_to_path_change,
candidate.finish_distance_to_path_change, clock_->now());
return;
}
if (candidate.lateral_shift < 0.0) {
rtc_interface_ptr_map_.at("right")->updateCooperateStatus(
uuid_map_.at("right"), isExecutionReady(), candidate.start_distance_to_path_change,
candidate.finish_distance_to_path_change, clock_->now());
return;
}

RCLCPP_WARN_STREAM(
getLogger(),
"Direction is UNKNOWN, start_distance = " << candidate.start_distance_to_path_change);
}

lanelet::ConstLanelets getCurrentLanes(const PathWithLaneId & path) const
{
const auto & route_handler = planner_data_->route_handler;
const auto & common_parameters = planner_data_->parameters;

lanelet::ConstLanelets reference_lanes{};
for (const auto & p : path.points) {
reference_lanes.push_back(
planner_data_->route_handler->getLaneletsFromId(p.lane_ids.front()));
}

lanelet::ConstLanelet current_lane;
lanelet::utils::query::getClosestLanelet(reference_lanes, getEgoPose(), &current_lane);

return route_handler->getLaneletSequence(
current_lane, getEgoPose(), common_parameters.backward_path_length,
common_parameters.forward_path_length);
}

void removePreviousRTCStatusLeft()
{
if (rtc_interface_ptr_map_.at("left")->isRegistered(uuid_map_.at("left"))) {
rtc_interface_ptr_map_.at("left")->removeCooperateStatus(uuid_map_.at("left"));
}
}

void removePreviousRTCStatusRight()
{
if (rtc_interface_ptr_map_.at("right")->isRegistered(uuid_map_.at("right"))) {
rtc_interface_ptr_map_.at("right")->removeCooperateStatus(uuid_map_.at("right"));
}
}

AvoidancePlanningData calcAvoidancePlanningData(DebugData & debug) const;
AvoidancePlanningData avoidance_data_;
mutable DebugData debug_data_;

ObjectDataArray registered_objects_;
mutable ObjectDataArray stopped_objects_;

void fillAvoidanceTargetObjects(AvoidancePlanningData & data, DebugData & debug) const;
void fillObjectEnvelopePolygon(const Pose & closest_pose, ObjectData & object_data) const;
void fillObjectMovingTime(ObjectData & object_data) const;
void updateRegisteredObject(const ObjectDataArray & objects);
void compensateDetectionLost(
ObjectDataArray & target_objects, ObjectDataArray & other_objects) const;
bool isTargetObjectType(const PredictedObject & object) const;

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);
bool isApprovedPathSafe(Pose & ego_pose_before_collision) const;
void calcTurnSignalInfo();

void updateSteeringFactorPtr(
const CandidateOutput & output, const LaneChangePath & selected_path) const;
bool isSafe() const;
bool isValidPath() const;
bool isValidPath(const PathWithLaneId & path) const;
bool isNearEndOfLane() const;
bool isCurrentSpeedLow() const;
bool isAbortConditionSatisfied();
bool hasFinishedLaneChange() const;
bool isAvoidancePlanRunning() const;
bool isAbortState() const;

// getter
Point getEgoPosition() const { return planner_data_->self_odometry->pose.pose.position; }
Pose getEgoPose() const { return planner_data_->self_odometry->pose.pose; }
Twist getEgoTwist() const;
std_msgs::msg::Header getRouteHeader() const;
void resetPathIfAbort();

// debug
void setObjectDebugVisualization() const;
mutable std::unordered_map<std::string, CollisionCheckDebug> object_debug_;
mutable std::vector<LaneChangePath> debug_valid_path_;
};
} // namespace behavior_path_planner

#endif // BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE_BY_LC__MODULE_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace behavior_path_planner
{
// Forward Declaration
class AvoidanceModule;
class AvoidanceByLCModule;
class LaneChangeModule;
#ifdef USE_OLD_ARCHITECTURE
class ExternalRequestLaneChangeModule;
Expand All @@ -49,6 +50,7 @@ class SceneModuleVisitor
void visitExternalRequestLaneChangeModule(const ExternalRequestLaneChangeModule * module) const;
#endif
void visitAvoidanceModule(const AvoidanceModule * module) const;
void visitAvoidanceByLCModule(const AvoidanceByLCModule * module) const;

std::shared_ptr<AvoidanceDebugMsgArray> getAvoidanceModuleDebugMsg() const;
std::shared_ptr<LaneChangeDebugMsgArray> getLaneChangeModuleDebugMsg() const;
Expand Down
Loading

0 comments on commit c8e97e0

Please sign in to comment.