Skip to content

Commit eb09f68

Browse files
authored
feat(motion_utils, etc): add header argument in convertToTrajectory (#6021)
* feat(motion_utils, etc): add header argument in convertToTrajectory Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> * fix include Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com> --------- Signed-off-by: Takayuki Murooka <takayuki5168@gmail.com>
1 parent 4784c33 commit eb09f68

File tree

15 files changed

+26
-72
lines changed

15 files changed

+26
-72
lines changed

common/motion_utils/include/motion_utils/trajectory/conversion.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "autoware_auto_planning_msgs/msg/detail/trajectory__struct.hpp"
1919
#include "autoware_auto_planning_msgs/msg/detail/trajectory_point__struct.hpp"
20+
#include "std_msgs/msg/header.hpp"
2021

2122
#include <vector>
2223

@@ -34,7 +35,8 @@ namespace motion_utils
3435
* points larger than the capacity. (Tier IV)
3536
*/
3637
autoware_auto_planning_msgs::msg::Trajectory convertToTrajectory(
37-
const std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> & trajectory);
38+
const std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> & trajectory,
39+
const std_msgs::msg::Header & header = std_msgs::msg::Header{});
3840

3941
/**
4042
* @brief Convert autoware_auto_planning_msgs::msg::Trajectory to

common/motion_utils/src/trajectory/conversion.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ namespace motion_utils
3030
* points larger than the capacity. (Tier IV)
3131
*/
3232
autoware_auto_planning_msgs::msg::Trajectory convertToTrajectory(
33-
const std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> & trajectory)
33+
const std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> & trajectory,
34+
const std_msgs::msg::Header & header)
3435
{
3536
autoware_auto_planning_msgs::msg::Trajectory output{};
37+
output.header = header;
3638
for (const auto & pt : trajectory) output.points.push_back(pt);
3739
return output;
3840
}

planning/obstacle_avoidance_planner/include/obstacle_avoidance_planner/utils/trajectory_utils.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ size_t findEgoSegmentIndex(
154154
points, ego_pose, ego_nearest_param.dist_threshold, ego_nearest_param.yaw_threshold);
155155
}
156156

157-
Trajectory createTrajectory(
158-
const std_msgs::msg::Header & header, const std::vector<TrajectoryPoint> & traj_points);
159-
160157
std::vector<TrajectoryPoint> resampleTrajectoryPoints(
161158
const std::vector<TrajectoryPoint> traj_points, const double interval);
162159

planning/obstacle_avoidance_planner/src/mpt_optimizer.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "obstacle_avoidance_planner/mpt_optimizer.hpp"
1616

1717
#include "interpolation/spline_interpolation_points_2d.hpp"
18+
#include "motion_utils/trajectory/conversion.hpp"
1819
#include "motion_utils/trajectory/trajectory.hpp"
1920
#include "obstacle_avoidance_planner/utils/geometry_utils.hpp"
2021
#include "obstacle_avoidance_planner/utils/trajectory_utils.hpp"
@@ -1708,17 +1709,17 @@ void MPTOptimizer::publishDebugTrajectories(
17081709
time_keeper_ptr_->tic(__func__);
17091710

17101711
// reference points
1711-
const auto ref_traj = trajectory_utils::createTrajectory(
1712-
header, trajectory_utils::convertToTrajectoryPoints(ref_points));
1712+
const auto ref_traj = motion_utils::convertToTrajectory(
1713+
trajectory_utils::convertToTrajectoryPoints(ref_points), header);
17131714
debug_ref_traj_pub_->publish(ref_traj);
17141715

17151716
// fixed reference points
17161717
const auto fixed_traj_points = extractFixedPoints(ref_points);
1717-
const auto fixed_traj = trajectory_utils::createTrajectory(header, fixed_traj_points);
1718+
const auto fixed_traj = motion_utils::convertToTrajectory(fixed_traj_points, header);
17181719
debug_fixed_traj_pub_->publish(fixed_traj);
17191720

17201721
// mpt points
1721-
const auto mpt_traj = trajectory_utils::createTrajectory(header, mpt_traj_points);
1722+
const auto mpt_traj = motion_utils::convertToTrajectory(mpt_traj_points, header);
17221723
debug_mpt_traj_pub_->publish(mpt_traj);
17231724

17241725
time_keeper_ptr_->toc(__func__, " ");

planning/obstacle_avoidance_planner/src/node.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "interpolation/spline_interpolation_points_2d.hpp"
1818
#include "motion_utils/marker/marker_helper.hpp"
19+
#include "motion_utils/trajectory/conversion.hpp"
1920
#include "obstacle_avoidance_planner/debug_marker.hpp"
2021
#include "obstacle_avoidance_planner/utils/geometry_utils.hpp"
2122
#include "obstacle_avoidance_planner/utils/trajectory_utils.hpp"
@@ -236,7 +237,7 @@ void ObstacleAvoidancePlanner::onPath(const Path::ConstSharedPtr path_ptr)
236237
"Backward path is NOT supported. Just converting path to trajectory");
237238

