Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2015 CNRS |
3 |
|
|
// Authors: Joseph Mirabel |
4 |
|
|
// |
5 |
|
|
// |
6 |
|
|
|
7 |
|
|
// Redistribution and use in source and binary forms, with or without |
8 |
|
|
// modification, are permitted provided that the following conditions are |
9 |
|
|
// met: |
10 |
|
|
// |
11 |
|
|
// 1. Redistributions of source code must retain the above copyright |
12 |
|
|
// notice, this list of conditions and the following disclaimer. |
13 |
|
|
// |
14 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright |
15 |
|
|
// notice, this list of conditions and the following disclaimer in the |
16 |
|
|
// documentation and/or other materials provided with the distribution. |
17 |
|
|
// |
18 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 |
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 |
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 |
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 |
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 |
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 |
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 |
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
29 |
|
|
// DAMAGE. |
30 |
|
|
|
31 |
|
|
#include <hpp/constraints/com-between-feet.hh> |
32 |
|
|
#include <hpp/pinocchio/center-of-mass-computation.hh> |
33 |
|
|
#include <hpp/pinocchio/device.hh> |
34 |
|
|
#include <hpp/pinocchio/joint.hh> |
35 |
|
|
#include <hpp/util/debug.hh> |
36 |
|
|
|
37 |
|
|
namespace hpp { |
38 |
|
|
namespace constraints { |
39 |
|
|
namespace { |
40 |
|
✗ |
static size_type size(std::vector<bool> mask) { |
41 |
|
✗ |
size_type res = 0; |
42 |
|
✗ |
for (std::vector<bool>::iterator it = mask.begin(); it != mask.end(); ++it) { |
43 |
|
✗ |
if (*it) ++res; |
44 |
|
|
} |
45 |
|
✗ |
return res; |
46 |
|
|
} |
47 |
|
|
} // namespace |
48 |
|
|
|
49 |
|
✗ |
ComBetweenFeetPtr_t ComBetweenFeet::create( |
50 |
|
|
const std::string& name, const DevicePtr_t& robot, const JointPtr_t& jointL, |
51 |
|
|
const JointPtr_t& jointR, const vector3_t pointL, const vector3_t pointR, |
52 |
|
|
const JointPtr_t& jointRef, const vector3_t pointRef, |
53 |
|
|
std::vector<bool> mask) { |
54 |
|
✗ |
CenterOfMassComputationPtr_t comc = CenterOfMassComputation::create(robot); |
55 |
|
✗ |
comc->add(robot->rootJoint()); |
56 |
|
|
return create(name, robot, comc, jointL, jointR, pointL, pointR, jointRef, |
57 |
|
✗ |
pointRef, mask); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
✗ |
ComBetweenFeetPtr_t ComBetweenFeet::create( |
61 |
|
|
const std::string& name, const DevicePtr_t& robot, |
62 |
|
|
const CenterOfMassComputationPtr_t& comc, const JointPtr_t& jointL, |
63 |
|
|
const JointPtr_t& jointR, const vector3_t pointL, const vector3_t pointR, |
64 |
|
|
const JointPtr_t& jointRef, const vector3_t pointRef, |
65 |
|
|
std::vector<bool> mask) { |
66 |
|
|
ComBetweenFeet* ptr = |
67 |
|
|
new ComBetweenFeet(name, robot, comc, jointL, jointR, pointL, pointR, |
68 |
|
✗ |
jointRef, pointRef, mask); |
69 |
|
✗ |
ComBetweenFeetPtr_t shPtr(ptr); |
70 |
|
✗ |
return shPtr; |
71 |
|
|
} |
72 |
|
|
|
73 |
|
✗ |
ComBetweenFeet::ComBetweenFeet(const std::string& name, |
74 |
|
|
const DevicePtr_t& robot, |
75 |
|
|
const CenterOfMassComputationPtr_t& comc, |
76 |
|
|
const JointPtr_t& jointL, |
77 |
|
|
const JointPtr_t& jointR, const vector3_t pointL, |
78 |
|
|
const vector3_t pointR, |
79 |
|
|
const JointPtr_t& jointRef, |
80 |
|
✗ |
const vector3_t pointRef, std::vector<bool> mask) |
81 |
|
|
: DifferentiableFunction(robot->configSize(), robot->numberDof(), |
82 |
|
✗ |
LiegroupSpace::Rn(size(mask)), name), |
83 |
|
✗ |
robot_(robot), |
84 |
|
✗ |
com_(PointCom::create(comc)), |
85 |
|
✗ |
left_(PointInJoint::create(jointL, pointL)), |
86 |
|
✗ |
right_(PointInJoint::create(jointR, pointR)), |
87 |
|
✗ |
pointRef_(), |
88 |
|
✗ |
jointRef_(jointRef), |
89 |
|
✗ |
mask_(mask) { |
90 |
|
✗ |
cross_.setZero(); |
91 |
|
✗ |
u_ = right_ - left_; |
92 |
|
✗ |
xmxl_ = com_ - left_; |
93 |
|
✗ |
xmxr_ = com_ - right_; |
94 |
|
✗ |
ecrossu_ = (com_ - (0.5 * (left_ + right_))) ^ (u_); |
95 |
|
|
// expr_ = RotationMultiply <ECrossU_t> (jointRef_, ecrossu_, true); |
96 |
|
✗ |
expr_ = JointTranspose(jointRef_) * ecrossu_; |
97 |
|
✗ |
xmxlDotu_ = xmxl_ * u_; |
98 |
|
✗ |
xmxrDotu_ = xmxr_ * u_; |
99 |
|
✗ |
for (int i = 0; i < 3; i++) pointRef_[i] = pointRef[i]; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
✗ |
void ComBetweenFeet::impl_compute(LiegroupElementRef result, |
103 |
|
|
ConfigurationIn_t argument) const { |
104 |
|
✗ |
robot_->currentConfiguration(argument); |
105 |
|
✗ |
robot_->computeForwardKinematics(pinocchio::JOINT_POSITION); |
106 |
|
✗ |
size_t index = 0; |
107 |
|
✗ |
if (mask_[0]) { |
108 |
|
✗ |
com_->invalidate(); |
109 |
|
✗ |
com_->computeValue(argument); |
110 |
|
✗ |
result.vector()[index++] = (com_->value() - pointRef_)[2]; |
111 |
|
|
} |
112 |
|
✗ |
if (mask_[1]) { |
113 |
|
✗ |
expr_->invalidate(); |
114 |
|
✗ |
expr_->computeValue(argument); |
115 |
|
✗ |
result.vector()[index++] = expr_->value()[2]; |
116 |
|
|
} |
117 |
|
✗ |
if (mask_[2]) { |
118 |
|
✗ |
xmxlDotu_->invalidate(); |
119 |
|
✗ |
xmxlDotu_->computeValue(argument); |
120 |
|
✗ |
result.vector()[index++] = xmxlDotu_->value()[0]; |
121 |
|
|
} |
122 |
|
✗ |
if (mask_[3]) { |
123 |
|
✗ |
xmxrDotu_->invalidate(); |
124 |
|
✗ |
xmxrDotu_->computeValue(argument); |
125 |
|
✗ |
result.vector()[index] = xmxrDotu_->value()[0]; |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
|
129 |
|
✗ |
void ComBetweenFeet::impl_jacobian(matrixOut_t jacobian, |
130 |
|
|
ConfigurationIn_t arg) const { |
131 |
|
✗ |
robot_->currentConfiguration(arg); |
132 |
|
✗ |
robot_->computeForwardKinematics(pinocchio::JOINT_POSITION | |
133 |
|
|
pinocchio::JACOBIAN); |
134 |
|
✗ |
size_t index = 0; |
135 |
|
✗ |
if (mask_[0]) { |
136 |
|
✗ |
com_->invalidate(); |
137 |
|
✗ |
com_->computeJacobian(arg); |
138 |
|
✗ |
jacobian.row(index++).leftCols(jointRef_->jacobian().cols()) = |
139 |
|
✗ |
com_->jacobian().row(2); |
140 |
|
|
} |
141 |
|
✗ |
if (mask_[1]) { |
142 |
|
✗ |
expr_->invalidate(); |
143 |
|
✗ |
expr_->computeJacobian(arg); |
144 |
|
✗ |
jacobian.row(index++).leftCols(jointRef_->jacobian().cols()) = |
145 |
|
✗ |
expr_->jacobian().row(2); |
146 |
|
|
} |
147 |
|
✗ |
if (mask_[2]) { |
148 |
|
✗ |
xmxlDotu_->invalidate(); |
149 |
|
✗ |
xmxlDotu_->computeJacobian(arg); |
150 |
|
✗ |
jacobian.row(index++).leftCols(jointRef_->jacobian().cols()) = |
151 |
|
✗ |
xmxlDotu_->jacobian(); |
152 |
|
|
} |
153 |
|
✗ |
if (mask_[3]) { |
154 |
|
✗ |
xmxrDotu_->invalidate(); |
155 |
|
✗ |
xmxrDotu_->computeJacobian(arg); |
156 |
|
✗ |
jacobian.row(index).leftCols(jointRef_->jacobian().cols()) = |
157 |
|
✗ |
xmxrDotu_->jacobian(); |
158 |
|
|
} |
159 |
|
|
} |
160 |
|
|
} // namespace constraints |
161 |
|
|
} // namespace hpp |
162 |
|
|
|