hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
polynomial.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-core.
5 // hpp-core 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-core 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-core. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HPP_CORE_TIME_PARAMETERIZATION_POLYNOMIAL_HH
18 # define HPP_CORE_TIME_PARAMETERIZATION_POLYNOMIAL_HH
19 
21 
22 # include <hpp/core/fwd.hh>
23 # include <hpp/core/config.hh>
25 
26 # include <path/math.hh>
27 
28 namespace hpp {
29  namespace core {
30  namespace timeParameterization {
31  class HPP_CORE_DLLAPI Polynomial : public TimeParameterization
32  {
33  public:
34  Polynomial (const vector_t& param) : a (param)
35  {
36  for (size_type i=0; i<a.size(); ++i){
37  assert(a[i] < std::numeric_limits<value_type>::infinity());
38  assert(a[i] > -std::numeric_limits<value_type>::infinity());
39  }
40  }
41 
42  const vector_t& parameters () const
43  {
44  return a;
45  }
46 
48  {
49  return TimeParameterizationPtr_t (new Polynomial (*this));
50  }
51 
53  value_type value (const value_type& t) const
54  {
55  return val (t);
56  }
57 
59  value_type derivative (const value_type& t, const size_type& order) const
60  {
61  return Jac(t, order);
62  }
63 
75  value_type derivativeBound (const value_type& low, const value_type& up) const
76  {
77  using std::max;
78  using std::fabs;
79  switch (a.size()) {
80  case 2:
81  return fabs(a[1]);
82  break;
83  case 3:
84  return max (fabs(Jac(low)), fabs(Jac(up)));
85  break;
86  case 4:
87  {
88  const value_type x_m = - a[2] / (3 * a[3]);
89  const value_type M = max(fabs(Jac(low)), fabs(Jac(up)));
90  if (low < x_m && x_m < up)
91  return max (M, fabs(a[1] - a[2] / 3*a[3]));
92  else
93  return M;
94  }
95  break;
96  default:
97  throw std::logic_error("not implemented");
98  }
99  }
100 
101  private:
102  value_type val (const value_type& t) const
103  {
104  value_type tn = 1;
105  value_type res = a[0];
106  for (size_type i = 1; i < a.size(); ++i)
107  {
108  tn *= t;
109  res += a[i] * tn;
110  }
111  assert (res == res);
112  return res;
113  }
114 
115  value_type Jac (const value_type& t) const
116  {
117  return Jac(t,1);
118  }
119 
120  value_type Jac (const value_type& t, const size_type& order) const
121  {
122  if (order >= a.size()) return 0;
123  const size_type MaxOrder = 10;
124  if (a.size() > MaxOrder)
125  throw std::invalid_argument ("Cannot compute the derivative of order greater than 10.");
126  typedef path::binomials<MaxOrder> Binomials_t;
127  const Binomials_t::Factorials_t& factors = Binomials_t::factorials();
128 
129  value_type res = 0;
130  value_type tn = 1;
131  for (size_type i = order; i < a.size(); ++i)
132  {
133  res += value_type(factors[i]/factors[i-order]) * a[i] * tn;
134  tn *= t;
135  }
136  return res;
137  }
138 
139  vector_t a;
140  }; // class Polynomial
141  } // namespace timeParameterization
142  } // namespace core
143 } // namespace hpp
144 #endif // HPP_CORE_TIME_PARAMETERIZATION_POLYNOMIAL_HH
TimeParameterizationPtr_t copy() const
Definition: polynomial.hh:47
value_type derivative(const value_type &t, const size_type &order) const
Computes .
Definition: polynomial.hh:59
pinocchio::size_type size_type
Definition: fwd.hh:156
assert(d.lhs()._blocks()==d.rhs()._blocks())
Definition: time-parameterization.hh:25
pinocchio::vector_t vector_t
Definition: fwd.hh:201
Vec3f a
pinocchio::value_type value_type
Definition: fwd.hh:157
boost::shared_ptr< TimeParameterization > TimeParameterizationPtr_t
Definition: fwd.hh:172
Transform3f t
value_type derivativeBound(const value_type &low, const value_type &up) const
Definition: polynomial.hh:75
Polynomial(const vector_t &param)
Definition: polynomial.hh:34
const vector_t & parameters() const
Definition: polynomial.hh:42
value_type value(const value_type &t) const
Computes .
Definition: polynomial.hh:53