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 |
|
|
#include <hpp/rbprm/interpolation/interpolation-constraints.hh> |
20 |
|
|
|
21 |
|
|
using namespace hpp::core; |
22 |
|
|
|
23 |
|
|
namespace hpp { |
24 |
|
|
namespace rbprm { |
25 |
|
|
namespace interpolation { |
26 |
|
|
|
27 |
|
|
void addContactConstraints(rbprm::RbPrmFullBodyPtr_t fullBody, |
28 |
|
|
pinocchio::DevicePtr_t device, |
29 |
|
|
core::ConfigProjectorPtr_t projector, |
30 |
|
|
const State &state, |
31 |
|
|
const std::vector<std::string> active) { |
32 |
|
|
std::vector<bool> cosntraintsR = setMaintainRotationConstraints(); |
33 |
|
|
for (std::vector<std::string>::const_iterator cit = active.begin(); |
34 |
|
|
cit != active.end(); ++cit) { |
35 |
|
|
RbPrmLimbPtr_t limb = fullBody->GetLimbs().at(*cit); |
36 |
|
|
// const fcl::Vec3f& ppos = state.contactPositions_.at(*cit); |
37 |
|
|
pinocchio::Transform3f localFrame(1), globalFrame(1); |
38 |
|
|
globalFrame.translation(state.contactPositions_.at(*cit)); |
39 |
|
|
// const fcl::Matrix3f& rotation = state.contactRotation_.at(*cit); |
40 |
|
|
const pinocchio::Frame effectorFrame = |
41 |
|
|
device->getFrameByName(limb->effector_.name()); |
42 |
|
|
pinocchio::JointPtr_t effectorJoint = effectorFrame.joint(); |
43 |
|
|
const constraints::DifferentiableFunctionPtr_t &function = |
44 |
|
|
constraints::Position::create( |
45 |
|
|
"", device, effectorJoint, |
46 |
|
|
effectorFrame.pinocchio().placement * localFrame, globalFrame); |
47 |
|
|
constraints::ComparisonTypes_t comp(function->outputDerivativeSize(), |
48 |
|
|
constraints::EqualToZero); |
49 |
|
|
projector->add(constraints::Implicit::create(function, comp)); |
50 |
|
|
if (limb->contactType_ == hpp::rbprm::_6_DOF) { |
51 |
|
|
pinocchio::Transform3f rotation(1); |
52 |
|
|
rotation.rotation( |
53 |
|
|
state.contactRotation_.at(*cit) * |
54 |
|
|
effectorFrame.pinocchio().placement.rotation().transpose()); |
55 |
|
|
const constraints::DifferentiableFunctionPtr_t &function_ = |
56 |
|
|
constraints::Orientation::create("", device, effectorJoint, rotation, |
57 |
|
|
cosntraintsR); |
58 |
|
|
constraints::ComparisonTypes_t comp_(function_->outputDerivativeSize(), |
59 |
|
|
constraints::EqualToZero); |
60 |
|
|
projector->add(constraints::Implicit::create(function_, comp_)); |
61 |
|
|
} |
62 |
|
|
} |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
std::string getEffectorLimb(const State &startState, const State &nextState) { |
66 |
|
|
return nextState.contactCreations(startState).front(); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
pinocchio::Frame getEffector(RbPrmFullBodyPtr_t fullbody, |
70 |
|
|
const State &startState, const State &nextState) { |
71 |
|
|
std::string effectorVar = getEffectorLimb(startState, nextState); |
72 |
|
|
return fullbody->device_->getFrameByName( |
73 |
|
|
fullbody->GetLimbs().at(effectorVar)->effector_.name()); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
} // namespace interpolation |
77 |
|
|
} // namespace rbprm |
78 |
|
|
} // namespace hpp |