hpp-constraints  4.9.1
Definition of basic geometric constraints for motion planning
symbolic-function.hh
Go to the documentation of this file.
1 // Copyright (c) 2015, LAAS-CNRS
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_SYMBOLIC_FUNCTION_HH
18 # define HPP_CONSTRAINTS_SYMBOLIC_FUNCTION_HH
19 
20 # include <boost/assign/list_of.hpp>
21 
22 # include <hpp/constraints/fwd.hh>
23 # include <hpp/constraints/config.hh>
26 
27 # include <hpp/pinocchio/device.hh>
29 
30 namespace hpp {
31  namespace constraints {
32 
36  template <typename Expression>
37  class HPP_CONSTRAINTS_DLLAPI SymbolicFunction : public DifferentiableFunction
38  {
39  public:
40  typedef boost::shared_ptr<SymbolicFunction> Ptr_t;
41  typedef boost::weak_ptr<SymbolicFunction> WkPtr_t;
42 
43  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
44 
46  static Ptr_t create (
47  const std::string& name, const DevicePtr_t& robot,
48  const typename Traits<Expression>::Ptr_t expr)
49  {
50  std::vector <bool> mask (expr->value ().size (), true);
51  return create (name, robot, expr, mask);
52  }
53 
55  static Ptr_t create (
56  const std::string& name, const DevicePtr_t& robot,
57  const typename Traits<Expression>::Ptr_t expr,
58  std::vector <bool> mask)
59  {
60  assert (mask.size() == (std::size_t) expr->value().size());
61  Ptr_t ptr (new SymbolicFunction (name,robot,expr,mask));
62  ptr->init (ptr);
63  return ptr;
64  }
65 
67  static Ptr_t create (const std::string& name, size_type sizeInput,
68  size_type sizeInputDerivative,
69  size_type sizeOutput,
70  const typename Traits<Expression>::Ptr_t expr)
71  {
72  std::vector<bool> mask (sizeOutput, true);
73  Ptr_t ptr (new SymbolicFunction (name,sizeInput,sizeInputDerivative,sizeOutput,expr,mask));
74  ptr->init (ptr);
75  return ptr;
76  }
77 
78  virtual ~SymbolicFunction () {}
79 
80  SymbolicFunction (const std::string& name, const DevicePtr_t& robot,
81  const typename Traits<Expression>::Ptr_t expr,
82  std::vector <bool> mask) :
83  DifferentiableFunction (robot->configSize(), robot->numberDof(),
84  LiegroupSpace::Rn (expr->value().size()),
85  name),
86  robot_ (robot), expr_ (expr), mask_ (mask)
87  {
88  size_type d = robot_->extraConfigSpace().dimension();
89  activeParameters_ .tail(d).setConstant(false);
90  activeDerivativeParameters_.tail(d).setConstant(false);
91  }
92 
93  SymbolicFunction (const std::string& name, size_type sizeInput,
94  size_type sizeInputDerivative,
95  size_type sizeOutput,
96  const typename Traits<Expression>::Ptr_t expr,
97  std::vector <bool> mask) :
98  DifferentiableFunction (sizeInput, sizeInputDerivative,
99  LiegroupSpace::Rn (sizeOutput), name),
100  robot_ (), expr_ (expr), mask_ (mask) {}
101 
102  protected:
107  virtual void impl_compute (LiegroupElementRef result,
108  ConfigurationIn_t argument) const
109  {
110  if (robot_) {
111  robot_->currentConfiguration (argument);
112  robot_->computeForwardKinematics ();
113  }
114  expr_->invalidate ();
115  expr_->computeValue (argument);
116  size_t index = 0;
117  for (std::size_t i = 0; i < mask_.size (); i++) {
118  if (mask_[i])
119  result.vector () [index++] = expr_->value () [i];
120  }
121  }
122 
123  virtual void impl_jacobian (matrixOut_t jacobian,
124  ConfigurationIn_t arg) const
125  {
126  if (robot_) {
127  robot_->currentConfiguration (arg);
128  robot_->computeForwardKinematics ();
129  }
130  expr_->invalidate ();
131  expr_->computeJacobian (arg);
132  size_t index = 0;
133 
134  const typename Expression::JacobianType_t& Je (expr_->jacobian());
135  size_type nv;
136  if (robot_) {
137  size_type d = robot_->extraConfigSpace().dimension();
138  nv = Je.cols();
139  assert(robot_->numberDof() == Je.cols() + d);
140  jacobian.rightCols(d).setZero();
141  } else {
142  nv = jacobian.cols();
143  }
144 
145  for (std::size_t i = 0; i < mask_.size (); i++) {
146  if (mask_[i])
147  jacobian.row(index++).head(nv) = Je.row (i);
148  }
149  }
150 
151  void init (const Ptr_t& self) {
152  wkPtr_ = self;
153  }
154  private:
155  WkPtr_t wkPtr_;
156  DevicePtr_t robot_;
157  typename Traits<Expression>::Ptr_t expr_;
158  std::vector <bool> mask_;
159  }; // class ComBetweenFeet
160  } // namespace constraints
161 } // namespace hpp
162 #endif // HPP_CONSTRAINTS_SYMBOLIC_FUNCTION_HH
void init(const Ptr_t &self)
Definition: symbolic-function.hh:151
virtual ~SymbolicFunction()
Definition: symbolic-function.hh:78
virtual void impl_jacobian(matrixOut_t jacobian, ConfigurationIn_t arg) const
Definition: symbolic-function.hh:123
const vector_type & vector() const
SymbolicFunction(const std::string &name, size_type sizeInput, size_type sizeInputDerivative, size_type sizeOutput, const typename Traits< Expression >::Ptr_t expr, std::vector< bool > mask)
Definition: symbolic-function.hh:93
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:91
ObjectFactory * create(ObjectFactory *parent=NULL, const XMLElement *element=NULL)
SymbolicFunction(const std::string &name, const DevicePtr_t &robot, const typename Traits< Expression >::Ptr_t expr, std::vector< bool > mask)
Definition: symbolic-function.hh:80
Definition: symbolic-function.hh:37
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: fwd.hh:88
assert(d.lhs()._blocks()==d.rhs()._blocks())
static EIGEN_MAKE_ALIGNED_OPERATOR_NEW Ptr_t create(const std::string &name, const DevicePtr_t &robot, const typename Traits< Expression >::Ptr_t expr)
Return a shared pointer to a new instance.
Definition: symbolic-function.hh:46
static Ptr_t create(const std::string &name, const DevicePtr_t &robot, const typename Traits< Expression >::Ptr_t expr, std::vector< bool > mask)
Return a shared pointer to a new instance.
Definition: symbolic-function.hh:55
Definition: differentiable-function.hh:50
boost::weak_ptr< SymbolicFunction > WkPtr_t
Definition: symbolic-function.hh:41
virtual void impl_compute(LiegroupElementRef result, ConfigurationIn_t argument) const
Definition: symbolic-function.hh:107
FCL_REAL d
HPP_CONSTRAINTS_CB_REF< Class > Ptr_t
Definition: symbolic-calculus.hh:107
pinocchio::size_type size_type
Definition: fwd.hh:35
Eigen::Ref< matrix_t > matrixOut_t
Definition: fwd.hh:44
FCL_REAL size() const
static Ptr_t create(const std::string &name, size_type sizeInput, size_type sizeInputDerivative, size_type sizeOutput, const typename Traits< Expression >::Ptr_t expr)
Return a shared pointer to a new instance.
Definition: symbolic-function.hh:67
boost::shared_ptr< SymbolicFunction > Ptr_t
Definition: symbolic-function.hh:40