-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autoware_trajectory): update autoware_trajectory interfaces (#10034
) * feat(autoware_trajectory): update autoware_trajectory interfaces Signed-off-by: Y.Hisaki <[email protected]> * add const Signed-off-by: Y.Hisaki <[email protected]> * Update shift.hpp Signed-off-by: Y.Hisaki <[email protected]> * fix names Signed-off-by: Y.Hisaki <[email protected]> * fix copyright Signed-off-by: Y.Hisaki <[email protected]> --------- Signed-off-by: Y.Hisaki <[email protected]>
- Loading branch information
Showing
38 changed files
with
1,951 additions
and
442 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
common/autoware_trajectory/examples/example_find_intervals.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2025 Tier IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "autoware/trajectory/path_point_with_lane_id.hpp" | ||
#include "autoware/trajectory/utils/find_intervals.hpp" | ||
|
||
#include <matplotlibcpp17/pyplot.h> | ||
|
||
#include <vector> | ||
|
||
using Trajectory = autoware::trajectory::Trajectory<tier4_planning_msgs::msg::PathPointWithLaneId>; | ||
|
||
tier4_planning_msgs::msg::PathPointWithLaneId path_point_with_lane_id( | ||
double x, double y, uint8_t lane_id) | ||
{ | ||
tier4_planning_msgs::msg::PathPointWithLaneId point; | ||
point.point.pose.position.x = x; | ||
point.point.pose.position.y = y; | ||
point.lane_ids.emplace_back(lane_id); | ||
return point; | ||
} | ||
|
||
int main() | ||
{ | ||
pybind11::scoped_interpreter guard{}; | ||
auto plt = matplotlibcpp17::pyplot::import(); | ||
|
||
std::vector<tier4_planning_msgs::msg::PathPointWithLaneId> points{ | ||
path_point_with_lane_id(0.41, 0.69, 0), path_point_with_lane_id(0.66, 1.09, 0), | ||
path_point_with_lane_id(0.93, 1.41, 0), path_point_with_lane_id(1.26, 1.71, 0), | ||
path_point_with_lane_id(1.62, 1.90, 0), path_point_with_lane_id(1.96, 1.98, 0), | ||
path_point_with_lane_id(2.48, 1.96, 1), path_point_with_lane_id(3.02, 1.87, 1), | ||
path_point_with_lane_id(3.56, 1.82, 1), path_point_with_lane_id(4.14, 2.02, 1), | ||
path_point_with_lane_id(4.56, 2.36, 1), path_point_with_lane_id(4.89, 2.72, 1), | ||
path_point_with_lane_id(5.27, 3.15, 1), path_point_with_lane_id(5.71, 3.69, 1), | ||
path_point_with_lane_id(6.09, 4.02, 0), path_point_with_lane_id(6.54, 4.16, 0), | ||
path_point_with_lane_id(6.79, 3.92, 0), path_point_with_lane_id(7.11, 3.60, 0), | ||
path_point_with_lane_id(7.42, 3.01, 0)}; | ||
|
||
auto trajectory = Trajectory::Builder{}.build(points); | ||
|
||
if (!trajectory) { | ||
return 1; | ||
} | ||
|
||
const auto intervals = autoware::trajectory::find_intervals( | ||
*trajectory, [](const tier4_planning_msgs::msg::PathPointWithLaneId & point) { | ||
return point.lane_ids[0] == 1; | ||
}); | ||
|
||
std::vector<double> x_id0; | ||
std::vector<double> y_id0; | ||
std::vector<double> x_id1; | ||
std::vector<double> y_id1; | ||
std::vector<double> x_all; | ||
std::vector<double> y_all; | ||
|
||
for (const auto & point : points) { | ||
if (point.lane_ids[0] == 0) { | ||
x_id0.push_back(point.point.pose.position.x); | ||
y_id0.push_back(point.point.pose.position.y); | ||
} else { | ||
x_id1.push_back(point.point.pose.position.x); | ||
y_id1.push_back(point.point.pose.position.y); | ||
} | ||
} | ||
|
||
for (double s = 0.0; s < trajectory->length(); s += 0.01) { | ||
auto p = trajectory->compute(s); | ||
x_all.push_back(p.point.pose.position.x); | ||
y_all.push_back(p.point.pose.position.y); | ||
} | ||
|
||
plt.plot(Args(x_all, y_all), Kwargs("color"_a = "blue")); | ||
plt.scatter(Args(x_id0, y_id0), Kwargs("color"_a = "blue", "label"_a = "lane_id = 0")); | ||
plt.scatter(Args(x_id1, y_id1), Kwargs("color"_a = "red", "label"_a = "lane_id = 1")); | ||
|
||
std::vector<double> x_cropped; | ||
std::vector<double> y_cropped; | ||
|
||
trajectory->crop(intervals[0].start, intervals[0].end - intervals[0].start); | ||
|
||
for (double s = 0.0; s < trajectory->length(); s += 0.01) { | ||
auto p = trajectory->compute(s); | ||
x_cropped.push_back(p.point.pose.position.x); | ||
y_cropped.push_back(p.point.pose.position.y); | ||
} | ||
|
||
plt.plot( | ||
Args(x_cropped, y_cropped), | ||
Kwargs("color"_a = "red", "label"_a = "interval between lane_id = 1")); | ||
|
||
plt.legend(); | ||
plt.show(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
// Copyright 2025 TIER IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "autoware/trajectory/point.hpp" | ||
#include "autoware/trajectory/utils/shift.hpp" | ||
|
||
#include <matplotlibcpp17/pyplot.h> | ||
|
||
#include <iostream> | ||
#include <vector> | ||
|
||
geometry_msgs::msg::Point point(double x, double y) | ||
{ | ||
geometry_msgs::msg::Point p; | ||
p.x = x; | ||
p.y = y; | ||
return p; | ||
} | ||
|
||
int main() | ||
{ | ||
pybind11::scoped_interpreter guard{}; | ||
auto plt = matplotlibcpp17::pyplot::import(); | ||
|
||
geometry_msgs::msg::Point p; | ||
(void)(p); | ||
|
||
std::vector<geometry_msgs::msg::Point> points = { | ||
point(0.49, 0.59), point(0.61, 1.22), point(0.86, 1.93), point(1.20, 2.56), point(1.51, 3.17), | ||
point(1.85, 3.76), point(2.14, 4.26), point(2.60, 4.56), point(3.07, 4.55), point(3.61, 4.30), | ||
point(3.95, 4.01), point(4.29, 3.68), point(4.90, 3.25), point(5.54, 3.10), point(6.24, 3.18), | ||
point(6.88, 3.54), point(7.51, 4.25), point(7.85, 4.93), point(8.03, 5.73), point(8.16, 6.52), | ||
point(8.31, 7.28), point(8.45, 7.93), point(8.68, 8.45), point(8.96, 8.96), point(9.32, 9.36)}; | ||
|
||
auto trajectory = | ||
autoware::trajectory::Trajectory<geometry_msgs::msg::Point>::Builder{}.build(points); | ||
|
||
if (!trajectory) { | ||
return 1; | ||
} | ||
|
||
std::cout << "length: " << trajectory->length() << std::endl; | ||
|
||
{ | ||
std::vector<double> x; | ||
std::vector<double> y; | ||
for (double s = 0.0; s < trajectory->length(); s += 0.01) { | ||
auto p = trajectory->compute(s); | ||
x.push_back(p.x); | ||
y.push_back(p.y); | ||
} | ||
plt.plot(Args(x, y), Kwargs("label"_a = "original")); | ||
|
||
x.clear(); | ||
y.clear(); | ||
|
||
autoware::trajectory::ShiftInterval shift_interval; | ||
shift_interval.end = -1.0; | ||
shift_interval.lateral_offset = 0.5; | ||
|
||
auto shifted_trajectory = autoware::trajectory::shift(*trajectory, shift_interval); | ||
|
||
for (double s = 0.0; s < shifted_trajectory.length(); s += 0.01) { | ||
auto p = shifted_trajectory.compute(s); | ||
x.push_back(p.x); | ||
y.push_back(p.y); | ||
} | ||
|
||
plt.axis(Args("equal")); | ||
plt.plot(Args(x, y), Kwargs("label"_a = "shifted")); | ||
plt.legend(); | ||
plt.show(); | ||
} | ||
|
||
{ | ||
std::vector<double> x; | ||
std::vector<double> y; | ||
for (double s = 0.0; s < trajectory->length(); s += 0.01) { | ||
auto p = trajectory->compute(s); | ||
x.push_back(p.x); | ||
y.push_back(p.y); | ||
} | ||
plt.plot(Args(x, y), Kwargs("label"_a = "original")); | ||
|
||
x.clear(); | ||
y.clear(); | ||
|
||
autoware::trajectory::ShiftInterval shift_interval; | ||
shift_interval.start = trajectory->length() / 4.0; | ||
shift_interval.end = trajectory->length() * 3.0 / 4.0; | ||
shift_interval.lateral_offset = 0.5; | ||
auto shifted_trajectory = autoware::trajectory::shift(*trajectory, shift_interval); | ||
|
||
for (double s = 0.0; s < shifted_trajectory.length(); s += 0.01) { | ||
auto p = shifted_trajectory.compute(s); | ||
x.push_back(p.x); | ||
y.push_back(p.y); | ||
} | ||
|
||
plt.axis(Args("equal")); | ||
plt.plot(Args(x, y), Kwargs("label"_a = "shifted")); | ||
plt.legend(); | ||
plt.show(); | ||
} | ||
|
||
{ | ||
std::vector<double> x; | ||
std::vector<double> y; | ||
for (double s = 0.0; s < trajectory->length(); s += 0.01) { | ||
auto p = trajectory->compute(s); | ||
x.push_back(p.x); | ||
y.push_back(p.y); | ||
} | ||
plt.plot(Args(x, y), Kwargs("label"_a = "original")); | ||
|
||
x.clear(); | ||
y.clear(); | ||
|
||
autoware::trajectory::ShiftInterval shift_interval; | ||
shift_interval.start = trajectory->length() * 3.0 / 4.0; | ||
shift_interval.end = trajectory->length() / 4.0; | ||
shift_interval.lateral_offset = 0.5; | ||
auto shifted_trajectory = autoware::trajectory::shift(*trajectory, shift_interval); | ||
|
||
for (double s = 0.0; s < shifted_trajectory.length(); s += 0.01) { | ||
auto p = shifted_trajectory.compute(s); | ||
x.push_back(p.x); | ||
y.push_back(p.y); | ||
} | ||
|
||
plt.axis(Args("equal")); | ||
plt.plot(Args(x, y), Kwargs("label"_a = "shifted")); | ||
plt.legend(); | ||
plt.show(); | ||
} | ||
|
||
{ | ||
std::vector<double> x; | ||
std::vector<double> y; | ||
for (double s = 0.0; s < trajectory->length(); s += 0.01) { | ||
auto p = trajectory->compute(s); | ||
x.push_back(p.x); | ||
y.push_back(p.y); | ||
} | ||
plt.plot(Args(x, y), Kwargs("label"_a = "original")); | ||
|
||
x.clear(); | ||
y.clear(); | ||
|
||
autoware::trajectory::ShiftInterval shift_interval1; | ||
shift_interval1.start = trajectory->length() / 4.0; | ||
shift_interval1.end = trajectory->length() * 2.0 / 4.0; | ||
shift_interval1.lateral_offset = 0.5; | ||
|
||
autoware::trajectory::ShiftInterval shift_interval2; | ||
shift_interval2.start = trajectory->length() * 2.0 / 4.0; | ||
shift_interval2.end = trajectory->length() * 3.0 / 4.0; | ||
shift_interval2.lateral_offset = -0.5; | ||
|
||
auto shifted_trajectory = | ||
autoware::trajectory::shift(*trajectory, {shift_interval1, shift_interval2}); | ||
|
||
for (double s = 0.0; s < shifted_trajectory.length(); s += 0.01) { | ||
auto p = shifted_trajectory.compute(s); | ||
x.push_back(p.x); | ||
y.push_back(p.y); | ||
} | ||
|
||
plt.axis(Args("equal")); | ||
plt.plot(Args(x, y), Kwargs("label"_a = "shifted")); | ||
plt.legend(); | ||
plt.show(); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.