1 |
|
|
// Copyright (c) 2014, LAAS-CNRS |
2 |
|
|
// Authors: Steve Tonneau (steve.tonneau@laas.fr) |
3 |
|
|
// |
4 |
|
|
// This file is part of hpp-rbprm. |
5 |
|
|
// hpp-rbprm 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-rbprm 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-rbprm. If not, see <http://www.gnu.org/licenses/>. |
16 |
|
|
|
17 |
|
|
#include <hpp/pinocchio/joint.hh> |
18 |
|
|
#include <hpp/rbprm/interpolation/com-rrt-shooter.hh> |
19 |
|
|
#include <hpp/rbprm/interpolation/time-constraint-utils.hh> |
20 |
|
|
#include <hpp/rbprm/rbprm-limb.hh> |
21 |
|
|
#include <hpp/rbprm/sampling/sample.hh> |
22 |
|
|
|
23 |
|
|
namespace hpp { |
24 |
|
|
using namespace core; |
25 |
|
|
namespace rbprm { |
26 |
|
|
namespace interpolation { |
27 |
|
|
|
28 |
|
|
TimeConstraintShooterPtr_t TimeConstraintShooter::create( |
29 |
|
|
const core::DevicePtr_t device, const hpp::core::PathPtr_t rootPath, |
30 |
|
|
const std::size_t pathDofRank, const T_TimeDependant& tds, |
31 |
|
|
core::ConfigProjectorPtr_t projector, const rbprm::T_Limb freeLimbs) { |
32 |
|
|
TimeConstraintShooter* ptr = new TimeConstraintShooter( |
33 |
|
|
device, rootPath, pathDofRank, tds, projector, freeLimbs); |
34 |
|
|
TimeConstraintShooterPtr_t shPtr(ptr); |
35 |
|
|
ptr->init(shPtr); |
36 |
|
|
return shPtr; |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
void TimeConstraintShooter::init(const TimeConstraintShooterPtr_t& self) { |
40 |
|
|
core::ConfigurationShooter::init(self); |
41 |
|
|
weak_ = self; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
TimeConstraintShooter::TimeConstraintShooter( |
45 |
|
|
const core::DevicePtr_t device, const hpp::core::PathPtr_t rootPath, |
46 |
|
|
const std::size_t pathDofRank, const T_TimeDependant& tds, |
47 |
|
|
core::ConfigProjectorPtr_t projector, const hpp::rbprm::T_Limb freeLimbs) |
48 |
|
|
: core::ConfigurationShooter(), |
49 |
|
|
rootPath_(rootPath), |
50 |
|
|
pathDofRank_(pathDofRank), |
51 |
|
|
configSize_(pathDofRank + 1), |
52 |
|
|
device_(device), |
53 |
|
|
freeLimbs_(freeLimbs), |
54 |
|
|
tds_(tds), |
55 |
|
|
projector_(projector) { |
56 |
|
|
// NOTHING |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
void TimeConstraintShooter::impl_shoot(Configuration_t& config) const { |
60 |
|
|
// edit path sampling dof |
61 |
|
|
value_type a = rootPath_->timeRange().first; |
62 |
|
|
value_type b = rootPath_->timeRange().second; |
63 |
|
|
value_type u = value_type(rand()) / value_type(RAND_MAX); |
64 |
|
|
value_type pathDofVal = (b - a) * u + a; |
65 |
|
|
config.resize(configSize_); |
66 |
|
|
bool successPathoperator; |
67 |
|
|
config.head(configSize_ - 1) = (*rootPath_)(pathDofVal, successPathoperator); |
68 |
|
|
assert(successPathoperator && "path operator () did not succeed"); |
69 |
|
|
config[pathDofRank_] = u; |
70 |
|
|
/*if(freeLimbs_.empty()) |
71 |
|
|
{ |
72 |
|
|
JointVector_t jv = device_->getJointVector (); |
73 |
|
|
for (JointVector_t::const_iterator itJoint = jv.begin (); |
74 |
|
|
itJoint != jv.end (); itJoint++) { |
75 |
|
|
std::size_t rank = (*itJoint)->rankInConfiguration (); |
76 |
|
|
(*itJoint)->configuration ()->uniformlySample (rank, config); |
77 |
|
|
} |
78 |
|
|
} |
79 |
|
|
else*/ |
80 |
|
|
{ |
81 |
|
|
// choose random limb configuration |
82 |
|
|
for (rbprm::CIT_Limb cit = freeLimbs_.begin(); cit != freeLimbs_.end(); |
83 |
|
|
++cit) { |
84 |
|
|
const rbprm::RbPrmLimbPtr_t limb = cit->second; |
85 |
|
|
if (limb->sampleContainer_.samples_.size() <= 1) { |
86 |
|
|
throw std::runtime_error( |
87 |
|
|
"In time-constraint-shooter: Limbs database should have more than " |
88 |
|
|
"1 samples."); |
89 |
|
|
} |
90 |
|
|
const int rand_int = |
91 |
|
|
(rand() % (int)(limb->sampleContainer_.samples_.size() - 1)); |
92 |
|
|
const sampling::Sample& sample = |
93 |
|
|
*(limb->sampleContainer_.samples_.begin() + rand_int); |
94 |
|
|
sampling::Load(sample, config); |
95 |
|
|
} |
96 |
|
|
} |
97 |
|
|
UpdateConstraints(config, tds_, pathDofRank_); |
98 |
|
|
} |
99 |
|
|
} // namespace interpolation |
100 |
|
|
} // namespace rbprm |
101 |
|
|
} // namespace hpp |