Skip to content

Commit 4099567

Browse files
committed
perf(goal_planner): reduce processing time (autowarefoundation#8195)
* perf(goal_palnner): reduce processing time Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * add const& return Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * use copy getter Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> * pre commit Signed-off-by: kosuke55 <kosuke.tnp@gmail.com> --------- Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
1 parent 38df365 commit 4099567

File tree

7 files changed

+186
-89
lines changed

7 files changed

+186
-89
lines changed

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/goal_planner_module.hpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ class ThreadSafeData
228228
DEFINE_SETTER_GETTER_WITH_MUTEX(std::optional<BehaviorModuleOutput>, last_previous_module_output)
229229
DEFINE_SETTER_GETTER_WITH_MUTEX(PreviousPullOverData, prev_data)
230230
DEFINE_SETTER_GETTER_WITH_MUTEX(CollisionCheckDebugMap, collision_check)
231+
DEFINE_SETTER_GETTER_WITH_MUTEX(PredictedObjects, static_target_objects)
232+
DEFINE_SETTER_GETTER_WITH_MUTEX(PredictedObjects, dynamic_target_objects)
231233

232234
private:
233235
std::shared_ptr<PullOverPath> pull_over_path_{nullptr};
@@ -241,6 +243,8 @@ class ThreadSafeData
241243
std::optional<BehaviorModuleOutput> last_previous_module_output_{};
242244
PreviousPullOverData prev_data_{};
243245
CollisionCheckDebugMap collision_check_{};
246+
PredictedObjects static_target_objects_{};
247+
PredictedObjects dynamic_target_objects_{};
244248

245249
std::recursive_mutex & mutex_;
246250
rclcpp::Clock::SharedPtr clock_;
@@ -520,9 +524,10 @@ class GoalPlannerModule : public SceneModuleInterface
520524
const PathWithLaneId & path,
521525
const std::shared_ptr<OccupancyGridBasedCollisionDetector> occupancy_grid_map) const;
522526
bool checkObjectsCollision(
523-
const PathWithLaneId & path, const std::shared_ptr<const PlannerData> planner_data,
524-
const GoalPlannerParameters & parameters, const double collision_check_margin,
525-
const bool extract_static_objects, const bool update_debug_data = false) const;
527+
const PathWithLaneId & path, const std::vector<double> & curvatures,
528+
const std::shared_ptr<const PlannerData> planner_data, const GoalPlannerParameters & parameters,
529+
const double collision_check_margin, const bool extract_static_objects,
530+
const bool update_debug_data = false) const;
526531

527532
// goal seach
528533
Pose calcRefinedGoal(const Pose & goal_pose) const;

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/pull_over_planner_base.hpp

+93-29
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,29 @@ struct PullOverPath
5252
size_t goal_id{};
5353
size_t id{};
5454
bool decided_velocity{false};
55-
double max_curvature{0.0}; // max curvature of the parking path
5655

57-
PathWithLaneId getFullPath() const
56+
/**
57+
* @brief Set paths and start/end poses
58+
* By setting partial_paths, full_path, parking_path and curvature are also set at the same time
59+
* @param input_partial_paths partial paths
60+
* @param input_start_pose start pose
61+
* @param input_end_pose end pose
62+
*/
63+
void setPaths(
64+
const std::vector<PathWithLaneId> input_partial_paths, const Pose & input_start_pose,
65+
const Pose & input_end_pose)
5866
{
59-
PathWithLaneId path{};
60-
for (size_t i = 0; i < partial_paths.size(); ++i) {
61-
if (i == 0) {
62-
path.points.insert(
63-
path.points.end(), partial_paths.at(i).points.begin(), partial_paths.at(i).points.end());
64-
} else {
65-
// skip overlapping point
66-
path.points.insert(
67-
path.points.end(), next(partial_paths.at(i).points.begin()),
68-
partial_paths.at(i).points.end());
69-
}
70-
}
71-
path.points = autoware::motion_utils::removeOverlapPoints(path.points);
67+
partial_paths = input_partial_paths;
68+
start_pose = input_start_pose;
69+
end_pose = input_end_pose;
7270

73-
return path;
71+
updatePathData();
7472
}
7573

76-
// path from the pull over start pose to the end pose
77-
PathWithLaneId getParkingPath() const
78-
{
79-
const PathWithLaneId full_path = getFullPath();
80-
const size_t start_idx =
81-
autoware::motion_utils::findNearestIndex(full_path.points, start_pose.position);
74+
// Note: return copy value (not const&) because the value is used in multi threads
75+
PathWithLaneId getFullPath() const { return full_path; }
8276

83-
PathWithLaneId parking_path{};
84-
std::copy(
85-
full_path.points.begin() + start_idx, full_path.points.end(),
86-
std::back_inserter(parking_path.points));
87-
88-
return parking_path;
89-
}
77+
PathWithLaneId getParkingPath() const { return parking_path; }
9078

9179
PathWithLaneId getCurrentPath() const
9280
{
@@ -108,6 +96,82 @@ struct PullOverPath
10896
}
10997

