hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
continuous-validation.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2014, 2015, 2016, 2017, 2018 CNRS
3 // Authors: Florent Lamiraux, Joseph Mirabel, Diane Bury
4 //
5 // This file is part of hpp-core
6 // hpp-core is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // hpp-core is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // hpp-core If not, see
17 // <http://www.gnu.org/licenses/>.
18 
19 #ifndef HPP_CORE_CONTINUOUS_VALIDATION_HH
20 # define HPP_CORE_CONTINUOUS_VALIDATION_HH
21 
22 # include <hpp/pinocchio/pool.hh>
23 
24 # include <hpp/core/fwd.hh>
25 # include <hpp/core/obstacle-user.hh>
26 # include <hpp/core/path.hh>
30 
31 namespace hpp {
32  namespace core {
33  using continuousValidation::IntervalValidation;
37 
86  class HPP_CORE_DLLAPI ContinuousValidation :
87  public PathValidation,
89  {
90  public:
94  class Initialize
95  {
96  public:
103  virtual void doExecute() const;
104  ContinuousValidation & owner() const { return *owner_; }
105  virtual ~Initialize () {}
106  protected:
108  }; // class Initialize
113  {
114  public:
120  virtual void doExecute(const CollisionObjectConstPtr_t &object) const;
121  ContinuousValidation & owner() const { return *owner_; }
122  virtual ~AddObstacle () {}
123  protected:
126  }; // class AddObstacle
127 
137  virtual bool validate (const PathPtr_t& path, bool reverse,
138  PathPtr_t& validPart,
139  PathValidationReportPtr_t& report);
143  virtual void addObstacle (const CollisionObjectConstPtr_t& object);
144 
151  virtual void removeObstacleFromJoint
152  (const JointPtr_t& joint, const CollisionObjectConstPtr_t& obstacle);
153 
161  void filterCollisionPairs (const RelativeMotion::matrix_type& relMotion);
162 
168  virtual void setSecurityMargins(const matrix_t& securityMatrix);
169 
172 
190  template <class Delegate> void add(const Delegate& delegate);
191 
194  template <class Delegate> void reset();
195 
198  void addIntervalValidation
199  (const IntervalValidationPtr_t& intervalValidation);
202  {
203  return tolerance_;
204  }
205 
207  {
208  return robot_;
209  }
212  void initialize();
213 
214  virtual ~ContinuousValidation ();
215  protected:
217 
218  static void setPath(IntervalValidations_t& intervalValidations,
219  const PathPtr_t &path, bool reverse);
220 
224  ContinuousValidation (const DevicePtr_t& robot,
225  const value_type& tolerance);
226 
237  virtual bool validateConfiguration
238  (IntervalValidations_t& intervalValidations,
239  const Configuration_t& config,
240  const value_type& t,
241  interval_t& interval,
242  PathValidationReportPtr_t& report);
243 
256  bool validateIntervals
257  (IntervalValidations_t& validations, const value_type &t,
258  interval_t &interval, PathValidationReportPtr_t &pathReport,
259  typename IntervalValidations_t::iterator& smallestInterval,
260  pinocchio::DeviceData& data)
261  {
262  typename IntervalValidations_t::iterator itMin = validations.begin();
263  for (IntervalValidations_t::iterator itVal (validations.begin());
264  itVal != validations.end(); ++itVal)
265  {
266  ValidationReportPtr_t report;
267  // the valid interval will not be greater than "interval" so we do not
268  // need to perform validation on a greater interval.
269  interval_t tmpInt = interval;
270  if (!(*itVal)->validateConfiguration(t, tmpInt, report, data))
271  {
273  pathReport->configurationReport = report;
274  pathReport->parameter = t;
275  return false;
276  }
277  else
278  {
279  if (interval.second > tmpInt.second)
280  {
281  itMin = itVal;
282  smallestInterval = itVal;
283  }
284  interval.first = std::max(interval.first, tmpInt.first);
285  interval.second = std::min(interval.second, tmpInt.second);
286  assert((*itVal)->path()->length() == 0 || interval.second > interval.first);
287  assert(interval.first <= t);
288  assert(t <= interval.second);
289  }
290  }
291  return true;
292  }
293 
296 
298  void init (ContinuousValidationWkPtr_t weak);
299 
301  IntervalValidations_t intervalValidations_;
303  IntervalValidations_t disabledBodyPairCollisions_;
304 
306 
308  private:
309  // Weak pointer to itself
310  ContinuousValidationWkPtr_t weak_;
311 
312  virtual bool validateStraightPath
313  (IntervalValidations_t& intervalValidations,
314  const PathPtr_t& path, bool reverse, PathPtr_t& validPart,
315  PathValidationReportPtr_t& report) = 0;
316 
317  std::vector<Initialize> initialize_;
318  std::vector<AddObstacle> addObstacle_;
319  }; // class ContinuousValidation
321  template <>
322  void ContinuousValidation::add<ContinuousValidation::AddObstacle>
323  (const ContinuousValidation::AddObstacle& delegate);
324 
325  template <>
326  void ContinuousValidation::reset<ContinuousValidation::AddObstacle>();
327 
328  template <>
329  void ContinuousValidation::add<ContinuousValidation::Initialize>
330  (const ContinuousValidation::Initialize& delegate);
331 
332  template <>
333  void ContinuousValidation::reset<ContinuousValidation::Initialize>();
334 
335  template <class Delegate> void ContinuousValidation::add
336  (const Delegate& delegate)
337  {
338  assert (false &&
339  "No delegate of this type in class ContinuousValidation.");
340  }
341  template <class Delegate> void ContinuousValidation::reset()
342  {
343  assert (false &&
344  "No delegate of this type in class ContinuousValidation.");
345  }
346 
347  } // namespace core
348 } // namespace hpp
349 #endif // HPP_CORE_CONTINUOUS_VALIDATION_HH
value_type tolerance() const
Get tolerance value.
Definition: continuous-validation.hh:201
boost::shared_ptr< Path > PathPtr_t
Definition: fwd.hh:170
IntervalValidations_t intervalValidations_
All BodyPairValidation to validate.
Definition: continuous-validation.hh:301
DevicePtr_t robot_
Definition: continuous-validation.hh:294
boost::shared_ptr< ValidationReport > ValidationReportPtr_t
Definition: fwd.hh:206
Definition: continuous-validation.hh:94
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:114
void add(const Delegate &delegate)
Definition: continuous-validation.hh:336
boost::shared_ptr< IntervalValidation > IntervalValidationPtr_t
Definition: fwd.hh:242
value_type tolerance_
Definition: continuous-validation.hh:295
pinocchio::Pool< IntervalValidations_t > bodyPairCollisionPool_
Definition: continuous-validation.hh:305
ContinuousValidation & owner() const
Definition: continuous-validation.hh:121
std::pair< value_type, value_type > interval_t
Definition: fwd.hh:158
pinocchio::DeviceWkPtr_t DeviceWkPtr_t
Definition: fwd.hh:115
bool initialize(MeshCollisionTraversalNode< BV, RelativeTransformationIsIdentity > &node, BVHModel< BV > &model1, Transform3f &tf1, BVHModel< BV > &model2, Transform3f &tf2, CollisionResult &result, bool use_refit=false, bool refit_bottomup=false)
Definition: continuous-validation.hh:86
std::vector< IntervalValidationPtr_t > IntervalValidations_t
Definition: fwd.hh:243
ContinuousValidation * owner_
Definition: continuous-validation.hh:107
pinocchio::JointPtr_t JointPtr_t
Definition: fwd.hh:133
DevicePtr_t robot() const
Definition: continuous-validation.hh:206
continuousValidation::IntervalValidations_t IntervalValidations_t
Definition: continuous-validation.hh:216
ContinuousValidation * owner_
Definition: continuous-validation.hh:124
Definition: continuous-validation.hh:112
ContinuousValidation & owner() const
Definition: continuous-validation.hh:104
assert(d.lhs()._blocks()==d.rhs()._blocks())
void reset()
Definition: continuous-validation.hh:341
pinocchio::matrix_t matrix_t
Definition: fwd.hh:145
Definition: path-validation.hh:35
pinocchio::value_type value_type
Definition: fwd.hh:157
virtual ~AddObstacle()
Definition: continuous-validation.hh:122
Definition: path-validation-report.hh:34
Definition: obstacle-user.hh:35
boost::shared_ptr< PathValidationReport > PathValidationReportPtr_t
Definition: fwd.hh:298
Transform3f t
virtual ~Initialize()
Definition: continuous-validation.hh:105
IntervalValidations_t disabledBodyPairCollisions_
BodyPairCollision for which collision is disabled.
Definition: continuous-validation.hh:303
value_type stepSize_
Definition: continuous-validation.hh:307
pinocchio::Configuration_t Configuration_t
Definition: fwd.hh:96
Eigen::Matrix< RelativeMotionType, Eigen::Dynamic, Eigen::Dynamic > matrix_type
Definition: relative-motion.hh:51
pinocchio::CollisionObjectConstPtr_t CollisionObjectConstPtr_t
Definition: fwd.hh:90
DeviceWkPtr_t robot_
Definition: continuous-validation.hh:125