Skip to content

Commit 70a07eb

Browse files
TomohitoAndosaka1-s
authored andcommitted
Merge pull request #1720 from tier4/cp-lane-change-stability
perf(lane_change): path stability and correctness
1 parent ae805fc commit 70a07eb

File tree

42 files changed

+6738
-2552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+6738
-2552
lines changed
File renamed without changes.

planning/autoware_route_handler/include/autoware/route_handler/route_handler.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ class RouteHandler
324324
lanelet::ConstLanelets getShoulderLaneletsAtPose(const Pose & pose) const;
325325
lanelet::ConstPolygon3d getIntersectionAreaById(const lanelet::Id id) const;
326326

327+
Pose get_pose_from_2d_arc_length(
328+
const lanelet::ConstLanelets & lanelet_sequence, const double s) const;
329+
327330
private:
328331
// MUST
329332
lanelet::routing::RoutingGraphPtr routing_graph_ptr_;

planning/autoware_route_handler/src/route_handler.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ namespace autoware::route_handler
4646
{
4747
namespace
4848
{
49+
using autoware::universe_utils::createPoint;
50+
using autoware::universe_utils::createQuaternionFromYaw;
4951
using autoware_planning_msgs::msg::LaneletPrimitive;
5052
using autoware_planning_msgs::msg::Path;
5153
using geometry_msgs::msg::Pose;
@@ -2225,4 +2227,29 @@ std::optional<lanelet::routing::LaneletPath> RouteHandler::findDrivableLanePath(
22252227
if (route) return route->shortestPath();
22262228
return {};
22272229
}
2230+
2231+
Pose RouteHandler::get_pose_from_2d_arc_length(
2232+
const lanelet::ConstLanelets & lanelet_sequence, const double s) const
2233+
{
2234+
double accumulated_distance2d = 0;
2235+
for (const auto & llt : lanelet_sequence) {
2236+
const auto & centerline = llt.centerline();
2237+
for (auto it = centerline.begin(); std::next(it) != centerline.end(); ++it) {
2238+
const auto pt = *it;
2239+
const auto next_pt = *std::next(it);
2240+
const double distance2d = lanelet::geometry::distance2d(to2D(pt), to2D(next_pt));
2241+
if (accumulated_distance2d + distance2d > s) {
2242+
const double ratio = (s - accumulated_distance2d) / distance2d;
2243+
const auto interpolated_pt = pt.basicPoint() * (1 - ratio) + next_pt.basicPoint() * ratio;
2244+
const auto yaw = std::atan2(next_pt.y() - pt.y(), next_pt.x() - pt.x());
2245+
Pose pose;
2246+
pose.position = createPoint(interpolated_pt.x(), interpolated_pt.y(), interpolated_pt.z());
2247+
pose.orientation = createQuaternionFromYaw(yaw);
2248+
return pose;
2249+
}
2250+
accumulated_distance2d += distance2d;
2251+
}
2252+
}
2253+
return Pose{};
2254+
}
22282255
} // namespace autoware::route_handler

planning/behavior_path_planner/autoware_behavior_path_avoidance_by_lane_change_module/src/interface.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ AvoidanceByLaneChangeInterface::AvoidanceByLaneChangeInterface(
4444
{
4545
}
4646

47+
// cppcheck-suppress unusedFunction
4748
bool AvoidanceByLaneChangeInterface::isExecutionRequested() const
4849
{
4950
return module_type_->isLaneChangeRequired() && module_type_->specialRequiredCheck() &&
5051
module_type_->isValidPath();
5152
}
53+
54+
// cppcheck-suppress unusedFunction
5255
void AvoidanceByLaneChangeInterface::processOnEntry()
5356
{
5457
waitApproval();

planning/behavior_path_planner/autoware_behavior_path_avoidance_by_lane_change_module/src/manager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ void AvoidanceByLaneChangeModuleManager::init(rclcpp::Node * node)
187187
avoidance_parameters_ = std::make_shared<AvoidanceByLCParameters>(p);
188188
}
189189

190-
std::unique_ptr<SceneModuleInterface>
191-
AvoidanceByLaneChangeModuleManager::createNewSceneModuleInstance()
190+
// cppcheck-suppress unusedFunction
191+
SMIPtr AvoidanceByLaneChangeModuleManager::createNewSceneModuleInstance()
192192
{
193193
return std::make_unique<AvoidanceByLaneChangeInterface>(
194194
name_, *node_, parameters_, avoidance_parameters_, rtc_interface_ptr_map_,

planning/behavior_path_planner/autoware_behavior_path_avoidance_by_lane_change_module/src/manager.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ using autoware::behavior_path_planner::LaneChangeModuleManager;
3232
using autoware::behavior_path_planner::LaneChangeModuleType;
3333
using autoware::behavior_path_planner::SceneModuleInterface;
3434

35+
using SMIPtr = std::unique_ptr<SceneModuleInterface>;
36+
3537
class AvoidanceByLaneChangeModuleManager : public LaneChangeModuleManager
3638
{
3739
public:
@@ -44,7 +46,7 @@ class AvoidanceByLaneChangeModuleManager : public LaneChangeModuleManager
4446

4547
void init(rclcpp::Node * node) override;
4648

47-
std::unique_ptr<SceneModuleInterface> createNewSceneModuleInstance() override;
49+
SMIPtr createNewSceneModuleInstance() override;
4850

4951
private:
5052
std::shared_ptr<AvoidanceByLCParameters> avoidance_parameters_;

planning/behavior_path_planner/autoware_behavior_path_avoidance_by_lane_change_module/src/scene.cpp

+49-13
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,55 @@
3434
#include <optional>
3535
#include <utility>
3636

37+
namespace
38+
{
39+
geometry_msgs::msg::Point32 create_point32(const geometry_msgs::msg::Pose & pose)
40+
{
41+
geometry_msgs::msg::Point32 p;
42+
p.x = static_cast<float>(pose.position.x);
43+
p.y = static_cast<float>(pose.position.y);
44+
p.z = static_cast<float>(pose.position.z);
45+
return p;
46+
};
47+
48+
geometry_msgs::msg::Polygon create_execution_area(
49+
const autoware::vehicle_info_utils::VehicleInfo & vehicle_info,
50+
const geometry_msgs::msg::Pose & pose, double additional_lon_offset, double additional_lat_offset)
51+
{
52+
const double & base_to_front = vehicle_info.max_longitudinal_offset_m;
53+
const double & width = vehicle_info.vehicle_width_m;
54+
const double & base_to_rear = vehicle_info.rear_overhang_m;
55+
56+
// if stationary object, extend forward and backward by the half of lon length
57+
const double forward_lon_offset = base_to_front + additional_lon_offset;
58+
const double backward_lon_offset = -base_to_rear;
59+
const double lat_offset = width / 2.0 + additional_lat_offset;
60+
61+
const auto p1 =
62+
autoware::universe_utils::calcOffsetPose(pose, forward_lon_offset, lat_offset, 0.0);
63+
const auto p2 =
64+
autoware::universe_utils::calcOffsetPose(pose, forward_lon_offset, -lat_offset, 0.0);
65+
const auto p3 =
66+
autoware::universe_utils::calcOffsetPose(pose, backward_lon_offset, -lat_offset, 0.0);
67+
const auto p4 =
68+
autoware::universe_utils::calcOffsetPose(pose, backward_lon_offset, lat_offset, 0.0);
69+
geometry_msgs::msg::Polygon polygon;
70+
71+
polygon.points.push_back(create_point32(p1));
72+
polygon.points.push_back(create_point32(p2));
73+
polygon.points.push_back(create_point32(p3));
74+
polygon.points.push_back(create_point32(p4));
75+
76+
return polygon;
77+
}
78+
} // namespace
79+
3780
namespace autoware::behavior_path_planner
3881
{
3982
using autoware::behavior_path_planner::Direction;
4083
using autoware::behavior_path_planner::LaneChangeModuleType;
4184
using autoware::behavior_path_planner::ObjectInfo;
4285
using autoware::behavior_path_planner::Point2d;
43-
using autoware::behavior_path_planner::utils::lane_change::debug::createExecutionArea;
44-
namespace utils = autoware::behavior_path_planner::utils;
4586

4687
AvoidanceByLaneChange::AvoidanceByLaneChange(
4788
const std::shared_ptr<LaneChangeParameters> & parameters,
@@ -83,9 +124,9 @@ bool AvoidanceByLaneChange::specialRequiredCheck() const
83124

84125
const auto & nearest_object = data.target_objects.front();
85126
const auto minimum_avoid_length = calcMinAvoidanceLength(nearest_object);
86-
const auto minimum_lane_change_length = calcMinimumLaneChangeLength();
127+
const auto minimum_lane_change_length = calc_minimum_dist_buffer();
87128

88-
lane_change_debug_.execution_area = createExecutionArea(
129+
lane_change_debug_.execution_area = create_execution_area(
89130
getCommonParam().vehicle_info, getEgoPose(),
90131
std::max(minimum_lane_change_length, minimum_avoid_length), calcLateralOffset());
91132

@@ -274,16 +315,11 @@ double AvoidanceByLaneChange::calcMinAvoidanceLength(const ObjectData & nearest_
274315
return avoidance_helper_->getMinAvoidanceDistance(shift_length);
275316
}
276317

277-
double AvoidanceByLaneChange::calcMinimumLaneChangeLength() const
318+
double AvoidanceByLaneChange::calc_minimum_dist_buffer() const
278319
{
279-
const auto current_lanes = get_current_lanes();
280-
if (current_lanes.empty()) {
281-
RCLCPP_DEBUG(logger_, "no empty lanes");
282-
return std::numeric_limits<double>::infinity();
283-
}
284-
285-
return utils::lane_change::calculation::calc_minimum_lane_change_length(
286-
getRouteHandler(), current_lanes.back(), *lane_change_parameters_, direction_);
320+
const auto [_, dist_buffer] = utils::lane_change::calculation::calc_lc_length_and_dist_buffer(
321+
common_data_ptr_, get_current_lanes());
322+
return dist_buffer.min;
287323
}
288324

289325
double AvoidanceByLaneChange::calcLateralOffset() const

planning/behavior_path_planner/autoware_behavior_path_avoidance_by_lane_change_module/src/scene.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AvoidanceByLaneChange : public NormalLaneChange
6363
void fillAvoidanceTargetObjects(AvoidancePlanningData & data, AvoidanceDebugData & debug) const;
6464

6565
double calcMinAvoidanceLength(const ObjectData & nearest_object) const;
66-
double calcMinimumLaneChangeLength() const;
66+
double calc_minimum_dist_buffer() const;
6767
double calcLateralOffset() const;
6868
};
6969
} // namespace autoware::behavior_path_planner

planning/behavior_path_planner/autoware_behavior_path_lane_change_module/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if(BUILD_TESTING)
1818
ament_add_ros_isolated_gmock(test_${PROJECT_NAME}
1919
test/test_behavior_path_planner_node_interface.cpp
2020
test/test_lane_change_utils.cpp
21+
# test/test_lane_change_scene.cpp
2122
)
2223

2324
target_link_libraries(test_${PROJECT_NAME}

0 commit comments

Comments
 (0)