|
| 1 | +// Copyright 2023 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_utils/trajectory/trajectory.hpp" |
| 16 | + |
| 17 | +#include <gtest/gtest.h> |
| 18 | +#include <gtest/internal/gtest-port.h> |
| 19 | +#include <tf2/LinearMath/Quaternion.h> |
| 20 | + |
| 21 | +#include <random> |
| 22 | + |
| 23 | +namespace |
| 24 | +{ |
| 25 | +using autoware_auto_planning_msgs::msg::Trajectory; |
| 26 | +using tier4_autoware_utils::createPoint; |
| 27 | +using tier4_autoware_utils::createQuaternionFromRPY; |
| 28 | + |
| 29 | +constexpr double epsilon = 1e-6; |
| 30 | + |
| 31 | +geometry_msgs::msg::Pose createPose( |
| 32 | + double x, double y, double z, double roll, double pitch, double yaw) |
| 33 | +{ |
| 34 | + geometry_msgs::msg::Pose p; |
| 35 | + p.position = createPoint(x, y, z); |
| 36 | + p.orientation = createQuaternionFromRPY(roll, pitch, yaw); |
| 37 | + return p; |
| 38 | +} |
| 39 | + |
| 40 | +template <class T> |
| 41 | +T generateTestTrajectory( |
| 42 | + const size_t num_points, const double point_interval, const double vel = 0.0, |
| 43 | + const double init_theta = 0.0, const double delta_theta = 0.0) |
| 44 | +{ |
| 45 | + using Point = typename T::_points_type::value_type; |
| 46 | + |
| 47 | + T traj; |
| 48 | + for (size_t i = 0; i < num_points; ++i) { |
| 49 | + const double theta = init_theta + i * delta_theta; |
| 50 | + const double x = i * point_interval * std::cos(theta); |
| 51 | + const double y = i * point_interval * std::sin(theta); |
| 52 | + |
| 53 | + Point p; |
| 54 | + p.pose = createPose(x, y, 0.0, 0.0, 0.0, theta); |
| 55 | + p.longitudinal_velocity_mps = vel; |
| 56 | + traj.points.push_back(p); |
| 57 | + } |
| 58 | + |
| 59 | + return traj; |
| 60 | +} |
| 61 | +} // namespace |
| 62 | + |
| 63 | +TEST(trajectory_benchmark, DISABLED_calcLateralOffset) |
| 64 | +{ |
| 65 | + std::random_device r; |
| 66 | + std::default_random_engine e1(r()); |
| 67 | + std::uniform_real_distribution<double> uniform_dist(0.0, 1000.0); |
| 68 | + |
| 69 | + using motion_utils::calcLateralOffset; |
| 70 | + |
| 71 | + const auto traj = generateTestTrajectory<Trajectory>(1000, 1.0, 0.0, 0.0, 0.1); |
| 72 | + constexpr auto nb_iteration = 10000; |
| 73 | + for (auto i = 0; i < nb_iteration; ++i) { |
| 74 | + const auto point = createPoint(uniform_dist(e1), uniform_dist(e1), 0.0); |
| 75 | + calcLateralOffset(traj.points, point); |
| 76 | + } |
| 77 | +} |
0 commit comments