hpp-constraints  4.9.1
Definition of basic geometric constraints for motion planning
explicit-constraint-set.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of hpp-constraints.
5 // hpp-constraints is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // hpp-constraints is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // hpp-constraints. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HPP_CONSTRAINTS_EXPLICIT_CONSTRAINT_SET_HH
18 #define HPP_CONSTRAINTS_EXPLICIT_CONSTRAINT_SET_HH
19 
20 #include <vector>
21 
22 #include <boost/function.hpp>
23 
24 #include <hpp/constraints/fwd.hh>
25 #include <hpp/constraints/config.hh>
26 
29 
30 namespace hpp {
31  namespace constraints {
34 
93  class HPP_CONSTRAINTS_DLLAPI ExplicitConstraintSet
94  {
95  public:
99 
102 
109  bool solve (vectorOut_t arg) const;
110 
113  bool isSatisfied (vectorIn_t arg) const;
114 
118  bool isSatisfied (vectorIn_t arg, vectorOut_t error) const;
119 
129  bool isConstraintSatisfied (const ImplicitPtr_t& constraint,
130  vectorIn_t arg, vectorOut_t error,
131  bool& constraintFound) const;
133 
136 
144  size_type add (const ExplicitPtr_t& constraint);
145 
152  bool contains (const ExplicitPtr_t& numericalConstraint) const;
153 
158  : configSpace_ (space)
159  , inArgs_ (), notOutArgs_ ()
160  , inDers_ (), notOutDers_ ()
161  , outArgs_ (), outDers_ ()
162  , argFunction_ (Eigen::VectorXi::Constant(space->nq (), -1))
163  , derFunction_ (Eigen::VectorXi::Constant(space->nv (), -1))
164  , squaredErrorThreshold_ (Eigen::NumTraits<value_type>::epsilon())
165  // , Jg (nv, nv)
166  , arg_ (space->nq ()), diff_(space->nv ()), diffSmall_()
167  {
168  notOutArgs_.addRow(0, space->nq ());
169  notOutDers_.addCol(0, space->nv ());
170  }
171 
173 
176 
178  void errorThreshold (const value_type& threshold)
179  {
180  squaredErrorThreshold_ = threshold * threshold;
181  }
184  {
185  return sqrt (squaredErrorThreshold_);
186  }
189  {
190  return squaredErrorThreshold_;
191  }
192 
194 
197 
199  const RowBlockIndices& inArgs () const
200  {
201  return inArgs_;
202  }
203 
205  const ColBlockIndices& inDers () const
206  {
207  return inDers_;
208  }
209 
213  const RowBlockIndices& freeArgs () const HPP_CONSTRAINTS_DEPRECATED
214  {
215  return notOutArgs_;
216  }
217 
221  const ColBlockIndices& freeDers () const HPP_CONSTRAINTS_DEPRECATED
222  {
223  return notOutDers_;
224  }
225 
229  const RowBlockIndices& notOutArgs () const
230  {
231  return notOutArgs_;
232  }
233 
237  const ColBlockIndices& notOutDers () const
238  {
239  return notOutDers_;
240  }
241 
243  ColBlockIndices activeParameters () const;
244 
246  const ColBlockIndices& activeDerivativeParameters () const;
247 
253  const Eigen::MatrixXi& inOutDependencies () const
254  {
255  return inOutDependencies_;
256  }
257 
259  Eigen::MatrixXi inOutDofDependencies () const;
260 
261  const Eigen::VectorXi& derFunction () const
262  {
263  return derFunction_;
264  }
265 
270  const RowBlockIndices& outArgs () const
271  {
272  return outArgs_;
273  }
274 
279  const RowBlockIndices& outDers () const
280  {
281  return outDers_;
282  }
283 
286  std::size_t argSize () const HPP_CONSTRAINTS_DEPRECATED
287  {
288  return configSpace_->nq ();
289  }
290 
293  std::size_t derSize () const HPP_CONSTRAINTS_DEPRECATED
294  {
295  return configSpace_->nv ();
296  }
297 
300  {
301  return configSpace_;
302  }
303 
305  std::size_t nq () const
306  {
307  return configSpace_->nq ();
308  }
309 
311  std::size_t nv () const
312  {
313  return configSpace_->nv ();
314  }
315 
317 
320  inline MatrixBlockView viewJacobian(matrix_t& jacobian) const
322  {
323  return MatrixBlockView(jacobian,
324  outDers_.nbIndices() , outDers_.indices(),
325  notOutDers_.nbIndices(), notOutDers_.indices());
326  }
327 
340  inline MatrixBlockView jacobianNotOutToOut (matrix_t& jacobian) const
341  {
342  return MatrixBlockView(jacobian,
343  outDers_.nbIndices() , outDers_.indices(),
344  notOutDers_.nbIndices(), notOutDers_.indices());
345  }
346 
363  void jacobian(matrixOut_t jacobian, vectorIn_t q) const;
364 
367 
387  vector_t rightHandSideFromInput (vectorIn_t p);
388 
409  bool rightHandSideFromInput (const ExplicitPtr_t& constraint,
410  vectorIn_t p);
411 
432  void rightHandSideFromInput (const size_type& i, vectorIn_t p);
433 
440  void rightHandSide (vectorIn_t rhs);
441 
446  bool rightHandSide (const ExplicitPtr_t& constraint, vectorIn_t rhs);
447 
452  bool getRightHandSide (const ExplicitPtr_t& constraint, vectorOut_t rhs) const ;
453 
458  void rightHandSide (const size_type& i, vectorIn_t rhs);
459 
463  vector_t rightHandSide () const;
464 
468  size_type rightHandSideSize () const;
469 
471 
472  std::ostream& print (std::ostream& os) const;
473 
474  private:
475  typedef std::vector<bool> Computed_t;
476 
481  void solveExplicitConstraint(const std::size_t& i, vectorOut_t arg)
482  const;
497  void computeJacobian(const std::size_t& i, matrixOut_t J) const;
498  void computeOrder(const std::size_t& iF, std::size_t& iOrder, Computed_t& computed);
499 
500  LiegroupSpacePtr_t configSpace_;
501 
502  struct Data {
503  Data (const ExplicitPtr_t& constraint);
504  ExplicitPtr_t constraint;
505  RowBlockIndices equalityIndices;
506  vector_t rhs_implicit;
507  vector_t rhs_explicit;
508  // implicit formulation
509  mutable LiegroupElement h_value;
510  // explicit formulation
511  mutable vector_t qin, qout;
512  mutable LiegroupElement f_value, res_qout;
513  // jacobian of f
514  mutable matrix_t jacobian;
515  }; // struct Data
516 
517  RowBlockIndices inArgs_, notOutArgs_;
518  ColBlockIndices inDers_, notOutDers_;
520  RowBlockIndices outArgs_, outDers_;
521 
522  Eigen::MatrixXi inOutDependencies_;
523 
524  std::vector<Data> data_;
525  std::vector<std::size_t> computationOrder_;
531  Eigen::VectorXi argFunction_, derFunction_;
532  value_type squaredErrorThreshold_;
533  // mutable matrix_t Jg;
534  mutable vector_t arg_, diff_, diffSmall_;
535  }; // class ExplicitConstraintSet
537  } // namespace constraints
538 } // namespace hpp
539 
540 #endif // HPP_CONSTRAINTS_EXPLICIT_CONSTRAINT_SET_HH
::pinocchio::DataTpl< value_type, 0, JointCollectionTpl > Data
pinocchio::vector_t vector_t
Definition: fwd.hh:45
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:46
void errorThreshold(const value_type &threshold)
Set error threshold.
Definition: explicit-constraint-set.hh:178
std::size_t nq() const
The number of variables.
Definition: explicit-constraint-set.hh:305
pinocchio::LiegroupSpacePtr_t LiegroupSpacePtr_t
Definition: fwd.hh:54
MatrixBlockView viewJacobian(matrix_t &jacobian) const HPP_CONSTRAINTS_DEPRECATED
Definition: explicit-constraint-set.hh:320
const RowBlockIndices & inArgs() const
Set of input configuration variables.
Definition: explicit-constraint-set.hh:199
Definition: fwd.hh:26
const RowBlockIndices & notOutArgs() const
Definition: explicit-constraint-set.hh:229
pinocchio::matrix_t matrix_t
Definition: fwd.hh:42
LiegroupSpacePtr_t configSpace() const
The Lie group on which constraints are defined.
Definition: explicit-constraint-set.hh:299
std::size_t nv() const
The number of derivative variables.
Definition: explicit-constraint-set.hh:311
Eigen::MatrixBlockView< matrix_t, Eigen::Dynamic, Eigen::Dynamic, false, false > MatrixBlockView
Definition: explicit-constraint-set.hh:98
ExplicitConstraintSet(const LiegroupSpacePtr_t &space)
Definition: explicit-constraint-set.hh:157
Definition: matrix-view.hh:111
const Eigen::MatrixXi & inOutDependencies() const
Definition: explicit-constraint-set.hh:253
boost::shared_ptr< Explicit > ExplicitPtr_t
Definition: fwd.hh:173
const Eigen::VectorXi & derFunction() const
Definition: explicit-constraint-set.hh:261
const RowBlockIndices & freeArgs() const HPP_CONSTRAINTS_DEPRECATED
Definition: explicit-constraint-set.hh:213
value_type errorThreshold() const
Get error threshold.
Definition: explicit-constraint-set.hh:183
Eigen::ColBlockIndices ColBlockIndices
Definition: explicit-constraint-set.hh:97
const ColBlockIndices & freeDers() const HPP_CONSTRAINTS_DEPRECATED
Definition: explicit-constraint-set.hh:221
const RowBlockIndices & outDers() const
Definition: explicit-constraint-set.hh:279
pinocchio::vectorOut_t vectorOut_t
Definition: fwd.hh:47
std::size_t derSize() const HPP_CONSTRAINTS_DEPRECATED
Definition: explicit-constraint-set.hh:293
Eigen::RowBlockIndices RowBlockIndices
Definition: explicit-constraint-set.hh:96
pinocchio::size_type size_type
Definition: fwd.hh:35
Eigen::Ref< matrix_t > matrixOut_t
Definition: fwd.hh:44
Eigen::NumTraits< value_type > NumTraits
Definition: by-substitution.hh:24
MatrixBlockView jacobianNotOutToOut(matrix_t &jacobian) const
Definition: explicit-constraint-set.hh:340
const ColBlockIndices & notOutDers() const
Definition: explicit-constraint-set.hh:237
std::size_t argSize() const HPP_CONSTRAINTS_DEPRECATED
Definition: explicit-constraint-set.hh:286
pinocchio::value_type value_type
Definition: fwd.hh:36
boost::shared_ptr< Implicit > ImplicitPtr_t
Definition: fwd.hh:157
const ColBlockIndices & inDers() const
Set of input velocity variables.
Definition: explicit-constraint-set.hh:205
DifferentiableFunctionSet DifferentiableFunctionStack HPP_CONSTRAINTS_DEPRECATED
Definition: fwd.hh:99
const RowBlockIndices & outArgs() const
Definition: explicit-constraint-set.hh:270
Definition: explicit-constraint-set.hh:93
value_type squaredErrorThreshold() const
Get error threshold.
Definition: explicit-constraint-set.hh:188