Skip to content

Commit ad9778e

Browse files
authored
perf(run_out): improve calculation cost of smoothPath (#5885)
* perf(run_out): improve calculation cost of smoothPath Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * re-index enum elements Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> --------- Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent a5d5479 commit ad9778e

File tree

2 files changed

+54
-33
lines changed

2 files changed

+54
-33
lines changed

planning/behavior_velocity_run_out_module/src/debug.hpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ class DebugValues
3535
public:
3636
enum class TYPE {
3737
CALCULATION_TIME = 0,
38-
CALCULATION_TIME_COLLISION_CHECK = 1,
39-
LATERAL_DIST = 2,
40-
LONGITUDINAL_DIST_OBSTACLE = 3,
41-
LONGITUDINAL_DIST_COLLISION = 4,
42-
COLLISION_POS_FROM_EGO_FRONT = 5,
43-
STOP_DISTANCE = 6,
44-
NUM_OBSTACLES = 7,
45-
LATERAL_PASS_DIST = 8,
38+
CALCULATION_TIME_PATH_PROCESSING = 1,
39+
CALCULATION_TIME_OBSTACLE_CREATION = 2,
40+
CALCULATION_TIME_COLLISION_CHECK = 3,
41+
CALCULATION_TIME_PATH_PLANNING = 4,
42+
LATERAL_DIST = 5,
43+
LONGITUDINAL_DIST_OBSTACLE = 6,
44+
LONGITUDINAL_DIST_COLLISION = 7,
45+
COLLISION_POS_FROM_EGO_FRONT = 8,
46+
STOP_DISTANCE = 9,
47+
NUM_OBSTACLES = 10,
48+
LATERAL_PASS_DIST = 11,
4649
SIZE, // this is the number of enum elements
4750
};
4851

planning/behavior_velocity_run_out_module/src/scene.cpp

+43-25
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool RunOutModule::modifyPathVelocity(
6060
PathWithLaneId * path, [[maybe_unused]] StopReason * stop_reason)
6161
{
6262
// timer starts
63-
const auto t1_modify_path = std::chrono::system_clock::now();
63+
const auto t_start = std::chrono::system_clock::now();
6464

6565
// set planner data
6666
const auto current_vel = planner_data_->current_velocity->twist.linear.x;
@@ -70,20 +70,27 @@ bool RunOutModule::modifyPathVelocity(
7070
// set height of debug data
7171
debug_ptr_->setHeight(current_pose.position.z);
7272

73-
// smooth velocity of the path to calculate time to collision accurately
74-
PathWithLaneId smoothed_path;
75-
if (!smoothPath(*path, smoothed_path, planner_data_)) {
76-
return true;
77-
}
78-
7973
// extend path to consider obstacles after the goal
80-
const auto extended_smoothed_path =
81-
run_out_utils::extendPath(smoothed_path, planner_param_.vehicle_param.base_to_front);
74+
const auto extended_path =
75+
run_out_utils::extendPath(*path, planner_param_.vehicle_param.base_to_front);
8276

8377
// trim path ahead of the base_link to make calculation easier
8478
const double trim_distance = planner_param_.run_out.detection_distance;
85-
const auto trim_smoothed_path =
86-
run_out_utils::trimPathFromSelfPose(extended_smoothed_path, current_pose, trim_distance);
79+
const auto trim_path =
80+
run_out_utils::trimPathFromSelfPose(extended_path, current_pose, trim_distance);
81+
82+
// smooth velocity of the path to calculate time to collision accurately
83+
PathWithLaneId extended_smoothed_path;
84+
if (!smoothPath(trim_path, extended_smoothed_path, planner_data_)) {
85+
return true;
86+
}
87+
88+
// record time for path processing
89+
const auto t_path_processing = std::chrono::system_clock::now();
90+
const auto elapsed_path_processing =
91+
std::chrono::duration_cast<std::chrono::microseconds>(t_path_processing - t_start);
92+
debug_ptr_->setDebugValues(
93+
DebugValues::TYPE::CALCULATION_TIME_PATH_PROCESSING, elapsed_path_processing.count() / 1000.0);
8794

8895
// create abstracted dynamic obstacles from objects or points
8996
dynamic_obstacle_creator_->setData(*planner_data_, planner_param_, *path, extended_smoothed_path);
@@ -92,18 +99,24 @@ bool RunOutModule::modifyPathVelocity(
9299

93100
// extract obstacles using lanelet information
94101
const auto partition_excluded_obstacles =
95-
excludeObstaclesOutSideOfPartition(dynamic_obstacles, trim_smoothed_path, current_pose);
102+
excludeObstaclesOutSideOfPartition(dynamic_obstacles, extended_smoothed_path, current_pose);
96103

97-
// timer starts
98-
const auto t1_collision_check = std::chrono::system_clock::now();
104+
// record time for obstacle creation
105+
const auto t_obstacle_creation = std::chrono::system_clock::now();
106+
const auto elapsed_obstacle_creation =
107+
std::chrono::duration_cast<std::chrono::microseconds>(t_obstacle_creation - t_path_processing);
108+
debug_ptr_->setDebugValues(
109+
DebugValues::TYPE::CALCULATION_TIME_OBSTACLE_CREATION,
110+
elapsed_obstacle_creation.count() / 1000.0);
99111

100112
// detect collision with dynamic obstacles using velocity planning of ego
101-
const auto dynamic_obstacle = detectCollision(partition_excluded_obstacles, trim_smoothed_path);
113+
const auto dynamic_obstacle =
114+
detectCollision(partition_excluded_obstacles, extended_smoothed_path);
102115

103-
// timer ends
104-
const auto t2_collision_check = std::chrono::system_clock::now();
116+
// record time for collision check
117+
const auto t_collision_check = std::chrono::system_clock::now();
105118
const auto elapsed_collision_check =
106-
std::chrono::duration_cast<std::chrono::microseconds>(t2_collision_check - t1_collision_check);
119+
std::chrono::duration_cast<std::chrono::microseconds>(t_collision_check - t_obstacle_creation);
107120
debug_ptr_->setDebugValues(
108121
DebugValues::TYPE::CALCULATION_TIME_COLLISION_CHECK, elapsed_collision_check.count() / 1000.0);
109122

@@ -112,7 +125,7 @@ bool RunOutModule::modifyPathVelocity(
112125
// after a certain amount of time has elapsed since the ego stopped,
113126
// approach the obstacle with slow velocity
114127
insertVelocityForState(
115-
dynamic_obstacle, *planner_data_, planner_param_, trim_smoothed_path, *path);
128+
dynamic_obstacle, *planner_data_, planner_param_, extended_smoothed_path, *path);
116129
} else {
117130
// just insert zero velocity for stopping
118131
insertStoppingVelocity(dynamic_obstacle, current_pose, current_vel, current_acc, *path);
@@ -124,14 +137,19 @@ bool RunOutModule::modifyPathVelocity(
124137
}
125138

126139
publishDebugValue(
127-
trim_smoothed_path, partition_excluded_obstacles, dynamic_obstacle, current_pose);
140+
extended_smoothed_path, partition_excluded_obstacles, dynamic_obstacle, current_pose);
128141

129-
// timer ends
130-
const auto t2_modify_path = std::chrono::system_clock::now();
131-
const auto elapsed_modify_path =
132-
std::chrono::duration_cast<std::chrono::microseconds>(t2_modify_path - t1_modify_path);
142+
// record time for collision check
143+
const auto t_path_planning = std::chrono::system_clock::now();
144+
const auto elapsed_path_planning =
145+
std::chrono::duration_cast<std::chrono::microseconds>(t_path_planning - t_collision_check);
133146
debug_ptr_->setDebugValues(
134-
DebugValues::TYPE::CALCULATION_TIME, elapsed_modify_path.count() / 1000.0);
147+
DebugValues::TYPE::CALCULATION_TIME_PATH_PLANNING, elapsed_path_planning.count() / 1000.0);
148+
149+
// record time for the function
150+
const auto t_end = std::chrono::system_clock::now();
151+
const auto elapsed_all = std::chrono::duration_cast<std::chrono::microseconds>(t_end - t_start);
152+
debug_ptr_->setDebugValues(DebugValues::TYPE::CALCULATION_TIME, elapsed_all.count() / 1000.0);
135153

136154
return true;
137155
}

0 commit comments

Comments
 (0)