hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
path.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2014 CNRS
3 // Authors: Florent Lamiraux
4 //
5 // This file is part of hpp-core
6 // hpp-core is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // hpp-core is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // hpp-core If not, see
17 // <http://www.gnu.org/licenses/>.
18 
19 #ifndef HPP_CORE_PATH_HH
20 # define HPP_CORE_PATH_HH
21 
22 # include <boost/concept_check.hpp>
23 # include <hpp/util/exception.hh>
24 # include <hpp/core/fwd.hh>
25 # include <hpp/core/config.hh>
27 # include <hpp/core/deprecated.hh>
30 
31 namespace hpp {
32  namespace core {
36 
60  class HPP_CORE_DLLAPI Path
61  {
62  public:
65 
67  virtual ~Path () {}
68 
70  virtual PathPtr_t copy () const = 0;
71 
76  virtual PathPtr_t copy (const ConstraintSetPtr_t& constraints) const = 0;
77 
79  template <class T> boost::shared_ptr<T> as (void)
80  {
81  assert (HPP_DYNAMIC_PTR_CAST (T, weak_.lock ()));
82  return HPP_STATIC_PTR_CAST (T, weak_.lock ());
83  }
84 
86  template <class T> boost::shared_ptr<const T> as (void) const
87  {
88  assert (HPP_DYNAMIC_PTR_CAST (const T, weak_.lock ()));
89  return HPP_STATIC_PTR_CAST (const T, weak_.lock ());
90  }
91 
93 
96 
103  PathPtr_t extract (const interval_t& subInterval) const;
104 
106  PathPtr_t extract (const value_type& tmin, const value_type& tmax) const
107  {
108  return extract (std::make_pair(tmin, tmax));
109  }
110 
113  virtual PathPtr_t reverse () const;
114 
116 
119 
121  Configuration_t operator () (const value_type& time) const
123  {
124  bool unused;
125  return (*this) (time, unused);
126  }
127 
128  Configuration_t operator () (const value_type& time, bool& success) const
129  {
130  return configAtParam (paramAtTime(time), success);
131  }
132 
133  bool operator () (ConfigurationOut_t result, const value_type& time)
134  const
135  {
136  value_type s = paramAtTime (time);
137  bool success = impl_compute (result, s);
138  if (!success) return false;
139  return applyConstraints (result, s);
140  }
141 
142  Configuration_t eval (const value_type& time, bool& success) const
143  {
144  return this->operator() (time, success);
145  }
146 
147  bool eval (ConfigurationOut_t result, const value_type& time)
148  const
149  {
150  return this->operator() (result, time);
151  }
152 
154  bool at (const value_type& time, ConfigurationOut_t result) const
155  {
156  return impl_compute (result, paramAtTime(time));
157  }
158 
168  void derivative (vectorOut_t result, const value_type& time,
169  size_type order) const;
170 
182  void velocityBound (vectorOut_t result, const value_type& t0, const value_type& t1) const
183  {
184  assert(result.size() == outputDerivativeSize());
185  assert(t0 <= t1);
186  impl_velocityBound (result,
187  paramAtTime (std::max(t0, timeRange().first )),
188  paramAtTime (std::min(t1, timeRange().second)));
189  if (timeParam_)
190  result *= timeParam_->derivativeBound (t0, t1);
191  }
192 
195 
198  {
199  return outputSize_;
200  }
201 
204  {
205  return outputDerivativeSize_;
206  }
207 
209  const interval_t& timeRange () const
210  {
211  return timeRange_;
212  }
213 
215  virtual value_type length () const
216  {
217  return timeRange_.second - timeRange_.first;
218  }
219 
221  virtual Configuration_t initial () const = 0;
222 
224  virtual Configuration_t end () const = 0;
225 
228  {
229  return constraints_;
230  }
231 
233 
238 
243  const interval_t& paramRange () const
244  {
245  return paramRange_;
246  }
247 
250  const interval_t& tr)
251  {
252  timeParam_ = tp;
253  timeRange (tr);
254  }
255 
257 
258  protected:
261  virtual std::ostream& print (std::ostream &os) const;
262 
272  Path (const interval_t& interval, size_type outputSize,
273  size_type outputDerivativeSize,
274  const ConstraintSetPtr_t& constraints);
275 
281  Path (const interval_t& interval, size_type outputSize,
282  size_type outputDerivativeSize);
283 
285  Path (const Path& path);
286 
288  Path (const Path& path, const ConstraintSetPtr_t& constraints);
289 
293  void init (const PathWkPtr_t& self);
294 
297 
302  void constraints (const ConstraintSetPtr_t& constraint) {
303  constraints_ = constraint;
304  }
305 
307  virtual void checkPath () const;
308 
309  void timeRange (const interval_t& timeRange)
310  {
311  timeRange_ = timeRange;
312  if (timeParam_) {
313  paramRange_.first = timeParam_->value(timeRange_.first );
314  paramRange_.second = timeParam_->value(timeRange_.second);
315  } else
316  paramRange_ = timeRange_;
317  }
318 
320  {
321  return timeParam_;
322  }
323 
325  {
326  return paramRange_.second - paramRange_.first;
327  }
328 
329  Configuration_t configAtParam (const value_type& param, bool& success) const
330  {
331  Configuration_t result (outputSize ());
332  success = impl_compute (result, param);
333  if (!success) return result;
334  success = applyConstraints (result, param);
335  return result;
336  }
337 
341  virtual bool impl_compute (ConfigurationOut_t configuration,
342  value_type param) const = 0;
343 
348  virtual void impl_derivative (vectorOut_t derivative,
349  const value_type& param,
350  size_type order) const
351  {
352  (void) derivative;
353  (void) param;
354  (void) order;
355  HPP_THROW_EXCEPTION (hpp::Exception, "not implemented");
356  }
357 
361  virtual void impl_velocityBound (vectorOut_t bound,
362  const value_type& param0,
363  const value_type& param1) const
364  {
365  (void) bound;
366  (void) param0;
367  (void) param1;
368  HPP_THROW_EXCEPTION (hpp::Exception, "not implemented");
369  }
370 
372  virtual PathPtr_t impl_extract (const interval_t& paramInterval) const;
373 
374  private:
376  interval_t timeRange_;
377 
378  value_type paramAtTime (const value_type& time) const
379  {
380  if (timeParam_) {
381  return timeParam_->value (time);
382  }
383  return time;
384  }
385 
386  bool applyConstraints (ConfigurationOut_t result, const value_type& param) const;
387 
389  size_type outputSize_;
391  size_type outputDerivativeSize_;
393  ConstraintSetPtr_t constraints_;
395  TimeParameterizationPtr_t timeParam_;
397  PathWkPtr_t weak_;
398  friend std::ostream& operator<< (std::ostream& os, const Path& path);
399  friend class ExtractedPath;
400  }; // class Path
401  inline std::ostream& operator<< (std::ostream& os, const Path& path)
402  {
403  return path.print (os);
404  }
406 
407  } // namespace core
408 } // namespace hpp
409 #endif // HPP_CORE_PATH_HH
boost::shared_ptr< Path > PathPtr_t
Definition: fwd.hh:170
virtual ~Path()
Destructor.
Definition: path.hh:67
size_type outputSize() const
Get size of configuration space.
Definition: path.hh:197
value_type paramLength() const
Definition: path.hh:324
CollisionGeometry * extract(const CollisionGeometry *model, const Transform3f &pose, const AABB &aabb)
size_type outputDerivativeSize() const
Get size of velocity.
Definition: path.hh:203
const interval_t & paramRange() const
Definition: path.hh:243
boost::shared_ptr< ConstraintSet > ConstraintSetPtr_t
Definition: fwd.hh:110
std::pair< value_type, value_type > interval_t
Definition: fwd.hh:158
void velocityBound(vectorOut_t result, const value_type &t0, const value_type &t1) const
Definition: path.hh:182
PathPtr_t extract(const value_type &tmin, const value_type &tmax) const
Definition: path.hh:106
pinocchio::ConfigurationOut_t ConfigurationOut_t
Definition: fwd.hh:98
pinocchio::size_type size_type
Definition: fwd.hh:156
void timeRange(const interval_t &timeRange)
Definition: path.hh:309
#define HPP_STATIC_PTR_CAST(t, x)
void timeParameterization(const TimeParameterizationPtr_t &tp, const interval_t &tr)
Set the time parameterization function.
Definition: path.hh:249
#define HPP_DYNAMIC_PTR_CAST(t, x)
virtual value_type length() const
Get length of definition interval.
Definition: path.hh:215
const ConstraintSetPtr_t & constraints() const
Get constraints the path is subject to.
Definition: path.hh:227
Configuration_t configAtParam(const value_type &param, bool &success) const
Definition: path.hh:329
boost::shared_ptr< const T > as(void) const
Static cast into a derived type.
Definition: path.hh:86
assert(d.lhs()._blocks()==d.rhs()._blocks())
interval_t paramRange_
Interval of parameters.
Definition: path.hh:296
const interval_t & timeRange() const
Get interval of definition.
Definition: path.hh:209
#define HPP_THROW_EXCEPTION(TYPE, MSG)
Configuration_t eval(const value_type &time, bool &success) const
Definition: path.hh:142
bool at(const value_type &time, ConfigurationOut_t result) const
Get the configuration at a parameter without applying the constraints.
Definition: path.hh:154
pinocchio::value_type value_type
Definition: fwd.hh:157
boost::shared_ptr< TimeParameterization > TimeParameterizationPtr_t
Definition: fwd.hh:172
virtual void impl_derivative(vectorOut_t derivative, const value_type &param, size_type order) const
Definition: path.hh:348
virtual std::ostream & print(std::ostream &os) const
void constraints(const ConstraintSetPtr_t &constraint)
Definition: path.hh:302
constraints::Implicit NumericalConstraint HPP_CORE_DEPRECATED
Definition: fwd.hh:347
const TimeParameterizationPtr_t & timeParameterization() const
Definition: path.hh:319
bool eval(ConfigurationOut_t result, const value_type &time) const
Definition: path.hh:147
pinocchio::vectorOut_t vectorOut_t
Definition: fwd.hh:203
virtual void impl_velocityBound(vectorOut_t bound, const value_type &param0, const value_type &param1) const
Definition: path.hh:361
std::ostream & operator<<(std::ostream &os, const Constraint &constraint)
Definition: constraint.hh:98
Definition: path.hh:60
pinocchio::Configuration_t Configuration_t
Definition: fwd.hh:96
boost::shared_ptr< T > as(void)
Static cast into a derived type.
Definition: path.hh:79