Skip to content

Commit c74c9ca

Browse files
committed
perf(velocity_smoother): not resample debug_trajectories is not used (autowarefoundation#8030)
* not resample debug_trajectories if not published Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * update dependant packages Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> --------- Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent 8311f5a commit c74c9ca

File tree

12 files changed

+40
-28
lines changed

12 files changed

+40
-28
lines changed

planning/autoware_velocity_smoother/include/autoware/velocity_smoother/smoother/analytical_jerk_constrained_smoother/analytical_jerk_constrained_smoother.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class AnalyticalJerkConstrainedSmoother : public SmootherBase
7373

7474
bool apply(
7575
const double initial_vel, const double initial_acc, const TrajectoryPoints & input,
76-
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories) override;
76+
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories,
77+
const bool publish_debug_trajs) override;
7778

7879
TrajectoryPoints resampleTrajectory(
7980
const TrajectoryPoints & input, [[maybe_unused]] const double v0,

planning/autoware_velocity_smoother/include/autoware/velocity_smoother/smoother/jerk_filtered_smoother.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class JerkFilteredSmoother : public SmootherBase
4747

4848
bool apply(
4949
const double initial_vel, const double initial_acc, const TrajectoryPoints & input,
50-
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories) override;
50+
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories,
51+
const bool publish_debug_trajs) override;
5152

5253
TrajectoryPoints resampleTrajectory(
5354
const TrajectoryPoints & input, [[maybe_unused]] const double v0,

planning/autoware_velocity_smoother/include/autoware/velocity_smoother/smoother/l2_pseudo_jerk_smoother.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class L2PseudoJerkSmoother : public SmootherBase
4545

4646
bool apply(
4747
const double initial_vel, const double initial_acc, const TrajectoryPoints & input,
48-
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories) override;
48+
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories,
49+
const bool publish_debug_trajs) override;
4950

5051
TrajectoryPoints resampleTrajectory(
5152
const TrajectoryPoints & input, const double v0, const geometry_msgs::msg::Pose & current_pose,

planning/autoware_velocity_smoother/include/autoware/velocity_smoother/smoother/linf_pseudo_jerk_smoother.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class LinfPseudoJerkSmoother : public SmootherBase
4545

4646
bool apply(
4747
const double initial_vel, const double initial_acc, const TrajectoryPoints & input,
48-
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories) override;
48+
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories,
49+
const bool publish_debug_trajs) override;
4950

5051
TrajectoryPoints resampleTrajectory(
5152
const TrajectoryPoints & input, const double v0, const geometry_msgs::msg::Pose & current_pose,

planning/autoware_velocity_smoother/include/autoware/velocity_smoother/smoother/smoother_base.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class SmootherBase
6161
virtual ~SmootherBase() = default;
6262
virtual bool apply(
6363
const double initial_vel, const double initial_acc, const TrajectoryPoints & input,
64-
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories) = 0;
64+
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories,
65+
const bool publish_debug_trajs) = 0;
6566

