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_RBPRM_POLYNOM_TRAJECTORY_HH |
20 |
|
|
#define HPP_RBPRM_POLYNOM_TRAJECTORY_HH |
21 |
|
|
|
22 |
|
|
#include <ndcurves/curve_abc.h> |
23 |
|
|
|
24 |
|
|
#include <hpp/core/config.hh> |
25 |
|
|
#include <hpp/core/fwd.hh> |
26 |
|
|
#include <hpp/core/path.hh> |
27 |
|
|
#include <hpp/rbprm/interpolation/time-dependant.hh> |
28 |
|
|
|
29 |
|
|
namespace hpp { |
30 |
|
|
namespace rbprm { |
31 |
|
|
namespace interpolation { |
32 |
|
|
HPP_PREDEF_CLASS(PolynomTrajectory); |
33 |
|
|
typedef shared_ptr<PolynomTrajectory> PolynomTrajectoryPtr_t; |
34 |
|
|
typedef ndcurves::curve_abc<core::value_type, core::value_type, true, |
35 |
|
|
Eigen::Vector3d> |
36 |
|
|
Polynom; |
37 |
|
|
typedef shared_ptr<Polynom> PolynomPtr_t; |
38 |
|
|
/// Linear interpolation between two configurations |
39 |
|
|
/// |
40 |
|
|
/// Degrees of freedom are interpolated depending on the type of |
41 |
|
|
/// \link hpp::pinocchio::Joint joint \endlink |
42 |
|
|
/// they parameterize: |
43 |
|
|
/// \li linear interpolation for translation joints, bounded rotation |
44 |
|
|
/// joints, and translation part of freeflyer joints, |
45 |
|
|
/// \li angular interpolation for unbounded rotation joints, |
46 |
|
|
/// \li constant angular velocity for SO(3) part of freeflyer joints. |
47 |
|
|
class HPP_CORE_DLLAPI PolynomTrajectory : public core::Path { |
48 |
|
|
public: |
49 |
|
|
typedef Path parent_t; |
50 |
|
|
/// Destructor |
51 |
|
|
virtual ~PolynomTrajectory() {} |
52 |
|
|
|
53 |
|
|
/// Create instance and return shared pointer |
54 |
|
|
/// \param device Robot corresponding to configurations |
55 |
|
|
/// \param init, end Start and end configurations of the path |
56 |
|
|
/// \param length Distance between the configurations. |
57 |
|
|
static PolynomTrajectoryPtr_t create(PolynomPtr_t polynom, |
58 |
|
|
core::value_type subSetStart = 0, |
59 |
|
|
core::value_type subSetEnd = 1) { |
60 |
|
|
PolynomTrajectory* ptr = |
61 |
|
|
new PolynomTrajectory(polynom, subSetStart, subSetEnd); |
62 |
|
|
PolynomTrajectoryPtr_t shPtr(ptr); |
63 |
|
|
ptr->init(shPtr); |
64 |
|
|
ptr->checkPath(); |
65 |
|
|
return shPtr; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
/// Create copy and return shared pointer |
69 |
|
|
/// \param path path to copy |
70 |
|
|
static PolynomTrajectoryPtr_t createCopy(const PolynomTrajectoryPtr_t& path) { |
71 |
|
|
PolynomTrajectory* ptr = new PolynomTrajectory(*path); |
72 |
|
|
PolynomTrajectoryPtr_t shPtr(ptr); |
73 |
|
|
ptr->init(shPtr); |
74 |
|
|
ptr->checkPath(); |
75 |
|
|
return shPtr; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
/// Return a shared pointer to this |
79 |
|
|
/// |
80 |
|
|
/// As ComTrajectoryP are immutable, and refered to by shared pointers, |
81 |
|
|
/// they do not need to be copied. |
82 |
|
|
virtual core::PathPtr_t copy() const { return createCopy(weak_.lock()); } |
83 |
|
|
|
84 |
|
|
/// Extraction/Reversion of a sub-path |
85 |
|
|
/// \param subInterval interval of definition of the extract path |
86 |
|
|
/// If upper bound of subInterval is smaller than lower bound, |
87 |
|
|
/// result is reversed. |
88 |
|
|
virtual core::PathPtr_t extract(const core::interval_t& subInterval) const; |
89 |
|
|
|
90 |
|
|
/// Get the initial configuration |
91 |
|
|
core::Configuration_t initial() const { |
92 |
|
|
return polynom_->operator()(subSetStart_); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
/// Get the final configuration |
96 |
|
|
core::Configuration_t end() const { return polynom_->operator()(subSetEnd_); } |
97 |
|
|
|
98 |
|
|
virtual void checkPath() const {} |
99 |
|
|
|
100 |
|
|
protected: |
101 |
|
|
/// Print path in a stream |
102 |
|
|
virtual std::ostream& print(std::ostream& os) const { |
103 |
|
|
os << "PolynomTrajectory:" << std::endl; |
104 |
|
|
os << "interval: [ " << timeRange().first << ", " << timeRange().second |
105 |
|
|
<< " ]" << std::endl; |
106 |
|
|
os << "initial configuration: " << initial() << std::endl; |
107 |
|
|
os << "final configuration: " << end() << std::endl; |
108 |
|
|
return os; |
109 |
|
|
} |
110 |
|
|
/// Constructor |
111 |
|
|
PolynomTrajectory(PolynomPtr_t polynom, core::value_type subSetStart, |
112 |
|
|
core::value_type subSetEnd); |
113 |
|
|
|
114 |
|
|
/// Copy constructor |
115 |
|
|
PolynomTrajectory(const PolynomTrajectory& path); |
116 |
|
|
|
117 |
|
|
void init(PolynomTrajectoryPtr_t self) { |
118 |
|
|
parent_t::init(self); |
119 |
|
|
weak_ = self; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
virtual bool impl_compute(core::ConfigurationOut_t result, |
123 |
|
|
core::value_type param) const; |
124 |
|
|
|
125 |
|
|
virtual core::PathPtr_t copy(const core::ConstraintSetPtr_t&) const { throw; } |
126 |
|
|
|
127 |
|
|
public: |
128 |
|
|
const PolynomPtr_t polynom_; |
129 |
|
|
const core::value_type subSetStart_; |
130 |
|
|
const core::value_type subSetEnd_; |
131 |
|
|
const core::value_type length_; |
132 |
|
|
|
133 |
|
|
private: |
134 |
|
|
PolynomTrajectoryWkPtr_t weak_; |
135 |
|
|
}; // class ComTrajectory |
136 |
|
|
} // namespace interpolation |
137 |
|
|
} // namespace rbprm |
138 |
|
|
} // namespace hpp |
139 |
|
|
#endif // HPP_RBPRM_POLYNOM_TRAJECTORY_HH |