238239
const auto traj_points = trajectory_utils::convertToTrajectoryPoints(path_ptr->points);
239-
const auto output_traj_msg = trajectory_utils::createTrajectory(path_ptr->header, traj_points);
240+
const auto output_traj_msg = motion_utils::convertToTrajectory(traj_points, path_ptr->header);
240241
traj_pub_->publish(output_traj_msg);
241242
return;
242243
}
@@ -268,7 +269,7 @@ void ObstacleAvoidancePlanner::onPath(const Path::ConstSharedPtr path_ptr)
268269
createFloat64Stamped(now(), time_keeper_ptr_->getAccumulatedTime()));
269270

270271
const auto output_traj_msg =
271-
trajectory_utils::createTrajectory(path_ptr->header, full_traj_points);
272+
motion_utils::convertToTrajectory(full_traj_points, path_ptr->header);
272273
traj_pub_->publish(output_traj_msg);
273274
}
274275

@@ -656,7 +657,7 @@ void ObstacleAvoidancePlanner::publishDebugData(const Header & header) const
656657

657658
// publish trajectories
658659
const auto debug_extended_traj =
659-
trajectory_utils::createTrajectory(header, debug_data_ptr_->extended_traj_points);
660+
motion_utils::convertToTrajectory(debug_data_ptr_->extended_traj_points, header);
660661
debug_extended_traj_pub_->publish(debug_extended_traj);
661662

662663
time_keeper_ptr_->toc(__func__, " ");

planning/obstacle_avoidance_planner/src/utils/trajectory_utils.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,6 @@ geometry_msgs::msg::Point getNearestPosition(
117117
return points.back().pose.position;
118118
}
119119

