Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
collision_margin_data.h
Go to the documentation of this file.
1
28#ifndef TESSERACT_COMMON_COLLISION_MARGIN_DATA_H
29#define TESSERACT_COMMON_COLLISION_MARGIN_DATA_H
30
33#include <boost/serialization/access.hpp>
34#include <Eigen/Core>
35#include <string>
36#include <unordered_map>
38
41
42namespace tesseract_common
43{
46{
48 NONE,
50 REPLACE,
56 MODIFY,
67};
68
70 std::unordered_map<tesseract_common::LinkNamesPair, double, tesseract_common::PairHash>;
71
74{
75public:
76 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
77
78 using Ptr = std::shared_ptr<CollisionMarginData>;
79 using ConstPtr = std::shared_ptr<const CollisionMarginData>;
80
81 CollisionMarginData(double default_collision_margin = 0)
82 : default_collision_margin_(default_collision_margin), max_collision_margin_(default_collision_margin)
83 {
84 }
85
86 CollisionMarginData(double default_collision_margin, PairsCollisionMarginData pair_collision_margins)
87 : default_collision_margin_(default_collision_margin), lookup_table_(std::move(pair_collision_margins))
88 {
90 }
91
93 : lookup_table_(std::move(pair_collision_margins))
94 {
96 }
97
102 void setDefaultCollisionMargin(double default_collision_margin)
103 {
104 default_collision_margin_ = default_collision_margin;
106 }
107
113
124 void setPairCollisionMargin(const std::string& obj1, const std::string& obj2, double collision_margin)
125 {
126 auto key = tesseract_common::makeOrderedLinkPair(obj1, obj2);
127 lookup_table_[key] = collision_margin;
129 }
130
140 double getPairCollisionMargin(const std::string& obj1, const std::string& obj2) const
141 {
142 thread_local LinkNamesPair key;
144 const auto it = lookup_table_.find(key);
145
146 if (it != lookup_table_.end())
147 return it->second;
148
150 }
151
157
166
171 void incrementMargins(const double& increment)
172 {
175 for (auto& pair : lookup_table_)
176 pair.second += increment;
177 }
178
183 void scaleMargins(const double& scale)
184 {
187 for (auto& pair : lookup_table_)
188 pair.second *= scale;
189 }
190
196 void apply(const CollisionMarginData& collision_margin_data, CollisionMarginOverrideType override_type)
197 {
198 switch (override_type)
199 {
201 {
202 *this = collision_margin_data;
203 break;
204 }
206 {
208
209 for (const auto& p : collision_margin_data.lookup_table_)
210 lookup_table_[p.first] = p.second;
211
213 break;
214 }
216 {
219 break;
220 }
222 {
223 lookup_table_ = collision_margin_data.lookup_table_;
225 break;
226 }
228 {
229 for (const auto& p : collision_margin_data.lookup_table_)
230 lookup_table_[p.first] = p.second;
231
233 break;
234 }
236 {
237 break;
238 }
239 }
240 }
241
242 bool operator==(const CollisionMarginData& rhs) const;
243 bool operator!=(const CollisionMarginData& rhs) const;
244
245private:
248
251
254
257 {
259 for (const auto& p : lookup_table_)
260 {
261 if (p.second > max_collision_margin_)
262 max_collision_margin_ = p.second;
263 }
264 }
266 template <class Archive>
267 void serialize(Archive& ar, const unsigned int version); // NOLINT
268};
269} // namespace tesseract_common
270#include <boost/serialization/export.hpp>
271#include <boost/serialization/tracking.hpp>
272BOOST_CLASS_EXPORT_KEY2(tesseract_common::CollisionMarginData, "CollisionMarginData")
273
274#endif // TESSERACT_COMMON_COLLISION_MARGIN_DATA_H
Stores information about how the margins allowed between collision objects.
Definition: collision_margin_data.h:74
void setPairCollisionMargin(const std::string &obj1, const std::string &obj2, double collision_margin)
Set the margin for a given contact pair.
Definition: collision_margin_data.h:124
void updateMaxCollisionMargin()
Update the max collision margin.
Definition: collision_margin_data.h:256
void apply(const CollisionMarginData &collision_margin_data, CollisionMarginOverrideType override_type)
Apply the contents of the provide CollisionMarginData based on the override type.
Definition: collision_margin_data.h:196
void serialize(Archive &ar, const unsigned int version)
Definition: collision_margin_data.cpp:70
double getDefaultCollisionMargin() const
Get the default collision margin.
Definition: collision_margin_data.h:112
double max_collision_margin_
Stores the largest collision margin.
Definition: collision_margin_data.h:250
bool operator!=(const CollisionMarginData &rhs) const
Definition: collision_margin_data.cpp:67
double getMaxCollisionMargin() const
Get the largest collision margin.
Definition: collision_margin_data.h:165
bool operator==(const CollisionMarginData &rhs) const
Definition: collision_margin_data.cpp:43
CollisionMarginData(double default_collision_margin=0)
Definition: collision_margin_data.h:81
std::shared_ptr< CollisionMarginData > Ptr
Definition: collision_margin_data.h:78
const PairsCollisionMarginData & getPairCollisionMargins() const
Get Collision Margin Data for stored pairs.
Definition: collision_margin_data.h:156
void scaleMargins(const double &scale)
Scale all margins by input value.
Definition: collision_margin_data.h:183
CollisionMarginData(double default_collision_margin, PairsCollisionMarginData pair_collision_margins)
Definition: collision_margin_data.h:86
PairsCollisionMarginData lookup_table_
A map of link pair names to contact distance.
Definition: collision_margin_data.h:253
void incrementMargins(const double &increment)
Increment all margins by input amount. Useful for inflating or reducing margins.
Definition: collision_margin_data.h:171
double getPairCollisionMargin(const std::string &obj1, const std::string &obj2) const
Get the pairs collision margin data.
Definition: collision_margin_data.h:140
friend class boost::serialization::access
Definition: collision_margin_data.h:265
void setDefaultCollisionMargin(double default_collision_margin)
Set the default collision margin.
Definition: collision_margin_data.h:102
CollisionMarginData(PairsCollisionMarginData pair_collision_margins)
Definition: collision_margin_data.h:92
std::shared_ptr< const CollisionMarginData > ConstPtr
Definition: collision_margin_data.h:79
double default_collision_margin_
Stores the collision margin used if no pair-specific one is set.
Definition: collision_margin_data.h:247
auto it
Definition: collision_core_unit.cpp:208
double scale
Definition: collision_margin_data_unit.cpp:133
double increment
Definition: collision_margin_data_unit.cpp:107
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
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, double, tesseract_common::PairHash > PairsCollisionMarginData
Definition: collision_margin_data.h:70
CollisionMarginOverrideType
Identifies how the provided contact margin data should be applied.
Definition: collision_margin_data.h:46
@ REPLACE
Replace the contact manager's CollisionMarginData.
@ OVERRIDE_DEFAULT_MARGIN
Override the contact managers default margin only.
@ MODIFY_PAIR_MARGIN
Modify the contact managers pair margin only.
@ NONE
Do not apply contact margin data.
@ MODIFY
Modify the contact managers default margin and pair margins.
@ OVERRIDE_PAIR_MARGIN
Override the contact managers pair margin only. This does not preserve any existing pair margin data.
Common Tesseract Types.
Common Tesseract Utility Functions.