hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
problem-solver.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 CNRS
3 // Authors: Florent Lamiraux
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_PROBLEM_SOLVER_HH
20 # define HPP_CORE_PROBLEM_SOLVER_HH
21 
22 # include <stdexcept>
23 # include <boost/function.hpp>
24 
25 # include <hpp/pinocchio/fwd.hh>
26 
27 # include <hpp/core/fwd.hh>
28 # include <hpp/core/config.hh>
29 # include <hpp/core/deprecated.hh>
30 # include <hpp/core/container.hh>
31 
32 namespace hpp {
33  namespace core {
38  {
39  };
40  typedef boost::function < DevicePtr_t (const std::string&) > RobotBuilder_t;
41  typedef boost::function < PathOptimizerPtr_t (const Problem&) >
43  typedef boost::function < PathPlannerPtr_t (const Problem&,
44  const RoadmapPtr_t&) >
46  typedef boost::function < PathValidationPtr_t (const DevicePtr_t&,
47  const value_type&) >
49  typedef boost::function < ConfigValidationPtr_t (const DevicePtr_t&) >
51  typedef boost::function <PathProjectorPtr_t (const Problem&,
52  const value_type&) >
54  typedef boost::function <ConfigurationShooterPtr_t (const Problem&) >
56  typedef boost::function <DistancePtr_t (const Problem&) >
58  typedef boost::function <SteeringMethodPtr_t (const Problem&) >
60  typedef std::vector<std::pair < std::string, CollisionObjectPtr_t > > AffordanceObjects_t;
62 
68  class HPP_CORE_DLLAPI ProblemSolver
69  {
70  public:
71 
72  typedef std::vector <PathOptimizerPtr_t> PathOptimizers_t;
73  typedef std::vector <std::string> PathOptimizerTypes_t;
74  typedef std::vector <std::string> ConfigValidationTypes_t;
75 
77  static ProblemSolverPtr_t create ();
78 
80  virtual ~ProblemSolver ();
81 
84  void robotType (const std::string& type);
85 
87  const std::string& robotType () const;
88 
94  DevicePtr_t createRobot (const std::string& name);
95 
97  virtual void robot (const DevicePtr_t& robot);
98 
100  const DevicePtr_t& robot () const;
101 
104  {
105  return problem_;
106  }
109  {
110  return initConf_;
111  }
113  virtual void initConfig (const ConfigurationPtr_t& config);
115  const Configurations_t& goalConfigs () const;
117  virtual void addGoalConfig (const ConfigurationPtr_t& config);
119  void resetGoalConfigs ();
120  /*
122  void addGoalConstraint (const ConstraintPtr_t& constraint);
124  void addGoalConstraint (const LockedJointPtr_t& lj);
126  void addGoalConstraint (const std::string& constraintName,
127  const std::string& functionName, const std::size_t priority);
129  void resetGoalConstraint ();
130  */
132  virtual void pathPlannerType (const std::string& type);
133  const std::string& pathPlannerType () const {
134  return pathPlannerType_;
135  }
137  void distanceType (const std::string& type);
138  const std::string& distanceType () const {
139  return distanceType_;
140  }
142  void steeringMethodType (const std::string& type);
143  const std::string& steeringMethodType () const {
144  return steeringMethodType_;
145  }
147  void configurationShooterType (const std::string& type);
148  const std::string& configurationShooterType () const {
149  return configurationShooterType_;
150  }
153  {
154  return pathPlanner_;
155  }
156 
160  void addPathOptimizer (const std::string& type);
161  const PathOptimizerTypes_t& pathOptimizerTypes () const {
162  return pathOptimizerTypes_;
163  }
165  void clearPathOptimizers ();
167  const PathOptimizerPtr_t& pathOptimizer (std::size_t rank) const
168  {
169  return pathOptimizers_ [rank];
170  }
171 
177  void optimizePath (PathVectorPtr_t path);
178 
184  virtual void pathValidationType (const std::string& type,
185  const value_type& tolerance);
186  const std::string& pathValidationType (value_type& tolerance) const {
187  tolerance = pathValidationTolerance_;
188  return pathValidationType_;
189  }
190 
194  void pathProjectorType (const std::string& type,
195  const value_type& step);
196 
198  const std::string& pathProjectorType (value_type& tolerance) const {
199  tolerance = pathProjectorTolerance_;
200  return pathProjectorType_;
201  }
202 
207  virtual void addConfigValidation (const std::string& type);
208 
210  const ConfigValidationTypes_t configValidationTypes () {
211  return configValidationTypes_;
212  }
213 
214  // Clear the vector of config validations
215  void clearConfigValidations ();
216 
218  void addConfigValidationBuilder (const std::string& type,
219  const ConfigValidationBuilder_t& builder);
220 
221  const RoadmapPtr_t& roadmap () const
222  {
223  return roadmap_;
224  }
225 
228 
230  void addConstraint (const ConstraintPtr_t& constraint);
231 
234  {
235  return constraints_;
236  }
237 
239  virtual void resetConstraints ();
240 
246  virtual void addNumericalConstraintToConfigProjector
247  (const std::string& configProjName, const std::string& constraintName,
248  const std::size_t priority = 0);
249 
259  virtual void addLockedJointToConfigProjector
260  (const std::string& configProjName, const std::string& lockedJointName)
262 
269  void addNumericalConstraint (const std::string& name,
271  constraint)
272  {
273  numericalConstraints.add (name, constraint);
274  }
275 
278  void comparisonType (const std::string& name,
279  const ComparisonTypes_t types);
280 
281  void comparisonType (const std::string& name,
282  const ComparisonType &type);
283 
284  ComparisonTypes_t comparisonType (const std::string& name) const;
285 
288  {
289  return numericalConstraints.get(name, constraints::ImplicitPtr_t());
290  }
291 
302  void computeValueAndJacobian (const Configuration_t& configuration,
303  vector_t& value, matrix_t& jacobian) const;
304 
306  void maxIterProjection (size_type iterations);
309  {
310  return maxIterProjection_;
311  }
312 
314  void maxIterPathPlanning (size_type iterations);
317  {
318  return maxIterPathPlanning_;
319  }
320 
322  void setTimeOutPathPlanning(double timeOut){
323  timeOutPathPlanning_ = timeOut;
324  }
325 
328  return timeOutPathPlanning_;
329  }
330 
331 
333  void errorThreshold (const value_type& threshold);
336  {
337  return errorThreshold_;
338  }
340 
342  virtual void resetProblem ();
343 
347  virtual void resetRoadmap ();
348 
351 
356  void createPathOptimizers ();
357 
361  virtual bool prepareSolveStepByStep ();
362 
367  virtual bool executeOneStep ();
368 
371  virtual void finishSolveStepByStep ();
372 
374  virtual void solve ();
375 
387  bool directPath (ConfigurationIn_t start, ConfigurationIn_t end,
388  bool validate, std::size_t& pathId, std::string& report);
389 
391  void addConfigToRoadmap (const ConfigurationPtr_t& config);
392 
400  void addEdgeToRoadmap (const ConfigurationPtr_t& config1,
401  const ConfigurationPtr_t& config2,
402  const PathPtr_t& path);
403 
405  void interrupt ();
406 
408  std::size_t addPath (const PathVectorPtr_t& path)
409  {
410  std::size_t s = paths_.size();
411  paths_.push_back (path);
412  return s;
413  }
414 
416  void erasePath (std::size_t pathId)
417  {
418  PathVectors_t::iterator it = paths_.begin();
419  std::advance(it, pathId);
420 
421  paths_.erase(it);
422  }
423 
425  const PathVectors_t& paths () const
426  {
427  return paths_;
428  }
430 
433 
440  virtual void addObstacle (const DevicePtr_t& device, bool collision,
441  bool distance);
442 
449  virtual void addObstacle (const CollisionObjectPtr_t &inObject, bool collision,
450  bool distance);
451 
454  virtual void removeObstacle (const std::string& name);
455 
462  virtual void addObstacle (const std::string& name,
463  /*const*/ FclCollisionObject &inObject,
464  bool collision,
465  bool distance);
466 
470  void removeObstacleFromJoint (const std::string& jointName,
471  const std::string& obstacleName);
472 
475  void cutObstacle (const std::string& name, const fcl::AABB& aabb);
476 
480  void filterCollisionPairs ();
481 
484  CollisionObjectPtr_t obstacle (const std::string& name) const;
485 
488  const Transform3f& obstacleFramePosition (const std::string& name) const;
489 
495  std::list <std::string> obstacleNames (bool collision, bool distance)
496  const;
497 
500  {
501  return distanceBetweenObjects_;
502  }
503 
505  { return obstacleModel_; }
507  { return obstacleData_; }
509 
511  const ObjectStdVector_t& collisionObstacles () const;
513  const ObjectStdVector_t& distanceObstacles () const;
514 
516  void roadmap (const RoadmapPtr_t& roadmap)
517  {
518  roadmap_ = roadmap;
519  }
520 
524  void initDistance ();
525 
529  void initSteeringMethod ();
530 
534  void initPathProjector ();
535 
537  void initPathValidation ();
538 
540  void initConfigValidation ();
541 
543  void initValidations ();
544 
546  virtual void initProblemTarget ();
547 
575 
592 
593  protected:
597  ProblemSolver ();
598 
601 
603  void problem (ProblemPtr_t problem);
604 
610  virtual void initializeProblem (ProblemPtr_t problem);
611 
616 
623  std::string pathProjectorType_;
626 
628  std::string pathPlannerType_;
629 
632  private:
634  ConfigurationPtr_t initConf_;
636  Configurations_t goalConfigurations_;
638  std::string robotType_;
640  std::string configurationShooterType_;
642  std::string distanceType_;
644  std::string steeringMethodType_;
646  PathOptimizerTypes_t pathOptimizerTypes_;
647  PathOptimizers_t pathOptimizers_;
649  std::string pathValidationType_;
651  value_type pathValidationTolerance_;
652  // Config validation methods
653  ConfigValidationTypes_t configValidationTypes_;
655  ObjectStdVector_t collisionObstacles_; // FIXME should be removed?
656  ObjectStdVector_t distanceObstacles_; // FIXME should be removed?
657  pinocchio::ModelPtr_t obstacleRModel_; // Contains the frames
658  pinocchio::DataPtr_t obstacleRData_; // Contains the frames
659  pinocchio::GeomModelPtr_t obstacleModel_;
660  pinocchio::GeomDataPtr_t obstacleData_;
661  // Tolerance for numerical constraint resolution
662  value_type errorThreshold_;
663  // Maximal number of iterations for numerical constraint resolution
664  size_type maxIterProjection_;
666  unsigned long int maxIterPathPlanning_;
668  double timeOutPathPlanning_;
670  segmentsMap_t passiveDofsMap_;
674  DistanceBetweenObjectsPtr_t distanceBetweenObjects_;
675 
676  void initProblem ();
677  }; // class ProblemSolver
678  } // namespace core
679 } // namespace hpp
680 
681 #endif // HPP_CORE_PROBLEM_SOLVER_HH
const std::string & steeringMethodType() const
Definition: problem-solver.hh:143
boost::function< ConfigValidationPtr_t(const DevicePtr_t &) > ConfigValidationBuilder_t
Definition: problem-solver.hh:50
Container< ConfigValidationBuilder_t > configValidations
Definition: problem-solver.hh:565
boost::shared_ptr< Path > PathPtr_t
Definition: fwd.hh:170
const PathOptimizerPtr_t & pathOptimizer(std::size_t rank) const
Get path optimizer at given rank.
Definition: problem-solver.hh:167
boost::shared_ptr< Data > DataPtr_t
boost::function< PathProjectorPtr_t(const Problem &, const value_type &) > PathProjectorBuilder_t
Definition: problem-solver.hh:53
std::size_t addPath(const PathVectorPtr_t &path)
Add a path.
Definition: problem-solver.hh:408
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:114
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: fwd.hh:97
Definition: problem-solver.hh:68
Definition: problem.hh:48
const ConfigurationPtr_t & initConfig() const
Get shared pointer to initial configuration.
Definition: problem-solver.hh:108
constraints::ComparisonTypes_t ComparisonTypes_t
Definition: fwd.hh:76
const PathOptimizerTypes_t & pathOptimizerTypes() const
Definition: problem-solver.hh:161
boost::shared_ptr< ConstraintSet > ConstraintSetPtr_t
Definition: fwd.hh:110
const PathPlannerPtr_t & pathPlanner() const
Get path planner.
Definition: problem-solver.hh:152
std::map< std::string, segments_t > segmentsMap_t
Definition: fwd.hh:212
boost::function< DevicePtr_t(const std::string &) > RobotBuilder_t
Definition: problem-solver.hh:40
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
pinocchio::size_type size_type
Definition: fwd.hh:156
const ConfigValidationTypes_t configValidationTypes()
Get config validation current types.
Definition: problem-solver.hh:210
PathPlannerPtr_t pathPlanner_
Definition: problem-solver.hh:617
pinocchio::CollisionObjectPtr_t CollisionObjectPtr_t
Definition: fwd.hh:89
const std::string & distanceType() const
Definition: problem-solver.hh:138
boost::function< ConfigurationShooterPtr_t(const Problem &) > ConfigurationShooterBuilder_t
Definition: problem-solver.hh:55
boost::shared_ptr< GeomData > GeomDataPtr_t
Container< PathPlannerBuilder_t > pathPlanners
Definition: problem-solver.hh:571
Container< PathProjectorBuilder_t > pathProjectors
Definition: problem-solver.hh:568
size_type maxIterPathPlanning() const
Get maximal number of iterations in config projector.
Definition: problem-solver.hh:316
void addNumericalConstraint(const std::string &name, const constraints::ImplicitPtr_t &constraint)
Definition: problem-solver.hh:269
Container< RobotBuilder_t > robots
Definition: problem-solver.hh:550
std::vector< PathVectorPtr_t > PathVectors_t
Definition: fwd.hh:196
boost::function< SteeringMethodPtr_t(const Problem &) > SteeringMethodBuilder_t
Definition: problem-solver.hh:59
boost::function< PathValidationPtr_t(const DevicePtr_t &, const value_type &) > PathValidationBuilder_t
Definition: problem-solver.hh:48
std::vector< std::pair< std::string, CollisionObjectPtr_t > > AffordanceObjects_t
Definition: problem-solver.hh:60
Container< DistanceBuilder_t > distances
Definition: problem-solver.hh:559
std::string pathProjectorType_
Path projector method.
Definition: problem-solver.hh:623
boost::shared_ptr< Model > ModelPtr_t
pinocchio::GeomDataPtr_t obstacleGeomData() const
Definition: problem-solver.hh:506
const std::string & configurationShooterType() const
Definition: problem-solver.hh:148
Container< JointAndShapes_t > jointAndShapes
Container of JointAndShapes_t.
Definition: problem-solver.hh:587
const std::string & pathProjectorType(value_type &tolerance) const
Get path projector current type and get tolerance.
Definition: problem-solver.hh:198
boost::shared_ptr< PathValidation > PathValidationPtr_t
Definition: fwd.hh:290
void erasePath(std::size_t pathId)
Erase a path.
Definition: problem-solver.hh:416
pinocchio::matrix_t matrix_t
Definition: fwd.hh:145
AABB aabb
boost::shared_ptr< Constraint > ConstraintPtr_t
Definition: fwd.hh:109
boost::shared_ptr< PathPlanner > PathPlannerPtr_t
Definition: fwd.hh:174
pinocchio::GeomModelPtr_t obstacleGeomModel() const
Definition: problem-solver.hh:504
RoadmapPtr_t roadmap_
Store roadmap.
Definition: problem-solver.hh:619
pinocchio::vector_t vector_t
Definition: fwd.hh:201
Member_lockedJoints_in_class_ProblemSolver_has_been_removed_use_member_numericalConstraints_instead lockedJoints
Definition: problem-solver.hh:581
Container< AffordanceConfig_t > affordanceConfigs
Container of AffordanceConfig_t.
Definition: problem-solver.hh:591
Container< ConfigurationShooterBuilder_t > configurationShooters
Definition: problem-solver.hh:553
pinocchio::value_type value_type
Definition: fwd.hh:157
Container< AffordanceObjects_t > affordanceObjects
Container of AffordanceObjects_t.
Definition: problem-solver.hh:589
DevicePtr_t robot_
Robot.
Definition: problem-solver.hh:613
boost::shared_ptr< PathOptimizer > PathOptimizerPtr_t
Definition: fwd.hh:173
boost::function< PathOptimizerPtr_t(const Problem &) > PathOptimizerBuilder_t
Definition: problem-solver.hh:42
Container< CenterOfMassComputationPtr_t > centerOfMassComputations
Container of CenterOfMassComputation.
Definition: problem-solver.hh:583
pinocchio::Transform3f Transform3f
Definition: fwd.hh:198
boost::shared_ptr< PathProjector > PathProjectorPtr_t
Definition: fwd.hh:306
const std::string & pathPlannerType() const
Definition: problem-solver.hh:133
ProblemPtr_t problem()
Get pointer to problem.
Definition: problem-solver.hh:103
Container< PathValidationBuilder_t > pathValidations
Definition: problem-solver.hh:562
double getTimeOutPathPlanning()
set time out for the path planning ( in seconds)
Definition: problem-solver.hh:327
std::vector< std::string > PathOptimizerTypes_t
Definition: problem-solver.hh:73
std::vector< ConfigurationPtr_t > Configurations_t
Definition: fwd.hh:100
pinocchio::ConfigurationPtr_t ConfigurationPtr_t
Definition: fwd.hh:99
PathVectors_t paths_
Paths.
Definition: problem-solver.hh:621
std::map< std::string, CenterOfMassComputationPtr_t > CenterOfMassComputationMap_t
Definition: fwd.hh:215
boost::shared_ptr< PathVector > PathVectorPtr_t
Definition: fwd.hh:176
boost::shared_ptr< DistanceBetweenObjects > DistanceBetweenObjectsPtr_t
Definition: fwd.hh:124
boost::shared_ptr< Roadmap > RoadmapPtr_t
Definition: fwd.hh:181
constraints::Implicit NumericalConstraint HPP_CORE_DEPRECATED
Definition: fwd.hh:347
Container< SteeringMethodBuilder_t > steeringMethods
Definition: problem-solver.hh:556
boost::function< DistancePtr_t(const Problem &) > DistanceBuilder_t
Definition: problem-solver.hh:57
value_type pathProjectorTolerance_
Tolerance of path projector.
Definition: problem-solver.hh:625
const std::string & pathValidationType(value_type &tolerance) const
Definition: problem-solver.hh:186
boost::function< PathPlannerPtr_t(const Problem &, const RoadmapPtr_t &) > PathPlannerBuilder_t
Definition: problem-solver.hh:45
pinocchio::vector3_t vector3_t
Definition: fwd.hh:148
const RoadmapPtr_t & roadmap() const
Definition: problem-solver.hh:221
constraints::ImplicitPtr_t numericalConstraint(const std::string &name)
Get constraint with given name.
Definition: problem-solver.hh:287
std::vector< std::string > ConfigValidationTypes_t
Definition: problem-solver.hh:74
std::string pathPlannerType_
Path planner.
Definition: problem-solver.hh:628
boost::shared_ptr< ProblemTarget > ProblemTargetPtr_t
Definition: fwd.hh:175
Container< PathOptimizerBuilder_t > pathOptimizers
Definition: problem-solver.hh:574
value_type errorThreshold() const
Get errorimal number of threshold in config projector.
Definition: problem-solver.hh:335
ProblemPtr_t problem_
Problem.
Definition: problem-solver.hh:615
void roadmap(const RoadmapPtr_t &roadmap)
Set the roadmap.
Definition: problem-solver.hh:516
ConstraintSetPtr_t constraints_
Store constraints until call to solve.
Definition: problem-solver.hh:600
boost::shared_ptr< Implicit > ImplicitPtr_t
boost::shared_ptr< GeomModel > GeomModelPtr_t
const PathVectors_t & paths() const
Return vector of paths.
Definition: problem-solver.hh:425
pinocchio::Configuration_t Configuration_t
Definition: fwd.hh:96
size_type maxIterProjection() const
Get maximal number of iterations in config projector.
Definition: problem-solver.hh:308
std::vector< PathOptimizerPtr_t > PathOptimizers_t
Definition: problem-solver.hh:72
ProblemTargetPtr_t target_
Shared pointer to the problem target.
Definition: problem-solver.hh:631
vector3_t AffordanceConfig_t
Definition: problem-solver.hh:61
boost::shared_ptr< Problem > ProblemPtr_t
Definition: fwd.hh:179
Container< segments_t > passiveDofs
Container of passive DoFs (as segments_t)
Definition: problem-solver.hh:585
const DistanceBetweenObjectsPtr_t & distanceBetweenObjects() const
Return list of pair of distance computations.
Definition: problem-solver.hh:499
Container< constraints::ImplicitPtr_t > numericalConstraints
Container of constraints::Implicit.
Definition: problem-solver.hh:577
std::vector< CollisionObjectPtr_t > ObjectStdVector_t
Definition: fwd.hh:167
FCL_REAL distance(const KDOP< N > &other, Vec3f *P=NULL, Vec3f *Q=NULL) const
const ConstraintSetPtr_t & constraints() const
Get constraint set.
Definition: problem-solver.hh:233
void setTimeOutPathPlanning(double timeOut)
set time out for the path planning ( in seconds)
Definition: problem-solver.hh:322