collision_matrix.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan, E. Gil Jones */
36 
37 #pragma once
38 
41 #include <moveit_msgs/AllowedCollisionMatrix.h>
42 #include <boost/function.hpp>
43 #include <iostream>
44 #include <vector>
45 #include <string>
46 #include <map>
47 
48 namespace collision_detection
49 {
51 namespace AllowedCollision
52 {
53 enum Type
54 {
57  NEVER,
58 
61  ALWAYS,
62 
67 };
68 } // namespace AllowedCollision
69 
72 using DecideContactFn = boost::function<bool(collision_detection::Contact&)>;
73 
74 MOVEIT_CLASS_FORWARD(AllowedCollisionMatrix); // Defines AllowedCollisionMatrixPtr, ConstPtr, WeakPtr... etc
75 
80 class AllowedCollisionMatrix
81 {
82 public:
84 
89  AllowedCollisionMatrix(const std::vector<std::string>& names, bool allowed = false);
90 
93 
95  AllowedCollisionMatrix(const moveit_msgs::AllowedCollisionMatrix& msg);
96 
102  bool getEntry(const std::string& name1, const std::string& name2,
103  AllowedCollision::Type& allowed_collision_type) const;
104 
112  bool getEntry(const std::string& name1, const std::string& name2, DecideContactFn& fn) const;
113 
117  bool hasEntry(const std::string& name) const;
118 
123  bool hasEntry(const std::string& name1, const std::string& name2) const;
124 
129  void removeEntry(const std::string& name1, const std::string& name2);
130 
133  void removeEntry(const std::string& name);
134 
141  void setEntry(const std::string& name1, const std::string& name2, bool allowed);
142 
149  void setEntry(const std::string& name1, const std::string& name2, const DecideContactFn& fn);
150 
159  void setEntry(const std::string& name, bool allowed);
160 
168  void setEntry(const std::string& name, const std::vector<std::string>& other_names, bool allowed);
169 
176  void setEntry(const std::vector<std::string>& names1, const std::vector<std::string>& names2, bool allowed);
177 
182  void setEntry(bool allowed);
183 
185  void getAllEntryNames(std::vector<std::string>& names) const;
186 
188  void getMessage(moveit_msgs::AllowedCollisionMatrix& msg) const;
189 
191  void clear();
192 
194  std::size_t getSize() const
195  {
196  return entries_.size();
197  }
198 
204  void setDefaultEntry(const std::string& name, bool allowed);
205 
210  void setDefaultEntry(const std::string& name, const DecideContactFn& fn);
211 
216  bool getDefaultEntry(const std::string& name, AllowedCollision::Type& allowed_collision) const;
217 
222  bool getDefaultEntry(const std::string& name, DecideContactFn& fn) const;
223 
230  bool getAllowedCollision(const std::string& name1, const std::string& name2, DecideContactFn& fn) const;
231 
238  bool getAllowedCollision(const std::string& name1, const std::string& name2,
239  AllowedCollision::Type& allowed_collision) const;
240 
242  void print(std::ostream& out) const;
243 
244 private:
245  bool getDefaultEntry(const std::string& name1, const std::string& name2,
246  AllowedCollision::Type& allowed_collision) const;
247 
248  std::map<std::string, std::map<std::string, AllowedCollision::Type> > entries_;
249  std::map<std::string, std::map<std::string, DecideContactFn> > allowed_contacts_;
250 
251  std::map<std::string, AllowedCollision::Type> default_entries_;
252  std::map<std::string, DecideContactFn> default_allowed_contacts_;
253 };
254 } // namespace collision_detection
collision_detection::AllowedCollisionMatrix::setDefaultEntry
void setDefaultEntry(const std::string &name, bool allowed)
Set the default value for entries that include name but are not set explicity with setEntry().
Definition: collision_matrix.cpp:276
collision_detection::AllowedCollisionMatrix::hasEntry
bool hasEntry(const std::string &name) const
Check if the allowed collision matrix has an entry at all for an element. Returns true if the element...
Definition: collision_matrix.cpp:158
collision_detection::AllowedCollisionMatrix::entries_
std::map< std::string, std::map< std::string, AllowedCollision::Type > > entries_
Definition: collision_matrix.h:280
collision_detection::AllowedCollisionMatrix::getDefaultEntry
bool getDefaultEntry(const std::string &name, AllowedCollision::Type &allowed_collision) const
Get the type of the allowed collision to be considered by default for an element. Return true if a de...
Definition: collision_matrix.cpp:289
collision_detection::AllowedCollisionMatrix::getSize
std::size_t getSize() const
Get the size of the allowed collision matrix (number of specified entries)
Definition: collision_matrix.h:226
collision_detection::MOVEIT_CLASS_FORWARD
MOVEIT_CLASS_FORWARD(AllowedCollisionMatrix)
collision_detection::AllowedCollisionMatrix::getAllowedCollision
bool getAllowedCollision(const std::string &name1, const std::string &name2, DecideContactFn &fn) const
Get the allowed collision predicate between two elements. Return true if a predicate for entry is inc...
Definition: collision_matrix.cpp:312
collision_detection::AllowedCollisionMatrix::getEntry
bool getEntry(const std::string &name1, const std::string &name2, AllowedCollision::Type &allowed_collision_type) const
Get the type of the allowed collision between two elements. Return true if the entry is included in t...
Definition: collision_matrix.cpp:145
collision_detection::AllowedCollisionMatrix::removeEntry
void removeEntry(const std::string &name1, const std::string &name2)
Remove an entry corresponding to a pair of elements. Nothing happens if the pair does not exist in th...
Definition: collision_matrix.cpp:210
collision_detection::AllowedCollision::ALWAYS
@ ALWAYS
Collisions between a particular pair of bodies does not imply that the robot configuration is in coll...
Definition: collision_matrix.h:157
class_forward.h
collision_detection::Contact
Definition of a contact point.
Definition: include/moveit/collision_detection/collision_common.h:105
collision_detection::AllowedCollisionMatrix::getMessage
void getMessage(moveit_msgs::AllowedCollisionMatrix &msg) const
Get the allowed collision matrix as a message.
Definition: collision_matrix.cpp:385
collision_common.h
collision_detection::AllowedCollisionMatrix::AllowedCollisionMatrix
AllowedCollisionMatrix()
Definition: collision_matrix.cpp:75
collision_detection::AllowedCollision::Type
Type
Definition: collision_matrix.h:117
collision_detection::AllowedCollision::CONDITIONAL
@ CONDITIONAL
The collision is allowed depending on a predicate evaluated on the produced contact....
Definition: collision_matrix.h:162
collision_detection::AllowedCollisionMatrix::print
void print(std::ostream &out) const
Print the allowed collision matrix.
Definition: collision_matrix.cpp:419
collision_detection::AllowedCollisionMatrix::clear
void clear()
Clear the allowed collision matrix.
Definition: collision_matrix.cpp:363
collision_detection::AllowedCollisionMatrix::allowed_contacts_
std::map< std::string, std::map< std::string, DecideContactFn > > allowed_contacts_
Definition: collision_matrix.h:281
collision_detection::AllowedCollisionMatrix::default_entries_
std::map< std::string, AllowedCollision::Type > default_entries_
Definition: collision_matrix.h:283
srdf
collision_detection::AllowedCollisionMatrix::default_allowed_contacts_
std::map< std::string, DecideContactFn > default_allowed_contacts_
Definition: collision_matrix.h:284
collision_detection::AllowedCollisionMatrix::getAllEntryNames
void getAllEntryNames(std::vector< std::string > &names) const
Get all the names known to the collision matrix.
Definition: collision_matrix.cpp:371
srdf::Model
collision_detection::DecideContactFn
boost::function< bool(collision_detection::Contact &)> DecideContactFn
Signature of predicate that decides whether a contact is allowed or not (when AllowedCollision::Type ...
Definition: collision_matrix.h:104
collision_detection::AllowedCollision::NEVER
@ NEVER
Collisions between the pair of bodies is never ok, i.e., if two bodies are in contact in a particular...
Definition: collision_matrix.h:153
collision_detection::AllowedCollisionMatrix::setEntry
void setEntry(const std::string &name1, const std::string &name2, bool allowed)
Set an entry corresponding to a pair of elements.
Definition: collision_matrix.cpp:172
collision_detection
Definition: collision_detector_allocator_allvalid.h:42


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Tue Dec 24 2024 03:27:14