hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
config-projector.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_CONFIG_PROJECTOR_HH
20 # define HPP_CORE_CONFIG_PROJECTOR_HH
21 
22 # include <Eigen/SVD>
23 
24 # include <hpp/statistics/success-bin.hh>
25 
26 # include <hpp/core/config.hh>
27 # include <hpp/core/constraint.hh>
28 # include <hpp/core/deprecated.hh>
29 
30 namespace hpp {
31  namespace core {
33 
36 
57  class HPP_CORE_DLLAPI ConfigProjector : public Constraint
58  {
59  public:
64  Constant
65  };
66 
73  static ConfigProjectorPtr_t create (const DevicePtr_t& robot,
74  const std::string& name,
75  value_type errorThreshold,
76  size_type maxIterations);
77 
80  static ConfigProjectorPtr_t createCopy (const ConfigProjectorPtr_t cp);
81 
83  virtual ConstraintPtr_t copy () const;
84 
86  virtual ~ConfigProjector ();
87 
92  bool contains (const constraints::ImplicitPtr_t& numericalConstraint)
93  const;
94 
98  bool add (const constraints::ImplicitPtr_t& numericalConstraint,
99  const segments_t& passiveDofs = segments_t (0),
100  const std::size_t priority = 0);
101 
111  bool add (const constraints::ImplicitPtr_t& numericalConstraint,
112  const std::size_t priority)
113  {
114  return add (numericalConstraint, segments_t(0), priority);
115  }
116 
117  void lastIsOptional (bool optional);
118 
119  bool lastIsOptional () const;
120 
125  bool optimize (ConfigurationOut_t config,
126  std::size_t maxIter = 0);
127 
129  const DevicePtr_t& robot () const
130  {
131  return robot_;
132  }
133 
143  void projectVectorOnKernel (ConfigurationIn_t from,
144  vectorIn_t velocity, vectorOut_t result);
145 
155  virtual void projectOnKernel (ConfigurationIn_t from,
157 
168  void computeValueAndJacobian (ConfigurationIn_t configuration,
169  vectorOut_t value,
170  matrixOut_t reducedJacobian);
171 
175  bool oneStep (ConfigurationOut_t config, vectorOut_t dq,
176  const value_type& alpha) HPP_CORE_DEPRECATED;
177 
185 
187  size_type numberFreeVariables () const;
188 
191  size_type numberNonLockedDof () const HPP_CORE_DEPRECATED;
192 
194  size_type dimension () const;
195 
200  void compressVector (vectorIn_t normal, vectorOut_t small) const;
201 
207  void uncompressVector (vectorIn_t small, vectorOut_t normal) const;
208 
214  void compressMatrix (matrixIn_t normal, matrixOut_t small,
215  bool rows = true) const;
216 
222  void uncompressMatrix (matrixIn_t small, matrixOut_t normal,
223  bool rows = true) const;
224 
226 
228  void maxIterations (size_type iterations);
230  size_type maxIterations () const;
231 
233  void errorThreshold (const value_type& threshold);
235  value_type errorThreshold () const;
236 
237  value_type residualError() const;
238 
239  const value_type& sigma() const;
240 
243 
259  vector_t rightHandSideFromConfig (ConfigurationIn_t config);
260 
263  void rightHandSideFromConfig (const constraints::ImplicitPtr_t& nm,
264  ConfigurationIn_t config);
265 
268  void rightHandSide (const vector_t& param);
269 
272  void rightHandSide (const constraints::ImplicitPtr_t& nm, vectorIn_t rhs);
273 
276  vector_t rightHandSide () const;
277 
279  void rightHandSideAt (const value_type& s);
280 
282 
284  virtual bool isSatisfied (ConfigurationIn_t config);
285 
291  virtual bool isSatisfied (ConfigurationIn_t config, vector_t& error);
292 
295  {
296  return statistics_;
297  }
298 
301  const NumericalConstraints_t& numericalConstraints () const;
302 
303  const BySubstitution& solver () const
304  {
305  return *solver_;
306  }
307 
310  {
311  lineSearchType_ = ls;
312  }
313 
316  {
317  return lineSearchType_;
318  }
319 
320  static void defaultLineSearch (LineSearchType ls);
321 
322  protected:
329  ConfigProjector (const DevicePtr_t& robot, const std::string& name,
330  value_type errorThreshold, size_type maxIterations);
332  ConfigProjector (const ConfigProjector& cp);
333 
335  void init (const ConfigProjectorPtr_t& self)
336  {
337  Constraint::init (self);
338  weak_ = self;
339  }
341  virtual bool impl_compute (ConfigurationOut_t configuration);
342 
343  private:
344  virtual std::ostream& print (std::ostream& os) const;
345  virtual void addToConstraintSet (const ConstraintSetPtr_t& constraintSet);
346 
347  DevicePtr_t robot_;
348  static LineSearchType defaultLineSearch_;
349  LineSearchType lineSearchType_;
350  BySubstitution* solver_;
351 
352  bool solverOneStep (ConfigurationOut_t config) const;
353  int solverSolve (ConfigurationOut_t config) const;
354 
355  ConfigProjectorWkPtr_t weak_;
357  }; // class ConfigProjector
359  } // namespace core
360 } // namespace hpp
361 #endif // HPP_CORE_CONFIG_PROJECTOR_HH
void lineSearchType(LineSearchType ls)
Set the line search type.
Definition: config-projector.hh:309
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:114
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: fwd.hh:97
boost::shared_ptr< ConstraintSet > ConstraintSetPtr_t
Definition: fwd.hh:110
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
pinocchio::ConfigurationOut_t ConfigurationOut_t
Definition: fwd.hh:98
pinocchio::size_type size_type
Definition: fwd.hh:156
Definition: config-projector.hh:57
constraints::NumericalConstraints_t NumericalConstraints_t
Definition: fwd.hh:213
LineSearchType lineSearchType() const
Get the line search type.
Definition: config-projector.hh:315
Definition: constraint.hh:37
void init(const ConstraintPtr_t &self)
Store shared pointer to itself.
Definition: constraint.hh:79
::hpp::statistics::SuccessStatistics & statistics()
Get the statistics.
Definition: config-projector.hh:294
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:202
Definition: config-projector.hh:61
constraints::matrixIn_t matrixIn_t
Definition: fwd.hh:149
boost::shared_ptr< Constraint > ConstraintPtr_t
Definition: fwd.hh:109
bool add(const constraints::ImplicitPtr_t &numericalConstraint, const std::size_t priority)
Definition: config-projector.hh:111
pinocchio::vector_t vector_t
Definition: fwd.hh:201
pinocchio::value_type value_type
Definition: fwd.hh:157
LineSearchType
Definition: config-projector.hh:60
void init(const ConfigProjectorPtr_t &self)
Store weak pointer to itself.
Definition: config-projector.hh:335
constraints::matrixOut_t matrixOut_t
Definition: fwd.hh:150
boost::shared_ptr< ConfigProjector > ConfigProjectorPtr_t
Definition: fwd.hh:104
constraints::Implicit NumericalConstraint HPP_CORE_DEPRECATED
Definition: fwd.hh:347
const BySubstitution & solver() const
Definition: config-projector.hh:303
constraints::segments_t segments_t
Definition: fwd.hh:162
pinocchio::vectorOut_t vectorOut_t
Definition: fwd.hh:203
Definition: config-projector.hh:62
Definition: config-projector.hh:63
constraints::solver::BySubstitution BySubstitution
Definition: config-projector.hh:32
boost::shared_ptr< Implicit > ImplicitPtr_t
const DevicePtr_t & robot() const
Get robot.
Definition: config-projector.hh:129