hpp-constraints: include/hpp/constraints/affine-function.hh Source File

hpp-constraints 9.0.2 Definition of basic geometric constraints for motion planning

Loading...
Searching...
No Matches
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
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// 1. Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright
13// notice, this list of conditions and the following disclaimer in the
14// documentation and/or other materials provided with the distribution.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27// DAMAGE.
28
29#ifndef HPP_CONSTRAINTS_AFFINE_FUNCTION_HH
30#define HPP_CONSTRAINTS_AFFINE_FUNCTION_HH
31
32#include <hpp/constraints/config.hh>
33#include <hpp/constraints/differentiable-function.hh>
34#include <hpp/constraints/fwd.hh>
35
36 namespace hpp {
37 namespace constraints {
38
41
46 class HPP_CONSTRAINTS_DLLAPI Identity
47 : public constraints::DifferentiableFunction {
48 public:
49 static IdentityPtr_t create(const LiegroupSpacePtr_t space,
50 const std::string& name) {
51 IdentityPtr_t ptr(new Identity(space, name));
52 return ptr;
53 }
54
55 Identity(const LiegroupSpacePtr_t space, const std::string& name)
56 : DifferentiableFunction(space->nq(), space->nv(), space, name) {}
57
58 protected:
59 void impl_compute(LiegroupElementRef y, vectorIn_t arg) const {
60 y.vector() = arg;
61 }
62
63 void impl_jacobian(matrixOut_t J, vectorIn_t) const { J.setIdentity(); }
64
65 bool isEqual(const DifferentiableFunction& other) const {
66 dynamic_cast<const Identity&>(other);
67 if (!DifferentiableFunction::isEqual(other)) return false;
68
69 return true;
70 }
71
72 private:
73 Identity() {}
74 HPP_SERIALIZABLE();
75}; // class Identity
76
81 class HPP_CONSTRAINTS_DLLAPI AffineFunction : public DifferentiableFunction {
82 public:
83 static AffineFunctionPtr_t create(const matrixIn_t& J,
84 const std::string name = "LinearFunction") {
85 return AffineFunctionPtr_t(new AffineFunction(J, name));
86 }
87
88 static AffineFunctionPtr_t create(const matrixIn_t& J, const vectorIn_t& b,
89 const std::string name = "LinearFunction") {
90 return AffineFunctionPtr_t(new AffineFunction(J, b, name));
91 }
92
93 protected:
94 AffineFunction(const matrixIn_t& J, const std::string name = "LinearFunction")
95 : DifferentiableFunction(J.cols(), J.cols(), LiegroupSpace::Rn(J.rows()),
96 name),
97 J_(J),
98 b_(vector_t::Zero(J.rows())) {
99 init();
100 }
101
102 AffineFunction(const matrixIn_t& J, const vectorIn_t& b,
103 const std::string name = "LinearFunction")
104 : DifferentiableFunction(J.cols(), J.cols(), LiegroupSpace::Rn(J.rows()),
105 name),
106 J_(J),
107 b_(b) {
108 init();
109 }
110
111 bool isEqual(const DifferentiableFunction& other) const {
112 const AffineFunction& castother =
113 dynamic_cast<const AffineFunction&>(other);
114 if (!DifferentiableFunction::isEqual(other)) return false;
115
116 if (J_ != castother.J_) return false;
117 if (b_ != castother.b_) return false;
118
119 return true;
120 }
121
122 private:
124 void impl_compute(LiegroupElementRef y, vectorIn_t x) const {
125 y.vector().noalias() = J_ * x + b_;
126 }
127
128 void impl_jacobian(matrixOut_t jacobian, vectorIn_t) const { jacobian = J_; }
129
130 void init() {
131 assert(J_.rows() == b_.rows());
132 activeParameters_ = (J_.array() != 0).colwise().any();
133 activeDerivativeParameters_ = activeParameters_;
134 }
135
136 const matrix_t J_;
137 const vector_t b_;
138
139 AffineFunction() {}
140 HPP_SERIALIZABLE();
141}; // class AffineFunction
142
147 struct HPP_CONSTRAINTS_DLLAPI ConstantFunction : public DifferentiableFunction {
148 public:
149 static ConstantFunctionPtr_t create(
150 const vector_t& constant, const size_type& sizeIn,
151 const size_type& sizeInDer, const std::string name = "ConstantFunction") {
152 return ConstantFunctionPtr_t(
153 new ConstantFunction(constant, sizeIn, sizeInDer, name));
154 }
155 static ConstantFunctionPtr_t create(
156 const LiegroupElement& element, const size_type& sizeIn,
157 const size_type& sizeInDer, const std::string name = "ConstantFunction") {
158 return ConstantFunctionPtr_t(
159 new ConstantFunction(element, sizeIn, sizeInDer, name));
160 }
161
162 protected:
163 ConstantFunction(const vector_t& constant, const size_type& sizeIn,
164 const size_type& sizeInDer,
165 const std::string name = "ConstantFunction")
166 : DifferentiableFunction(sizeIn, sizeInDer,
167 LiegroupSpace::Rn(constant.rows()), name),
168 c_(constant, outputSpace()) {}
169
170 ConstantFunction(const LiegroupElement& element, const size_type& sizeIn,
171 const size_type& sizeInDer,
172 const std::string name = "ConstantFunction")
173 : DifferentiableFunction(sizeIn, sizeInDer, element.space(), name),
174 c_(element) {}
175
177 void impl_compute(LiegroupElementRef r, vectorIn_t) const { r = c_; }
178
179 void impl_jacobian(matrixOut_t J, vectorIn_t) const { J.setZero(); }
180
181 bool isEqual(const DifferentiableFunction& other) const {
182 const ConstantFunction& castother =
183 dynamic_cast<const ConstantFunction&>(other);
184 if (!DifferentiableFunction::isEqual(other)) return false;
185
186 if (c_.vector() == castother.c_.vector()) return false;
187
188 return true;
189 }
190
191 const LiegroupElement c_;
192
193 private:
194 ConstantFunction() {}
195 HPP_SERIALIZABLE();
196}; // class ConstantFunction
197
199} // namespace constraints
200} // namespace hpp
201
202#endif // HPP_CONSTRAINTS_AFFINE_FUNCTION_HH
hpp::constraints::AffineFunction
Definition affine-function.hh:81
hpp::constraints::AffineFunction::AffineFunction
AffineFunction(const matrixIn_t &J, const vectorIn_t &b, const std::string name="LinearFunction")
Definition affine-function.hh:102
hpp::constraints::AffineFunction::AffineFunction
AffineFunction(const matrixIn_t &J, const std::string name="LinearFunction")
Definition affine-function.hh:94
hpp::constraints::AffineFunction::create
static AffineFunctionPtr_t create(const matrixIn_t &J, const std::string name="LinearFunction")
Definition affine-function.hh:83
hpp::constraints::AffineFunction::isEqual
bool isEqual(const DifferentiableFunction &other) const
Definition affine-function.hh:111
hpp::constraints::AffineFunction::create
static AffineFunctionPtr_t create(const matrixIn_t &J, const vectorIn_t &b, const std::string name="LinearFunction")
Definition affine-function.hh:88
hpp::constraints::DifferentiableFunction
Definition differentiable-function.hh:63
hpp::constraints::Identity
Definition affine-function.hh:47
hpp::constraints::Identity::isEqual
bool isEqual(const DifferentiableFunction &other) const
Definition affine-function.hh:65
hpp::constraints::Identity::impl_jacobian
void impl_jacobian(matrixOut_t J, vectorIn_t) const
Definition affine-function.hh:63
hpp::constraints::Identity::create
static IdentityPtr_t create(const LiegroupSpacePtr_t space, const std::string &name)
Definition affine-function.hh:49
hpp::constraints::Identity::Identity
Identity(const LiegroupSpacePtr_t space, const std::string &name)
Definition affine-function.hh:55
hpp::constraints::Identity::impl_compute
void impl_compute(LiegroupElementRef y, vectorIn_t arg) const
User implementation of function evaluation.
Definition affine-function.hh:59
hpp::pinocchio::LiegroupElementBase
hpp::pinocchio::LiegroupElementBase::vector
const vector_type & vector() const
hpp::pinocchio::LiegroupSpace
config.hh
HPP_CONSTRAINTS_DLLAPI
#define HPP_CONSTRAINTS_DLLAPI
Definition config.hh:88
differentiable-function.hh
fwd.hh
hpp::constraints::AffineFunctionPtr_t
shared_ptr< AffineFunction > AffineFunctionPtr_t
Definition fwd.hh:137
hpp::constraints::LiegroupSpacePtr_t
pinocchio::LiegroupSpacePtr_t LiegroupSpacePtr_t
Definition fwd.hh:70
hpp::constraints::ConstantFunctionPtr_t
shared_ptr< ConstantFunction > ConstantFunctionPtr_t
Definition fwd.hh:138
hpp::constraints::size_type
pinocchio::size_type size_type
Definition fwd.hh:48
hpp::constraints::vectorIn_t
pinocchio::vectorIn_t vectorIn_t
Definition fwd.hh:61
hpp::constraints::matrixOut_t
Eigen::Ref< matrix_t > matrixOut_t
Definition fwd.hh:59
hpp::constraints::matrixIn_t
Eigen::Ref< const matrix_t > matrixIn_t
Definition fwd.hh:58
hpp::constraints::vector_t
pinocchio::vector_t vector_t
Definition fwd.hh:60
hpp::constraints::IdentityPtr_t
shared_ptr< Identity > IdentityPtr_t
Definition fwd.hh:136
hpp::pinocchio::vector_t
Eigen::Matrix< value_type, Eigen::Dynamic, 1 > vector_t
hpp::pinocchio::matrix_t
Eigen::Matrix< value_type, Eigen::Dynamic, Eigen::Dynamic > matrix_t
hpp
HPP_SERIALIZABLE
#define HPP_SERIALIZABLE()
hpp::constraints::ConstantFunction
Definition affine-function.hh:147
hpp::constraints::ConstantFunction::ConstantFunction
ConstantFunction(const vector_t &constant, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition affine-function.hh:163
hpp::constraints::ConstantFunction::c_
const LiegroupElement c_
Definition affine-function.hh:191
hpp::constraints::ConstantFunction::create
static ConstantFunctionPtr_t create(const vector_t &constant, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition affine-function.hh:149
hpp::constraints::ConstantFunction::create
static ConstantFunctionPtr_t create(const LiegroupElement &element, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition affine-function.hh:155
hpp::constraints::ConstantFunction::impl_compute
void impl_compute(LiegroupElementRef r, vectorIn_t) const
User implementation of function evaluation.
Definition affine-function.hh:177
hpp::constraints::ConstantFunction::isEqual
bool isEqual(const DifferentiableFunction &other) const
Definition affine-function.hh:181
hpp::constraints::ConstantFunction::impl_jacobian
void impl_jacobian(matrixOut_t J, vectorIn_t) const
Definition affine-function.hh:179
hpp::constraints::ConstantFunction::ConstantFunction
ConstantFunction(const LiegroupElement &element, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition affine-function.hh:170