120-
Trajectory createTrajectory(
121-
const std_msgs::msg::Header & header, const std::vector<TrajectoryPoint> & traj_points)
122-
{
123-
auto traj = motion_utils::convertToTrajectory(traj_points);
124-
traj.header = header;
125-
126-
return traj;
127-
}
128-
129120
std::vector<TrajectoryPoint> resampleTrajectoryPoints(
130121
const std::vector<TrajectoryPoint> traj_points, const double interval)
131122
{

planning/obstacle_cruise_planner/src/node.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,6 @@ std::vector<TrajectoryPoint> extendTrajectoryPoints(
171171
return output_points;
172172
}
173173

174-
Trajectory createTrajectory(
175-
const std::vector<TrajectoryPoint> & traj_points, const std_msgs::msg::Header & header)
176-
{
177-
auto traj = motion_utils::convertToTrajectory(traj_points);
178-
traj.header = header;
179-
180-
return traj;
181-
}
182-
183174
std::vector<int> getTargetObjectType(rclcpp::Node & node, const std::string & param_prefix)
184175
{
185176
std::unordered_map<std::string, int> types_map{
@@ -525,7 +516,7 @@ void ObstacleCruisePlannerNode::onTrajectory(const Trajectory::ConstSharedPtr ms
525516
publishVelocityLimit(slow_down_vel_limit, "slow_down");
526517

527518
// 7. Publish trajectory
528-
const auto output_traj = createTrajectory(slow_down_traj_points, msg->header);
519+
const auto output_traj = motion_utils::convertToTrajectory(slow_down_traj_points, msg->header);
529520
trajectory_pub_->publish(output_traj);
530521

531522
// 8. Publish debug data

planning/path_smoother/include/path_smoother/utils/trajectory_utils.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ size_t findEgoSegmentIndex(
113113
points, ego_pose, ego_nearest_param.dist_threshold, ego_nearest_param.yaw_threshold);
114114
}
115115

116-
Trajectory createTrajectory(
117-
const std_msgs::msg::Header & header, const std::vector<TrajectoryPoint> & traj_points);
118-
119116
Path create_path(Path path_msg, const std::vector<TrajectoryPoint> & traj_points);
120117

121118
std::vector<TrajectoryPoint> resampleTrajectoryPoints(

planning/path_smoother/src/elastic_band.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "path_smoother/elastic_band.hpp"
1616

17+
#include "motion_utils/trajectory/conversion.hpp"
1718
#include "motion_utils/trajectory/trajectory.hpp"
1819
#include "path_smoother/type_alias.hpp"
1920
#include "path_smoother/utils/geometry_utils.hpp"
@@ -262,7 +263,7 @@ std::vector<TrajectoryPoint> EBPathSmoother::smoothTrajectory(
262263

263264
// 8. publish eb trajectory
264265
const auto eb_traj =
265-
trajectory_utils::createTrajectory(createHeader(clock_.now()), *eb_traj_points);
266+
motion_utils::convertToTrajectory(*eb_traj_points, createHeader(clock_.now()));
266267
debug_eb_traj_pub_->publish(eb_traj);
267268

268269
time_keeper_ptr_->toc(__func__, " ");
@@ -389,7 +390,7 @@ void EBPathSmoother::updateConstraint(
389390

390391
// publish fixed trajectory
391392
const auto eb_fixed_traj =
392-
trajectory_utils::createTrajectory(createHeader(clock_.now()), debug_fixed_traj_points);
393+
motion_utils::convertToTrajectory(debug_fixed_traj_points, createHeader(clock_.now()));
393394
debug_eb_fixed_traj_pub_->publish(eb_fixed_traj);
394395

395396
time_keeper_ptr_->toc(__func__, " ");

planning/path_smoother/src/elastic_band_smoother.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "path_smoother/elastic_band_smoother.hpp"
1616

1717
#include "interpolation/spline_interpolation_points_2d.hpp"
18+
#include "motion_utils/trajectory/conversion.hpp"
1819
#include "path_smoother/utils/geometry_utils.hpp"
1920
#include "path_smoother/utils/trajectory_utils.hpp"
2021
#include "rclcpp/time.hpp"
@@ -167,7 +168,7 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
167168
"Backward path is NOT supported. Just converting path to trajectory");
168169

169170
const auto traj_points = trajectory_utils::convertToTrajectoryPoints(path_ptr->points);
170-
const auto output_traj_msg = trajectory_utils::createTrajectory(path_ptr->header, traj_points);
171+
const auto output_traj_msg = motion_utils::convertToTrajectory(traj_points, path_ptr->header);
171172
traj_pub_->publish(output_traj_msg);
172173
path_pub_->publish(*path_ptr);
173174
return;
@@ -220,7 +221,7 @@ void ElasticBandSmoother::onPath(const Path::ConstSharedPtr path_ptr)
220221
createFloat64Stamped(now(), time_keeper_ptr_->getAccumulatedTime()));
221222

222223
const auto output_traj_msg =
223-
trajectory_utils::createTrajectory(path_ptr->header, full_traj_points);
224+
motion_utils::convertToTrajectory(full_traj_points, path_ptr->header);
224225
traj_pub_->publish(output_traj_msg);
225226
const auto output_path_msg = trajectory_utils::create_path(*path_ptr, full_traj_points);
226227
path_pub_->publish(output_path_msg);

planning/path_smoother/src/utils/trajectory_utils.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ namespace path_smoother
3434
{
3535
namespace trajectory_utils
3636
{
37-
Trajectory createTrajectory(
38-
const std_msgs::msg::Header & header, const std::vector<TrajectoryPoint> & traj_points)
39-
{
40-
auto traj = motion_utils::convertToTrajectory(traj_points);
41-
traj.header = header;
42-
43-
return traj;
44-
}
45-
4637
Path create_path(Path path_msg, const std::vector<TrajectoryPoint> & traj_points)
4738
{
4839
path_msg.points.clear();

planning/planning_topic_converter/src/path_to_trajectory.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ std::vector<TrajectoryPoint> convertToTrajectoryPoints(const std::vector<PathPoi
4040
}
4141
return traj_points;
4242
}
43-
44-
Trajectory createTrajectory(
45-
const std_msgs::msg::Header & header, const std::vector<TrajectoryPoint> & trajectory_points)
46-
{
47-
auto trajectory = motion_utils::convertToTrajectory(trajectory_points);
48-
trajectory.header = header;
49-
50-
return trajectory;
51-
}
5243
} // namespace
5344

5445
PathToTrajectory::PathToTrajectory(const rclcpp::NodeOptions & options)
@@ -59,7 +50,7 @@ PathToTrajectory::PathToTrajectory(const rclcpp::NodeOptions & options)
5950
void PathToTrajectory::process(const Path::ConstSharedPtr msg)
6051
{
6152
const auto trajectory_points = convertToTrajectoryPoints(msg->points);
62-
const auto output = createTrajectory(msg->header, trajectory_points);
53+
const auto output = motion_utils::convertToTrajectory(trajectory_points, msg->header);
6354
pub_->publish(output);
6455
}
6556

planning/sampling_based_planner/path_sampler/include/path_sampler/utils/trajectory_utils.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ size_t findEgoSegmentIndex(
138138
points, ego_pose, ego_nearest_param.dist_threshold, ego_nearest_param.yaw_threshold);
139139
}
140140

141-
Trajectory createTrajectory(
142-
const std_msgs::msg::Header & header, const std::vector<TrajectoryPoint> & traj_points);
143-
144141
std::vector<TrajectoryPoint> resampleTrajectoryPoints(
145142
const std::vector<TrajectoryPoint> traj_points, const double interval);
146143

planning/sampling_based_planner/path_sampler/src/node.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "interpolation/spline_interpolation_points_2d.hpp"
1818
#include "motion_utils/marker/marker_helper.hpp"
19+
#include "motion_utils/trajectory/conversion.hpp"
1920
#include "path_sampler/path_generation.hpp"
2021
#include "path_sampler/prepare_inputs.hpp"
2122
#include "path_sampler/utils/geometry_utils.hpp"
@@ -244,13 +245,12 @@ void PathSampler::onPath(const Path::SharedPtr path_ptr)
244245
if (!generated_traj_points.empty()) {
245246
auto full_traj_points = extendTrajectory(planner_data.traj_points, generated_traj_points);
246247
const auto output_traj_msg =
247-
trajectory_utils::createTrajectory(path_ptr->header, full_traj_points);
248+
motion_utils::convertToTrajectory(full_traj_points, path_ptr->header);
248249
traj_pub_->publish(output_traj_msg);
249250
} else {
250251
auto stopping_traj = trajectory_utils::convertToTrajectoryPoints(planner_data.traj_points);
251252
for (auto & p : stopping_traj) p.longitudinal_velocity_mps = 0.0;
252-
const auto output_traj_msg =
253-
trajectory_utils::createTrajectory(path_ptr->header, stopping_traj);
253+
const auto output_traj_msg = motion_utils::convertToTrajectory(stopping_traj, path_ptr->header);
254254
traj_pub_->publish(output_traj_msg);
255255
}
256256

planning/sampling_based_planner/path_sampler/src/utils/trajectory_utils.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ void compensateLastPose(
5858
}
5959
}
6060

61-
Trajectory createTrajectory(
62-
const std_msgs::msg::Header & header, const std::vector<TrajectoryPoint> & traj_points)
63-
{
64-
auto traj = motion_utils::convertToTrajectory(traj_points);
65-
traj.header = header;
66-
67-
return traj;
68-
}
69-
7061
std::vector<TrajectoryPoint> resampleTrajectoryPoints(
7162
const std::vector<TrajectoryPoint> traj_points, const double interval)
7263
{

0 commit comments

Comments
 (0)