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