|
| 1 | +// Copyright 2022 Tier IV, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "motion_velocity_smoother/trajectory_utils.hpp" |
| 16 | + |
| 17 | +#include <gtest/gtest.h> |
| 18 | + |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +using autoware_auto_planning_msgs::msg::TrajectoryPoint; |
| 22 | +using motion_velocity_smoother::trajectory_utils::TrajectoryPoints; |
| 23 | + |
| 24 | +TrajectoryPoints genStraightTrajectory(const size_t size) |
| 25 | +{ |
| 26 | + double x = 0.0; |
| 27 | + double dx = 1.0; |
| 28 | + geometry_msgs::msg::Quaternion o; |
| 29 | + o.x = 0.0; |
| 30 | + o.y = 0.0; |
| 31 | + o.z = 0.0; |
| 32 | + o.w = 1.0; |
| 33 | + |
| 34 | + TrajectoryPoints tps; |
| 35 | + TrajectoryPoint p; |
| 36 | + for (size_t i = 0; i < size; ++i) { |
| 37 | + p.pose.position.x = x; |
| 38 | + p.pose.orientation = o; |
| 39 | + x += dx; |
| 40 | + tps.push_back(p); |
| 41 | + } |
| 42 | + return tps; |
| 43 | +} |
| 44 | + |
| 45 | +TEST(TestTrajectoryUtils, CalcTrajectoryCurvatureFrom3Points) |
| 46 | +{ |
| 47 | + // the output curvature vector should have the same size of the input trajectory. |
| 48 | + const auto checkOutputSize = [](const size_t trajectory_size, const size_t idx_dist) { |
| 49 | + const auto trajectory_points = genStraightTrajectory(trajectory_size); |
| 50 | + const auto curvatures = |
| 51 | + motion_velocity_smoother::trajectory_utils::calcTrajectoryCurvatureFrom3Points( |
| 52 | + trajectory_points, idx_dist); |
| 53 | + EXPECT_EQ(curvatures.size(), trajectory_size) << ", idx_dist = " << idx_dist; |
| 54 | + }; |
| 55 | + |
| 56 | + const auto trajectory_size_arr = {0, 1, 2, 3, 4, 5, 10, 100}; |
| 57 | + const auto idx_dist_arr = {0, 1, 2, 3, 4, 5, 10, 100}; |
| 58 | + for (const auto trajectory_size : trajectory_size_arr) { |
| 59 | + for (const auto idx_dist : idx_dist_arr) { |
| 60 | + checkOutputSize(trajectory_size, idx_dist); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments