hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
obstacle-user.hh
Go to the documentation of this file.
1 // Copyright (c) 2019 CNRS
2 // Authors: Joseph Mirabel
3 //
4 // This file is part of hpp-core
5 // hpp-core is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // hpp-core is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // hpp-core If not, see
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef HPP_CORE_OBSTACLE_USER_HH
19 # define HPP_CORE_OBSTACLE_USER_HH
20 
21 # include <hpp/fcl/collision_data.h>
22 
23 # include <hpp/core/config.hh>
24 # include <hpp/core/fwd.hh>
26 
27 namespace hpp {
28  namespace core {
35  class HPP_CORE_DLLAPI ObstacleUserInterface
36  {
37  public:
38  virtual ~ObstacleUserInterface () {}
39 
42  virtual void addObstacle (const CollisionObjectConstPtr_t& object) = 0;
43 
47  virtual void removeObstacleFromJoint(const JointPtr_t& joint,
48  const CollisionObjectConstPtr_t& object) = 0;
49 
57  virtual void filterCollisionPairs (const RelativeMotion::matrix_type& relMotion) = 0;
63  virtual void setSecurityMargins(const matrix_t& securityMatrix) = 0;
64  }; // class ObstacleUserInterface
65 
82  template<typename Derived>
83  class HPP_CORE_DLLAPI ObstacleUserVector : public ObstacleUserInterface
84  {
85  public:
86  virtual ~ObstacleUserVector () {}
87 
94  {
95  for (std::size_t i = 0; i < validations_.size(); ++i) {
96  boost::shared_ptr<ObstacleUserInterface> oui =
98  if (oui) oui->addObstacle (object);
99  }
100  }
101 
108  const CollisionObjectConstPtr_t& object)
109  {
110  for (std::size_t i = 0; i < validations_.size(); ++i) {
111  boost::shared_ptr<ObstacleUserInterface> oui =
113  if (oui) oui->removeObstacleFromJoint (joint, object);
114  }
115  }
116 
123  {
124  for (std::size_t i = 0; i < validations_.size(); ++i) {
125  boost::shared_ptr<ObstacleUserInterface> oui =
127  if (oui) oui->filterCollisionPairs (relMotion);
128  }
129  }
130 
136  void setSecurityMargins(const matrix_t& securityMatrix)
137  {
138  for (std::size_t i = 0; i < validations_.size(); ++i) {
139  boost::shared_ptr<ObstacleUserInterface> oui =
141  if (oui) oui->setSecurityMargins (securityMatrix);
142  }
143  }
144 
145  protected:
146  typedef Derived value_t;
147  typedef std::vector<value_t> values_t;
148 
149  values_t validations_;
150  }; // class ObstacleUserVector
151 
153  class HPP_CORE_DLLAPI ObstacleUser : public ObstacleUserInterface
154  {
155  public:
156  virtual ~ObstacleUser () {}
157 
158  typedef std::pair<CollisionObjectConstPtr_t, CollisionObjectConstPtr_t> CollisionPair_t;
159  typedef std::vector<CollisionPair_t> CollisionPairs_t;
160  typedef std::vector<fcl::CollisionRequest> CollisionRequests_t;
161 
162  static bool collide (const CollisionPairs_t& pairs,
163  const CollisionRequests_t& reqs,
165  std::size_t& i,
166  pinocchio::DeviceData& data);
167 
168  // Get pairs checked for collision
169  const CollisionPairs_t& pairs () const
170  {
171  return cPairs_;
172  }
173 
174  // Get pairs checked for collision
175  CollisionPairs_t& pairs ()
176  {
177  return cPairs_;
178  }
179 
180  // Get requests of collision pairs
181  const CollisionRequests_t& requests () const
182  {
183  return cRequests_;
184  }
185 
186  // Get requests of collision pairs
187  CollisionRequests_t& requests ()
188  {
189  return cRequests_;
190  }
191 
193  {
194  return defaultRequest_;
195  }
196 
197  void setRequests (const fcl::CollisionRequest& r);
198 
201  virtual void addObstacle (const CollisionObjectConstPtr_t& object);
202 
208  virtual void addObstacleToJoint (const CollisionObjectConstPtr_t& object,
209  const JointPtr_t& joint, const bool includeChildren);
210 
214  virtual void removeObstacleFromJoint(const JointPtr_t& joint,
215  const CollisionObjectConstPtr_t& object);
216 
225  virtual void filterCollisionPairs (const RelativeMotion::matrix_type& relMotion);
226 
232  virtual void setSecurityMargins(const matrix_t& securityMatrix);
233  protected:
236  : robot_ (robot), defaultRequest_ (fcl::NO_REQUEST,1)
237  {}
238 
240  ObstacleUser (const ObstacleUser& other)
241  : robot_ (other.robot_),
242  defaultRequest_ (other.defaultRequest_),
243  cPairs_ (other.cPairs_),
244  pPairs_ (other.pPairs_),
245  dPairs_ (other.dPairs_),
246  cRequests_ (other.cRequests_),
247  pRequests_ (other.pRequests_),
248  dRequests_ (other.dRequests_)
249  {}
250 
251  void addRobotCollisionPairs ();
252 
255 
256  CollisionPairs_t cPairs_,
257  pPairs_,
258  dPairs_;
259  CollisionRequests_t cRequests_,
260  pRequests_,
261  dRequests_;
262  }; // class ObstacleUser
263  } // namespace core
264 } // namespace hpp
265 #endif // HPP_CORE_OBSTACLE_USER_HH
fcl::CollisionRequest & defaultRequest()
Definition: obstacle-user.hh:192
const CollisionPairs_t & pairs() const
Definition: obstacle-user.hh:169
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:114
Definition: obstacle-user.hh:83
values_t validations_
Definition: obstacle-user.hh:149
Derived value_t
Definition: obstacle-user.hh:146
ObstacleUser(DevicePtr_t robot)
Constructor of body pair collision.
Definition: obstacle-user.hh:235
std::vector< CollisionPair_t > CollisionPairs_t
Definition: obstacle-user.hh:159
void addObstacle(const CollisionObjectConstPtr_t &object)
Definition: obstacle-user.hh:93
CollisionRequests_t pRequests_
Active collision requests.
Definition: obstacle-user.hh:259
FCL_REAL r
pinocchio::JointPtr_t JointPtr_t
Definition: fwd.hh:133
#define HPP_DYNAMIC_PTR_CAST(t, x)
CollisionPairs_t & pairs()
Definition: obstacle-user.hh:175
virtual ~ObstacleUser()
Definition: obstacle-user.hh:156
std::pair< CollisionObjectConstPtr_t, CollisionObjectConstPtr_t > CollisionPair_t
Definition: obstacle-user.hh:158
DevicePtr_t robot_
Definition: obstacle-user.hh:253
pinocchio::matrix_t matrix_t
Definition: fwd.hh:145
fcl::CollisionRequest defaultRequest_
Definition: obstacle-user.hh:254
virtual ~ObstacleUserInterface()
Definition: obstacle-user.hh:38
virtual ~ObstacleUserVector()
Definition: obstacle-user.hh:86
void filterCollisionPairs(const RelativeMotion::matrix_type &relMotion)
Definition: obstacle-user.hh:122
void setSecurityMargins(const matrix_t &securityMatrix)
Definition: obstacle-user.hh:136
void removeObstacleFromJoint(const JointPtr_t &joint, const CollisionObjectConstPtr_t &object)
Definition: obstacle-user.hh:107
CollisionRequests_t & requests()
Definition: obstacle-user.hh:187
std::vector< fcl::CollisionRequest > CollisionRequests_t
Definition: obstacle-user.hh:160
std::size_t collide(const CollisionObject *o1, const CollisionObject *o2, const CollisionRequest &request, CollisionResult &result)
Definition: obstacle-user.hh:35
const CollisionRequests_t & requests() const
Definition: obstacle-user.hh:181
NO_REQUEST
std::vector< value_t > values_t
Definition: obstacle-user.hh:147
ObstacleUser(const ObstacleUser &other)
Copy constructor.
Definition: obstacle-user.hh:240
Eigen::Matrix< RelativeMotionType, Eigen::Dynamic, Eigen::Dynamic > matrix_type
Definition: relative-motion.hh:51
Stores a set of obstacles (movable or static).
Definition: obstacle-user.hh:153
CollisionPairs_t pPairs_
Active collision pairs.
Definition: obstacle-user.hh:256
pinocchio::CollisionObjectConstPtr_t CollisionObjectConstPtr_t
Definition: fwd.hh:90