Skip to content

Commit 003ee0c

Browse files
authored
fix(motion_utils): remove only first point whose orientation is invalid (#7084)
fix(motion_utils): don't continue when it removes invalid orientation point Signed-off-by: satoshi-ota <satoshi.ota928@gmail.com>
1 parent c090aa4 commit 003ee0c

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -1921,20 +1921,21 @@ insertOrientation<std::vector<autoware_auto_planning_msgs::msg::TrajectoryPoint>
19211921
* radians (default: M_PI_2)
19221922
*/
19231923
template <class T>
1924-
void removeInvalidOrientationPoints(T & points, const double max_yaw_diff = M_PI_2)
1924+
void removeFirstInvalidOrientationPoints(T & points, const double max_yaw_diff = M_PI_2)
19251925
{
1926-
for (size_t i = 1; i < points.size();) {
1927-
const auto p1 = tier4_autoware_utils::getPose(points.at(i - 1));
1928-
const auto p2 = tier4_autoware_utils::getPose(points.at(i));
1926+
for (auto itr = points.begin(); std::next(itr) != points.end();) {
1927+
const auto p1 = tier4_autoware_utils::getPose(*itr);
1928+
const auto p2 = tier4_autoware_utils::getPose(*std::next(itr));
19291929
const double yaw1 = tf2::getYaw(p1.orientation);
19301930
const double yaw2 = tf2::getYaw(p2.orientation);
19311931

19321932
if (
19331933
max_yaw_diff < std::abs(tier4_autoware_utils::normalizeRadian(yaw1 - yaw2)) ||
19341934
!tier4_autoware_utils::isDrivingForward(p1, p2)) {
1935-
points.erase(points.begin() + i);
1935+
points.erase(std::next(itr));
1936+
return;
19361937
} else {
1937-
++i;
1938+
itr++;
19381939
}
19391940
}
19401941
}

common/motion_utils/test/src/trajectory/test_trajectory.cpp

+5-16
Original file line numberDiff line numberDiff line change
@@ -5337,10 +5337,10 @@ TEST(trajectory, cropPoints)
53375337
}
53385338
}
53395339

5340-
TEST(Trajectory, removeInvalidOrientationPoints)
5340+
TEST(Trajectory, removeFirstInvalidOrientationPoints)
53415341
{
53425342
using motion_utils::insertOrientation;
5343-
using motion_utils::removeInvalidOrientationPoints;
5343+
using motion_utils::removeFirstInvalidOrientationPoints;
53445344

53455345
const double max_yaw_diff = M_PI_2;
53465346

@@ -5351,7 +5351,7 @@ TEST(Trajectory, removeInvalidOrientationPoints)
53515351
auto modified_traj = traj;
53525352
insertOrientation(modified_traj.points, true);
53535353
modifyTrajectory(modified_traj);
5354-
removeInvalidOrientationPoints(modified_traj.points, max_yaw_diff);
5354+
removeFirstInvalidOrientationPoints(modified_traj.points, max_yaw_diff);
53555355
EXPECT_EQ(modified_traj.points.size(), expected_size);
53565356
for (size_t i = 0; i < modified_traj.points.size() - 1; ++i) {
53575357
EXPECT_EQ(traj.points.at(i), modified_traj.points.at(i));
@@ -5374,7 +5374,7 @@ TEST(Trajectory, removeInvalidOrientationPoints)
53745374
[&](Trajectory & t) {
53755375
auto invalid_point = t.points.back();
53765376
invalid_point.pose.orientation =
5377-
tf2::toMsg(tf2::Quaternion(tf2::Vector3(0, 0, 1), 3 * M_PI_2));
5377+
tf2::toMsg(tf2::Quaternion(tf2::Vector3(0, 0, 1), 3 * M_PI_4));
53785378
t.points.push_back(invalid_point);
53795379
},
53805380
traj.points.size());
@@ -5385,21 +5385,10 @@ TEST(Trajectory, removeInvalidOrientationPoints)
53855385
[&](Trajectory & t) {
53865386
auto invalid_point = t.points[4];
53875387
invalid_point.pose.orientation =
5388-
tf2::toMsg(tf2::Quaternion(tf2::Vector3(0, 0, 1), 3 * M_PI_2));
5388+
tf2::toMsg(tf2::Quaternion(tf2::Vector3(0, 0, 1), 3 * M_PI_4));
53895389
t.points.insert(t.points.begin() + 4, invalid_point);
53905390
},
53915391
traj.points.size());
5392-
5393-
// invalid point at the beginning
5394-
testRemoveInvalidOrientationPoints(
5395-
traj,
5396-
[&](Trajectory & t) {
5397-
auto invalid_point = t.points.front();
5398-
invalid_point.pose.orientation =
5399-
tf2::toMsg(tf2::Quaternion(tf2::Vector3(0, 0, 1), 3 * M_PI_2));
5400-
t.points.insert(t.points.begin(), invalid_point);
5401-
},
5402-
1); // expected size is 1 since only the first point remains
54035392
}
54045393

54055394
TEST(trajectory, calcYawDeviation)

planning/behavior_path_planner_common/src/utils/path_shifter/path_shifter.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace behavior_path_planner
5353

5454
using motion_utils::findNearestIndex;
5555
using motion_utils::insertOrientation;
56-
using motion_utils::removeInvalidOrientationPoints;
56+
using motion_utils::removeFirstInvalidOrientationPoints;
5757
using motion_utils::removeOverlapPoints;
5858

5959
void PathShifter::setPath(const PathWithLaneId & path)
@@ -155,14 +155,14 @@ bool PathShifter::generate(
155155
shifted_path->path.points = removeOverlapPoints(shifted_path->path.points);
156156
// Use orientation before shift to remove points in reverse order
157157
// before setting wrong azimuth orientation
158-
removeInvalidOrientationPoints(shifted_path->path.points);
158+
removeFirstInvalidOrientationPoints(shifted_path->path.points);
159159
size_t previous_size{shifted_path->path.points.size()};
160160
do {
161161
previous_size = shifted_path->path.points.size();
162162
// Set the azimuth orientation to the next point at each point
163163
insertOrientation(shifted_path->path.points, true);
164164
// Use azimuth orientation to remove points in reverse order
165-
removeInvalidOrientationPoints(shifted_path->path.points);
165+
removeFirstInvalidOrientationPoints(shifted_path->path.points);
166166
} while (previous_size != shifted_path->path.points.size());
167167

168168
// DEBUG

0 commit comments

Comments
 (0)