1 |
|
|
// |
2 |
|
|
// Copyright (c) 2014 CNRS |
3 |
|
|
// Authors: Steve Tonneau (steve.tonneau@laas.fr) |
4 |
|
|
// |
5 |
|
|
// This file is part of hpp-rbprm. |
6 |
|
|
// hpp-rbprm 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-rbprm 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_TIME_CONSTRAINT_HELPER_HH |
20 |
|
|
#define HPP_TIME_CONSTRAINT_HELPER_HH |
21 |
|
|
|
22 |
|
|
#include <hpp/core/config-projector.hh> |
23 |
|
|
#include <hpp/core/path-projector/progressive.hh> |
24 |
|
|
#include <hpp/core/path.hh> |
25 |
|
|
#include <hpp/core/problem.hh> |
26 |
|
|
#include <hpp/core/weighed-distance.hh> |
27 |
|
|
#include <hpp/rbprm/config.hh> |
28 |
|
|
#include <hpp/rbprm/interpolation/time-constraint-steering.hh> |
29 |
|
|
#include <hpp/rbprm/rbprm-device.hh> |
30 |
|
|
#include <hpp/rbprm/rbprm-fullbody.hh> |
31 |
|
|
#include <hpp/rbprm/rbprm-state.hh> |
32 |
|
|
#include <map> |
33 |
|
|
#include <vector> |
34 |
|
|
|
35 |
|
|
namespace hpp { |
36 |
|
|
namespace rbprm { |
37 |
|
|
namespace interpolation { |
38 |
|
|
|
39 |
|
|
/// Helper struct for applying creating planning problems with |
40 |
|
|
/// time dependant constraints in rbprm. Maintains a pointer |
41 |
|
|
/// to a RbPrmFullbody object, and creates a new instance |
42 |
|
|
/// of a problem for a clone of the associated Device. |
43 |
|
|
/// |
44 |
|
|
template <class Path_T, class ShooterFactory_T, typename ConstraintFactory_T> |
45 |
|
|
class HPP_CORE_DLLAPI TimeConstraintHelper { |
46 |
|
|
typedef shared_ptr<core::pathProjector::Progressive> ProgressivePtr_t; |
47 |
|
|
typedef core::pathProjector::Progressive Progressive; |
48 |
|
|
|
49 |
|
|
public: |
50 |
|
|
/// \param fullbody robot considered for applying a planner. The associated |
51 |
|
|
/// Device will be cloned to avoid side effects during the planning, |
52 |
|
|
/// An extra DOF is added to the cloned device, as required by the algorithm. |
53 |
|
|
/// \param referenceProblem an internal problem will be created, |
54 |
|
|
/// using this parameter as a reference, for retrieving collision obstacles |
55 |
|
|
TimeConstraintHelper(RbPrmFullBodyPtr_t fullbody, |
56 |
|
|
const ShooterFactory_T& shooterFactory, |
57 |
|
|
const ConstraintFactory_T& constraintFactory, |
58 |
|
|
core::ProblemPtr_t referenceProblem, |
59 |
|
|
core::PathPtr_t refPath, |
60 |
|
|
const pinocchio::value_type error_treshold = 1e-3) |
61 |
|
|
: fullbody_(fullbody), |
62 |
|
|
fullBodyDevice_(fullbody->device_->clone()), |
63 |
|
|
rootProblem_(core::Problem::create(fullBodyDevice_)), |
64 |
|
|
refPath_(refPath), |
65 |
|
|
shooterFactory_(shooterFactory), |
66 |
|
|
constraintFactory_(constraintFactory) { |
67 |
|
|
// adding extra DOF for including time in sampling |
68 |
|
|
fullBodyDevice_->setDimensionExtraConfigSpace( |
69 |
|
|
fullBodyDevice_->extraConfigSpace().dimension() + 1); |
70 |
|
|
proj_ = core::ConfigProjector::create(rootProblem_->robot(), "proj", |
71 |
|
|
error_treshold, 1000); |
72 |
|
|
rootProblem_->collisionObstacles(referenceProblem->collisionObstacles()); |
73 |
|
|
steeringMethod_ = TimeConstraintSteering<Path_T>::create( |
74 |
|
|
rootProblem_, fullBodyDevice_->configSize() - 1); |
75 |
|
|
rootProblem_->steeringMethod(steeringMethod_); |
76 |
|
|
ProgressivePtr_t pProj = |
77 |
|
|
Progressive::create(rootProblem_->distance(), steeringMethod_, 0.06); |
78 |
|
|
// rootProblem_->pathProjector(pProj); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
~TimeConstraintHelper() {} |
82 |
|
|
|
83 |
|
|
void SetConstraints(const State& from, const State& to) { |
84 |
|
|
constraintFactory_(*this, from, to); |
85 |
|
|
} |
86 |
|
|
void SetConfigShooter(const State& from, const State& to); |
87 |
|
|
void InitConstraints(); |
88 |
|
|
void SetContactConstraints(const State& from, const State& to); |
89 |
|
|
core::PathVectorPtr_t Run(const State& from, const State& to, |
90 |
|
|
const size_t maxIterations = 0); |
91 |
|
|
|
92 |
|
|
public: |
93 |
|
|
RbPrmFullBodyPtr_t fullbody_; |
94 |
|
|
core::DevicePtr_t fullBodyDevice_; |
95 |
|
|
core::ProblemPtr_t rootProblem_; |
96 |
|
|
core::PathPlannerPtr_t planner_; |
97 |
|
|
core::PathPtr_t refPath_; |
98 |
|
|
core::ConfigProjectorPtr_t proj_; |
99 |
|
|
shared_ptr<TimeConstraintSteering<Path_T> > steeringMethod_; |
100 |
|
|
const ShooterFactory_T& shooterFactory_; |
101 |
|
|
const ConstraintFactory_T& constraintFactory_; |
102 |
|
|
}; |
103 |
|
|
|
104 |
|
|
/// Runs the LimbRRT to create a kinematic, continuous, |
105 |
|
|
/// collision free path between an ordered State contrainer (Between each |
106 |
|
|
/// consecutive state, only one effector position differs between the states). |
107 |
|
|
/// Equilibrium is not verified along the path. To achieve this, an oriented RRT |
108 |
|
|
/// is run for the transitioning limb. The root path between two State is given |
109 |
|
|
/// by the problem steering method defined in the helper parameter. An extra DOF |
110 |
|
|
/// is used to sample a root position along the normalized path as well as the |
111 |
|
|
/// limb configuration. To avoid going back and forth, two configurations can |
112 |
|
|
/// thus only be connected if the first configuration has a DOF value lower than |
113 |
|
|
/// the second one. The LimbRRT algorithm is a modification of the original |
114 |
|
|
/// algorithm introduced in Qiu et al. "A Hierarchical Framework for Realizing |
115 |
|
|
/// Dynamically-stable Motions of Humanoid Robot in Obstacle-cluttered |
116 |
|
|
/// Environments" If OpenMP is activated, the interpolation between the states |
117 |
|
|
/// is run in parallel WARNING: At the moment, no more than 100 states can be |
118 |
|
|
/// interpolated simultaneously |
119 |
|
|
/// TODO: include parametrization of shortcut algorithm |
120 |
|
|
/// |
121 |
|
|
/// \param helper holds the problem parameters and the considered device |
122 |
|
|
/// An extra DOF is added to the cloned device, as required by the algorithm. |
123 |
|
|
/// The method assumes that the steering method associated with the helper's |
124 |
|
|
/// rootProblem_ produces a collision free path all parts of the Device |
125 |
|
|
/// different that the transitioning limb. Here the steering method of the |
126 |
|
|
/// reference problem will be used to generate a root path between each |
127 |
|
|
/// consecutive state with the assumption that the path is valid. \param |
128 |
|
|
/// iterator to the initial State \param to iterator to the final State \param |
129 |
|
|
/// numOptimizations Number of iterations of the shortcut algorithm to apply |
130 |
|
|
/// between each states \param maxIterations : the maximal number of iterations |
131 |
|
|
/// allowed for the path-planner to solve the problem, 0 = no limitations |
132 |
|
|
/// \return the resulting path vector, concatenation of all the interpolation |
133 |
|
|
/// paths between the State |
134 |
|
|
template <class Helper_T, class ShooterFactory_T, typename ConstraintFactory_T, |
135 |
|
|
typename StateConstIterator> |
136 |
|
|
core::PathPtr_t HPP_RBPRM_DLLAPI interpolateStates( |
137 |
|
|
RbPrmFullBodyPtr_t fullbody, core::ProblemPtr_t referenceProblem, |
138 |
|
|
const ShooterFactory_T& shooterFactory, |
139 |
|
|
const ConstraintFactory_T& constraintFactory, |
140 |
|
|
const StateConstIterator& startState, const StateConstIterator& endState, |
141 |
|
|
const std::size_t numOptimizations = 10, const bool keepExtraDof = false, |
142 |
|
|
const pinocchio::value_type error_treshold = 0.001, |
143 |
|
|
const size_t maxIterations = 0); |
144 |
|
|
|
145 |
|
|
/// Runs the LimbRRT to create a kinematic, continuous, |
146 |
|
|
/// collision free path between an ordered State contrainer (Between each |
147 |
|
|
/// consecutive state, only one effector position differs between the states). |
148 |
|
|
/// Equilibrium is not verified along the path. To achieve this, an oriented RRT |
149 |
|
|
/// is run for the transitioning limb. The root path between two State is given |
150 |
|
|
/// by the problem steering method defined in the helper parameter. An extra DOF |
151 |
|
|
/// is used to sample a root position along the normalized path as well as the |
152 |
|
|
/// limb configuration. To avoid going back and forth, two configurations can |
153 |
|
|
/// thus only be connected if the first configuration has a DOF value lower than |
154 |
|
|
/// the second one. The LimbRRT algorithm is a modification of the original |
155 |
|
|
/// algorithm introduced in Qiu et al. "A Hierarchical Framework for Realizing |
156 |
|
|
/// Dynamically-stable Motions of Humanoid Robot in Obstacle-cluttered |
157 |
|
|
/// Environments" If OpenMP is activated, the interpolation between the states |
158 |
|
|
/// is run in parallel WARNING: At the moment, no more than 100 states can be |
159 |
|
|
/// interpolated simultaneously |
160 |
|
|
/// TODO: include parametrization of shortcut algorithm |
161 |
|
|
/// |
162 |
|
|
/// \param helper holds the problem parameters and the considered device |
163 |
|
|
/// An extra DOF is added to the cloned device, as required by the algorithm. |
164 |
|
|
/// The method assumes that the steering method associated with the helper's |
165 |
|
|
/// rootProblem_ produces a collision free path all parts of the Device |
166 |
|
|
/// different that the transitioning limb. \param path reference path for the |
167 |
|
|
/// root \param iterator to the initial State with its associated keyFrame in |
168 |
|
|
/// the path \param to iterator to the final State with its associated keyFrame |
169 |
|
|
/// in the path \param numOptimizations Number of iterations of the shortcut |
170 |
|
|
/// algorithm to apply between each states \param maxIterations : the maximal |
171 |
|
|
/// number of iterations allowed for the path-planner to solve the problem, 0 = |
172 |
|
|
/// no limitations \return the resulting path vector, concatenation of all the |
173 |
|
|
/// interpolation paths between the State |
174 |
|
|
template <class Helper_T, class ShooterFactory_T, typename ConstraintFactory_T> |
175 |
|
|
core::PathPtr_t HPP_RBPRM_DLLAPI interpolateStatesFromPath( |
176 |
|
|
RbPrmFullBodyPtr_t fullbody, core::ProblemPtr_t referenceProblem, |
177 |
|
|
const ShooterFactory_T& shooterFactory, |
178 |
|
|
const ConstraintFactory_T& constraintFactory, const core::PathPtr_t refPath, |
179 |
|
|
const CIT_StateFrame& startState, const CIT_StateFrame& endState, |
180 |
|
|
const std::size_t numOptimizations = 10, const bool keepExtraDof = false, |
181 |
|
|
const pinocchio::value_type error_treshold = 0.001, |
182 |
|
|
const size_t maxIterations = 0); |
183 |
|
|
|
184 |
|
|
/*typedef core::PathPtr_t (*interpolate_states)(rbprm::RbPrmFullBodyPtr_t, |
185 |
|
|
core::ProblemPtr_t,const rbprm::CIT_State&, const rbprm::CIT_State&,const |
186 |
|
|
std::size_t); |
187 |
|
|
|
188 |
|
|
typedef core::PathPtr_t |
189 |
|
|
(*interpolate_states_from_path)(rbprm::RbPrmFullBodyPtr_t, core::ProblemPtr_t, |
190 |
|
|
const core::PathPtr_t, const rbprm::CIT_StateFrame&,const |
191 |
|
|
rbprm::CIT_StateFrame&,const std::size_t);*/ |
192 |
|
|
} // namespace interpolation |
193 |
|
|
} // namespace rbprm |
194 |
|
|
} // namespace hpp |
195 |
|
|
|
196 |
|
|
#include <hpp/rbprm/interpolation/time-constraint-helper.inl> |
197 |
|
|
#endif // HPP_TIME_CONSTRAINT_HELPER_HH |