Skip to content

Commit 81983eb

Browse files
authored
refactor(common): extern template for motion_utils / remove tier4_autoware_utils.hpp / remove motion_utis.hpp (autowarefoundation#5027)
1 parent 2476395 commit 81983eb

File tree

64 files changed

+1517
-347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1517
-347
lines changed

common/motion_utils/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ autoware_package()
77
find_package(Boost REQUIRED)
88

99
ament_auto_add_library(motion_utils SHARED
10-
src/motion_utils.cpp
1110
src/distance/distance.cpp
1211
src/marker/marker_helper.cpp
1312
src/marker/virtual_wall_marker_creator.cpp
1413
src/resample/resample.cpp
14+
src/trajectory/trajectory.cpp
1515
src/trajectory/interpolation.cpp
1616
src/trajectory/path_with_lane_id.cpp
17+
src/trajectory/tmp_conversion.cpp
1718
src/vehicle/vehicle_state_checker.cpp
1819
)
1920

common/motion_utils/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ const size_t ego_nearest_seg_idx = findFirstNearestSegmentIndex(points, ego_pose
109109
const size_t dyn_obj_nearest_seg_idx = findFirstNearestSegmentIndex(points, dyn_obj_pose, dyn_obj_nearest_dist_threshold);
110110
const double length_from_ego_to_obj = calcSignedArcLength(points, ego_pose, ego_nearest_seg_idx, dyn_obj_pose, dyn_obj_nearest_seg_idx);
111111
```
112+
113+
## For developers
114+
115+
Some of the template functions in `trajectory.hpp` are mostly used for specific types (`autoware_auto_planning_msgs::msg::PathPoint`, `autoware_auto_planning_msgs::msg::PathPoint`, `autoware_auto_planning_msgs::msg::TrajectoryPoint`), so they are exported as `extern template` functions to speed-up compilation time.
116+
117+
`motion_utils.hpp` header file was removed because the source files that directly/indirectly include this file took a long time for preprocessing.

common/motion_utils/include/motion_utils/marker/marker_helper.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
#ifndef MOTION_UTILS__MARKER__MARKER_HELPER_HPP_
1616
#define MOTION_UTILS__MARKER__MARKER_HELPER_HPP_
1717

18-
#include "motion_utils/resample/resample_utils.hpp"
18+
#include <rclcpp/time.hpp>
1919

2020
#include <visualization_msgs/msg/marker_array.hpp>
2121

22-
#include <functional>
2322
#include <string>
24-
#include <vector>
2523

2624
namespace motion_utils
2725
{

common/motion_utils/include/motion_utils/marker/virtual_wall_marker_creator.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
#ifndef MOTION_UTILS__MARKER__VIRTUAL_WALL_MARKER_CREATOR_HPP_
1616
#define MOTION_UTILS__MARKER__VIRTUAL_WALL_MARKER_CREATOR_HPP_
1717

18-
#include "motion_utils/marker/marker_helper.hpp"
18+
#include <rclcpp/time.hpp>
1919

2020
#include <geometry_msgs/msg/pose.hpp>
21+
#include <visualization_msgs/msg/marker_array.hpp>
2122

2223
#include <string>
2324
#include <unordered_map>
2425
#include <vector>
25-
2626
namespace motion_utils
2727
{
2828

common/motion_utils/include/motion_utils/motion_utils.hpp

-27
This file was deleted.

common/motion_utils/include/motion_utils/resample/resample.hpp

-11
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515
#ifndef MOTION_UTILS__RESAMPLE__RESAMPLE_HPP_
1616
#define MOTION_UTILS__RESAMPLE__RESAMPLE_HPP_
1717

18-
#include "interpolation/interpolation_utils.hpp"
19-
#include "interpolation/linear_interpolation.hpp"
20-
#include "interpolation/spline_interpolation.hpp"
21-
#include "interpolation/zero_order_hold.hpp"
22-
#include "motion_utils/trajectory/trajectory.hpp"
23-
#include "tier4_autoware_utils/geometry/geometry.hpp"
24-
#include "tier4_autoware_utils/geometry/pose_deviation.hpp"
25-
#include "tier4_autoware_utils/math/constants.hpp"
26-
27-
#include <rclcpp/rclcpp.hpp>
28-
2918
#include "autoware_auto_planning_msgs/msg/path.hpp"
3019
#include "autoware_auto_planning_msgs/msg/path_with_lane_id.hpp"
3120
#include "autoware_auto_planning_msgs/msg/trajectory.hpp"

common/motion_utils/include/motion_utils/resample/resample_utils.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <motion_utils/constants.hpp>
1919
#include <motion_utils/trajectory/trajectory.hpp>
2020
#include <tier4_autoware_utils/geometry/geometry.hpp>
21-
#include <tier4_autoware_utils/geometry/path_with_lane_id_geometry.hpp>
2221

2322
#include <vector>
2423

common/motion_utils/include/motion_utils/trajectory/path_with_lane_id.hpp

+8-74
Original file line numberDiff line numberDiff line change
@@ -15,90 +15,24 @@
1515
#ifndef MOTION_UTILS__TRAJECTORY__PATH_WITH_LANE_ID_HPP_
1616
#define MOTION_UTILS__TRAJECTORY__PATH_WITH_LANE_ID_HPP_
1717

18-
#include "motion_utils/trajectory/trajectory.hpp"
19-
#include "tier4_autoware_utils/geometry/path_with_lane_id_geometry.hpp"
18+
#include "autoware_auto_planning_msgs/msg/path_with_lane_id.hpp"
19+
#include <geometry_msgs/msg/point.hpp>
2020

2121
#include <boost/optional.hpp>
2222

23-
#include <algorithm>
2423
#include <utility>
25-
#include <vector>
26-
2724
namespace motion_utils
2825
{
29-
inline boost::optional<std::pair<size_t, size_t>> getPathIndexRangeWithLaneId(
30-
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, const int64_t target_lane_id)
31-
{
32-
size_t start_idx = 0; // NOTE: to prevent from maybe-uninitialized error
33-
size_t end_idx = 0; // NOTE: to prevent from maybe-uninitialized error
34-
35-
bool found_first_idx = false;
36-
for (size_t i = 0; i < path.points.size(); ++i) {
37-
const auto & p = path.points.at(i);
38-
for (const auto & id : p.lane_ids) {
39-
if (id == target_lane_id) {
40-
if (!found_first_idx) {
41-
start_idx = i;
42-
found_first_idx = true;
43-
}
44-
end_idx = i;
45-
}
46-
}
47-
}
48-
49-
if (found_first_idx) {
50-
// NOTE: In order to fully cover lanes with target_lane_id, start_idx and end_idx are expanded.
51-
start_idx = static_cast<size_t>(std::max(0, static_cast<int>(start_idx) - 1));
52-
end_idx = std::min(path.points.size() - 1, end_idx + 1);
26+
boost::optional<std::pair<size_t, size_t>> getPathIndexRangeWithLaneId(
27+
const autoware_auto_planning_msgs::msg::PathWithLaneId & path, const int64_t target_lane_id);
5328

54-
return std::make_pair(start_idx, end_idx);
55-
}
56-
57-
return {};
58-
}
59-
60-
inline size_t findNearestIndexFromLaneId(
29+
size_t findNearestIndexFromLaneId(
6130
const autoware_auto_planning_msgs::msg::PathWithLaneId & path,
62-
const geometry_msgs::msg::Point & pos, const int64_t lane_id)
63-
{
64-
const auto opt_range = getPathIndexRangeWithLaneId(path, lane_id);
65-
if (opt_range) {
66-
const size_t start_idx = opt_range->first;
67-
const size_t end_idx = opt_range->second;
68-
69-
validateNonEmpty(path.points);
31+
const geometry_msgs::msg::Point & pos, const int64_t lane_id);
7032

71-
const auto sub_points = std::vector<autoware_auto_planning_msgs::msg::PathPointWithLaneId>{
72-
path.points.begin() + start_idx, path.points.begin() + end_idx + 1};
73-
validateNonEmpty(sub_points);
74-
75-
return start_idx + findNearestIndex(sub_points, pos);
76-
}
77-
78-
return findNearestIndex(path.points, pos);
79-
}
80-
81-
inline size_t findNearestSegmentIndexFromLaneId(
33+
size_t findNearestSegmentIndexFromLaneId(
8234
const autoware_auto_planning_msgs::msg::PathWithLaneId & path,
83-
const geometry_msgs::msg::Point & pos, const int64_t lane_id)
84-
{
85-
const size_t nearest_idx = findNearestIndexFromLaneId(path, pos, lane_id);
86-
87-
if (nearest_idx == 0) {
88-
return 0;
89-
}
90-
if (nearest_idx == path.points.size() - 1) {
91-
return path.points.size() - 2;
92-
}
93-
94-
const double signed_length = calcLongitudinalOffsetToSegment(path.points, nearest_idx, pos);
95-
96-
if (signed_length <= 0) {
97-
return nearest_idx - 1;
98-
}
99-
100-
return nearest_idx;
101-
}
35+
const geometry_msgs::msg::Point & pos, const int64_t lane_id);
10236

10337
// @brief Calculates the path to be followed by the rear wheel center in order to make the vehicle
10438
// center follow the input path

common/motion_utils/include/motion_utils/trajectory/tmp_conversion.hpp

+4-25
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@
1515
#ifndef MOTION_UTILS__TRAJECTORY__TMP_CONVERSION_HPP_
1616
#define MOTION_UTILS__TRAJECTORY__TMP_CONVERSION_HPP_
1717

18-
#include "tier4_autoware_utils/geometry/geometry.hpp"
19-
#include "tier4_autoware_utils/geometry/pose_deviation.hpp"
20-
2118
#include "autoware_auto_planning_msgs/msg/trajectory.hpp"
2219
#include "autoware_auto_planning_msgs/msg/trajectory_point.hpp"
2320

24-
#include <boost/optional.hpp>
25-
26-
#include <algorithm>
2721
#include <vector>
2822

2923
namespace motion_utils
@@ -39,30 +33,15 @@ namespace motion_utils
3933
* @todo Decide how to handle the situation that we need to use the trajectory with the size of
4034
* points larger than the capacity. (Tier IV)
4135
*/
42-
inline autoware_auto_planning_msgs::msg::Trajectory convertToTrajectory(
43-
const std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> & trajectory)
44-
{
45-
autoware_auto_planning_msgs::msg::Trajectory output{};
46-
for (const auto & pt : trajectory) {
47-
output.points.push_back(pt);
48-
if (output.points.size() >= output.CAPACITY) {
49-
break;
50-
}
51-
}
52-
return output;
53-
}
36+
autoware_auto_planning_msgs::msg::Trajectory convertToTrajectory(
37+
const std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> & trajectory);
5438

5539
/**
5640
* @brief Convert autoware_auto_planning_msgs::msg::Trajectory to
5741
* std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint>.
5842
*/
59-
inline std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> convertToTrajectoryPointArray(
60-
const autoware_auto_planning_msgs::msg::Trajectory & trajectory)
61-
{
62-
std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> output(trajectory.points.size());
63-
std::copy(trajectory.points.begin(), trajectory.points.end(), output.begin());
64-
return output;
65-
}
43+
std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint> convertToTrajectoryPointArray(
44+
const autoware_auto_planning_msgs::msg::Trajectory & trajectory);
6645

6746
} // namespace motion_utils
6847

0 commit comments

Comments
 (0)