Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
collision_multi_threaded_unit.hpp
Go to the documentation of this file.
1#ifndef TESSERACT_COLLISION_COLLISION_MULTI_THREADED_UNIT_HPP
2#define TESSERACT_COLLISION_COLLISION_MULTI_THREADED_UNIT_HPP
3
6#include <console_bridge/console.h>
7#include <chrono>
9
14
16{
17inline void runTest(DiscreteContactManager& checker, bool use_convex_mesh = false)
18{
19 // Add Meshed Sphere to checker
21 if (use_convex_mesh)
22 {
23 auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
24 auto mesh_faces = std::make_shared<Eigen::VectorXi>();
26 std::string(TESSERACT_SUPPORT_DIR) + "/meshes/sphere_p25m.ply", *mesh_vertices, *mesh_faces, true),
27 0);
28
29 auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
31 }
32 else
33 {
34 sphere = std::make_shared<tesseract_geometry::Sphere>(0.25);
35 }
36
37 double delta = 0.55;
38
39 std::size_t t = 10;
40 std::vector<std::string> link_names;
42 for (std::size_t x = 0; x < t; ++x)
43 {
44 for (std::size_t y = 0; y < t; ++y)
45 {
46 for (std::size_t z = 0; z < t; ++z)
47 {
48 CollisionShapesConst obj3_shapes;
50 Eigen::Isometry3d sphere_pose;
51 sphere_pose.setIdentity();
52
53 obj3_shapes.push_back(CollisionShapePtr(sphere->clone()));
54 obj3_poses.push_back(sphere_pose);
55
56 link_names.push_back("sphere_link_" + std::to_string(x) + std::to_string(y) + std::to_string(z));
57
58 location[link_names.back()] = sphere_pose;
59 location[link_names.back()].translation() = Eigen::Vector3d(
60 static_cast<double>(x) * delta, static_cast<double>(y) * delta, static_cast<double>(z) * delta);
61 checker.addCollisionObject(link_names.back(), 0, obj3_shapes, obj3_poses);
62 }
63 }
64 }
65
66 // Check if they are in collision
67 checker.setActiveCollisionObjects(link_names);
68 std::vector<std::string> check_active_links = checker.getActiveCollisionObjects();
70
71 EXPECT_TRUE(checker.getIsContactAllowedFn() == nullptr);
72
73 checker.setCollisionMarginData(CollisionMarginData(0.1));
74 EXPECT_NEAR(checker.getCollisionMarginData().getMaxCollisionMargin(), 0.1, 1e-5);
75 checker.setCollisionObjectsTransform(location);
76
77 long num_threads = 4;
78 std::vector<ContactResultVector> result_vector(static_cast<std::size_t>(num_threads));
79 std::vector<DiscreteContactManager::Ptr> contact_manager(static_cast<std::size_t>(num_threads));
80 contact_manager[0] = checker.clone();
81 contact_manager[1] = checker.clone();
82 contact_manager[2] = checker.clone();
83 contact_manager[3] = checker.clone();
84
85 auto start_time = std::chrono::high_resolution_clock::now();
86
87#pragma omp parallel for num_threads(num_threads) shared(location)
88 for (long i = 0; i < num_threads; ++i) // NOLINT
89 {
90 const int tn = omp_get_thread_num();
91 CONSOLE_BRIDGE_logDebug("Thread (ID: %i): %i of %i", tn, i, num_threads);
92 const DiscreteContactManager::Ptr& manager = contact_manager[static_cast<size_t>(tn)];
93 for (const auto& co : location)
94 {
95 if (tn == 0)
96 {
97 Eigen::Isometry3d pose = co.second;
98 pose.translation()[0] += 0.1;
99 manager->setCollisionObjectsTransform(co.first, pose);
100 }
101 else if (tn == 1)
102 {
103 Eigen::Isometry3d pose = co.second;
104 pose.translation()[1] += 0.1;
105 std::vector<std::string> names = { co.first };
107 manager->setCollisionObjectsTransform(names, transforms);
108 }
109 else if (tn == 2)
110 {
111 Eigen::Isometry3d pose = co.second;
112 pose.translation()[2] += 0.1;
113 manager->setCollisionObjectsTransform(co.first, pose);
114 }
115 else
116 {
117 Eigen::Isometry3d pose = co.second;
118 pose.translation()[0] -= 0.1;
119 std::vector<std::string> names = { co.first };
121 manager->setCollisionObjectsTransform(names, transforms);
122 }
123 }
124
125 ContactResultMap result;
126 manager->contactTest(result, ContactRequest(ContactTestType::ALL));
127 result.flattenMoveResults(result_vector[static_cast<size_t>(tn)]);
128 }
129 auto end_time = std::chrono::high_resolution_clock::now();
130
131 CONSOLE_BRIDGE_logInform("DT: %f ms", std::chrono::duration<double, std::milli>(end_time - start_time).count());
132
133 for (long i = 0; i < num_threads; ++i)
134 {
135 EXPECT_TRUE(result_vector[static_cast<std::size_t>(i)].size() == 2700);
136 }
137}
138} // namespace tesseract_collision::test_suite
139
140#endif // TESSERACT_COLLISION_COLLISION_MULTI_THREADED_UNIT_HPP
std::shared_ptr< DiscreteContactManager > Ptr
Definition: discrete_contact_manager.h:47
EXPECT_NEAR(config.contact_manager_config.margin_data.getDefaultCollisionMargin(), 5, 1e-6)
tesseract_collision::ContactResultVector result_vector
Definition: collision_core_unit.cpp:410
results link_names[0]
Definition: collision_core_unit.cpp:146
EXPECT_TRUE(tesseract_common::isIdentical< tesseract_collision::ObjectPairKey >(pairs, check_pairs, false))
This is a collection of common methods.
This is a collection of common methods.
This is the discrete contact manager base class.
Tesseract Geometries.
EXPECT_GT(m.m.condition, 1e+20)
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: large_dataset_benchmarks.hpp:17
void runTest(ContinuousContactManager &checker)
Definition: collision_box_box_cast_unit.hpp:111
tesseract_common::CollisionMarginData CollisionMarginData
Definition: types.h:50
tesseract_geometry::Geometry::Ptr CollisionShapePtr
Definition: types.h:49
std::vector< tesseract_geometry::Geometry::ConstPtr > CollisionShapesConst
Definition: types.h:47
int loadSimplePlyFile(const std::string &path, tesseract_common::VectorVector3d &vertices, Eigen::VectorXi &faces, bool triangles_only=false)
Loads a simple ply file given a path.
Definition: common.cpp:285
tesseract_geometry::ConvexMesh::Ptr makeConvexMesh(const tesseract_geometry::Mesh &mesh)
Definition: convex_hull_utils.cpp:114
AlignedMap< std::string, Eigen::Isometry3d > TransformMap
Definition: types.h:66
template bool isIdentical< std::string >(const std::vector< std::string > &, const std::vector< std::string > &, bool, const std::function< bool(const std::string &, const std::string &)> &, const std::function< bool(const std::string &, const std::string &)> &)
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
Definition: types.h:62
auto pose
Definition: tesseract_environment_collision.cpp:118
DiscreteContactManager::Ptr manager
Definition: tesseract_environment_collision.cpp:109
auto sphere
Definition: tesseract_geometry_unit.cpp:23
auto mesh
Definition: tesseract_geometry_unit.cpp:25