|
| 1 | +#include <gtest/gtest.h> |
| 2 | + |
| 3 | +#include <roboplan/core/path_utils.hpp> |
| 4 | +#include <roboplan/core/scene.hpp> |
| 5 | +#include <roboplan_example_models/resources.hpp> |
| 6 | + |
| 7 | +namespace roboplan { |
| 8 | + |
| 9 | +class RoboPlanPathUtilsTest : public ::testing::Test { |
| 10 | +protected: |
| 11 | + void SetUp() override { |
| 12 | + const auto share_prefix = roboplan_example_models::get_package_share_dir(); |
| 13 | + const auto urdf_path = share_prefix / "ur_robot_model" / "ur5_gripper.urdf"; |
| 14 | + const auto srdf_path = share_prefix / "ur_robot_model" / "ur5_gripper.srdf"; |
| 15 | + const std::vector<std::filesystem::path> package_paths = {share_prefix}; |
| 16 | + scene_ = std::make_shared<Scene>("test_scene", urdf_path, srdf_path, package_paths); |
| 17 | + } |
| 18 | + |
| 19 | +public: |
| 20 | + // No default constructors, so must be pointers. |
| 21 | + std::shared_ptr<Scene> scene_; |
| 22 | + |
| 23 | + JointPath getTestPath(const size_t num_points) { |
| 24 | + JointPath test_path; |
| 25 | + test_path.joint_names = scene_->getJointNames(); |
| 26 | + |
| 27 | + if (num_points == 0) |
| 28 | + return test_path; |
| 29 | + |
| 30 | + Eigen::VectorXd q1(6); |
| 31 | + Eigen::VectorXd q2(6); |
| 32 | + Eigen::VectorXd q3(6); |
| 33 | + q1 << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0; |
| 34 | + q2 << 0.5, 0.0, 0.0, 0.0, 0.0, 0.0; |
| 35 | + q3 << 1.0, 0.0, 0.0, 0.0, 0.0, 0.0; |
| 36 | + |
| 37 | + if (num_points >= 1) |
| 38 | + test_path.positions.push_back(q1); |
| 39 | + if (num_points >= 2) |
| 40 | + test_path.positions.push_back(q2); |
| 41 | + if (num_points >= 3) |
| 42 | + test_path.positions.push_back(q3); |
| 43 | + |
| 44 | + return test_path; |
| 45 | + } |
| 46 | +}; |
| 47 | + |
| 48 | +TEST_F(RoboPlanPathUtilsTest, testGetNormalizedPathScaling) { |
| 49 | + |
| 50 | + JointPath empty_path = getTestPath(0); |
| 51 | + auto empty_scalings = getNormalizedPathScaling(*scene_, empty_path); |
| 52 | + EXPECT_TRUE(empty_scalings.empty()); |
| 53 | + |
| 54 | + JointPath length_1_path = getTestPath(1); |
| 55 | + auto length_1_path_scalings = getNormalizedPathScaling(*scene_, length_1_path); |
| 56 | + ASSERT_EQ(length_1_path_scalings.size(), 1); |
| 57 | + EXPECT_DOUBLE_EQ(length_1_path_scalings[0], 1.0); |
| 58 | + |
| 59 | + // Path with 3 evenly spaced points |
| 60 | + auto test_path = getTestPath(3); |
| 61 | + auto path_scalings = getNormalizedPathScaling(*scene_, test_path); |
| 62 | + |
| 63 | + ASSERT_EQ(path_scalings.size(), 3); |
| 64 | + EXPECT_DOUBLE_EQ(path_scalings[0], 0.0); |
| 65 | + EXPECT_DOUBLE_EQ(path_scalings[1], 0.5); |
| 66 | + EXPECT_DOUBLE_EQ(path_scalings[2], 1.0); |
| 67 | +} |
| 68 | + |
| 69 | +} // namespace roboplan |
0 commit comments