|
| 1 | +// Copyright 2024 TIER IV, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <ament_index_cpp/get_package_share_directory.hpp> |
| 16 | +#include <autoware/behavior_path_start_planner_module/geometric_pull_out.hpp> |
| 17 | +#include <autoware/behavior_path_start_planner_module/start_planner_module.hpp> |
| 18 | +#include <autoware/behavior_path_start_planner_module/util.hpp> |
| 19 | +#include <autoware/lane_departure_checker/lane_departure_checker.hpp> |
| 20 | +#include <autoware/route_handler/route_handler.hpp> |
| 21 | +#include <autoware_lanelet2_extension/utility/query.hpp> |
| 22 | +#include <autoware_planning_test_manager/autoware_planning_test_manager_utils.hpp> |
| 23 | +#include <autoware_test_utils/autoware_test_utils.hpp> |
| 24 | + |
| 25 | +#include <gtest/gtest.h> |
| 26 | + |
| 27 | +#include <iostream> |
| 28 | +#include <memory> |
| 29 | +#include <optional> |
| 30 | +#include <string> |
| 31 | +#include <vector> |
| 32 | + |
| 33 | +using autoware::behavior_path_planner::GeometricPullOut; |
| 34 | +using autoware::behavior_path_planner::StartPlannerParameters; |
| 35 | +using autoware::lane_departure_checker::LaneDepartureChecker; |
| 36 | +using autoware::test_utils::get_absolute_path_to_config; |
| 37 | +using autoware_planning_msgs::msg::LaneletRoute; |
| 38 | +using RouteSections = std::vector<autoware_planning_msgs::msg::LaneletSegment>; |
| 39 | +using autoware_planning_test_manager::utils::makeBehaviorRouteFromLaneId; |
| 40 | + |
| 41 | +namespace autoware::behavior_path_planner |
| 42 | +{ |
| 43 | + |
| 44 | +class TestGeometricPullOut : public ::testing::Test |
| 45 | +{ |
| 46 | +public: |
| 47 | + std::optional<PullOutPath> plan( |
| 48 | + const Pose & start_pose, const Pose & goal_pose, PlannerDebugData & planner_debug_data) |
| 49 | + { |
| 50 | + return geometric_pull_out_->plan(start_pose, goal_pose, planner_debug_data); |
| 51 | + } |
| 52 | + |
| 53 | +protected: |
| 54 | + void SetUp() override |
| 55 | + { |
| 56 | + rclcpp::init(0, nullptr); |
| 57 | + node_ = rclcpp::Node::make_shared("geometric_pull_out", get_node_options()); |
| 58 | + |
| 59 | + load_parameters(); |
| 60 | + initialize_vehicle_info(); |
| 61 | + initialize_lane_departure_checker(); |
| 62 | + initialize_routeHandler(); |
| 63 | + initialize_geometric_pull_out_planner(); |
| 64 | + initialize_planner_data(); |
| 65 | + } |
| 66 | + |
| 67 | + void TearDown() override { rclcpp::shutdown(); } |
| 68 | + // Member variables |
| 69 | + std::shared_ptr<rclcpp::Node> node_; |
| 70 | + std::shared_ptr<autoware::route_handler::RouteHandler> route_handler_; |
| 71 | + autoware::vehicle_info_utils::VehicleInfo vehicle_info_; |
| 72 | + std::shared_ptr<GeometricPullOut> geometric_pull_out_; |
| 73 | + std::shared_ptr<LaneDepartureChecker> lane_departure_checker_; |
| 74 | + PlannerData planner_data_; |
| 75 | + |
| 76 | +private: |
| 77 | + rclcpp::NodeOptions get_node_options() const |
| 78 | + { |
| 79 | + // Load common configuration files |
| 80 | + auto node_options = rclcpp::NodeOptions{}; |
| 81 | + |
| 82 | + const auto common_param_path = |
| 83 | + get_absolute_path_to_config("autoware_test_utils", "test_common.param.yaml"); |
| 84 | + const auto nearest_search_param_path = |
| 85 | + get_absolute_path_to_config("autoware_test_utils", "test_nearest_search.param.yaml"); |
| 86 | + const auto vehicle_info_param_path = |
| 87 | + get_absolute_path_to_config("autoware_test_utils", "test_vehicle_info.param.yaml"); |
| 88 | + const auto behavior_path_planner_param_path = get_absolute_path_to_config( |
| 89 | + "autoware_behavior_path_planner", "behavior_path_planner.param.yaml"); |
| 90 | + const auto drivable_area_expansion_param_path = get_absolute_path_to_config( |
| 91 | + "autoware_behavior_path_planner", "drivable_area_expansion.param.yaml"); |
| 92 | + const auto scene_module_manager_param_path = get_absolute_path_to_config( |
| 93 | + "autoware_behavior_path_planner", "scene_module_manager.param.yaml"); |
| 94 | + const auto start_planner_param_path = get_absolute_path_to_config( |
| 95 | + "autoware_behavior_path_start_planner_module", "start_planner.param.yaml"); |
| 96 | + |
| 97 | + autoware::test_utils::updateNodeOptions( |
| 98 | + node_options, {common_param_path, nearest_search_param_path, vehicle_info_param_path, |
| 99 | + behavior_path_planner_param_path, drivable_area_expansion_param_path, |
| 100 | + scene_module_manager_param_path, start_planner_param_path}); |
| 101 | + |
| 102 | + return node_options; |
| 103 | + } |
| 104 | + |
| 105 | + void load_parameters() |
| 106 | + { |
| 107 | + const auto dp_double = [&](const std::string & s) { |
| 108 | + return node_->declare_parameter<double>(s); |
| 109 | + }; |
| 110 | + const auto dp_bool = [&](const std::string & s) { return node_->declare_parameter<bool>(s); }; |
| 111 | + // Load parameters required for planning |
| 112 | + const std::string ns = "start_planner."; |
| 113 | + lane_departure_check_expansion_margin_ = |
| 114 | + dp_double(ns + "lane_departure_check_expansion_margin"); |
| 115 | + pull_out_max_steer_angle_ = dp_double(ns + "pull_out_max_steer_angle"); |
| 116 | + pull_out_arc_path_interval_ = dp_double(ns + "arc_path_interval"); |
| 117 | + center_line_path_interval_ = dp_double(ns + "center_line_path_interval"); |
| 118 | + th_moving_object_velocity_ = dp_double(ns + "th_moving_object_velocity"); |
| 119 | + divide_pull_out_path_ = dp_bool(ns + "divide_pull_out_path"); |
| 120 | + backward_path_length_ = dp_double("backward_path_length"); |
| 121 | + forward_path_length_ = dp_double("forward_path_length"); |
| 122 | + } |
| 123 | + |
| 124 | + void initialize_vehicle_info() |
| 125 | + { |
| 126 | + vehicle_info_ = autoware::vehicle_info_utils::VehicleInfoUtils(*node_).getVehicleInfo(); |
| 127 | + } |
| 128 | + |
| 129 | + void initialize_lane_departure_checker() |
| 130 | + { |
| 131 | + lane_departure_checker_ = std::make_shared<LaneDepartureChecker>(); |
| 132 | + lane_departure_checker_->setVehicleInfo(vehicle_info_); |
| 133 | + |
| 134 | + autoware::lane_departure_checker::Param lane_departure_checker_params{}; |
| 135 | + lane_departure_checker_params.footprint_extra_margin = lane_departure_check_expansion_margin_; |
| 136 | + lane_departure_checker_->setParam(lane_departure_checker_params); |
| 137 | + } |
| 138 | + |
| 139 | + void initialize_routeHandler() |
| 140 | + { |
| 141 | + // Load a sample lanelet map and create a route handler |
| 142 | + const auto shoulder_map_path = autoware::test_utils::get_absolute_path_to_lanelet_map( |
| 143 | + "autoware_test_utils", "road_shoulder/lanelet2_map.osm"); |
| 144 | + const auto map_bin_msg = autoware::test_utils::make_map_bin_msg(shoulder_map_path, 0.5); |
| 145 | + |
| 146 | + route_handler_ = std::make_shared<autoware::route_handler::RouteHandler>(map_bin_msg); |
| 147 | + } |
| 148 | + |
| 149 | + void initialize_geometric_pull_out_planner() |
| 150 | + { |
| 151 | + auto parameters = std::make_shared<StartPlannerParameters>(); |
| 152 | + parameters->parallel_parking_parameters.pull_out_max_steer_angle = pull_out_max_steer_angle_; |
| 153 | + parameters->parallel_parking_parameters.pull_out_arc_path_interval = |
| 154 | + pull_out_arc_path_interval_; |
| 155 | + parameters->parallel_parking_parameters.center_line_path_interval = center_line_path_interval_; |
| 156 | + parameters->th_moving_object_velocity = th_moving_object_velocity_; |
| 157 | + parameters->divide_pull_out_path = divide_pull_out_path_; |
| 158 | + |
| 159 | + auto time_keeper = std::make_shared<autoware::universe_utils::TimeKeeper>(); |
| 160 | + geometric_pull_out_ = |
| 161 | + std::make_shared<GeometricPullOut>(*node_, *parameters, lane_departure_checker_, time_keeper); |
| 162 | + } |
| 163 | + |
| 164 | + void initialize_planner_data() |
| 165 | + { |
| 166 | + planner_data_.parameters.backward_path_length = backward_path_length_; |
| 167 | + planner_data_.parameters.forward_path_length = forward_path_length_; |
| 168 | + planner_data_.parameters.wheel_base = vehicle_info_.wheel_base_m; |
| 169 | + planner_data_.parameters.wheel_tread = vehicle_info_.wheel_tread_m; |
| 170 | + planner_data_.parameters.front_overhang = vehicle_info_.front_overhang_m; |
| 171 | + planner_data_.parameters.left_over_hang = vehicle_info_.left_overhang_m; |
| 172 | + planner_data_.parameters.right_over_hang = vehicle_info_.right_overhang_m; |
| 173 | + } |
| 174 | + |
| 175 | + // Parameter variables |
| 176 | + double lane_departure_check_expansion_margin_{0.0}; |
| 177 | + double pull_out_max_steer_angle_{0.0}; |
| 178 | + double pull_out_arc_path_interval_{0.0}; |
| 179 | + double center_line_path_interval_{0.0}; |
| 180 | + double th_moving_object_velocity_{0.0}; |
| 181 | + double backward_path_length_{0.0}; |
| 182 | + double forward_path_length_{0.0}; |
| 183 | + bool divide_pull_out_path_{false}; |
| 184 | +}; |
| 185 | + |
| 186 | +TEST_F(TestGeometricPullOut, GenerateValidGeometricPullOutPath) |
| 187 | +{ |
| 188 | + const auto start_pose = |
| 189 | + geometry_msgs::build<geometry_msgs::msg::Pose>() |
| 190 | + .position(geometry_msgs::build<geometry_msgs::msg::Point>().x(362.181).y(362.164).z(100.000)) |
| 191 | + .orientation( |
| 192 | + geometry_msgs::build<geometry_msgs::msg::Quaternion>().x(0.0).y(0.0).z(0.709650).w( |
| 193 | + 0.704554)); |
| 194 | + |
| 195 | + const auto goal_pose = |
| 196 | + geometry_msgs::build<geometry_msgs::msg::Pose>() |
| 197 | + .position(geometry_msgs::build<geometry_msgs::msg::Point>().x(365.658).y(507.253).z(100.000)) |
| 198 | + .orientation( |
| 199 | + geometry_msgs::build<geometry_msgs::msg::Quaternion>().x(0.0).y(0.0).z(0.705897).w( |
| 200 | + 0.708314)); |
| 201 | + |
| 202 | + // Set up current odometry at start pose |
| 203 | + auto odometry = std::make_shared<nav_msgs::msg::Odometry>(); |
| 204 | + odometry->pose.pose = start_pose; |
| 205 | + odometry->header.frame_id = "map"; |
| 206 | + planner_data_.self_odometry = odometry; |
| 207 | + |
| 208 | + // Setup route |
| 209 | + const auto route = makeBehaviorRouteFromLaneId( |
| 210 | + 4619, 4635, "autoware_test_utils", "road_shoulder/lanelet2_map.osm"); |
| 211 | + route_handler_->setRoute(route); |
| 212 | + |
| 213 | + // Update planner data with the route handler |
| 214 | + planner_data_.route_handler = route_handler_; |
| 215 | + geometric_pull_out_->setPlannerData(std::make_shared<PlannerData>(planner_data_)); |
| 216 | + |
| 217 | + // Plan the pull out path |
| 218 | + PlannerDebugData debug_data; |
| 219 | + auto result = plan(start_pose, goal_pose, debug_data); |
| 220 | + |
| 221 | + // Assert that a valid geometric geometric pull out path is generated |
| 222 | + ASSERT_TRUE(result.has_value()) << "Geometric pull out path generation failed."; |
| 223 | + EXPECT_EQ(result->partial_paths.size(), 2UL) |
| 224 | + << "Generated geometric pull out path does not have the expected number of partial paths."; |
| 225 | + EXPECT_EQ(debug_data.conditions_evaluation.back(), "success") |
| 226 | + << "Geometric pull out path planning did not succeed."; |
| 227 | +} |
| 228 | + |
| 229 | +} // namespace autoware::behavior_path_planner |
0 commit comments