hpp-constraints  4.9.1
Definition of basic geometric constraints for motion planning
affine-function.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_AFFINE_FUNCTION_HH
18 # define HPP_CONSTRAINTS_AFFINE_FUNCTION_HH
19 
20 # include <hpp/constraints/fwd.hh>
21 # include <hpp/constraints/config.hh>
22 
24 
25 namespace hpp {
26  namespace constraints {
27 
30 
35  class HPP_CONSTRAINTS_DLLAPI Identity
37  {
38  public:
39  static IdentityPtr_t create (const LiegroupSpacePtr_t space, const std::string& name)
40  {
41  IdentityPtr_t ptr (new Identity (space, name));
42  return ptr;
43  }
44 
45  Identity (const LiegroupSpacePtr_t space, const std::string& name) :
46  DifferentiableFunction (space->nq(), space->nv(), space, name) {}
47 
48  protected:
50  {
51  y.vector() = arg;
52  }
53 
55  {
56  J.setIdentity();
57  }
58  }; // class Identity
59 
64  class HPP_CONSTRAINTS_DLLAPI AffineFunction
65  : public DifferentiableFunction
66  {
67  public:
69  const std::string name = "LinearFunction")
70  : DifferentiableFunction (J.cols(), J.cols(), LiegroupSpace::Rn
71  (J.rows()), name),
72  J_ (J), b_ (vector_t::Zero(J.rows()))
73  {
74  init();
75  }
76 
78  const std::string name = "LinearFunction")
79  : DifferentiableFunction (J.cols(), J.cols(), LiegroupSpace::Rn
80  (J.rows()), name),
81  J_ (J), b_ (b)
82  {
83  init();
84  }
85 
86  private:
88  void impl_compute (LiegroupElementRef y, vectorIn_t x) const
89  {
90  y.vector ().noalias() = J_ * x + b_;
91  }
92 
93  void impl_jacobian (matrixOut_t jacobian, vectorIn_t) const
94  {
95  jacobian = J_;
96  }
97 
98  void init ()
99  {
100  assert(J_.rows() == b_.rows());
101  activeParameters_ = (J_.array() != 0).colwise().any();
102  activeDerivativeParameters_ = activeParameters_;
103  }
104 
105  const matrix_t J_;
106  const vector_t b_;
107  }; // class AffineFunction
108 
113  struct HPP_CONSTRAINTS_DLLAPI ConstantFunction
114  : public DifferentiableFunction
115  {
116  public:
117  ConstantFunction (const vector_t& constant,
118  const size_type& sizeIn,
119  const size_type& sizeInDer,
120  const std::string name = "ConstantFunction") :
121  DifferentiableFunction (sizeIn, sizeInDer, LiegroupSpace::Rn
122  (constant.rows()), name),
123  c_ (constant, LiegroupSpace::Rn (constant.rows()))
124  {}
125 
127  const size_type& sizeIn,
128  const size_type& sizeInDer,
129  const std::string name = "ConstantFunction") :
130  DifferentiableFunction (sizeIn, sizeInDer, element.space(), name),
131  c_ (element)
132  {}
133 
135  void impl_compute (LiegroupElementRef r, vectorIn_t) const { r = c_; }
136 
137  void impl_jacobian (matrixOut_t J, vectorIn_t) const { J.setZero(); }
138 
140  }; // class ConstantFunction
141 
143  } // namespace constraints
144 } // namespace hpp
145 
146 
147 #endif // HPP_CONSTRAINTS_AFFINE_FUNCTION_HH
pinocchio::vector_t vector_t
Definition: fwd.hh:45
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:46
Identity(const LiegroupSpacePtr_t space, const std::string &name)
Definition: affine-function.hh:45
const vector_type & vector() const
void impl_compute(LiegroupElementRef y, vectorIn_t arg) const
User implementation of function evaluation.
Definition: affine-function.hh:49
Vec3f b
pinocchio::LiegroupSpacePtr_t LiegroupSpacePtr_t
Definition: fwd.hh:54
Eigen::Ref< const matrix_t > matrixIn_t
Definition: fwd.hh:43
void impl_jacobian(matrixOut_t J, vectorIn_t) const
Definition: affine-function.hh:137
ConstantFunction(const vector_t &constant, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition: affine-function.hh:117
Definition: affine-function.hh:64
FCL_REAL r
pinocchio::matrix_t matrix_t
Definition: fwd.hh:42
static IdentityPtr_t create(const LiegroupSpacePtr_t space, const std::string &name)
Definition: affine-function.hh:39
assert(d.lhs()._blocks()==d.rhs()._blocks())
Definition: differentiable-function.hh:50
Definition: affine-function.hh:113
void impl_jacobian(matrixOut_t J, vectorIn_t) const
Definition: affine-function.hh:54
const LiegroupElement c_
Definition: affine-function.hh:139
pinocchio::size_type size_type
Definition: fwd.hh:35
Eigen::Ref< matrix_t > matrixOut_t
Definition: fwd.hh:44
void impl_compute(LiegroupElementRef r, vectorIn_t) const
User implementation of function evaluation.
Definition: affine-function.hh:135
AffineFunction(const matrixIn_t &J, const std::string name="LinearFunction")
Definition: affine-function.hh:68
boost::shared_ptr< Identity > IdentityPtr_t
Definition: fwd.hh:116
AffineFunction(const matrixIn_t &J, const vectorIn_t &b, const std::string name="LinearFunction")
Definition: affine-function.hh:77
ConstantFunction(const LiegroupElement &element, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition: affine-function.hh:126
Definition: affine-function.hh:35