6667
virtual TrajectoryPoints resampleTrajectory(
6768
const TrajectoryPoints & input, const double v0, const geometry_msgs::msg::Pose & current_pose,

planning/autoware_velocity_smoother/src/node.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,8 @@ bool VelocitySmootherNode::smoothVelocity(
676676

677677
std::vector<TrajectoryPoints> debug_trajectories;
678678
if (!smoother_->apply(
679-
initial_motion.vel, initial_motion.acc, clipped, traj_smoothed, debug_trajectories)) {
679+
initial_motion.vel, initial_motion.acc, clipped, traj_smoothed, debug_trajectories,
680+
publish_debug_trajs_)) {
680681
RCLCPP_WARN(get_logger(), "Fail to solve optimization.");
681682
}
682683

@@ -716,15 +717,13 @@ bool VelocitySmootherNode::smoothVelocity(
716717
pub_trajectory_steering_rate_limited_->publish(toTrajectoryMsg(tmp));
717718
}
718719

719-
if (!debug_trajectories.empty()) {
720-
for (auto & debug_trajectory : debug_trajectories) {
721-
debug_trajectory.insert(
722-
debug_trajectory.begin(), traj_resampled.begin(),
723-
traj_resampled.begin() + traj_resampled_closest);
724-
for (size_t i = 0; i < traj_resampled_closest; ++i) {
725-
debug_trajectory.at(i).longitudinal_velocity_mps =
726-
debug_trajectory.at(traj_resampled_closest).longitudinal_velocity_mps;
727-
}
720+
for (auto & debug_trajectory : debug_trajectories) {
721+
debug_trajectory.insert(
722+
debug_trajectory.begin(), traj_resampled.begin(),
723+
traj_resampled.begin() + traj_resampled_closest);
724+
for (size_t i = 0; i < traj_resampled_closest; ++i) {
725+
debug_trajectory.at(i).longitudinal_velocity_mps =
726+
debug_trajectory.at(traj_resampled_closest).longitudinal_velocity_mps;
728727
}
729728
}
730729
publishDebugTrajectories(debug_trajectories);

planning/autoware_velocity_smoother/src/smoother/analytical_jerk_constrained_smoother/analytical_jerk_constrained_smoother.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ AnalyticalJerkConstrainedSmoother::Param AnalyticalJerkConstrainedSmoother::getP
103103

104104
bool AnalyticalJerkConstrainedSmoother::apply(
105105
const double initial_vel, const double initial_acc, const TrajectoryPoints & input,
106-
TrajectoryPoints & output, [[maybe_unused]] std::vector<TrajectoryPoints> & debug_trajectories)
106+
TrajectoryPoints & output, [[maybe_unused]] std::vector<TrajectoryPoints> & debug_trajectories,
107+
[[maybe_unused]] const bool publish_debug_trajs)
107108
{
108109
RCLCPP_DEBUG(logger_, "-------------------- Start --------------------");
109110

planning/autoware_velocity_smoother/src/smoother/jerk_filtered_smoother.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ JerkFilteredSmoother::Param JerkFilteredSmoother::getParam() const
5757

5858
bool JerkFilteredSmoother::apply(
5959
const double v0, const double a0, const TrajectoryPoints & input, TrajectoryPoints & output,
60-
std::vector<TrajectoryPoints> & debug_trajectories)
60+
std::vector<TrajectoryPoints> & debug_trajectories, const bool publish_debug_trajs)
6161
{
6262
autoware::universe_utils::ScopedTimeTrack st(__func__, *time_keeper_);
6363

@@ -114,10 +114,12 @@ bool JerkFilteredSmoother::apply(
114114
auto opt_resampled_trajectory = resample(filtered);
115115

116116
// Set debug trajectories
117-
debug_trajectories.resize(3);
118-
debug_trajectories[0] = resample(forward_filtered);
119-
debug_trajectories[1] = resample(backward_filtered);
120-
debug_trajectories[2] = resample(filtered);
117+
if (publish_debug_trajs) {
118+
debug_trajectories.resize(3);
119+
debug_trajectories[0] = resample(forward_filtered);
120+
debug_trajectories[1] = resample(backward_filtered);
121+
debug_trajectories[2] = resample(filtered);
122+
}
121123

122124
// Ensure terminal velocity is zero
123125
opt_resampled_trajectory.back().longitudinal_velocity_mps = 0.0;
@@ -127,9 +129,12 @@ bool JerkFilteredSmoother::apply(
127129
// No need to do optimization
128130
output.front().longitudinal_velocity_mps = v0;
129131
output.front().acceleration_mps2 = a0;
130-
debug_trajectories[0] = output;
131-
debug_trajectories[1] = output;
132-
debug_trajectories[2] = output;
132+
if (publish_debug_trajs) {
133+
debug_trajectories.resize(3);
134+
debug_trajectories[0] = output;
135+
debug_trajectories[1] = output;
136+
debug_trajectories[2] = output;
137+
}
133138
return true;
134139
}
135140

planning/autoware_velocity_smoother/src/smoother/l2_pseudo_jerk_smoother.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ L2PseudoJerkSmoother::Param L2PseudoJerkSmoother::getParam() const
5353

5454
bool L2PseudoJerkSmoother::apply(
5555
const double initial_vel, const double initial_acc, const TrajectoryPoints & input,
56-
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories)
56+
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories,
57+
[[maybe_unused]] const bool publish_debug_trajs)
5758
{
5859
debug_trajectories.clear();
5960

planning/autoware_velocity_smoother/src/smoother/linf_pseudo_jerk_smoother.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ LinfPseudoJerkSmoother::Param LinfPseudoJerkSmoother::getParam() const
5353

5454
bool LinfPseudoJerkSmoother::apply(
5555
const double initial_vel, const double initial_acc, const TrajectoryPoints & input,
56-
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories)
56+
TrajectoryPoints & output, std::vector<TrajectoryPoints> & debug_trajectories,
57+
[[maybe_unused]] const bool publish_debug_trajs)
5758
{
5859
debug_trajectories.clear();
5960

planning/behavior_velocity_planner/autoware_behavior_velocity_planner_common/src/utilization/trajectory_utils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ bool smoothPath(
7676
TrajectoryPoints traj_smoothed;
7777
clipped.insert(
7878
clipped.end(), traj_resampled.begin() + traj_resampled_closest, traj_resampled.end());
79-
if (!smoother->apply(v0, a0, clipped, traj_smoothed, debug_trajectories)) {
79+
if (!smoother->apply(v0, a0, clipped, traj_smoothed, debug_trajectories, false)) {
8080
std::cerr << "[behavior_velocity][trajectory_utils]: failed to smooth" << std::endl;
8181
return false;
8282
}

planning/motion_velocity_planner/autoware_motion_velocity_planner_node/src/node.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ autoware::motion_velocity_planner::TrajectoryPoints MotionVelocityPlannerNode::s
361361
autoware::motion_velocity_planner::TrajectoryPoints traj_smoothed;
362362
clipped.insert(
363363
clipped.end(), traj_resampled.begin() + traj_resampled_closest, traj_resampled.end());
364-
if (!smoother->apply(v0, a0, clipped, traj_smoothed, debug_trajectories)) {
364+
if (!smoother->apply(v0, a0, clipped, traj_smoothed, debug_trajectories, false)) {
365365
RCLCPP_ERROR(get_logger(), "failed to smooth");
366366
}
367367
traj_smoothed.insert(

0 commit comments

Comments
 (0)