Skip to content

Commit b4d8e7c

Browse files
authored
test(bpp_common): add test for path utils (autowarefoundation#9122)
* add test file for path utils Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * fix Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * add tests for map irrelevant function Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * add test for getUnshiftedEgoPose Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> * add docstring and remove unneccesary function Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> --------- Signed-off-by: Go Sakayori <go.sakayori@tier4.jp>
1 parent 8c38590 commit b4d8e7c

File tree

5 files changed

+314
-18
lines changed

5 files changed

+314
-18
lines changed

planning/behavior_path_planner/autoware_behavior_path_planner_common/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC
3434

3535
if(BUILD_TESTING)
3636
ament_add_ros_isolated_gmock(test_${PROJECT_NAME}_utilities
37-
test/test_utils.cpp
37+
test/test_utils.cpp
38+
test/test_path_utils.cpp
3839
)
3940

4041
target_link_libraries(test_${PROJECT_NAME}_utilities

planning/behavior_path_planner/autoware_behavior_path_planner_common/include/autoware/behavior_path_planner_common/utils/path_utils.hpp

+52-4
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,76 @@ PathWithLaneId resamplePathWithSpline(
5858
const PathWithLaneId & path, const double interval, const bool keep_input_points = false,
5959
const std::pair<double, double> target_section = {0.0, std::numeric_limits<double>::max()});
6060

61+
/**
62+
* @brief Gets index based on target index and arc length.
63+
* @param [in] path Path.
64+
* @param [in] target_idx Target index.
65+
* @param [in] signed_arc Signed arc length. (Positive is forward)
66+
* @return Index
67+
*/
6168
size_t getIdxByArclength(
6269
const PathWithLaneId & path, const size_t target_idx, const double signed_arc);
6370

71+
/**
72+
* @brief Clips path according to the target index and length.
73+
* @param [in] path Path.
74+
* @param [in] target_idx Target index.
75+
* @param [in] forward Forward distance from target index.
76+
* @param [in] backward Backward distance from target index.
77+
* @return Index
78+
*/
6479
void clipPathLength(
6580
PathWithLaneId & path, const size_t target_idx, const double forward, const double backward);
6681

67-
void clipPathLength(
68-
PathWithLaneId & path, const size_t target_idx, const BehaviorPathPlannerParameters & params);
69-
7082
PathWithLaneId convertWayPointsToPathWithLaneId(
7183
const autoware::freespace_planning_algorithms::PlannerWaypoints & waypoints,
7284
const double velocity, const lanelet::ConstLanelets & lanelets);
7385

86+
/**
87+
* @brief Get indices where the driving direction would reverse.
88+
* @param [in] path Original path.
89+
* @return Indices.
90+
*/
7491
std::vector<size_t> getReversingIndices(const PathWithLaneId & path);
7592

93+
/**
94+
* @brief Divide path by given indices.
95+
* @param [in] path Original path.
96+
* @param [in] indices Where to split the path.
97+
* @return Divided paths.
98+
*/
7699
std::vector<PathWithLaneId> dividePath(
77100
const PathWithLaneId & path, const std::vector<size_t> & indices);
78101

102+
/**
103+
* @brief Corrects the velocity implemented in the trajectory by judging the vehicle driving
104+
* direction.
105+
* @param [in] divided_paths Multiple path with lane ID.
106+
* @return
107+
*/
79108
void correctDividedPathVelocity(std::vector<PathWithLaneId> & divided_paths);
80109

81110
// only two points is supported
82-
std::vector<double> splineTwoPoints(
111+
std::vector<double> spline_two_points(
83112
const std::vector<double> & base_s, const std::vector<double> & base_x, const double begin_diff,
84113
const double end_diff, const std::vector<double> & new_s);
85114

115+
/**
116+
* @brief Interpolates pose between 2 pose.
117+
* @param [in] start_pose Start pose.
118+
* @param [in] end_pose End pose.
119+
* @param [in] resample_interval Resampling interval.
120+
* @return Array of pose
121+
*/
86122
std::vector<Pose> interpolatePose(
87123
const Pose & start_pose, const Pose & end_pose, const double resample_interval);
88124

125+
/**
126+
* @brief Get ego pose which is not shifted.
127+
* @param [in] ego_pose Ego pose.
128+
* @param [in] prev_path Previous path with lane ID.
129+
* @return Unshifted pose.
130+
*/
89131
geometry_msgs::msg::Pose getUnshiftedEgoPose(
90132
const geometry_msgs::msg::Pose & ego_pose, const ShiftedPath & prev_path);
91133

@@ -94,6 +136,12 @@ PathWithLaneId calcCenterLinePath(
94136
const double longest_dist_to_shift_line,
95137
const std::optional<PathWithLaneId> & prev_module_path = std::nullopt);
96138

139+
/**
140+
* @brief Combines 2 path which do not overlap.
141+
* @param [in] path1 First path.
142+
* @param [in] path2 Second path.
143+
* @return Combined path.
144+
*/
97145
PathWithLaneId combinePath(const PathWithLaneId & path1, const PathWithLaneId & path2);
98146

99147
BehaviorModuleOutput getReferencePath(

planning/behavior_path_planner/autoware_behavior_path_planner_common/src/utils/path_utils.cpp

+4-11
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <tf2/utils.h>
2828

2929
#include <algorithm>
30-
#include <limits>
3130
#include <optional>
3231
#include <utility>
3332
#include <vector>
@@ -102,6 +101,7 @@ PathWithLaneId resamplePathWithSpline(
102101
transformed_path, 0, transformed_path.size());
103102
for (size_t i = 0; i < path.points.size(); ++i) {
104103
const double s = s_vec.at(i);
104+
105105
for (const auto & lane_id : path.points.at(i).lane_ids) {
106106
if (!keep_input_points && (unique_lane_ids.find(lane_id) != unique_lane_ids.end())) {
107107
continue;
@@ -202,13 +202,6 @@ void clipPathLength(
202202
path.points = clipped_points;
203203
}
204204

205-
// TODO(murooka) This function should be replaced with autoware::motion_utils::cropPoints
206-
void clipPathLength(
207-
PathWithLaneId & path, const size_t target_idx, const BehaviorPathPlannerParameters & params)
208-
{
209-
clipPathLength(path, target_idx, params.forward_path_length, params.backward_path_length);
210-
}
211-
212205
PathWithLaneId convertWayPointsToPathWithLaneId(
213206
const autoware::freespace_planning_algorithms::PlannerWaypoints & waypoints,
214207
const double velocity, const lanelet::ConstLanelets & lanelets)
@@ -311,7 +304,7 @@ void correctDividedPathVelocity(std::vector<PathWithLaneId> & divided_paths)
311304
}
312305

313306
// only two points is supported
314-
std::vector<double> splineTwoPoints(
307+
std::vector<double> spline_two_points(
315308
const std::vector<double> & base_s, const std::vector<double> & base_x, const double begin_diff,
316309
const double end_diff, const std::vector<double> & new_s)
317310
{
@@ -350,10 +343,10 @@ std::vector<Pose> interpolatePose(
350343
new_s.push_back(s);
351344
}
352345

353-
const std::vector<double> interpolated_x = splineTwoPoints(
346+
const std::vector<double> interpolated_x = spline_two_points(
354347
base_s, base_x, std::cos(tf2::getYaw(start_pose.orientation)),
355348
std::cos(tf2::getYaw(end_pose.orientation)), new_s);
356-
const std::vector<double> interpolated_y = splineTwoPoints(
349+
const std::vector<double> interpolated_y = spline_two_points(
357350
base_s, base_y, std::sin(tf2::getYaw(start_pose.orientation)),
358351
std::sin(tf2::getYaw(end_pose.orientation)), new_s);
359352
for (size_t i = 0; i < interpolated_x.size(); ++i) {

0 commit comments

Comments
 (0)