hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
gradient-based.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2014 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_PATH_OPTIMIZATION_GRADIENT_BASED_HH
20 # define HPP_CORE_PATH_OPTIMIZATION_GRADIENT_BASED_HH
21 
23 #include <hpp/core/path-vector.hh>
25 
26 namespace hpp {
27  namespace core {
30  namespace pathOptimization {
31  class CollisionConstraintsResult;
32  typedef std::vector <CollisionConstraintsResult>
34 
35  class HPP_CORE_DLLAPI GradientBased : public PathOptimizer
36  {
37  public:
40  static GradientBasedPtr_t create (const Problem& problem);
41 
43  virtual PathVectorPtr_t optimize (const PathVectorPtr_t& path);
44 
45  protected:
46  GradientBased (const Problem& problem);
47 
48  private:
49  typedef Eigen::JacobiSVD < matrix_t > Jacobi_t;
50 
51  void compressHessian (matrixIn_t normal, matrixOut_t small) const;
52  void compressVector (vectorIn_t normal, vectorOut_t small) const;
53  void uncompressVector (vectorIn_t small, vectorOut_t normal) const;
54 
55  void initialize (const PathVectorPtr_t& path);
56 
58  void pathToVector (const PathVectorPtr_t& path, vectorOut_t x) const {
59  size_type index = 0;
60  for (std::size_t i=0; i < path->numberPaths () - 1; ++i) {
61  const PathPtr_t& localPath = path->pathAtRank (i);
62  value_type t1 = localPath->timeRange ().second;
63  (*localPath) (x.segment (index, configSize_), t1);
64  index += configSize_;
65  }
66  assert (index == x.size ());
67  }
68 
70  void vectorToPath (vectorIn_t x, const PathVectorPtr_t& result) const {
71  Configuration_t q0 = initial_, q1;
72  size_type index = 0;
73  while (index < x.size ()) {
74  q1 = x.segment (index, configSize_);
75  PathPtr_t p = (*steeringMethod_) (q0, q1);
76  result->appendPath (p);
77  q0 = q1;
78  index += configSize_;
79  }
80  q1 = end_;
81  PathPtr_t p = (*steeringMethod_) (q0, q1);
82  result->appendPath (p);
83  }
84 
85  void initializeProblemConstraints ();
93  void updateProblemConstraints (vectorIn_t x);
94 
106  bool constraintsSatisfied
107  (vectorOut_t& x, PathVectorPtr_t& path,
108  CollisionConstraintsResults_t& collisionConstraints);
109 
120  bool solveConstraints (vectorOut_t x, PathVectorPtr_t& path,
121  CollisionConstraintsResults_t&
122  collisionConstraints);
124  void integrate (vectorIn_t x0, vectorIn_t step, vectorOut_t x1) const;
125 
127  vector_t computeIterate (vectorIn_t x) const;
128 
130  void displayPath (vectorIn_t x, std::string
131 #ifdef HPP_DEBUG
132  prefix
133 #endif
134  ) const {
135  hppDout(info, prefix);
136  for (int i=0; i<x.size (); i++)
137  hppDout(info, x[i]);
138  hppDout(info, "finish path parsing");
139  }
140 
148  void addCollisionConstraint (const CollisionConstraintsResult& ccr,
149  const PathVectorPtr_t& path) const;
150 
158  void updateRightHandSide (const CollisionConstraintsResults_t&
159  collisionConstraints,
160  const PathVectorPtr_t& path) const;
161 
163  bool getProblemConstraints ();
164 
165  mutable CostPtr_t cost_;
166  DevicePtr_t robot_;
167  size_type configSize_;
168  size_type robotNumberDofs_;
169  size_type robotNbNonLockedDofs_;
170  size_type numberDofs_;
171  size_type fSize_; // dimension of collision constraints
172  mutable Configuration_t initial_;
173  mutable Configuration_t end_;
174  WeighedDistancePtr_t distance_;
175  steeringMethod::StraightPtr_t steeringMethod_;
180  mutable matrix_t H_, Hinverse_, J_;
181  mutable matrix_t Hz_, gz_;
182  mutable vector_t stepNormal_;
183  mutable bool fullRank_;
184  mutable size_type nbWaypoints_;
185  mutable value_type alpha_;
186  mutable rowvector_t rgrad_;
187  mutable vector_t rhs_;
188  mutable vector_t value_;
189  mutable vector_t p_, p0_;
190  value_type epsilon_;
191  std::size_t iterMax_;
192  value_type alphaInit_; // .1, .2, .4
193  value_type alphaMax_;
194  }; // GradientBased
195  } // namespace pathOptimization
196  } // namespace core
197 } // namespace hpp
198 #endif // HPP_CORE_PATH_OPTIMIZATION_GRADIENT_BASED_HH
boost::shared_ptr< Path > PathPtr_t
Definition: fwd.hh:170
boost::shared_ptr< WeighedDistance > WeighedDistancePtr_t
Definition: fwd.hh:207
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:114
#define hppDout(channel, data)
Definition: problem.hh:48
boost::shared_ptr< GradientBased > GradientBasedPtr_t
Definition: fwd.hh:271
std::vector< CollisionConstraintsResult > CollisionConstraintsResults_t
Definition: gradient-based.hh:31
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)
boost::shared_ptr< Cost > CostPtr_t
Definition: fwd.hh:269
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
pinocchio::size_type size_type
Definition: fwd.hh:156
Definition: gradient-based.hh:35
assert(d.lhs()._blocks()==d.rhs()._blocks())
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:202
constraints::matrixIn_t matrixIn_t
Definition: fwd.hh:149
pinocchio::matrix_t matrix_t
Definition: fwd.hh:145
Definition: path-optimizer.hh:32
pinocchio::vector_t vector_t
Definition: fwd.hh:201
pinocchio::value_type value_type
Definition: fwd.hh:157
constraints::matrixOut_t matrixOut_t
Definition: fwd.hh:150
boost::shared_ptr< PathVector > PathVectorPtr_t
Definition: fwd.hh:176
pinocchio::vectorOut_t vectorOut_t
Definition: fwd.hh:203
boost::shared_ptr< Straight > StraightPtr_t
Definition: fwd.hh:26
pinocchio::Configuration_t Configuration_t
Definition: fwd.hh:96
Eigen::Matrix< value_type, 1, Eigen::Dynamic > rowvector_t
Definition: fwd.hh:204