Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
fcl_utils.h
Go to the documentation of this file.
1
42#ifndef TESSERACT_COLLISION_FCL_UTILS_H
43#define TESSERACT_COLLISION_FCL_UTILS_H
44
47#include <fcl/broadphase/broadphase_dynamic_AABB_tree-inl.h>
48#include <fcl/narrowphase/collision-inl.h>
49#include <fcl/narrowphase/distance-inl.h>
50#include <memory>
51#include <set>
52#include <console_bridge/console.h>
54
58
60{
61using CollisionGeometryPtr = std::shared_ptr<fcl::CollisionGeometryd>;
62using CollisionObjectPtr = std::shared_ptr<FCLCollisionObjectWrapper>;
63using CollisionObjectRawPtr = fcl::CollisionObjectd*;
64using CollisionObjectConstPtr = std::shared_ptr<const fcl::CollisionObjectd>;
65
67{
71 AllFilter = -1 // all bits sets: DefaultFilter | StaticFilter | KinematicFilter
72};
73
79{
80public:
81 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
82
83 using Ptr = std::shared_ptr<CollisionObjectWrapper>;
84 using ConstPtr = std::shared_ptr<const CollisionObjectWrapper>;
85
87 CollisionObjectWrapper(std::string name,
88 const int& type_id,
91
94 bool m_enabled{ true };
95
96 const std::string& getName() const { return name_; }
97 const int& getTypeID() const { return type_id_; }
99 bool sameObject(const CollisionObjectWrapper& other) const
100 {
101 return name_ == other.name_ && type_id_ == other.type_id_ && shapes_.size() == other.shapes_.size() &&
102 shape_poses_.size() == other.shape_poses_.size() &&
103 std::equal(shapes_.begin(), shapes_.end(), other.shapes_.begin()) &&
104 std::equal(shape_poses_.begin(),
105 shape_poses_.end(),
106 other.shape_poses_.begin(),
107 [](const Eigen::Isometry3d& t1, const Eigen::Isometry3d& t2) { return t1.isApprox(t2); });
108 }
109
111
113
114 void setCollisionObjectsTransform(const Eigen::Isometry3d& pose)
115 {
117 for (unsigned i = 0; i < collision_objects_.size(); ++i)
118 {
120 co->setTransform(pose * shape_poses_[i]);
121 co->updateAABB(); // This a tesseract function that updates abb to take into account contact distance
122 }
123 }
124
125 void setContactDistanceThreshold(double contact_distance)
126 {
127 contact_distance_ = contact_distance;
128 for (auto& co : collision_objects_)
129 co->setContactDistanceThreshold(contact_distance_);
130 }
131
133 const Eigen::Isometry3d& getCollisionObjectsTransform() const { return world_pose_; }
134 const std::vector<CollisionObjectPtr>& getCollisionObjects() const { return collision_objects_; }
135 std::vector<CollisionObjectPtr>& getCollisionObjects() { return collision_objects_; }
136 const std::vector<CollisionObjectRawPtr>& getCollisionObjectsRaw() const { return collision_objects_raw_; }
137 std::vector<CollisionObjectRawPtr>& getCollisionObjectsRaw() { return collision_objects_raw_; }
138 std::shared_ptr<CollisionObjectWrapper> clone() const
139 {
140 auto clone_cow = std::make_shared<CollisionObjectWrapper>();
141 clone_cow->name_ = name_;
142 clone_cow->type_id_ = type_id_;
143 clone_cow->shapes_ = shapes_;
144 clone_cow->shape_poses_ = shape_poses_;
145 clone_cow->collision_geometries_ = collision_geometries_;
146
147 clone_cow->collision_objects_.reserve(collision_objects_.size());
148 clone_cow->collision_objects_raw_.reserve(collision_objects_.size());
149 for (const auto& co : collision_objects_)
150 {
151 assert(std::dynamic_pointer_cast<FCLCollisionObjectWrapper>(co) != nullptr);
152 auto collObj =
153 std::make_shared<FCLCollisionObjectWrapper>(*std::static_pointer_cast<FCLCollisionObjectWrapper>(co));
154 collObj->setUserData(clone_cow.get());
155 collObj->setTransform(co->getTransform());
156 collObj->updateAABB();
157 clone_cow->collision_objects_.push_back(collObj);
158 clone_cow->collision_objects_raw_.push_back(collObj.get());
159 }
160
161 clone_cow->m_collisionFilterGroup = m_collisionFilterGroup;
162 clone_cow->m_collisionFilterMask = m_collisionFilterMask;
163 clone_cow->m_enabled = m_enabled;
164 return clone_cow;
165 }
166
172 int getShapeIndex(const fcl::CollisionObjectd* co) const;
173
174protected:
175 std::string name_; // name of the collision object
176 int type_id_{ -1 }; // user defined type id
177 Eigen::Isometry3d world_pose_{ Eigen::Isometry3d::Identity() };
180 std::vector<CollisionGeometryPtr> collision_geometries_;
181 std::vector<CollisionObjectPtr> collision_objects_;
186 std::vector<CollisionObjectRawPtr> collision_objects_raw_;
187
188 double contact_distance_{ 0 };
189};
190
192
194using Link2COW = std::map<std::string, COW::Ptr>;
195using Link2ConstCOW = std::map<std::string, COW::ConstPtr>;
196
197inline COW::Ptr createFCLCollisionObject(const std::string& name,
198 const int& type_id,
199 const CollisionShapesConst& shapes,
200 const tesseract_common::VectorIsometry3d& shape_poses,
201 bool enabled)
202{
203 // dont add object that does not have geometry
204 if (shapes.empty() || shape_poses.empty() || (shapes.size() != shape_poses.size()))
205 {
206 CONSOLE_BRIDGE_logDebug("ignoring link %s", name.c_str());
207 return nullptr;
208 }
209
210 auto new_cow = std::make_shared<COW>(name, type_id, shapes, shape_poses);
211
212 new_cow->m_enabled = enabled;
213 CONSOLE_BRIDGE_logDebug("Created collision object for link %s", new_cow->getName().c_str());
214 return new_cow;
215}
216
224inline void updateCollisionObjectFilters(const std::vector<std::string>& active,
225 const COW::Ptr& cow,
226 const std::unique_ptr<fcl::BroadPhaseCollisionManagerd>& static_manager,
227 const std::unique_ptr<fcl::BroadPhaseCollisionManagerd>& dynamic_manager)
228{
229 // For descrete checks we can check static to kinematic and kinematic to
230 // kinematic
231 if (!isLinkActive(active, cow->getName()))
232 {
233 if (cow->m_collisionFilterGroup != CollisionFilterGroups::StaticFilter)
234 {
235 std::vector<CollisionObjectPtr>& objects = cow->getCollisionObjects();
236 // This link was dynamic but is now static
237 for (auto& co : objects)
238 dynamic_manager->unregisterObject(co.get());
239
240 for (auto& co : objects)
241 static_manager->registerObject(co.get());
242 }
243 cow->m_collisionFilterGroup = CollisionFilterGroups::StaticFilter;
244 }
245 else
246 {
247 if (cow->m_collisionFilterGroup != CollisionFilterGroups::KinematicFilter)
248 {
249 std::vector<CollisionObjectPtr>& objects = cow->getCollisionObjects();
250 // This link was static but is now dynamic
251 for (auto& co : objects)
252 static_manager->unregisterObject(co.get());
253
254 for (auto& co : objects)
255 dynamic_manager->registerObject(co.get());
256 }
257 cow->m_collisionFilterGroup = CollisionFilterGroups::KinematicFilter;
258 }
259
260 // If the group is StaticFilter then the Mask is KinematicFilter, then StaticFilter groups can only collide with
261 // KinematicFilter groups. If the group is KinematicFilter then the mask is StaticFilter and KinematicFilter meaning
262 // that KinematicFilter groups can collide with both StaticFilter and KinematicFilter groups.
263 if (cow->m_collisionFilterGroup == CollisionFilterGroups::StaticFilter)
264 {
265 cow->m_collisionFilterMask = CollisionFilterGroups::KinematicFilter;
266 }
267 else
268 {
270 }
271}
272
273bool collisionCallback(fcl::CollisionObjectd* o1, fcl::CollisionObjectd* o2, void* data);
274
275bool distanceCallback(fcl::CollisionObjectd* o1, fcl::CollisionObjectd* o2, void* data);
276
277} // namespace tesseract_collision::tesseract_collision_fcl
278#endif // TESSERACT_COLLISION_FCL_UTILS_H
This is a Tesseract link collision object wrapper which add items specific to tesseract....
Definition: fcl_utils.h:79
std::shared_ptr< const CollisionObjectWrapper > ConstPtr
Definition: fcl_utils.h:84
CollisionShapesConst shapes_
Definition: fcl_utils.h:178
std::shared_ptr< CollisionObjectWrapper > clone() const
Definition: fcl_utils.h:138
void setCollisionObjectsTransform(const Eigen::Isometry3d &pose)
Definition: fcl_utils.h:114
double contact_distance_
The contact distance threshold.
Definition: fcl_utils.h:188
void setContactDistanceThreshold(double contact_distance)
Definition: fcl_utils.h:125
std::vector< CollisionObjectPtr > & getCollisionObjects()
Definition: fcl_utils.h:135
bool sameObject(const CollisionObjectWrapper &other) const
Check if two objects point to the same source object.
Definition: fcl_utils.h:99
const CollisionShapesConst & getCollisionGeometries() const
Definition: fcl_utils.h:110
std::vector< CollisionObjectPtr > collision_objects_
Definition: fcl_utils.h:181
int getShapeIndex(const fcl::CollisionObjectd *co) const
Given fcl collision shape get the index to the links collision shape.
Definition: fcl_utils.cpp:368
std::vector< CollisionObjectRawPtr > & getCollisionObjectsRaw()
Definition: fcl_utils.h:137
const tesseract_common::VectorIsometry3d & getCollisionGeometriesTransforms() const
Definition: fcl_utils.h:112
const std::string & getName() const
Definition: fcl_utils.h:96
std::vector< CollisionObjectRawPtr > collision_objects_raw_
The raw pointer is also stored because FCL accepts vectors for batch process. Note: They are updating...
Definition: fcl_utils.h:186
std::shared_ptr< CollisionObjectWrapper > Ptr
Definition: fcl_utils.h:83
const std::vector< CollisionObjectPtr > & getCollisionObjects() const
Definition: fcl_utils.h:134
const int & getTypeID() const
Definition: fcl_utils.h:97
double getContactDistanceThreshold() const
Definition: fcl_utils.h:132
std::vector< CollisionGeometryPtr > collision_geometries_
Definition: fcl_utils.h:180
Eigen::Isometry3d world_pose_
Collision Object World Transformation.
Definition: fcl_utils.h:177
tesseract_common::VectorIsometry3d shape_poses_
Definition: fcl_utils.h:179
const std::vector< CollisionObjectRawPtr > & getCollisionObjectsRaw() const
Definition: fcl_utils.h:136
const Eigen::Isometry3d & getCollisionObjectsTransform() const
Definition: fcl_utils.h:133
results type_id[0]
Definition: collision_core_unit.cpp:152
CollisionMarginData data(default_margin)
Definition: collision_margin_data_unit.cpp:34
This is a collection of common methods.
Collision Object Wrapper to modify AABB with contact distance threshold.
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: fcl_collision_object_wrapper.h:36
std::shared_ptr< FCLCollisionObjectWrapper > CollisionObjectPtr
Definition: fcl_utils.h:62
void updateCollisionObjectFilters(const std::vector< std::string > &active, const COW::Ptr &cow, const std::unique_ptr< fcl::BroadPhaseCollisionManagerd > &static_manager, const std::unique_ptr< fcl::BroadPhaseCollisionManagerd > &dynamic_manager)
Update collision objects filters.
Definition: fcl_utils.h:224
std::map< std::string, COW::Ptr > Link2COW
Definition: fcl_utils.h:194
fcl::CollisionObjectd * CollisionObjectRawPtr
Definition: fcl_utils.h:63
std::map< std::string, COW::ConstPtr > Link2ConstCOW
Definition: fcl_utils.h:195
CollisionGeometryPtr createShapePrimitive(const CollisionShapeConstPtr &geom)
Definition: fcl_utils.cpp:153
std::shared_ptr< const fcl::CollisionObjectd > CollisionObjectConstPtr
Definition: fcl_utils.h:64
COW::Ptr createFCLCollisionObject(const std::string &name, const int &type_id, const CollisionShapesConst &shapes, const tesseract_common::VectorIsometry3d &shape_poses, bool enabled)
Definition: fcl_utils.h:197
bool collisionCallback(fcl::CollisionObjectd *o1, fcl::CollisionObjectd *o2, void *data)
Definition: fcl_utils.cpp:202
std::shared_ptr< fcl::CollisionGeometryd > CollisionGeometryPtr
Definition: fcl_utils.h:61
bool distanceCallback(fcl::CollisionObjectd *o1, fcl::CollisionObjectd *o2, void *data)
Definition: fcl_utils.cpp:271
CollisionFilterGroups
Definition: fcl_utils.h:67
@ KinematicFilter
Definition: fcl_utils.h:70
@ StaticFilter
Definition: fcl_utils.h:69
@ DefaultFilter
Definition: fcl_utils.h:68
@ AllFilter
Definition: fcl_utils.h:71
tesseract_geometry::Geometry::ConstPtr CollisionShapeConstPtr
Definition: types.h:48
std::vector< tesseract_geometry::Geometry::ConstPtr > CollisionShapesConst
Definition: types.h:47
bool isLinkActive(const std::vector< std::string > &active, const std::string &name)
This will check if a link is active provided a list. If the list is empty the link is considered acti...
Definition: common.cpp:79
AlignedVector< Eigen::Isometry3d > VectorIsometry3d
Definition: types.h:62
Tesseracts Collision Common Types.
auto pose
Definition: tesseract_environment_collision.cpp:118
auto geom
Definition: tesseract_geometry_unit.cpp:51