convex_concave_unit.cpp
Go to the documentation of this file.
3 #include <gtest/gtest.h>
5 
6 #include "tesseract_collision/bullet/bullet_contact_checker.h"
7 
8 TEST(TesseractConvexConcaveUnit, ConvexConcaveUnit)
9 {
10  tesseract::BulletContactChecker checker;
11 
12  // Add box to checker
13  tesseract::CollisionShapePtr box = std::make_shared<shapes::Box>(1, 1, 1);
14  Eigen::Isometry3d box_pose;
15  box_pose.setIdentity();
16 
18  VectorIsometry3d obj1_poses;
19  tesseract::CollisionObjectTypeVector obj1_types;
20  obj1_shapes.push_back(box);
21  obj1_poses.push_back(box_pose);
22  obj1_types.push_back(tesseract::CollisionObjectType::UseShapeType);
23 
24  checker.addObject("box_link", 0, obj1_shapes, obj1_poses, obj1_types);
25 
26  // Add box to checker
27  tesseract::CollisionShapePtr thin_box = std::make_shared<shapes::Box>(0.1, 1, 1);
28  Eigen::Isometry3d thin_box_pose;
29  thin_box_pose.setIdentity();
30 
32  VectorIsometry3d obj2_poses;
33  tesseract::CollisionObjectTypeVector obj2_types;
34  obj2_shapes.push_back(thin_box);
35  obj2_poses.push_back(thin_box_pose);
36  obj2_types.push_back(tesseract::CollisionObjectType::UseShapeType);
37 
38  checker.addObject("thin_box_link", 0, obj2_shapes, obj2_poses, obj2_types);
39 
40  // Add Meshed Sphere to checker
41  tesseract::CollisionShapePtr sphere(shapes::createMeshFromResource("package://tesseract_collision/test/sphere.stl"));
42  Eigen::Isometry3d sphere_pose;
43  sphere_pose.setIdentity();
44 
46  VectorIsometry3d obj3_poses;
47  tesseract::CollisionObjectTypeVector obj3_types;
48  obj3_shapes.push_back(sphere);
49  obj3_poses.push_back(sphere_pose);
50  // Since this is a mesh this will be considered a concave shape
51  obj3_types.push_back(tesseract::CollisionObjectType::UseShapeType);
52 
53  checker.addObject("sphere_link", 0, obj3_shapes, obj3_poses, obj3_types);
54 
55  // Check if they are in collision
56  tesseract::ContactRequest req;
57  req.link_names.push_back("box_link");
58  req.link_names.push_back("sphere_link");
59  req.contact_distance = 0.1;
60  req.type = tesseract::ContactRequestType::CLOSEST;
61 
62  // Test when object is inside another
63  tesseract::TransformMap location;
64  location["box_link"] = Eigen::Isometry3d::Identity();
65  location["sphere_link"] = Eigen::Isometry3d::Identity();
66 
67  tesseract::ContactResultMap result;
68  checker.calcCollisionsDiscrete(req, location, result);
69 
70  tesseract::ContactResultVector result_vector;
71  tesseract::flattenMoveResults(result, result_vector);
72 
73  // This does fail need to create an issue on bullet
74  EXPECT_LT(std::abs(result_vector[0].distance + 0.75), 0.0001);
75  EXPECT_TRUE(!result_vector.empty());
76 
77  // Test object is out side the contact distance
78  location["sphere_link"].translation() = Eigen::Vector3d(1, 0, 0);
79  result.clear();
80  result_vector.clear();
81 
82  checker.calcCollisionsDiscrete(req, location, result);
83  tesseract::flattenMoveResults(result, result_vector);
84 
85  EXPECT_TRUE(result_vector.empty());
86 
87  // Test object right at the contact distance
88  result.clear();
89  result_vector.clear();
90  req.contact_distance = 0.251;
91 
92  checker.calcCollisionsDiscrete(req, location, result);
93  tesseract::flattenMoveResults(result, result_vector);
94 
95  EXPECT_LT(std::abs(0.25 - result_vector[0].distance), 0.0001);
96  EXPECT_TRUE(!result_vector.empty());
97 
98  // // Test Cast object
99  // result.clear();
100  // result_vector.clear();
101  // tesseract::TransformMap location2;
102  // location.clear();
103  // location["thin_box_link"] = Eigen::Isometry3d::Identity();
104  // location["sphere_link"] = Eigen::Isometry3d::Identity();
105  // location2["thin_box_link"] = Eigen::Isometry3d::Identity();
106  // location2["sphere_link"] = Eigen::Isometry3d::Identity();
107 
108  // location["sphere_link"].translation() = Eigen::Vector3d(1, 0, 0);
109  // location2["sphere_link"].translation() = Eigen::Vector3d(-1, 0, 0);
110 
111  // req.link_names.clear();
112  // req.link_names.push_back("sphere_link");
113  // req.contact_distance = 0.1;
114  // req.type = tesseract::ContactRequestType::SINGLE;
115 
116  // checker.calcCollisionsContinuous(req, location, location2, result);
117  // tesseract::flattenMoveResults(result,
118  // result_vector);
119  // EXPECT_TRUE(!result_vector.empty());
120 }
121 
122 int main(int argc, char** argv)
123 {
124  testing::InitGoogleTest(&argc, argv);
125 
126  return RUN_ALL_TESTS();
127 }
VectorIsometry3d
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
main
int main(int argc, char **argv)
Definition: convex_concave_unit.cpp:122
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_collision::ContactResultVector
tesseract_common::AlignedVector< ContactResult > ContactResultVector
Definition: types.h:136
EXPECT_TRUE
#define EXPECT_TRUE(args)
TEST
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH TESSERACT_COMMON_IGNORE_WARNINGS_POP TEST(TesseractConvexConcaveUnit, ConvexConcaveUnit)
Definition: convex_concave_unit.cpp:8
tesseract_collision::CollisionShapePtr
std::shared_ptr< tesseract_geometry::Geometry > CollisionShapePtr
Definition: types.h:50
tesseract_collision::CollisionShapesConst
std::vector< CollisionShapeConstPtr > CollisionShapesConst
Definition: types.h:51
TESSERACT_COMMON_IGNORE_WARNINGS_POP
Definition: create_convex_hull.cpp:37
distance
template void distance(DistanceTraversalNodeBase< double > *node, BVHFrontList *front_list, int qsize)
macros.h


tesseract_collision
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:52