3 #include <gtest/gtest.h>
18 bool operator()(
const std::string& s1,
const std::string& s2)
const override
25 TEST(TesseractCoreUnit, ContactManagerConfigTest)
36 tesseract_common::testSerialization<tesseract_collision::ContactManagerConfig>(config,
"ContactManagerConfig");
65 tesseract_common::testSerialization<tesseract_collision::ContactManagerConfig>(config,
"ContactManagerConfig");
91 tesseract_common::testSerialization<tesseract_collision::ContactManagerConfig>(config,
"ContactManagerConfig");
125 EXPECT_ANY_THROW(config.
validate());
138 EXPECT_ANY_THROW(config.
validate());
149 TEST(TesseractCoreUnit, getCollisionObjectPairsUnit)
151 std::vector<std::string> active_links{
"link_1",
"link_2",
"link_3" };
152 std::vector<std::string> static_links{
"base_link",
"part_link" };
154 std::vector<tesseract_collision::ObjectPairKey> check_pairs;
165 std::vector<tesseract_collision::ObjectPairKey> pairs =
168 EXPECT_TRUE(tesseract_common::isIdentical<tesseract_collision::ObjectPairKey>(pairs, check_pairs,
false));
171 auto validator = std::make_shared<TestContactAllowedValidator>();
185 EXPECT_TRUE(tesseract_common::isIdentical<tesseract_collision::ObjectPairKey>(pairs, check_pairs,
false));
188 TEST(TesseractCoreUnit, isContactAllowedUnit)
190 auto validator = std::make_shared<TestContactAllowedValidator>();
197 TEST(TesseractCoreUnit, scaleVerticesUnit)
200 base_vertices.emplace_back(0, 0, 0);
201 base_vertices.emplace_back(0, 0, 1);
202 base_vertices.emplace_back(0, 1, 1);
203 base_vertices.emplace_back(0, 1, 0);
204 base_vertices.emplace_back(1, 0, 0);
205 base_vertices.emplace_back(1, 0, 1);
206 base_vertices.emplace_back(1, 1, 1);
207 base_vertices.emplace_back(1, 1, 0);
213 for (std::size_t i = 0; i < 8; ++i)
215 EXPECT_TRUE(test_vertices[i].isApprox(base_vertices[i]));
219 test_vertices = base_vertices;
221 EXPECT_TRUE(test_vertices[0].isApprox(Eigen::Vector3d(-4.5, -4.5, -4.5)));
222 EXPECT_TRUE(test_vertices[1].isApprox(Eigen::Vector3d(-4.5, -4.5, 5.5)));
223 EXPECT_TRUE(test_vertices[2].isApprox(Eigen::Vector3d(-4.5, 5.5, 5.5)));
224 EXPECT_TRUE(test_vertices[3].isApprox(Eigen::Vector3d(-4.5, 5.5, -4.5)));
225 EXPECT_TRUE(test_vertices[4].isApprox(Eigen::Vector3d(5.5, -4.5, -4.5)));
226 EXPECT_TRUE(test_vertices[5].isApprox(Eigen::Vector3d(5.5, -4.5, 5.5)));
227 EXPECT_TRUE(test_vertices[6].isApprox(Eigen::Vector3d(5.5, 5.5, 5.5)));
228 EXPECT_TRUE(test_vertices[7].isApprox(Eigen::Vector3d(5.5, 5.5, -4.5)));
231 test_vertices = base_vertices;
233 EXPECT_TRUE(test_vertices[0].isApprox(Eigen::Vector3d(0, 0, 0)));
234 EXPECT_TRUE(test_vertices[1].isApprox(Eigen::Vector3d(0, 0, 10)));
235 EXPECT_TRUE(test_vertices[2].isApprox(Eigen::Vector3d(0, 10, 10)));
236 EXPECT_TRUE(test_vertices[3].isApprox(Eigen::Vector3d(0, 10, 0)));
237 EXPECT_TRUE(test_vertices[4].isApprox(Eigen::Vector3d(10, 0, 0)));
238 EXPECT_TRUE(test_vertices[5].isApprox(Eigen::Vector3d(10, 0, 10)));
239 EXPECT_TRUE(test_vertices[6].isApprox(Eigen::Vector3d(10, 10, 10)));
240 EXPECT_TRUE(test_vertices[7].isApprox(Eigen::Vector3d(10, 10, 0)));
243 TEST(TesseractCoreUnit, ContactResultsUnit)
271 tesseract_common::testSerialization<tesseract_collision::ContactResult>(results,
"ContactResult");
278 results.
transform[0] = Eigen::Isometry3d::Identity() * Eigen::Translation3d(1, 2, 3);
279 results.
transform[1] = Eigen::Isometry3d::Identity() * Eigen::Translation3d(1, 2, 3);
288 results.
normal = Eigen::Vector3d(1, 2, 3);
293 results.
cc_transform[0] = Eigen::Isometry3d::Identity() * Eigen::Translation3d(1, 2, 3);
294 results.
cc_transform[1] = Eigen::Isometry3d::Identity() * Eigen::Translation3d(1, 2, 3);
297 tesseract_common::testSerialization<tesseract_collision::ContactResult>(results,
"ContactResult");
328 tesseract_common::testSerialization<tesseract_collision::ContactResult>(results,
"ContactResult");
331 TEST(TesseractCoreUnit, ContactResultMapUnit)
340 tesseract_common::testSerialization<tesseract_collision::ContactResultMap>(result_map,
"ContactResultMap");
358 auto it = result_map.
find(key1);
362 tesseract_common::testSerialization<tesseract_collision::ContactResultMap>(result_map,
"ContactResultMap");
374 it = result_map.
find(key1);
378 tesseract_common::testSerialization<tesseract_collision::ContactResultMap>(result_map,
"ContactResultMap");
390 it = result_map.
find(key1);
394 it = result_map.
find(key2);
398 tesseract_common::testSerialization<tesseract_collision::ContactResultMap>(result_map,
"ContactResultMap");
415 it = result_map.
find(key1);
420 it = result_map.
find(key2);
436 tesseract_common::testSerialization<tesseract_collision::ContactResultMap>(result_map,
"ContactResultMap");
450 auto it = result_map.
find(key1);
463 it = result_map.
find(key1);
476 it = result_map.
find(key1);
480 it = result_map.
find(key2);
495 tesseract_common::testSerialization<tesseract_collision::ContactResultMap>(result_map,
"ContactResultMap");
509 auto it = result_map.
find(key1);
522 it = result_map.
find(key1);
535 it = result_map.
find(key1);
548 it = result_map.
find(key1);
552 it = result_map.
find(key2);
561 it = result_map.
find(key1);
566 it = result_map.
find(key2);
594 auto it = result_map.
find(key1);
607 it = result_map.
find(key1);
620 it = result_map.
find(key1);
633 it = result_map.
find(key1);
637 it = result_map.
find(key2);
665 auto it = result_map.
find(key1);
668 it = result_map.
find(key2);
684 it = result_map.
find(key1);
689 it = result_map.
find(key2);
707 auto it = result_map.
find(key1);
710 it = result_map.
find(key2);
726 it = result_map.
find(key1);
730 it = result_map.
find(key2);
747 auto it = result_map.
find(key1);
750 it = result_map.
find(key2);
754 std::vector<std::reference_wrapper<tesseract_collision::ContactResult>> result_vector;
766 it = result_map.
find(key1);
770 it = result_map.
find(key2);
787 auto it = result_map.
find(key1);
790 it = result_map.
find(key2);
794 std::vector<std::reference_wrapper<const tesseract_collision::ContactResult>> result_vector;
806 it = result_map.
find(key1);
810 it = result_map.
find(key2);
827 auto it = result_map.
find(key1);
830 it = result_map.
find(key2);
835 if (key1 == pair.first)
838 result_map.
filter(filter);
848 it = result_map.
find(key1);
853 it = result_map.
find(key2);
859 TEST(TesseractCoreUnit, ContactRequestUnit)
869 tesseract_common::testSerialization<tesseract_collision::ContactRequest>(request,
"ContactRequest");
880 tesseract_common::testSerialization<tesseract_collision::ContactRequest>(request,
"ContactRequest");
884 TEST(TesseractCoreUnit, CollisionCheckConfigUnit)
893 tesseract_common::testSerialization<tesseract_collision::CollisionCheckConfig>(config,
"CollisionCheckConfig");
907 tesseract_common::testSerialization<tesseract_collision::CollisionCheckConfig>(config,
"CollisionCheckConfig");
911 TEST(TesseractCoreUnit, ContactTrajectorySubstepResultsUnit)
915 int substep_number = 5;
916 Eigen::VectorXd start_state(3);
917 Eigen::VectorXd end_state(3);
918 start_state << 1.0, 2.0, 3.0;
919 end_state << 4.0, 5.0, 6.0;
931 int substep_number = 3;
932 Eigen::VectorXd state(2);
945 int substep_number = 2;
946 Eigen::VectorXd state(1);
977 EXPECT_EQ(worst[0].link_names[0],
"link3");
978 EXPECT_EQ(worst[0].link_names[1],
"link4");
988 TEST(TesseractCoreUnit, ContactTrajectoryStepResultsUnit)
993 Eigen::VectorXd start_state(3);
994 Eigen::VectorXd end_state(3);
995 start_state << 1.0, 2.0, 3.0;
996 end_state << 4.0, 5.0, 6.0;
997 int num_substeps = 5;
1012 int step_number = 2;
1013 Eigen::VectorXd state(2);
1018 int expected_substeps = 2;
1031 int step_number = 1;
1032 Eigen::VectorXd state(1);
1039 results.
resize(new_size);
1048 int step_number = 1;
1049 Eigen::VectorXd start_state(2);
1050 Eigen::VectorXd end_state(2);
1051 start_state << 0.0, 0.0;
1052 end_state << 1.0, 1.0;
1053 int num_substeps = 3;
1058 for (
size_t i = 0; i < results.
substeps.size(); ++i)
1060 auto& substep = results.
substeps[i];
1061 if (substep.state0.size() == 0)
1062 substep.state0 = start_state;
1063 if (substep.state1.size() == 0)
1064 substep.state1 = end_state;
1065 if (substep.substep < 0)
1066 substep.substep =
static_cast<int>(i);
1086 results.
substeps[0].contacts.addContactResult(key1, crv1);
1096 results.
substeps[1].contacts.addContactResult(key1, crv3);
1097 results.
substeps[1].contacts.addContactResult(key2, crv2);
1109 if (!worst_collision.empty())
1122 int step_number = 0;
1123 Eigen::VectorXd state(1);
1129 for (
size_t i = 0; i < results.
substeps.size(); ++i)
1131 auto& substep = results.
substeps[i];
1132 if (substep.state0.size() == 0)
1133 substep.state0 = state;
1134 if (substep.state1.size() == 0)
1135 substep.state1 = state;
1136 if (substep.substep < 0)
1137 substep.substep =
static_cast<int>(i);
1154 TEST(TesseractCoreUnit, ContactTrajectoryResultsUnit)
1158 std::vector<std::string> joint_names = {
"joint1",
"joint2",
"joint3" };
1170 std::vector<std::string> joint_names = {
"joint1",
"joint2" };
1184 std::vector<std::string> joint_names = {
"joint1" };
1197 std::vector<std::string> joint_names = {
"joint1",
"joint2" };
1203 Eigen::VectorXd step1_start(2);
1204 Eigen::VectorXd step1_end(2);
1205 step1_start << 0.0, 0.0;
1206 step1_end << 1.0, 1.0;
1208 results.
steps[0].step = 0;
1209 results.
steps[0].state0 = step1_start;
1210 results.
steps[0].state1 = step1_end;
1211 results.
steps[0].resize(2);
1223 results.
steps[0].substeps[0].substep = 0;
1224 results.
steps[0].substeps[0].contacts.addContactResult(key1, crv1);
1227 Eigen::VectorXd step2_start(2);
1228 Eigen::VectorXd step2_end(2);
1229 step2_start << 1.0, 1.0;
1230 step2_end << 2.0, 2.0;
1232 results.
steps[1].step = 1;
1233 results.
steps[1].state0 = step2_start;
1234 results.
steps[1].state1 = step2_end;
1235 results.
steps[1].resize(3);
1247 results.
steps[1].substeps[1].substep = 1;
1248 results.
steps[1].substeps[1].contacts.addContactResult(key2, crv2);
1258 results.
steps[1].substeps[2].substep = 2;
1259 results.
steps[1].substeps[2].contacts.addContactResult(key2, crv3);
1272 EXPECT_EQ(worst_collision[0].link_names[0],
"link3");
1273 EXPECT_EQ(worst_collision[0].link_names[1],
"link4");
1295 std::vector<std::string> joint_names = {
"joint1" };
1316 EXPECT_TRUE(ss.str().find(
"No contacts detected") != std::string::npos);
1320 EXPECT_TRUE(freq_ss.str().find(
"No contacts detected") != std::string::npos);
1326 testing::InitGoogleTest(&argc, argv);
1328 return RUN_ALL_TESTS();