1 #ifndef TESSERACT_COLLISION_CONTACT_MANAGER_CONFIG_UNIT_H
2 #define TESSERACT_COLLISION_CONTACT_MANAGER_CONFIG_UNIT_H
20 Eigen::Isometry3d sphere_pose;
21 sphere_pose.setIdentity();
25 obj1_shapes.push_back(sphere);
26 obj1_poses.push_back(sphere_pose);
28 checker.addCollisionObject(
"sphere_link", 0, obj1_shapes, obj1_poses);
33 CollisionShapePtr thin_box = std::make_shared<tesseract_geometry::Box>(0.1, 1, 1);
34 Eigen::Isometry3d thin_box_pose;
35 thin_box_pose.setIdentity();
39 obj2_shapes.push_back(thin_box);
40 obj2_poses.push_back(thin_box_pose);
42 checker.addCollisionObject(
"thin_box_link", 0, obj2_shapes, obj2_poses);
50 Eigen::Isometry3d sphere1_pose;
51 sphere1_pose.setIdentity();
55 obj3_shapes.push_back(sphere1);
56 obj3_poses.push_back(sphere1_pose);
58 checker.addCollisionObject(
"sphere1_link", 0, obj3_shapes, obj3_poses);
68 Eigen::Isometry3d sphere_pose;
69 sphere_pose.setIdentity();
70 sphere_pose.translation()[2] = 0.25;
74 obj1_shapes.push_back(sphere);
75 obj1_poses.push_back(sphere_pose);
77 checker.addCollisionObject(
"sphere_link", 0, obj1_shapes, obj1_poses,
false);
78 EXPECT_FALSE(checker.isCollisionObjectEnabled(
"sphere_link"));
79 checker.enableCollisionObject(
"sphere_link");
80 EXPECT_TRUE(checker.isCollisionObjectEnabled(
"sphere_link"));
85 CollisionShapePtr thin_box = std::make_shared<tesseract_geometry::Box>(0.1, 1, 1);
86 Eigen::Isometry3d thin_box_pose;
87 thin_box_pose.setIdentity();
91 obj2_shapes.push_back(thin_box);
92 obj2_poses.push_back(thin_box_pose);
94 checker.addCollisionObject(
"thin_box_link", 0, obj2_shapes, obj2_poses);
102 Eigen::Isometry3d sphere1_pose;
103 sphere1_pose.setIdentity();
104 sphere1_pose.translation()[2] = 0.25;
108 obj3_shapes.push_back(sphere1);
109 obj3_poses.push_back(sphere1_pose);
111 checker.addCollisionObject(
"sphere1_link", 0, obj3_shapes, obj3_poses);
112 EXPECT_TRUE(checker.isCollisionObjectEnabled(
"sphere1_link"));
117 inline void runTest(DiscreteContactManager& checker)
125 std::vector<std::string> active_links{
"sphere_link",
"sphere1_link" };
126 checker.setActiveCollisionObjects(active_links);
127 std::vector<std::string> check_active_links = checker.getActiveCollisionObjects();
128 EXPECT_TRUE(tesseract_common::isIdentical<std::string>(active_links, check_active_links,
false));
130 EXPECT_TRUE(checker.getContactAllowedValidator() ==
nullptr);
132 checker.setDefaultCollisionMargin(0.5);
133 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.5, 1e-5);
134 EXPECT_TRUE(checker.isCollisionObjectEnabled(
"thin_box_link"));
136 ContactManagerConfig config;
137 config.modify_object_enabled[
"thin_box_link"] =
false;
139 checker.applyContactManagerConfig(config);
140 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.5, 1e-5);
141 EXPECT_FALSE(checker.isCollisionObjectEnabled(
"thin_box_link"));
143 config.default_margin = 0.1;
144 checker.applyContactManagerConfig(config);
145 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.1, 1e-5);
149 location[
"sphere_link"] = Eigen::Isometry3d::Identity();
150 location[
"sphere1_link"] = Eigen::Isometry3d::Identity();
151 location[
"sphere1_link"].translation()(0) = 0.2;
152 checker.setCollisionObjectsTransform(location);
155 ContactResultMap result;
159 result.flattenMoveResults(result_vector);
162 EXPECT_NEAR(result_vector[0].distance, -0.30, 0.0001);
164 std::vector<int> idx = { 0, 1, 1 };
165 if (result_vector[0].link_names[0] !=
"sphere_link")
168 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.25, 0.001);
169 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
170 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.0, 0.001);
171 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.05, 0.001);
172 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
173 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.0, 0.001);
175 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
176 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
177 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.0016);
183 location[
"sphere1_link"].translation() = Eigen::Vector3d(1, 0, 0);
185 result_vector.clear();
186 checker.setCollisionObjectsTransform(
"sphere1_link", location[
"sphere1_link"]);
189 result.flattenCopyResults(result_vector);
197 result_vector.clear();
199 config = ContactManagerConfig(0.52);
200 checker.applyContactManagerConfig(config);
201 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.52, 1e-5);
203 result.flattenMoveResults(result_vector);
206 EXPECT_NEAR(result_vector[0].distance, 0.5, 0.0001);
209 if (result_vector[0].link_names[0] !=
"sphere_link")
212 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.25, 0.001);
213 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
214 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.0, 0.001);
215 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], 0.75, 0.001);
216 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
217 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.0, 0.001);
219 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
220 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
221 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
224 inline void runTest(ContinuousContactManager& checker)
232 std::vector<std::string> active_links{
"sphere_link",
"sphere1_link" };
233 checker.setActiveCollisionObjects(active_links);
234 std::vector<std::string> check_active_links = checker.getActiveCollisionObjects();
235 EXPECT_TRUE(tesseract_common::isIdentical<std::string>(active_links, check_active_links,
false));
237 EXPECT_TRUE(checker.getContactAllowedValidator() ==
nullptr);
239 checker.setDefaultCollisionMargin(0.5);
240 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.5, 1e-5);
241 EXPECT_TRUE(checker.isCollisionObjectEnabled(
"thin_box_link"));
243 ContactManagerConfig config;
244 config.modify_object_enabled[
"thin_box_link"] =
false;
246 checker.applyContactManagerConfig(config);
247 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.5, 1e-5);
248 EXPECT_FALSE(checker.isCollisionObjectEnabled(
"thin_box_link"));
250 config.default_margin = 0.1;
251 checker.applyContactManagerConfig(config);
252 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.1, 1e-5);
256 location_start[
"sphere_link"] = Eigen::Isometry3d::Identity();
257 location_start[
"sphere_link"].translation()(0) = -0.2;
258 location_start[
"sphere_link"].translation()(1) = -1.0;
260 location_start[
"sphere1_link"] = Eigen::Isometry3d::Identity();
261 location_start[
"sphere1_link"].translation()(0) = 0.2;
262 location_start[
"sphere1_link"].translation()(2) = -1.0;
266 location_end[
"sphere_link"] = Eigen::Isometry3d::Identity();
267 location_end[
"sphere_link"].translation()(0) = -0.2;
268 location_end[
"sphere_link"].translation()(1) = 1.0;
270 location_end[
"sphere1_link"] = Eigen::Isometry3d::Identity();
271 location_end[
"sphere1_link"].translation()(0) = 0.2;
272 location_end[
"sphere1_link"].translation()(2) = 1.0;
274 checker.setCollisionObjectsTransform(location_start, location_end);
277 ContactResultMap result;
281 result.flattenCopyResults(result_vector);
284 EXPECT_NEAR(result_vector[0].distance, -0.1, 0.0001);
286 std::vector<int> idx = { 0, 1, 1 };
287 if (result_vector[0].link_names[0] !=
"sphere_link")
290 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[0])], 0.5, 0.001);
291 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[1])], 0.5, 0.001);
293 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
295 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
298 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.05, 0.001);
299 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
300 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
302 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.05, 0.001);
303 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
304 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
306 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][0], 0.25, 0.001);
307 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
308 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
309 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][0], -0.25, 0.001);
310 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
311 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
313 EXPECT_TRUE(result_vector[0].transform[
static_cast<size_t>(idx[0])].isApprox(location_start[
"sphere_link"], 0.0001));
314 EXPECT_TRUE(result_vector[0].transform[
static_cast<size_t>(idx[1])].isApprox(location_start[
"sphere1_link"], 0.0001));
315 EXPECT_TRUE(result_vector[0].cc_transform[
static_cast<size_t>(idx[0])].isApprox(location_end[
"sphere_link"], 0.0001));
317 result_vector[0].cc_transform[
static_cast<size_t>(idx[1])].isApprox(location_end[
"sphere1_link"], 0.0001));
319 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
320 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
321 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
328 location_start[
"sphere_link"] = Eigen::Isometry3d::Identity();
329 location_start[
"sphere_link"].translation()(0) = -0.2;
330 location_start[
"sphere_link"].translation()(1) = -0.5;
332 location_start[
"sphere1_link"] = Eigen::Isometry3d::Identity();
333 location_start[
"sphere1_link"].translation()(0) = 0.2;
334 location_start[
"sphere1_link"].translation()(2) = -1.0;
337 location_end[
"sphere_link"] = Eigen::Isometry3d::Identity();
338 location_end[
"sphere_link"].translation()(0) = -0.2;
339 location_end[
"sphere_link"].translation()(1) = 1.0;
341 location_end[
"sphere1_link"] = Eigen::Isometry3d::Identity();
342 location_end[
"sphere1_link"].translation()(0) = 0.2;
343 location_end[
"sphere1_link"].translation()(2) = 1.0;
345 checker.setCollisionObjectsTransform(location_start, location_end);
349 result_vector.clear();
352 result.flattenMoveResults(result_vector);
355 EXPECT_NEAR(result_vector[0].distance, -0.1, 0.0001);
358 if (result_vector[0].link_names[0] !=
"sphere_link")
361 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[0])], 0.3333, 0.001);
362 EXPECT_NEAR(result_vector[0].cc_time[
static_cast<size_t>(idx[1])], 0.5, 0.001);
364 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[0]))] ==
366 EXPECT_TRUE(result_vector[0].cc_type[
static_cast<size_t>(
static_cast<size_t>(idx[1]))] ==
369 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][0], 0.05, 0.001);
370 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
371 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
373 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][0], -0.05, 0.001);
374 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
375 EXPECT_NEAR(result_vector[0].nearest_points[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
377 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][0], 0.25, 0.001);
378 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][1], 0.0, 0.001);
379 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[0])][2], 0.25, 0.001);
380 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][0], -0.25, 0.001);
381 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][1], 0.0, 0.001);
382 EXPECT_NEAR(result_vector[0].nearest_points_local[
static_cast<size_t>(idx[1])][2], 0.25, 0.001);
384 EXPECT_TRUE(result_vector[0].transform[
static_cast<size_t>(idx[0])].isApprox(location_start[
"sphere_link"], 0.0001));
385 EXPECT_TRUE(result_vector[0].transform[
static_cast<size_t>(idx[1])].isApprox(location_start[
"sphere1_link"], 0.0001));
386 EXPECT_TRUE(result_vector[0].cc_transform[
static_cast<size_t>(idx[0])].isApprox(location_end[
"sphere_link"], 0.0001));
388 result_vector[0].cc_transform[
static_cast<size_t>(idx[1])].isApprox(location_end[
"sphere1_link"], 0.0001));
390 EXPECT_NEAR(result_vector[0].normal[0], idx[2] * 1.0, 0.001);
391 EXPECT_NEAR(result_vector[0].normal[1], idx[2] * 0.0, 0.001);
392 EXPECT_NEAR(result_vector[0].normal[2], idx[2] * 0.0, 0.001);
395 #endif // TESSERACT_COLLISION_CONTACT_MANAGER_CONFIG_UNIT_H