11098
bool isValidPath() const { return type != PullOverPlannerType::NONE; }
99+
100+
std::vector<double> getFullPathCurvatures() const { return full_path_curvatures; }
101+
std::vector<double> getParkingPathCurvatures() const { return parking_path_curvatures; }
102+
double getFullPathMaxCurvature() const { return full_path_max_curvature; }
103+
double getParkingPathMaxCurvature() const { return parking_path_max_curvature; }
104+
105+
private:
106+
void updatePathData()
107+
{
108+
updateFullPath();
109+
updateParkingPath();
110+
updateCurvatures();
111+
}
112+
113+
void updateFullPath()
114+
{
115+
PathWithLaneId path{};
116+
for (size_t i = 0; i < partial_paths.size(); ++i) {
117+
if (i == 0) {
118+
path.points.insert(
119+
path.points.end(), partial_paths.at(i).points.begin(), partial_paths.at(i).points.end());
120+
} else {
121+
// skip overlapping point
122+
path.points.insert(
123+
path.points.end(), next(partial_paths.at(i).points.begin()),
124+
partial_paths.at(i).points.end());
125+
}
126+
}
127+
full_path.points = autoware::motion_utils::removeOverlapPoints(path.points);
128+
}
129+
130+
void updateParkingPath()
131+
{
132+
if (full_path.points.empty()) {
133+
updateFullPath();
134+
}
135+
const size_t start_idx =
136+
autoware::motion_utils::findNearestIndex(full_path.points, start_pose.position);
137+
138+
PathWithLaneId path{};
139+
std::copy(
140+
full_path.points.begin() + start_idx, full_path.points.end(),
141+
std::back_inserter(path.points));
142+
parking_path = path;
143+
}
144+
145+
void updateCurvatures()
146+
{
147+
const auto calculateCurvaturesAndMax =
148+
[](const auto & path) -> std::pair<std::vector<double>, double> {
149+
std::vector<double> curvatures = autoware::motion_utils::calcCurvature(path.points);
150+
double max_curvature = 0.0;
151+
if (!curvatures.empty()) {
152+
max_curvature = std::abs(*std::max_element(
153+
curvatures.begin(), curvatures.end(),
154+
[](const double & a, const double & b) { return std::abs(a) < std::abs(b); }));
155+
}
156+
return std::make_pair(curvatures, max_curvature);
157+
};
158+
std::tie(full_path_curvatures, full_path_max_curvature) =
159+
calculateCurvaturesAndMax(getFullPath());
160+
std::tie(parking_path_curvatures, parking_path_max_curvature) =
161+
calculateCurvaturesAndMax(getParkingPath());
162+
}
163+
164+
// curvatures
165+
std::vector<double> full_path_curvatures{};
166+
std::vector<double> parking_path_curvatures{};
167+
std::vector<double> current_path_curvatures{};
168+
double parking_path_max_curvature{0.0};
169+
double full_path_max_curvature{0.0};
170+
double current_path_max_curvature{0.0};
171+
172+
// path
173+
PathWithLaneId full_path{};
174+
PathWithLaneId parking_path{};
111175
};
112176

113177
class PullOverPlannerBase

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/include/autoware/behavior_path_goal_planner_module/util.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ using geometry_msgs::msg::Twist;
4242
using tier4_planning_msgs::msg::PathWithLaneId;
4343
using visualization_msgs::msg::Marker;
4444
using visualization_msgs::msg::MarkerArray;
45+
using Shape = autoware_perception_msgs::msg::Shape;
4546
using Polygon2d = autoware::universe_utils::Polygon2d;
4647

4748
lanelet::ConstLanelets getPullOverLanes(

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/freespace_pull_over.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ std::optional<PullOverPath> FreespacePullOver::plan(const Pose & goal_pose)
129129
}
130130

131131
PullOverPath pull_over_path{};
132-
pull_over_path.partial_paths = partial_paths;
133132
pull_over_path.pairs_terminal_velocity_and_accel = pairs_terminal_velocity_and_accel;
134-
pull_over_path.start_pose = current_pose;
135-
pull_over_path.end_pose = goal_pose;
133+
pull_over_path.setPaths(partial_paths, current_pose, goal_pose);
136134
pull_over_path.type = getPlannerType();
137135

138136
return pull_over_path;

planning/behavior_path_planner/autoware_behavior_path_goal_planner_module/src/geometric_pull_over.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ std::optional<PullOverPath> GeometricPullOver::plan(const Pose & goal_pose)
7272

7373
PullOverPath pull_over_path{};
7474
pull_over_path.type = getPlannerType();
75-
pull_over_path.partial_paths = planner_.getPaths();
7675
pull_over_path.pairs_terminal_velocity_and_accel = planner_.getPairsTerminalVelocityAndAccel();
77-
pull_over_path.start_pose = planner_.getStartPose();
78-
pull_over_path.end_pose = planner_.getArcEndPose();
76+
pull_over_path.setPaths(planner_.getPaths(), planner_.getStartPose(), planner_.getArcEndPose());
7977

8078
return pull_over_path;
8179
}

0 commit comments

Comments
 (0)