hpp-core  6.0.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 
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // 2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 // DAMAGE.
29 
30 #ifndef HPP_CORE_CONFIG_PROJECTOR_HH
31 #define HPP_CORE_CONFIG_PROJECTOR_HH
32 
33 #include <Eigen/SVD>
34 #include <hpp/core/config.hh>
35 #include <hpp/core/constraint.hh>
36 #include <hpp/core/deprecated.hh>
37 #include <hpp/statistics/success-bin.hh>
38 
39 namespace hpp {
40 namespace core {
42 
45 
67  public:
68  enum LineSearchType { Backtracking, ErrorNormBased, FixedSequence, Constant };
69 
77  const std::string& name,
78  value_type errorThreshold,
79  size_type maxIterations);
80 
84 
86  virtual ConstraintPtr_t copy() const;
87 
89  virtual ~ConfigProjector();
90 
95  bool contains(const constraints::ImplicitPtr_t& numericalConstraint) const;
96 
106  bool add(const constraints::ImplicitPtr_t& numericalConstraint,
107  const std::size_t priority = 0);
108 
109  void lastIsOptional(bool optional);
110 
111  bool lastIsOptional() const;
112 
117  bool optimize(ConfigurationOut_t config, std::size_t maxIter = 0);
118 
120  const DevicePtr_t& robot() const { return robot_; }
121 
132  vectorOut_t result);
133 
144  ConfigurationOut_t result);
145 
157  vectorOut_t value, matrixOut_t reducedJacobian);
158 
166 
169 
172 
177  void compressVector(vectorIn_t normal, vectorOut_t small) const;
178 
184  void uncompressVector(vectorIn_t small, vectorOut_t normal) const;
185 
192  bool rows = true) const;
193 
200  bool rows = true) const;
201 
203 
205  void maxIterations(size_type iterations);
208 
210  void errorThreshold(const value_type& threshold);
213 
215 
216  const value_type& sigma() const;
217 
220 
237 
240  void rightHandSideFromConfig(const constraints::ImplicitPtr_t& nm,
241  ConfigurationIn_t config);
242 
245  void rightHandSide(const vector_t& param);
246 
249  void rightHandSide(const constraints::ImplicitPtr_t& nm, vectorIn_t rhs);
250 
254 
256  void rightHandSideAt(const value_type& s);
257 
259 
262  virtual bool isSatisfied(ConfigurationIn_t config);
263 
268  virtual bool isSatisfied(ConfigurationIn_t config, value_type errorThreshold);
269 
276  virtual bool isSatisfied(ConfigurationIn_t config, vector_t& error);
277 
279  ::hpp::statistics::SuccessStatistics& statistics() { return statistics_; }
280 
284 
285  const BySubstitution& solver() const { return *solver_; }
286 
287  BySubstitution& solver() { return *solver_; }
288 
290  void lineSearchType(LineSearchType ls) { lineSearchType_ = ls; }
291 
293  LineSearchType lineSearchType() const { return lineSearchType_; }
294 
296 
297  protected:
304  ConfigProjector(const DevicePtr_t& robot, const std::string& name,
305  value_type errorThreshold, size_type maxIterations);
308 
310  void init(const ConfigProjectorPtr_t& self) {
311  Constraint::init(self);
312  weak_ = self;
313  }
315  virtual bool impl_compute(ConfigurationOut_t configuration);
316 
317  private:
318  virtual std::ostream& print(std::ostream& os) const;
319 
320  DevicePtr_t robot_;
321  static LineSearchType defaultLineSearch_;
322  LineSearchType lineSearchType_;
323  BySubstitution* solver_;
324 
325  bool solverOneStep(ConfigurationOut_t config) const;
326  int solverSolve(ConfigurationOut_t config) const;
327 
328  ConfigProjectorWkPtr_t weak_;
329  ::hpp::statistics::SuccessStatistics statistics_;
330 
331  ConfigProjector() {}
332  HPP_SERIALIZABLE();
333 }; // class ConfigProjector
335 } // namespace core
336 } // namespace hpp
337 #endif // HPP_CORE_CONFIG_PROJECTOR_HH
Definition: config-projector.hh:66
size_type numberFreeVariables() const
Return the number of free variables.
void uncompressMatrix(matrixIn_t small, matrixOut_t normal, bool rows=true) const
void init(const ConfigProjectorPtr_t &self)
Store weak pointer to itself.
Definition: config-projector.hh:310
void errorThreshold(const value_type &threshold)
Set error threshold.
static ConfigProjectorPtr_t create(const DevicePtr_t &robot, const std::string &name, value_type errorThreshold, size_type maxIterations)
void lastIsOptional(bool optional)
bool contains(const constraints::ImplicitPtr_t &numericalConstraint) const
LineSearchType
Definition: config-projector.hh:68
@ Backtracking
Definition: config-projector.hh:68
size_type dimension() const
Get constraint dimension.
void compressVector(vectorIn_t normal, vectorOut_t small) const
LineSearchType lineSearchType() const
Get the line search type.
Definition: config-projector.hh:293
virtual ConstraintPtr_t copy() const
return shared pointer to copy
virtual bool impl_compute(ConfigurationOut_t configuration)
Numerically solve constraint.
void rightHandSideAt(const value_type &s)
Update the right hand side using Implicit::rightHandSideAt.
bool add(const constraints::ImplicitPtr_t &numericalConstraint, const std::size_t priority=0)
ConfigProjector(const ConfigProjector &cp)
Copy constructor.
void rightHandSide(const vector_t &param)
value_type residualError() const
const BySubstitution & solver() const
Definition: config-projector.hh:285
static void defaultLineSearch(LineSearchType ls)
virtual void projectOnKernel(ConfigurationIn_t from, ConfigurationIn_t to, ConfigurationOut_t result)
vector_t rightHandSideFromConfig(ConfigurationIn_t config)
virtual bool isSatisfied(ConfigurationIn_t config, vector_t &error)
virtual ~ConfigProjector()
Destructor.
size_type maxIterations() const
Get maximal number of iterations in config projector.
static ConfigProjectorPtr_t createCopy(const ConfigProjectorPtr_t cp)
::hpp::statistics::SuccessStatistics & statistics()
Get the statistics.
Definition: config-projector.hh:279
const value_type & sigma() const
BySubstitution & solver()
Definition: config-projector.hh:287
void computeValueAndJacobian(ConfigurationIn_t configuration, vectorOut_t value, matrixOut_t reducedJacobian)
void rightHandSide(const constraints::ImplicitPtr_t &nm, vectorIn_t rhs)
void compressMatrix(matrixIn_t normal, matrixOut_t small, bool rows=true) const
ConfigProjector(const DevicePtr_t &robot, const std::string &name, value_type errorThreshold, size_type maxIterations)
value_type errorThreshold() const
Get errorimal number of threshold in config projector.
virtual bool isSatisfied(ConfigurationIn_t config)
void lineSearchType(LineSearchType ls)
Set the line search type.
Definition: config-projector.hh:290
void uncompressVector(vectorIn_t small, vectorOut_t normal) const
vector_t rightHandSide() const
void projectVectorOnKernel(ConfigurationIn_t from, vectorIn_t velocity, vectorOut_t result)
const NumericalConstraints_t & numericalConstraints() const
virtual bool isSatisfied(ConfigurationIn_t config, value_type errorThreshold)
void maxIterations(size_type iterations)
Set maximal number of iterations.
const DevicePtr_t & robot() const
Get robot.
Definition: config-projector.hh:120
void rightHandSideFromConfig(const constraints::ImplicitPtr_t &nm, ConfigurationIn_t config)
bool optimize(ConfigurationOut_t config, std::size_t maxIter=0)
Definition: constraint.hh:49
void init(const ConstraintPtr_t &self)
Store shared pointer to itself.
Definition: constraint.hh:82
#define HPP_CORE_DLLAPI
Definition: config.hh:88
constraints::NumericalConstraints_t NumericalConstraints_t
Definition: fwd.hh:232
pinocchio::value_type value_type
Definition: fwd.hh:174
shared_ptr< Constraint > ConstraintPtr_t
Definition: fwd.hh:129
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:221
pinocchio::vectorOut_t vectorOut_t
Definition: fwd.hh:222
pinocchio::ConfigurationOut_t ConfigurationOut_t
Definition: fwd.hh:109
pinocchio::vector_t vector_t
Definition: fwd.hh:220
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: fwd.hh:108
pinocchio::size_type size_type
Definition: fwd.hh:173
constraints::solver::BySubstitution BySubstitution
Definition: config-projector.hh:41
shared_ptr< ConfigProjector > ConfigProjectorPtr_t
Definition: fwd.hh:114
constraints::matrixOut_t matrixOut_t
Definition: fwd.hh:167
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:134
constraints::matrixIn_t matrixIn_t
Definition: fwd.hh:166
Definition: bi-rrt-planner.hh:35