se2ez
collision.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef SE2EZ_CORE_COLLISION_
4 #define SE2EZ_CORE_COLLISION_
5 
6 #include <set>
7 #include <map>
8 
10 #include <se2ez/core/math.h>
11 
12 namespace se2ez
13 {
14  /** \cond IGNORE */
15  SE2EZ_CLASS_FORWARD(State)
16  /** \endcond */
17 
18  /** \cond IGNORE */
20  SE2EZ_CLASS_FORWARD(CollisionManager)
21  /** \endcond */
22 
23  /** \class se2ez::ACMPtr
24  \brief A shared pointer wrapper for se2ez::ACM. */
25 
26  /** \class se2ez::ACMConstPtr
27  \brief A const shared pointer wrapper for se2ez::ACM. */
28 
29  /** \class se2ez::CollisionManagerPtr
30  \brief A shared pointer wrapper for se2ez::CollisionManager. */
31 
32  /** \class se2ez::CollisionManagerConstPtr
33  \brief A const shared pointer wrapper for se2ez::CollisionManager. */
34 
35  /** \brief An allowed collision map / matrix for the robot. Stores what frames are allowed to collide with
36  * each other.
37  */
38  class ACM
39  {
40  public:
41  /** \brief Disable collision checking between frame \e a and \e b.
42  * \param[in] a One frame.
43  * \param[in] b Other frame.
44  */
45  void disable(const std::string &a, const std::string &b);
46 
47  /** \brief Enable collision checking between frame \e a and \e b.
48  * \param[in] a One frame.
49  * \param[in] b Other frame.
50  */
51  void enable(const std::string &a, const std::string &b);
52 
53  /** \brief Returns true if frame \e a and frame \e b can collide.
54  * \param[in] a One frame.
55  * \param[in] b Other frame.
56  * \return True if \e a and \e b can collide, false if they do not.
57  */
58  bool collide(const std::string &a, const std::string &b) const;
59 
60  /** \brief Clears all entries within the ACM.
61  */
62  void clear();
63 
64  private:
65  std::set<std::pair<std::string, std::string>> disabled_; ///< Set of all disabled frame pairs
66  };
67 
68  /** \brief An abstract class that all collision managers must implement.
69  */
71  {
72  public:
73  /** \brief A class that contains all information about the signed distance of a frame to another.
74  */
76  {
78 
79  double distance{math::inf}; ///< Distance to collision.
80  Eigen::Vector2d point; ///< Point on fixture where normal begins.
81  Eigen::Vector2d normal; ///< Normal vector to collision.
82  std::string frame; ///< Frame closet to collision.
83  std::string collider; ///< Frame this frame is closest to collision with.
84 
85  /** \brief Flips the direction of the normal and swaps the endpoint.
86  */
87  void flip();
88  };
89 
90  /** \brief A map of frame names to their signed distances.
91  */
93 
94  /** \brief Constructor.
95  */
97 
98  /** \brief Check if a state is in collision.
99  * \param[in] state State to check for collisions using an allowed collision map.
100  * \return Returns true if state is in collision, false otherwise.
101  */
102  virtual bool collide(StatePtr &state) = 0;
103 
104  /** \brief Check if a state is in collision.
105  * \param[in] state State to check for collisions using an allowed collision map.
106  * \param[out] frames What frames are in collision.
107  * \return Returns true if state is in collision, false otherwise.
108  */
109  virtual bool collide(StatePtr &state, std::set<std::string> &frames) = 0;
110 
111  /** \brief Computes the signed distance of a scene to collision.
112  * \param[in] state State to computed signed distance for.
113  * \return Returns signed distance.
114  */
115  virtual SignedDistance distance(StatePtr &state) = 0;
116 
117  /** \brief Computes the signed distance of a scene to collision.
118  * \param[in] state State to computed signed distance for.
119  * \param[out] frames Distance of frame to collision.
120  * \return Returns signed distance.
121  */
122  virtual SignedDistance distance(StatePtr &state, SignedDistanceMap &frames) = 0;
123 
124  /** \brief Compiles internal data structures for collision checking. Needs to be called if the robot
125  * is updated.
126  */
127  virtual void compile() = 0;
128 
129  /** \brief Sets a new ACM to use.
130  * \param[in] acm New ACM to use.
131  */
132  virtual void setACM(const ACMPtr &acm);
133 
134  /** \brief Gets the current ACM.
135  * \return The ACM.
136  */
137  virtual ACMPtr getACM();
138 
139  protected:
140  ACMPtr acm_{nullptr}; ///< ACM for collision manager.
141  };
142 } // namespace se2ez
143 
144 #endif
A shared pointer wrapper for se2ez::State.
virtual bool collide(StatePtr &state)=0
Check if a state is in collision.
Eigen::Vector2d normal
Normal vector to collision.
Definition: collision.h:81
An abstract class that all collision managers must implement.
Definition: collision.h:70
An allowed collision map / matrix for the robot. Stores what frames are allowed to collide with each ...
Definition: collision.h:38
A class that contains all information about the signed distance of a frame to another.
Definition: collision.h:75
virtual ACMPtr getACM()
Gets the current ACM.
Definition: collision.cpp:60
static const double inf
Definition: math.h:37
CollisionManager()
Constructor.
Definition: collision.cpp:51
std::string collider
Frame this frame is closest to collision with.
Definition: collision.h:83
#define SE2EZ_EIGEN_CLASS
Definition: class_forward.h:14
A shared pointer wrapper for se2ez::ACM.
std::set< std::pair< std::string, std::string > > disabled_
Set of all disabled frame pairs.
Definition: collision.h:65
std::string frame
Frame closet to collision.
Definition: collision.h:82
Eigen::Vector2d point
Point on fixture where normal begins.
Definition: collision.h:80
ACMPtr acm_
ACM for collision manager.
Definition: collision.h:140
virtual void setACM(const ACMPtr &acm)
Sets a new ACM to use.
Definition: collision.cpp:55
Main namespace.
Definition: collision.h:11
void flip()
Flips the direction of the normal and swaps the endpoint.
Definition: collision.cpp:45
virtual void compile()=0
Compiles internal data structures for collision checking. Needs to be called if the robot is updated...
SE2EZ_EIGEN_CLASS double distance
Distance to collision.
Definition: collision.h:79
#define SE2EZ_CLASS_FORWARD(C)
Definition: class_forward.h:9