Skip to content

Commit 5460752

Browse files
committed
Start adding unit tests for path shortcutting
1 parent 1fb484a commit 5460752

2 files changed

Lines changed: 79 additions & 1 deletion

File tree

roboplan/test/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ target_link_libraries(
1919
GTest::gtest_main
2020
roboplan_example_models::roboplan_example_models
2121
)
22+
add_executable(test_path_utils test_path_utils.cpp)
23+
set_property(TARGET test_path_utils PROPERTY CXX_STANDARD 20)
24+
target_link_libraries(
25+
test_path_utils
26+
roboplan
27+
GTest::gtest_main
28+
roboplan_example_models::roboplan_example_models
29+
)
2230

2331
# TODO: Define tests as a variable
2432

@@ -30,7 +38,8 @@ if ( ament_cmake_gtest_FOUND )
3038

3139
ament_add_gtest_test(test_types)
3240
ament_add_gtest_test(test_scene)
41+
ament_add_gtest_test(test_path_utils)
3342
else()
3443
include(GoogleTest)
35-
gtest_discover_tests(test_types test_scene)
44+
gtest_discover_tests(test_types test_scene test_path_utils)
3645
endif()

roboplan/test/test_path_utils.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)