hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
spline.hh
Go to the documentation of this file.
1 // Copyright (c) 2017 CNRS
2 // Authors: Joseph Mirabel
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
16 // <http://www.gnu.org/licenses/>.
17 
18 #ifndef HPP_CORE_PATH_SPLINE_HH
19 # define HPP_CORE_PATH_SPLINE_HH
20 
21 # include <hpp/core/path.hh>
22 
23 # include <hpp/pinocchio/device.hh>
24 # include <hpp/pinocchio/liegroup-element.hh>
25 
26 # include <hpp/core/fwd.hh>
28 # include <hpp/core/config.hh>
29 
30 namespace hpp {
31  namespace core {
32  namespace path {
35 
39  };
40 
42  namespace internal {
43  template <int SplineType, int Degree> struct spline_basis_function;
44  template <int SplineType, int Degree> struct sbf_traits {
45  enum { NbCoeffs = Degree + 1 };
46  typedef Eigen::Matrix<value_type, NbCoeffs, 1> Coeffs_t;
47  typedef Eigen::Matrix<value_type, NbCoeffs, NbCoeffs> IntegralCoeffs_t;
48  };
49  }
51 
79  template <int _PolynomeBasis, int _Order>
80  class HPP_CORE_DLLAPI Spline : public Path
81  {
82  public:
83  enum {
84  PolynomeBasis = _PolynomeBasis,
85  Order = _Order,
86  NbCoeffs = _Order + 1,
87  NbPowerOfT = 2 * NbCoeffs + 1
88  };
89 
90  typedef internal::sbf_traits<PolynomeBasis, Order> sbf_traits;
91  typedef internal::spline_basis_function<PolynomeBasis, Order> BasisFunction_t;
92  typedef Eigen::Matrix<value_type, NbPowerOfT, 1> PowersOfT_t;
93  typedef typename sbf_traits::Coeffs_t BasisFunctionVector_t;
94  typedef typename sbf_traits::IntegralCoeffs_t BasisFunctionIntegralMatrix_t;
95 
96  typedef Eigen::Matrix<value_type, NbCoeffs, Eigen::Dynamic, Eigen::RowMajor> ParameterMatrix_t;
97  typedef Eigen::Map<const vector_t, Eigen::Aligned> ConstParameterVector_t;
98  typedef Eigen::Map< vector_t, Eigen::Aligned> ParameterVector_t;
99 
100  typedef boost::shared_ptr<Spline> Ptr_t;
101  typedef boost::weak_ptr<Spline> WkPtr_t;
102 
104  {
105  return parameterSize_;
106  }
107 
116  {
117  assert (res.size() == NbCoeffs);
118  impl_paramDerivative (res, t);
119  }
120 
123  {
124  assert (dParam.size() == NbCoeffs * parameterSize_);
125  impl_paramIntegrate (dParam);
126  }
127 
131  value_type squaredNormIntegral (const size_type order) const;
132 
136  void squaredNormIntegralDerivative (const size_type order, vectorOut_t res) const;
137 
143  static void timeFreeBasisFunctionDerivative (const size_type order, const value_type& u, BasisFunctionVector_t& res);
144 
145  static void timeFreeBasisFunctionDerivative (const size_type order, const value_type& u, vectorOut_t res)
146  {
147  assert (res.size() == NbCoeffs);
148  BasisFunctionVector_t tmp;
149  timeFreeBasisFunctionDerivative(order, u, tmp);
150  res = tmp;
151  }
152 
158  void basisFunctionDerivative (const size_type order, const value_type& u, BasisFunctionVector_t& res) const;
159 
160  void basisFunctionDerivative (const size_type order, const value_type& u, vectorOut_t res) const
161  {
162  assert (res.size() == NbCoeffs);
163  BasisFunctionVector_t tmp;
164  basisFunctionDerivative(order, u, tmp);
165  res = tmp;
166  }
167 
170  void maxVelocity (vectorOut_t res) const;
171 
177  void squaredNormBasisFunctionIntegral (const size_type order, BasisFunctionIntegralMatrix_t& res) const;
178 
180  {
181  // assert (res.size() == NbCoeffs);
182  BasisFunctionIntegralMatrix_t tmp;
183  squaredNormBasisFunctionIntegral (order, tmp);
184  res = tmp;
185  }
186 
187  virtual Configuration_t initial () const
188  {
189  Configuration_t q (outputSize());
190  bool res = operator() (q, timeRange().first);
191  assert(res); (void)res;
192  return q;
193  }
194 
195  virtual Configuration_t end () const
196  {
197  Configuration_t q (outputSize());
198  bool res = operator() (q, timeRange().second);
199  assert(res); (void)res;
200  return q;
201  }
202 
206  const Configuration_t& base () const
207  {
208  return base_.vector();
209  }
210 
212  void base (const Configuration_t& q)
213  {
214  base_.vector() = q;
215  }
216 
218  const ParameterMatrix_t& parameters () const
219  {
220  return parameters_;
221  }
222 
225  void parameters (const ParameterMatrix_t& m)
226  {
227  parameters_ = m;
228  }
229 
231  ConstParameterVector_t rowParameters () const
232  {
233  return ConstParameterVector_t (parameters_.data(), parameters_.size());
234  }
235 
238  {
239  ParameterVector_t(parameters_.data(), parameters_.size()) = p;
240  }
241 
242  PathPtr_t copy () const
243  {
244  Ptr_t other (new Spline (*this));
245  other->init(other);
246  return other;
247  }
248 
249  PathPtr_t copy (const ConstraintSetPtr_t& constraints) const
250  {
251  Ptr_t other (new Spline (*this, constraints));
252  other->init(other);
253  return other;
254  }
255 
256  virtual ~Spline () {}
257 
258  static Ptr_t create (const DevicePtr_t& robot,
259  const interval_t& interval,
260  const ConstraintSetPtr_t& constraints)
261  {
262  Ptr_t shPtr (new Spline(robot, interval, constraints));
263  shPtr->init(shPtr);
264  return shPtr;
265  }
266 
274  static void value (pinocchio::LiegroupElementConstRef base,
275  Eigen::Ref<const ParameterMatrix_t> params,
276  const value_type& u,
277  ConfigurationOut_t config,
278  vectorOut_t velocity);
279 
280  protected:
281  Spline (const DevicePtr_t& robot,
282  const interval_t& interval,
283  const ConstraintSetPtr_t& constraints)
284  : Path (interval, robot->configSize(), robot->numberDof(), constraints),
285  parameterSize_ (robot->numberDof()),
286  robot_ (robot),
287  base_ (robot->RnxSOnConfigSpace()->vectorSpacesMerged()),
288  parameters_ ((int)NbCoeffs, parameterSize_),
289  velocity_ (parameterSize_)
290  {
291  powersOfT_(0) = 1;
292  for (size_type i = 1; i < NbPowerOfT; ++i)
293  powersOfT_(i) = powersOfT_(i - 1) * length();
294  }
295 
296  Spline (const Spline& path);
297 
298  Spline (const Spline& path, const ConstraintSetPtr_t& constraints);
299 
300  void init (const Ptr_t& self) { Path::init(self); weak_ = self; }
301 
302  std::ostream& print (std::ostream &os) const;
303 
304  bool impl_compute (ConfigurationOut_t configuration, value_type t) const;
305 
306  void impl_derivative (vectorOut_t res, const value_type& t, size_type order) const;
307 
308  void impl_paramDerivative (vectorOut_t res, const value_type& t) const;
309 
310  void impl_paramIntegrate (vectorIn_t dParam);
311 
312  void impl_velocityBound (vectorOut_t result, const value_type& t0, const value_type& t1) const;
313 
324  ParameterMatrix_t parameters_;
325 
326  private:
327  WkPtr_t weak_;
328 
329  mutable vector_t velocity_;
330  mutable PowersOfT_t powersOfT_;
331 
332  friend class steeringMethod::Spline<_PolynomeBasis, _Order>;
333  }; // class Spline
335  } // namespace path
336  } // namespace core
337 } // namespace hpp
338 #endif // HPP_CORE_PATH_SPLINE_HH
internal::sbf_traits< PolynomeBasis, Order > sbf_traits
Definition: spline.hh:90
boost::shared_ptr< Spline > Ptr_t
Definition: spline.hh:100
boost::shared_ptr< Path > PathPtr_t
Definition: fwd.hh:170
sbf_traits::IntegralCoeffs_t BasisFunctionIntegralMatrix_t
Definition: spline.hh:94
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:114
PolynomeBasisType
Definition: spline.hh:36
sbf_traits::Coeffs_t BasisFunctionVector_t
Definition: spline.hh:93
boost::shared_ptr< ConstraintSet > ConstraintSetPtr_t
Definition: fwd.hh:110
std::pair< value_type, value_type > interval_t
Definition: fwd.hh:158
virtual Configuration_t initial() const
Get the initial configuration.
Definition: spline.hh:187
pinocchio::ConfigurationOut_t ConfigurationOut_t
Definition: fwd.hh:98
pinocchio::size_type size_type
Definition: fwd.hh:156
PathPtr_t copy(const ConstraintSetPtr_t &constraints) const
Definition: spline.hh:249
const ParameterMatrix_t & parameters() const
Each row corresponds to a velocity of the robot.
Definition: spline.hh:218
Spline(const DevicePtr_t &robot, const interval_t &interval, const ConstraintSetPtr_t &constraints)
Definition: spline.hh:281
DevicePtr_t robot_
Definition: spline.hh:316
void parameterIntegrate(vectorIn_t dParam)
Adds dParam to the parameters.
Definition: spline.hh:122
void squaredNormBasisFunctionIntegral(const size_type order, matrixOut_t res) const
Definition: spline.hh:179
internal::spline_basis_function< PolynomeBasis, Order > BasisFunction_t
Definition: spline.hh:91
virtual ~Spline()
Definition: spline.hh:256
ConstParameterVector_t rowParameters() const
Concatenate the parameters as one vector (P_0^T, ..., P_n^T).
Definition: spline.hh:231
const Configuration_t & base() const
Definition: spline.hh:206
PathPtr_t copy() const
Return a shared pointer to a copy of this.
Definition: spline.hh:242
assert(d.lhs()._blocks()==d.rhs()._blocks())
Definition: spline.hh:38
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:202
void init(const PathWkPtr_t &self)
static void timeFreeBasisFunctionDerivative(const size_type order, const value_type &u, vectorOut_t res)
Definition: spline.hh:145
pinocchio::vector_t vector_t
Definition: fwd.hh:201
LiegroupElement base_
Definition: spline.hh:320
pinocchio::value_type value_type
Definition: fwd.hh:157
ParameterMatrix_t parameters_
Definition: spline.hh:324
void parameterDerivativeCoefficients(vectorOut_t res, const value_type &t) const
Definition: spline.hh:115
Eigen::Map< vector_t, Eigen::Aligned > ParameterVector_t
Definition: spline.hh:98
constraints::matrixOut_t matrixOut_t
Definition: fwd.hh:150
Transform3f t
void init(const Ptr_t &self)
Definition: spline.hh:300
FCL_REAL length[2]
size_type parameterSize() const
Definition: spline.hh:103
pinocchio::vectorOut_t vectorOut_t
Definition: fwd.hh:203
void base(const Configuration_t &q)
Definition: spline.hh:212
void basisFunctionDerivative(const size_type order, const value_type &u, vectorOut_t res) const
Definition: spline.hh:160
void rowParameters(vectorIn_t p)
Set the parameters.
Definition: spline.hh:237
Eigen::Matrix< value_type, NbCoeffs, Eigen::Dynamic, Eigen::RowMajor > ParameterMatrix_t
Definition: spline.hh:96
Eigen::Map< const vector_t, Eigen::Aligned > ConstParameterVector_t
Definition: spline.hh:97
Definition: path.hh:60
size_type parameterSize_
Robot number of degrees of freedom.
Definition: spline.hh:315
pinocchio::Configuration_t Configuration_t
Definition: fwd.hh:96
Eigen::Matrix< value_type, NbPowerOfT, 1 > PowersOfT_t
Definition: spline.hh:92
virtual Configuration_t end() const
Get the final configuration.
Definition: spline.hh:195
static Ptr_t create(const DevicePtr_t &robot, const interval_t &interval, const ConstraintSetPtr_t &constraints)
Definition: spline.hh:258
boost::weak_ptr< Spline > WkPtr_t
Definition: spline.hh:101
void parameters(const ParameterMatrix_t &m)
Definition: spline.hh:225