|
15 | 15 | #ifndef MOTION_UTILS__TRAJECTORY__PATH_WITH_LANE_ID_HPP_
|
16 | 16 | #define MOTION_UTILS__TRAJECTORY__PATH_WITH_LANE_ID_HPP_
|
17 | 17 |
|
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> |
20 | 20 |
|
21 | 21 | #include <boost/optional.hpp>
|
22 | 22 |
|
23 |
| -#include <algorithm> |
24 | 23 | #include <utility>
|
25 |
| -#include <vector> |
26 |
| - |
27 | 24 | namespace motion_utils
|
28 | 25 | {
|
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); |
53 | 28 |
|
54 |
| - return std::make_pair(start_idx, end_idx); |
55 |
| - } |
56 |
| - |
57 |
| - return {}; |
58 |
| -} |
59 |
| - |
60 |
| -inline size_t findNearestIndexFromLaneId( |
| 29 | +size_t findNearestIndexFromLaneId( |
61 | 30 | 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); |
70 | 32 |
|
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( |
82 | 34 | 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); |
102 | 36 |
|
103 | 37 | // @brief Calculates the path to be followed by the rear wheel center in order to make the vehicle
|
104 | 38 | // center follow the input path
|
|
0 commit comments