Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
  • Loading branch information
takayuki5168 committed Apr 14, 2023
1 parent 24e542c commit acf6198
Show file tree
Hide file tree
Showing 11 changed files with 616 additions and 0 deletions.
1 change: 1 addition & 0 deletions launch/tier4_planning_launch/launch/planning.launch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<!-- behavior path planner -->
<arg name="side_shift_param_path"/>
<arg name="avoidance_param_path"/>
<arg name="dynamic_avoidance_param_path"/>
<arg name="lane_change_param_path"/>
<arg name="lane_following_param_path"/>
<arg name="pull_over_param_path"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def launch_setup(context, *args, **kwargs):
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("dynamic_avoidance_param_path").perform(context), "r") as f:
dynamic_avoidance_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 @@ -88,6 +90,7 @@ def launch_setup(context, *args, **kwargs):
side_shift_param,
avoidance_param,
avoidance_by_lc_param,
dynamic_avoidance_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 @@ -15,6 +15,7 @@ set(common_src
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/dynamic_avoidance/dynamic_avoidance_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 @@ -65,6 +66,7 @@ else()
src/planner_manager.cpp
src/scene_module/avoidance/manager.cpp
src/scene_module/avoidance_by_lc/manager.cpp
src/scene_module/dynamic_avoidance/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
Expand Up @@ -21,6 +21,7 @@
#ifdef USE_OLD_ARCHITECTURE
#include "behavior_path_planner/behavior_tree_manager.hpp"
#include "behavior_path_planner/scene_module/avoidance/avoidance_module.hpp"
#include "behavior_path_planner/scene_module/dynamic_avoidance/dynamic_avoidance_module.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"
Expand All @@ -31,6 +32,7 @@
#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/dynamic_avoidance/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 Down Expand Up @@ -76,6 +78,7 @@ namespace behavior_path_planner
{
using autoware_adapi_v1_msgs::msg::OperationModeState;
using autoware_auto_mapping_msgs::msg::HADMapBin;
using autoware_auto_perception_msgs::msg::PredictedObject;
using autoware_auto_perception_msgs::msg::PredictedObjects;
using autoware_auto_planning_msgs::msg::Path;
using autoware_auto_planning_msgs::msg::PathWithLaneId;
Expand Down Expand Up @@ -150,6 +153,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<DynamicAvoidanceParameters> dynamic_avoidance_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 @@ -163,6 +167,7 @@ class BehaviorPathPlannerNode : public rclcpp::Node
#endif

AvoidanceParameters getAvoidanceParam();
DynamicAvoidanceParameters getDynamicAvoidanceParam();
LaneChangeParameters getLaneChangeParam();
LaneFollowingParameters getLaneFollowingParam();
SideShiftParameters getSideShiftParam();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
namespace behavior_path_planner
{
using autoware_adapi_v1_msgs::msg::OperationModeState;
using autoware_auto_perception_msgs::msg::PredictedObject;
using autoware_auto_perception_msgs::msg::PredictedObjects;
using autoware_auto_planning_msgs::msg::PathWithLaneId;
using autoware_auto_vehicle_msgs::msg::HazardLightsCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct BehaviorPathPlannerParameters

ModuleConfigParameters config_avoidance;
ModuleConfigParameters config_avoidance_by_lc;
ModuleConfigParameters config_dynamic_avoidance;
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,99 @@
// Copyright 2021 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__DYNAMIC_AVOIDANCE__DYNAMIC_AVOIDANCE_MODULE_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__DYNAMIC_AVOIDANCE__DYNAMIC_AVOIDANCE_MODULE_HPP_

#include "behavior_path_planner/scene_module/scene_module_interface.hpp"

#include <rclcpp/rclcpp.hpp>

#include <autoware_auto_perception_msgs/msg/predicted_object.hpp>
#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
#include <autoware_auto_vehicle_msgs/msg/turn_indicators_command.hpp>
#include <tier4_planning_msgs/msg/avoidance_debug_msg.hpp>
#include <tier4_planning_msgs/msg/avoidance_debug_msg_array.hpp>

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

namespace behavior_path_planner
{
struct DynamicAvoidanceParameters
{
bool avoid_car{true};
bool avoid_truck{true};
bool avoid_bus{true};
bool avoid_trailer{true};
bool avoid_unknown{false};
bool avoid_bicycle{false};
bool avoid_motorcycle{false};
bool avoid_pedestrian{false};

// drivable area expansion
double drivable_area_right_bound_offset{};
double drivable_area_left_bound_offset{};
std::vector<std::string> drivable_area_types_to_skip{};
};

class DynamicAvoidanceModule : public SceneModuleInterface
{
public:
struct DynamicAvoidanceObject
{
explicit DynamicAvoidanceObject(const PredictedObject & predicted_object)
: pose(predicted_object.kinematics.initial_pose_with_covariance.pose),
shape(predicted_object.shape)
{
}

geometry_msgs::msg::Pose pose;
autoware_auto_perception_msgs::msg::Shape shape;
};

DynamicAvoidanceModule(
const std::string & name, rclcpp::Node & node,
std::shared_ptr<DynamicAvoidanceParameters> parameters);

bool isExecutionRequested() const override;
bool isExecutionReady() const override;
ModuleStatus updateState() override;
ModuleStatus getNodeStatusWhileWaitingApproval() const override { return ModuleStatus::SUCCESS; }
BehaviorModuleOutput plan() override;
CandidateOutput planCandidate() const override;
BehaviorModuleOutput planWaitingApproval() override;
void onEntry() override;
void onExit() override;
// void updateData() override;
void acceptVisitor(
[[maybe_unused]] const std::shared_ptr<SceneModuleVisitor> & visitor) const override
{
}

private:
std::vector<DynamicAvoidanceObject> calcTargetObjects() const;
lanelet::ConstLanelets getAdjacentLanes(
const double forward_distance, const double backward_distance) const;
Pose getEgoPose() const;
tier4_autoware_utils::Polygon2d calcDynamicObstaclesPolygon(
const PathWithLaneId & path, const DynamicAvoidanceObject & object);

std::shared_ptr<DynamicAvoidanceParameters> parameters_;
};
} // namespace behavior_path_planner

#endif // BEHAVIOR_PATH_PLANNER__SCENE_MODULE__DYNAMIC_AVOIDANCE__DYNAMIC_AVOIDANCE_MODULE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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__DYNAMIC_AVOIDANCE__MANAGER_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__DYNAMIC_AVOIDANCE__MANAGER_HPP_

#include "behavior_path_planner/scene_module/dynamic_avoidance/dynamic_avoidance_module.hpp"
#include "behavior_path_planner/scene_module/scene_module_manager_interface.hpp"

#include <rclcpp/rclcpp.hpp>

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

namespace behavior_path_planner
{

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

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

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

private:
std::shared_ptr<DynamicAvoidanceParameters> parameters_;
std::vector<std::shared_ptr<DynamicAvoidanceModule>> registered_modules_;
};

} // namespace behavior_path_planner

#endif // BEHAVIOR_PATH_PLANNER__SCENE_MODULE__DYNAMIC_AVOIDANCE__MANAGER_HPP_
50 changes: 50 additions & 0 deletions planning/behavior_path_planner/src/behavior_path_planner_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ BehaviorPathPlannerNode::BehaviorPathPlannerNode(const rclcpp::NodeOptions & nod
// set parameters
{
avoidance_param_ptr_ = std::make_shared<AvoidanceParameters>(getAvoidanceParam());
dynamic_avoidance_param_ptr_ =
std::make_shared<DynamicAvoidanceParameters>(getDynamicAvoidanceParam());
lane_change_param_ptr_ = std::make_shared<LaneChangeParameters>(getLaneChangeParam());
lane_following_param_ptr_ = std::make_shared<LaneFollowingParameters>(getLaneFollowingParam());
pull_out_param_ptr_ = std::make_shared<PullOutParameters>(getPullOutParam());
Expand Down Expand Up @@ -152,6 +154,10 @@ BehaviorPathPlannerNode::BehaviorPathPlannerNode(const rclcpp::NodeOptions & nod
"Avoidance", create_publisher<Path>(path_candidate_name_space + "avoidance", 1));
bt_manager_->registerSceneModule(avoidance_module);

auto dynamic_avoidance_module = std::make_shared<DynamicAvoidanceModule>(
"DynamicAvoidance", *this, dynamic_avoidance_param_ptr_);
bt_manager_->registerSceneModule(dynamic_avoidance_module);

auto lane_following_module =
std::make_shared<LaneFollowingModule>("LaneFollowing", *this, lane_following_param_ptr_);
bt_manager_->registerSceneModule(lane_following_module);
Expand Down Expand Up @@ -296,6 +302,12 @@ BehaviorPathPlannerNode::BehaviorPathPlannerNode(const rclcpp::NodeOptions & nod
"avoidance_by_lane_change",
create_publisher<Path>(path_reference_name_space + "avoidance_by_lane_change", 1));
}

if (p.config_dynamic_avoidance.enable_module) {
auto manager = std::make_shared<DynamicAvoidanceModuleManager>(
this, "dynamic_avoidance", p.config_dynamic_avoidance, dynamic_avoidance_param_ptr_);
planner_manager_->registerSceneModuleManager(manager);
}
}
#endif

Expand Down Expand Up @@ -352,6 +364,15 @@ BehaviorPathPlannerParameters BehaviorPathPlannerNode::getCommonParam()
p.config_avoidance = get_scene_module_manager_param("avoidance.");
p.config_avoidance_by_lc = get_scene_module_manager_param("avoidance_by_lc.");

{
const std::string ns = "dynamic_avoidance.";
p.config_dynamic_avoidance.enable_module = declare_parameter<bool>(ns + "enable_module");
p.config_dynamic_avoidance.enable_simultaneous_execution =
declare_parameter<bool>(ns + "enable_simultaneous_execution");
p.config_dynamic_avoidance.priority = declare_parameter<int>(ns + "priority");
p.config_dynamic_avoidance.max_module_size = declare_parameter<int>(ns + "max_module_size");
}

// vehicle info
const auto vehicle_info = VehicleInfoUtil(*this).getVehicleInfo();
p.vehicle_info = vehicle_info;
Expand Down Expand Up @@ -643,6 +664,35 @@ AvoidanceParameters BehaviorPathPlannerNode::getAvoidanceParam()
return p;
}

DynamicAvoidanceParameters BehaviorPathPlannerNode::getDynamicAvoidanceParam()
{
DynamicAvoidanceParameters p{};

{ // target object
std::string ns = "dynamic_avoidance.target_object.";
p.avoid_car = declare_parameter<bool>(ns + "car");
p.avoid_truck = declare_parameter<bool>(ns + "truck");
p.avoid_bus = declare_parameter<bool>(ns + "bus");
p.avoid_trailer = declare_parameter<bool>(ns + "trailer");
p.avoid_unknown = declare_parameter<bool>(ns + "unknown");
p.avoid_bicycle = declare_parameter<bool>(ns + "bicycle");
p.avoid_motorcycle = declare_parameter<bool>(ns + "motorcycle");
p.avoid_pedestrian = declare_parameter<bool>(ns + "pedestrian");
}

{ // drivable area
std::string ns = "dynamic_avoidance.";
p.drivable_area_right_bound_offset =
declare_parameter<double>(ns + "drivable_area_right_bound_offset");
p.drivable_area_left_bound_offset =
declare_parameter<double>(ns + "drivable_area_left_bound_offset");
p.drivable_area_types_to_skip =
declare_parameter<std::vector<std::string>>(ns + "drivable_area_types_to_skip");
}

return p;
}

LaneFollowingParameters BehaviorPathPlannerNode::getLaneFollowingParam()
{
LaneFollowingParameters p{};
Expand Down
Loading

0 comments on commit acf6198

Please sign in to comment.