Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
allowed_collision_matrix.h
Go to the documentation of this file.
1#ifndef TESSERACT_COMMON_ALLOWED_COLLISION_MATRIX_H
2#define TESSERACT_COMMON_ALLOWED_COLLISION_MATRIX_H
3
6#include <boost/serialization/access.hpp>
7#include <string>
8#include <vector>
9#include <memory>
10#include <Eigen/Eigen>
11#include <unordered_map>
14
16{
18 std::unordered_map<tesseract_common::LinkNamesPair, std::string, tesseract_common::PairHash>;
19
20bool operator==(const AllowedCollisionEntries& entries_1, const AllowedCollisionEntries& entries_2);
21
23{
24public:
25 // LCOV_EXCL_START
26 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
27 // LCOV_EXCL_STOP
28
29 using Ptr = std::shared_ptr<AllowedCollisionMatrix>;
30 using ConstPtr = std::shared_ptr<const AllowedCollisionMatrix>;
31
33 virtual ~AllowedCollisionMatrix() = default;
38
45 virtual void addAllowedCollision(const std::string& link_name1,
46 const std::string& link_name2,
47 const std::string& reason)
48 {
49 auto link_pair = tesseract_common::makeOrderedLinkPair(link_name1, link_name2);
50 lookup_table_[link_pair] = reason;
51 }
52
60
66 virtual void removeAllowedCollision(const std::string& link_name1, const std::string& link_name2)
67 {
68 auto link_pair = tesseract_common::makeOrderedLinkPair(link_name1, link_name2);
69 lookup_table_.erase(link_pair);
70 }
71
76 virtual void removeAllowedCollision(const std::string& link_name)
77 {
78 for (auto it = lookup_table_.begin(); it != lookup_table_.end() /* not hoisted */; /* no increment */)
79 {
80 if (it->first.first == link_name || it->first.second == link_name)
81 {
82 it = lookup_table_.erase(it);
83 }
84 else
85 {
86 ++it;
87 }
88 }
89 }
90
97 virtual bool isCollisionAllowed(const std::string& link_name1, const std::string& link_name2) const
98 {
99 thread_local LinkNamesPair link_pair;
100 tesseract_common::makeOrderedLinkPair(link_pair, link_name1, link_name2);
101 return (lookup_table_.find(link_pair) != lookup_table_.end());
102 }
103
109
115 {
116 lookup_table_.insert(acm.getAllAllowedCollisions().begin(), acm.getAllAllowedCollisions().end());
117 }
118
119 friend std::ostream& operator<<(std::ostream& os, const AllowedCollisionMatrix& acm)
120 {
121 for (const auto& pair : acm.getAllAllowedCollisions())
122 os << "link=" << pair.first.first << " link=" << pair.first.second << " reason=" << pair.second << std::endl;
123 return os;
124 }
125 bool operator==(const AllowedCollisionMatrix& rhs) const;
126 bool operator!=(const AllowedCollisionMatrix& rhs) const;
127
128private:
130
132 template <class Archive>
133 void serialize(Archive& ar, const unsigned int version); // NOLINT
134};
135
136} // namespace tesseract_common
137
138#include <boost/serialization/export.hpp>
139#include <boost/serialization/tracking.hpp>
140BOOST_CLASS_EXPORT_KEY2(tesseract_common::AllowedCollisionMatrix, "AllowedCollisionMatrix")
141
142#endif // TESSERACT_SCENE_GRAPH_ALLOWED_COLLISION_MATRIX_H
Definition: allowed_collision_matrix.h:23
void insertAllowedCollisionMatrix(const AllowedCollisionMatrix &acm)
Inserts an allowable collision matrix ignoring duplicate pairs.
Definition: allowed_collision_matrix.h:114
virtual void removeAllowedCollision(const std::string &link_name)
Remove disabled collision for any pair with link_name from allowed collision matrix.
Definition: allowed_collision_matrix.h:76
friend std::ostream & operator<<(std::ostream &os, const AllowedCollisionMatrix &acm)
Definition: allowed_collision_matrix.h:119
AllowedCollisionMatrix & operator=(const AllowedCollisionMatrix &)=default
AllowedCollisionEntries lookup_table_
Definition: allowed_collision_matrix.h:129
bool operator!=(const AllowedCollisionMatrix &rhs) const
Definition: allowed_collision_matrix.cpp:68
std::shared_ptr< const AllowedCollisionMatrix > ConstPtr
Definition: allowed_collision_matrix.h:30
void clearAllowedCollisions()
Clears the list of allowed collisions, so that no collision will be allowed.
Definition: allowed_collision_matrix.h:108
const AllowedCollisionEntries & getAllAllowedCollisions() const
Get all of the entries in the allowed collision matrix.
Definition: allowed_collision_matrix.h:59
AllowedCollisionMatrix(AllowedCollisionMatrix &&)=default
virtual bool isCollisionAllowed(const std::string &link_name1, const std::string &link_name2) const
This checks if two links are allowed to be in collision.
Definition: allowed_collision_matrix.h:97
bool operator==(const AllowedCollisionMatrix &rhs) const
Definition: allowed_collision_matrix.cpp:61
virtual void removeAllowedCollision(const std::string &link_name1, const std::string &link_name2)
Remove disabled collision pair from allowed collision matrix.
Definition: allowed_collision_matrix.h:66
friend class boost::serialization::access
Definition: allowed_collision_matrix.h:131
virtual void addAllowedCollision(const std::string &link_name1, const std::string &link_name2, const std::string &reason)
Disable collision between two collision objects.
Definition: allowed_collision_matrix.h:45
AllowedCollisionMatrix(const AllowedCollisionMatrix &)=default
void serialize(Archive &ar, const unsigned int version)
Definition: allowed_collision_matrix.cpp:71
AllowedCollisionMatrix & operator=(AllowedCollisionMatrix &&)=default
std::shared_ptr< AllowedCollisionMatrix > Ptr
Definition: allowed_collision_matrix.h:29
auto it
Definition: collision_core_unit.cpp:208
auto acm
Definition: collision_core_unit.cpp:33
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: allowed_collision_matrix.h:16
bool operator==(const AllowedCollisionEntries &entries_1, const AllowedCollisionEntries &entries_2)
Definition: allowed_collision_matrix.cpp:43
LinkNamesPair makeOrderedLinkPair(const std::string &link_name1, const std::string &link_name2)
Create a pair of strings, where the pair.first is always <= pair.second.
Definition: types.cpp:56
std::pair< std::string, std::string > LinkNamesPair
Definition: types.h:71
std::unordered_map< tesseract_common::LinkNamesPair, std::string, tesseract_common::PairHash > AllowedCollisionEntries
Definition: allowed_collision_matrix.h:18
Common Tesseract Types.