Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
collision_octomap_sphere_unit.hpp
Go to the documentation of this file.
1#ifndef TESSERACT_COLLISION_COLLISION_OCTOMAP_SPHERE_UNIT_HPP
2#define TESSERACT_COLLISION_COLLISION_OCTOMAP_SPHERE_UNIT_HPP
3
6#include <octomap/octomap.h>
7#include <console_bridge/console.h>
8#include <chrono>
10
15
17{
18namespace detail
19{
20inline void addCollisionObjects(DiscreteContactManager& checker, bool use_convex_mesh = false)
21{
23 // Add Octomap
25 std::string path = std::string(TESSERACT_SUPPORT_DIR) + "/meshes/blender_monkey.bt";
26 auto ot = std::make_shared<octomap::OcTree>(path);
27 CollisionShapePtr dense_octomap = std::make_shared<tesseract_geometry::Octree>(ot, tesseract_geometry::Octree::BOX);
28 Eigen::Isometry3d octomap_pose;
29 octomap_pose.setIdentity();
30
31 CollisionShapesConst obj1_shapes;
33 obj1_shapes.push_back(dense_octomap);
34 obj1_poses.push_back(octomap_pose);
35
36 checker.addCollisionObject("octomap_link", 0, obj1_shapes, obj1_poses);
37
39 // Add sphere to checker. If use_convex_mesh = true then this
40 // sphere will be added as a convex hull mesh.
43
44 if (use_convex_mesh)
45 {
46 auto mesh_vertices = std::make_shared<tesseract_common::VectorVector3d>();
47 auto mesh_faces = std::make_shared<Eigen::VectorXi>();
49 std::string(TESSERACT_SUPPORT_DIR) + "/meshes/sphere_p25m.ply", *mesh_vertices, *mesh_faces, true),
50 0);
51
52 auto mesh = std::make_shared<tesseract_geometry::Mesh>(mesh_vertices, mesh_faces);
54 }
55 else
56 {
57 sphere = std::make_shared<tesseract_geometry::Sphere>(0.25);
58 }
59
60 Eigen::Isometry3d sphere_pose;
61 sphere_pose.setIdentity();
62
63 CollisionShapesConst obj2_shapes;
65 obj2_shapes.push_back(sphere);
66 obj2_poses.push_back(sphere_pose);
67
68 checker.addCollisionObject("sphere_link", 0, obj2_shapes, obj2_poses);
69
70 EXPECT_TRUE(checker.getCollisionObjects().size() == 2);
71 for (const auto& co : checker.getCollisionObjects())
72 {
73 EXPECT_TRUE(checker.getCollisionObjectGeometries(co).size() == 1);
74 EXPECT_TRUE(checker.getCollisionObjectGeometriesTransforms(co).size() == 1);
75 for (const auto& cgt : checker.getCollisionObjectGeometriesTransforms(co))
76 {
77 EXPECT_TRUE(cgt.isApprox(Eigen::Isometry3d::Identity(), 1e-5));
78 }
79 }
80}
81
82inline void runTestTyped(DiscreteContactManager& checker, double tol, ContactTestType test_type)
83{
85 // Test when object is in collision
87 std::vector<std::string> active_links{ "octomap_link", "sphere_link" };
89 std::vector<std::string> check_active_links = checker.getActiveCollisionObjects();
91
92 EXPECT_TRUE(checker.getIsContactAllowedFn() == nullptr);
93
96
97 // Set the collision object transforms
99 location["octomap_link"] = Eigen::Isometry3d::Identity();
100 location["sphere_link"] = Eigen::Isometry3d::Identity();
101 location["sphere_link"].translation() = Eigen::Vector3d(0, 0, 1);
102 checker.setCollisionObjectsTransform(location);
103
104 // Perform collision check
105 ContactResultMap result;
106 checker.contactTest(result, ContactRequest(test_type));
107
110
111 EXPECT_TRUE(!result_vector.empty());
112 if (test_type == ContactTestType::CLOSEST)
113 {
114 EXPECT_TRUE(result_vector.size() == 1);
115 EXPECT_NEAR(result_vector[0].distance, -0.25, tol);
116 }
117 else if (test_type == ContactTestType::FIRST)
118 {
119 EXPECT_TRUE(result_vector.size() == 1);
121 }
122 else
123 {
126 }
127}
128} // namespace detail
129
130inline void runTest(DiscreteContactManager& checker, double tol, bool use_convex_mesh)
131{
132 // Add collision objects
133 detail::addCollisionObjects(checker, use_convex_mesh);
134
135 // Call it again to test adding same object
136 detail::addCollisionObjects(checker, use_convex_mesh);
137
141}
142
143} // namespace tesseract_collision::test_suite
144
145#endif // TESSERACT_COLLISION_COLLISION_OCTOMAP_SPHERE_UNIT_HPP
This structure hold contact results for link pairs.
Definition: types.h:154
void flattenMoveResults(ContactResultVector &v)
Definition: types.cpp:215
Definition: discrete_contact_manager.h:41
virtual void setActiveCollisionObjects(const std::vector< std::string > &names)=0
Set which collision objects can move.
virtual void contactTest(ContactResultMap &collisions, const ContactRequest &request)=0
Perform a contact test for all objects based.
virtual void setCollisionObjectsTransform(const std::string &name, const Eigen::Isometry3d &pose)=0
Set a single collision object's transforms.
virtual void setDefaultCollisionMarginData(double default_collision_margin)=0
Set the default collision margin.
virtual const std::vector< std::string > & getActiveCollisionObjects() const =0
Get which collision objects can move.
virtual const CollisionMarginData & getCollisionMarginData() const =0
Get the contact distance threshold.
virtual IsContactAllowedFn getIsContactAllowedFn() const =0
Get the active function for determining if two links are allowed to be in collision.
double getMaxCollisionMargin() const
Get the largest collision margin.
Definition: collision_margin_data.h:165
@ BOX
Definition: octree.h:50
EXPECT_NEAR(config.contact_manager_config.margin_data.getDefaultCollisionMargin(), 5, 1e-6)
tesseract_collision::ContactResultVector result_vector
Definition: collision_core_unit.cpp:410
results distance
Definition: collision_core_unit.cpp:139
EXPECT_FALSE(tesseract_collision::isContactAllowed("base_link", "link_2", acm, false))
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
void runTestTyped(DiscreteContactManager &checker, ContactTestType test_type)
Definition: collision_box_box_unit.hpp:125
void addCollisionObjects(ContinuousContactManager &checker)
Definition: collision_box_box_cast_unit.hpp:11
Definition: large_dataset_benchmarks.hpp:17
void runTest(ContinuousContactManager &checker)
Definition: collision_box_box_cast_unit.hpp:111
tesseract_geometry::Geometry::Ptr CollisionShapePtr
Definition: types.h:49
std::vector< tesseract_geometry::Geometry::ConstPtr > CollisionShapesConst
Definition: types.h:47
tesseract_common::AlignedVector< ContactResult > ContactResultVector
Definition: types.h:134
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
ContactTestType
Definition: types.h:70
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
The ContactRequest struct.
Definition: types.h:294
std::vector< std::string > active_links
Definition: tesseract_environment_collision.cpp:112
auto sphere
Definition: tesseract_geometry_unit.cpp:23
auto mesh
Definition: tesseract_geometry_unit.cpp:25
tesseract_common::fs::path path
Definition: tesseract_srdf_unit.cpp:1992