1 #ifndef TESSERACT_COLLISION_COLLISION_BOX_SPHERE_UNIT_HPP
2 #define TESSERACT_COLLISION_COLLISION_BOX_SPHERE_UNIT_HPP
14 inline void addCollisionObjects(DiscreteContactManager& checker,
bool use_convex_mesh =
false)
20 Eigen::Isometry3d box_pose;
21 box_pose.setIdentity();
25 obj1_shapes.push_back(box);
26 obj1_poses.push_back(box_pose);
28 checker.addCollisionObject(
"box_link", 0, obj1_shapes, obj1_poses,
false);
29 checker.enableCollisionObject(
"box_link");
34 CollisionShapePtr thin_box = std::make_shared<tesseract_geometry::Box>(0.1, 1, 1);
35 Eigen::Isometry3d thin_box_pose;
36 thin_box_pose.setIdentity();
40 obj2_shapes.push_back(thin_box);
41 obj2_poses.push_back(thin_box_pose);
43 checker.addCollisionObject(
"thin_box_link", 0, obj2_shapes, obj2_poses);
44 checker.disableCollisionObject(
"thin_box_link");
54 auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
55 auto mesh_faces = std::make_shared<Eigen::VectorXi>();
64 auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
69 sphere = std::make_shared<tesseract_geometry::Sphere>(0.25);
72 Eigen::Isometry3d sphere_pose;
73 sphere_pose.setIdentity();
77 obj3_shapes.push_back(sphere);
78 obj3_poses.push_back(sphere_pose);
80 checker.addCollisionObject(
"sphere_link", 0, obj3_shapes, obj3_poses);
85 CollisionShapePtr remove_box = std::make_shared<tesseract_geometry::Box>(0.1, 1, 1);
86 Eigen::Isometry3d remove_box_pose;
87 remove_box_pose.setIdentity();
91 obj4_shapes.push_back(remove_box);
92 obj4_poses.push_back(remove_box_pose);
94 checker.addCollisionObject(
"remove_box_link", 0, obj4_shapes, obj4_poses);
95 EXPECT_TRUE(checker.getCollisionObjects().size() == 4);
96 EXPECT_TRUE(checker.hasCollisionObject(
"remove_box_link"));
97 checker.removeCollisionObject(
"remove_box_link");
98 EXPECT_FALSE(checker.hasCollisionObject(
"remove_box_link"));
103 EXPECT_FALSE(checker.removeCollisionObject(
"link_does_not_exist"));
104 EXPECT_FALSE(checker.enableCollisionObject(
"link_does_not_exist"));
105 EXPECT_FALSE(checker.disableCollisionObject(
"link_does_not_exist"));
116 EXPECT_TRUE(checker.getCollisionObjects().size() == 3);
117 for (
const auto& co : checker.getCollisionObjects())
119 EXPECT_TRUE(checker.getCollisionObjectGeometries(co).size() == 1);
120 EXPECT_TRUE(checker.getCollisionObjectGeometriesTransforms(co).size() == 1);
121 for (
const auto& cgt : checker.getCollisionObjectGeometriesTransforms(co))
123 EXPECT_TRUE(cgt.isApprox(Eigen::Isometry3d::Identity(), 1e-5));
133 std::vector<std::string> active_links{
"box_link",
"sphere_link" };
136 EXPECT_TRUE(tesseract_common::isIdentical<std::string>(active_links, check_active_links,
false));
145 location[
"box_link"] = Eigen::Isometry3d::Identity();
146 location[
"sphere_link"] = Eigen::Isometry3d::Identity();
147 location[
"sphere_link"].translation()(0) = 0.2;
160 std::vector<int> idx = { 0, 1, 1 };
161 if (result_vector[0].link_names[0] !=
"box_link")
164 if (result_vector[0].single_contact_point)
166 EXPECT_NEAR(result_vector[0].nearest_points[0][0], result_vector[0].nearest_points[1][0], 0.001);
167 EXPECT_FALSE(std::abs(result_vector[0].nearest_points[0][0] - (0.5)) > 0.001 &&
168 std::abs(result_vector[0].nearest_points[0][0] - (-0.05)) > 0.001);
169 EXPECT_NEAR(result_vector[0].nearest_points[0][1], 0.0, 0.001);
170 EXPECT_NEAR(result_vector[0].nearest_points[0][2], 0.0, 0.001);
174 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.5, 0.001);
175 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
176 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.0, 0.001);
177 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.05, 0.001);
178 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
179 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.0, 0.001);
182 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
183 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
184 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
189 location[
"sphere_link"].translation() = Eigen::Vector3d(1, 0, 0);
191 result_vector.clear();
204 result_vector.clear();
215 if (result_vector[0].link_names[0] !=
"box_link")
218 if (result_vector[0].single_contact_point)
220 EXPECT_NEAR(result_vector[0].nearest_points[0][0], result_vector[0].nearest_points[1][0], 0.001);
221 EXPECT_FALSE(std::abs(result_vector[0].nearest_points[0][0] - (0.5)) > 0.001 &&
222 std::abs(result_vector[0].nearest_points[0][0] - (0.75)) > 0.001);
223 EXPECT_NEAR(result_vector[0].nearest_points[0][1], 0.0, 0.001);
224 EXPECT_NEAR(result_vector[0].nearest_points[0][2], 0.0, 0.001);
228 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.5, 0.001);
229 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
230 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.0, 0.001);
231 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], 0.75, 0.001);
232 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
233 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.0, 0.001);
236 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
237 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
238 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
246 std::vector<std::string> active_links{
"box_link",
"sphere_link" };
249 EXPECT_TRUE(tesseract_common::isIdentical<std::string>(active_links, check_active_links,
false));
258 location[
"box_link"] = Eigen::Isometry3d::Identity();
259 location[
"sphere_link"] = Eigen::Isometry3d::Identity();
260 location[
"sphere_link"].translation()(0) = 0.2;
272 EXPECT_NEAR(result_vector[0].nearest_points[0][1], result_vector[0].nearest_points[1][1], 0.001);
273 EXPECT_NEAR(result_vector[0].nearest_points[0][2], result_vector[0].nearest_points[1][2], 0.001);
275 std::vector<int> idx = { 0, 1, 1 };
276 if (result_vector[0].link_names[0] !=
"box_link")
279 if (result_vector[0].single_contact_point)
281 EXPECT_NEAR(result_vector[0].nearest_points[0][0], result_vector[0].nearest_points[1][0], 0.001);
282 EXPECT_FALSE(std::abs(result_vector[0].nearest_points[0][0] - (0.5)) > 0.001 &&
283 std::abs(result_vector[0].nearest_points[0][0] - (-0.03776)) > 0.001);
287 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.5, 0.001);
288 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.03776, 0.001);
291 EXPECT_GT((idx[2] * result_vector[0].normal).dot(Eigen::Vector3d(1, 0, 0)), 0.0);
292 EXPECT_LT(std::abs(std::acos((idx[2] * result_vector[0].normal).dot(Eigen::Vector3d(1, 0, 0)))), 0.00001);
297 location[
"sphere_link"].translation() = Eigen::Vector3d(1, 0, 0);
299 result_vector.clear();
311 result_vector.clear();
320 EXPECT_NEAR(result_vector[0].nearest_points[0][1], result_vector[0].nearest_points[1][1], 0.001);
321 EXPECT_NEAR(result_vector[0].nearest_points[0][2], result_vector[0].nearest_points[1][2], 0.001);
324 if (result_vector[0].link_names[0] !=
"box_link")
327 if (result_vector[0].single_contact_point)
329 EXPECT_NEAR(result_vector[0].nearest_points[0][0], result_vector[0].nearest_points[1][0], 0.001);
330 EXPECT_FALSE(std::abs(result_vector[0].nearest_points[0][0] - (0.5)) > 0.001 &&
331 std::abs(result_vector[0].nearest_points[0][0] - (0.76224)) > 0.001);
335 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.5, 0.001);
336 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], 0.76224, 0.001);
339 EXPECT_GT((idx[2] * result_vector[0].normal).dot(Eigen::Vector3d(1, 0, 0)), 0.0);
340 EXPECT_LT(std::abs(std::acos((idx[2] * result_vector[0].normal).dot(Eigen::Vector3d(1, 0, 0)))), 0.00001);
359 #endif // TESSERACT_COLLISION_COLLISION_BOX_SPHERE_UNIT_HPP