30 #ifndef EXOTICA_CORE_COLLISION_SCENE_H_ 31 #define EXOTICA_CORE_COLLISION_SCENE_H_ 33 #include <Eigen/Dense> 38 #include <unordered_map> 39 #include <unordered_set> 45 #define REGISTER_COLLISION_SCENE_TYPE(TYPE, DERIV) EXOTICA_CORE_REGISTER(exotica::CollisionScene, TYPE, DERIV) 66 inline void setEntry(
const std::string& name1,
const std::string& name2) {
entries_[name1].insert(name2); }
72 names.push_back(it.first);
79 if (it ==
entries_.end())
return true;
80 return it->second.find(name2) == it->second.end();
84 std::unordered_map<std::string, std::unordered_set<std::string>>
entries_;
92 std::shared_ptr<KinematicElement>
e1;
93 std::shared_ptr<KinematicElement>
e2;
100 double penetration_depth = 0.0;
106 std::stringstream ss;
109 ss <<
"ContinuousCollisionProxy: '" << e1->segment.getName() <<
"' - '" << e2->segment.getName() <<
" in_collision: " << in_collision <<
" time_of_contact " << time_of_contact <<
" depth: " << penetration_depth;
113 ss <<
"ContinuousCollisionProxy (empty)";
124 std::shared_ptr<KinematicElement>
e1;
125 std::shared_ptr<KinematicElement>
e2;
134 std::stringstream ss;
137 ss <<
"Proxy: '" << e1->segment.getName() <<
"' - '" << e2->segment.getName() <<
"', c1: " << contact1.transpose() <<
" c2: " << contact2.transpose() <<
" n1: " << normal1.transpose() <<
" n2: " << normal2.transpose() <<
" d: " << distance;
141 ss <<
"Proxy (empty)";
154 virtual void InstantiateBase(
const Initializer& init);
163 virtual bool IsAllowedToCollide(
const std::string& o1,
const std::string& o2,
const bool&
self);
168 virtual bool IsStateValid(
bool self =
true,
double safe_distance = 0.0) = 0;
193 virtual std::vector<CollisionProxy>
GetCollisionDistance(
const std::string& o1,
const bool&
self,
const bool& disable_collision_scene_update) {
ThrowPretty(
"Not implemented!"); }
207 virtual std::vector<std::string> GetCollisionWorldLinks() = 0;
211 virtual std::vector<std::string> GetCollisionRobotLinks() = 0;
225 virtual std::vector<ContinuousCollisionProxy>
ContinuousCollisionCast(
const std::vector<std::vector<std::tuple<std::string, Eigen::Isometry3d, Eigen::Isometry3d>>>& motion_transforms) {
ThrowPretty(
"Not implemented!"); }
228 virtual Eigen::Vector3d GetTranslation(
const std::string& name) = 0;
238 always_externally_updated_collision_scene_ = value;
245 ThrowPretty(
"Link scaling needs to be greater than or equal to 0");
246 robot_link_scale_ = scale;
247 needs_update_of_collision_objects_ =
true;
254 ThrowPretty(
"Link scaling needs to be greater than or equal to 0");
255 world_link_scale_ = scale;
256 needs_update_of_collision_objects_ =
true;
263 HIGHLIGHT_NAMED(
"SetRobotLinkPadding",
"Generally, padding should be positive.");
264 robot_link_padding_ = padding;
265 needs_update_of_collision_objects_ =
true;
272 HIGHLIGHT_NAMED(
"SetRobotLinkPadding",
"Generally, padding should be positive.");
273 world_link_padding_ = padding;
274 needs_update_of_collision_objects_ =
true;
280 replace_primitive_shapes_with_meshes_ = value;
281 needs_update_of_collision_objects_ =
true;
286 virtual void UpdateCollisionObjects(
const std::map<std::string, std::weak_ptr<KinematicElement>>& objects) = 0;
289 virtual void UpdateCollisionObjectTransforms() = 0;
294 replace_cylinders_with_capsules_ = value;
295 needs_update_of_collision_objects_ =
true;
308 bool needs_update_of_collision_objects_ =
true;
317 bool always_externally_updated_collision_scene_ =
false;
320 double robot_link_scale_ = 1.0;
323 double world_link_scale_ = 1.0;
326 double robot_link_padding_ = 0.0;
329 double world_link_padding_ = 0.0;
332 bool replace_primitive_shapes_with_meshes_ =
false;
335 bool replace_cylinders_with_capsules_ =
false;
338 std::string robot_link_replacement_config_ =
"";
344 #endif // EXOTICA_CORE_COLLISION_SCENE_H_
virtual std::vector< CollisionProxy > GetRobotToRobotCollisionDistance(double check_margin)
Gets the closest distances between links within the robot that are closer than check_margin.
Eigen::Vector3d contact_pos
bool GetAlwaysExternallyUpdatedCollisionScene() const
virtual std::vector< CollisionProxy > GetCollisionDistance(bool self)
Computes collision distances.
void SetWorldLinkPadding(const double padding)
std::weak_ptr< Scene > scene_
Stores a pointer to the Scene which owns this CollisionScene.
The class of collision scene.
void SetRobotLinkPadding(const double padding)
std::string Print() const
void AssignScene(std::shared_ptr< Scene > scene)
Sets a scene pointer to the CollisionScene for access to methods.
virtual ContinuousCollisionProxy ContinuousCollisionCheck(const std::string &o1, const KDL::Frame &tf1_beg, const KDL::Frame &tf1_end, const std::string &o2, const KDL::Frame &tf2_beg, const KDL::Frame &tf2_end)
Performs a continuous collision check between two objects with a linear interpolation between two giv...
double GetRobotLinkScale() const
virtual std::vector< ContinuousCollisionProxy > ContinuousCollisionCast(const std::vector< std::vector< std::tuple< std::string, Eigen::Isometry3d, Eigen::Isometry3d >>> &motion_transforms)
Performs a continuous collision check by casting the active objects passed in against the static envi...
void SetACM(const AllowedCollisionMatrix &acm)
AllowedCollisionMatrix & operator=(const AllowedCollisionMatrix &other)
std::shared_ptr< KinematicElement > e1
void SetWorldLinkScale(const double scale)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW ContinuousCollisionProxy()
virtual std::vector< CollisionProxy > GetCollisionDistance(const std::vector< std::string > &objects, const bool &self)
Gets the closest distance of any collision object which is allowed to collide with any collision obje...
virtual ~CollisionScene()
bool hasEntry(const std::string &name) const
void SetAlwaysExternallyUpdatedCollisionScene(const bool value)
void set_replace_cylinders_with_capsules(const bool value)
std::string Print() const
bool get_replace_cylinders_with_capsules() const
bool GetReplacePrimitiveShapesWithMeshes() const
The class of EXOTica Scene.
void setEntry(const std::string &name1, const std::string &name2)
size_t getNumberOfEntries() const
virtual std::vector< CollisionProxy > GetCollisionDistance(const std::string &o1, const std::string &o2)
Computes collision distances between two objects.
virtual std::vector< CollisionProxy > GetCollisionDistance(const std::string &o1, const bool &self)
Gets the closest distance of any collision object which is allowed to collide with any collision obje...
~AllowedCollisionMatrix()
double GetRobotLinkPadding() const
#define HIGHLIGHT_NAMED(name, x)
virtual std::vector< CollisionProxy > GetRobotToWorldCollisionDistance(double check_margin)
Gets the closest distances between links of the robot and the environment that are closer than check_...
std::shared_ptr< CollisionScene > CollisionScenePtr
Eigen::Vector3d contact_normal
AllowedCollisionMatrix acm_
The allowed collision matrix.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CollisionProxy()
double GetWorldLinkScale() const
virtual bool IsCollisionFree(const std::string &o1, const std::string &o2, double safe_distance=0.0)
Checks if two objects are in collision.
virtual std::vector< CollisionProxy > GetCollisionDistance(const std::string &o1, const bool &self, const bool &disable_collision_scene_update)
Gets the closest distance of any collision object which is allowed to collide with any collision obje...
bool getAllowedCollision(const std::string &name1, const std::string &name2) const
std::shared_ptr< KinematicElement > e2
void getAllEntryNames(std::vector< std::string > &names) const
double distance(const urdf::Pose &transform)
virtual void Setup()
Setup additional construction that requires initialiser parameter.
void SetRobotLinkScale(const double scale)
std::shared_ptr< KinematicElement > e2
std::shared_ptr< KinematicElement > e1
std::unordered_map< std::string, std::unordered_set< std::string > > entries_
AllowedCollisionMatrix(const AllowedCollisionMatrix &acm)
void SetReplacePrimitiveShapesWithMeshes(const bool value)
double GetWorldLinkPadding() const