Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2019 INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#include "pinocchio/multibody/joint/joint-generic.hpp" |
6 |
|
|
#include "pinocchio/multibody/liegroup/liegroup.hpp" |
7 |
|
|
|
8 |
|
|
#include <boost/test/unit_test.hpp> |
9 |
|
|
#include <boost/utility/binary.hpp> |
10 |
|
|
|
11 |
|
|
using namespace pinocchio; |
12 |
|
|
|
13 |
|
|
BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE) |
14 |
|
|
|
15 |
|
|
typedef Eigen::Matrix<double, 6, Eigen::Dynamic> Matrix6x; |
16 |
|
|
|
17 |
|
|
template<typename JointModel> |
18 |
|
✗ |
void test_constraint_mimic(const JointModelBase<JointModel> & jmodel) |
19 |
|
|
{ |
20 |
|
|
typedef typename traits<JointModel>::JointDerived Joint; |
21 |
|
|
typedef typename traits<Joint>::Constraint_t ConstraintType; |
22 |
|
|
typedef typename traits<Joint>::JointDataDerived JointData; |
23 |
|
|
typedef ScaledJointMotionSubspace<ConstraintType> ScaledJointMotionSubspaceType; |
24 |
|
|
|
25 |
|
✗ |
JointData jdata = jmodel.createData(); |
26 |
|
|
|
27 |
|
✗ |
const double scaling_factor = 2.; |
28 |
|
✗ |
ConstraintType constraint_ref(jdata.S), constraint_ref_shared(jdata.S); |
29 |
|
✗ |
ScaledJointMotionSubspaceType scaled_constraint(constraint_ref_shared, scaling_factor); |
30 |
|
|
|
31 |
|
✗ |
BOOST_CHECK(constraint_ref.nv() == scaled_constraint.nv()); |
32 |
|
|
|
33 |
|
|
typedef typename JointModel::TangentVector_t TangentVector_t; |
34 |
|
✗ |
TangentVector_t v = TangentVector_t::Random(); |
35 |
|
|
|
36 |
|
✗ |
Motion m = scaled_constraint * v; |
37 |
|
✗ |
Motion m_ref = scaling_factor * (Motion)(constraint_ref * v); |
38 |
|
|
|
39 |
|
✗ |
BOOST_CHECK(m.isApprox(m_ref)); |
40 |
|
|
|
41 |
|
|
{ |
42 |
|
✗ |
SE3 M = SE3::Random(); |
43 |
|
✗ |
typename ScaledJointMotionSubspaceType::DenseBase S = M.act(scaled_constraint); |
44 |
|
✗ |
typename ScaledJointMotionSubspaceType::DenseBase S_ref = |
45 |
|
|
scaling_factor * M.act(constraint_ref); |
46 |
|
|
|
47 |
|
✗ |
BOOST_CHECK(S.isApprox(S_ref)); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
{ |
51 |
|
✗ |
typename ScaledJointMotionSubspaceType::DenseBase S = scaled_constraint.matrix(); |
52 |
|
✗ |
typename ScaledJointMotionSubspaceType::DenseBase S_ref = |
53 |
|
|
scaling_factor * constraint_ref.matrix(); |
54 |
|
|
|
55 |
|
✗ |
BOOST_CHECK(S.isApprox(S_ref)); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
{ |
59 |
|
✗ |
Motion v = Motion::Random(); |
60 |
|
✗ |
typename ScaledJointMotionSubspaceType::DenseBase S = v.cross(scaled_constraint); |
61 |
|
✗ |
typename ScaledJointMotionSubspaceType::DenseBase S_ref = |
62 |
|
|
scaling_factor * v.cross(constraint_ref); |
63 |
|
|
|
64 |
|
✗ |
BOOST_CHECK(S.isApprox(S_ref)); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
// Test transpose operations |
68 |
|
|
{ |
69 |
|
✗ |
const Eigen::DenseIndex dim = 20; |
70 |
|
✗ |
const Matrix6x Fin = Matrix6x::Random(6, dim); |
71 |
|
✗ |
Eigen::MatrixXd Fout = scaled_constraint.transpose() * Fin; |
72 |
|
✗ |
Eigen::MatrixXd Fout_ref = scaling_factor * (constraint_ref.transpose() * Fin); |
73 |
|
✗ |
BOOST_CHECK(Fout.isApprox(Fout_ref)); |
74 |
|
|
|
75 |
|
✗ |
Force force_in(Force::Random()); |
76 |
|
✗ |
Eigen::MatrixXd Stf = (scaled_constraint.transpose() * force_in); |
77 |
|
✗ |
Eigen::MatrixXd Stf_ref = scaling_factor * (constraint_ref.transpose() * force_in); |
78 |
|
✗ |
BOOST_CHECK(Stf_ref.isApprox(Stf)); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
// CRBA Y*S |
82 |
|
|
{ |
83 |
|
✗ |
Inertia Y = Inertia::Random(); |
84 |
|
✗ |
Eigen::MatrixXd YS = Y * scaled_constraint; |
85 |
|
✗ |
Eigen::MatrixXd YS_ref = scaling_factor * (Y * constraint_ref); |
86 |
|
|
|
87 |
|
✗ |
BOOST_CHECK(YS.isApprox(YS_ref)); |
88 |
|
|
} |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
struct TestJointConstraint |
92 |
|
|
{ |
93 |
|
|
|
94 |
|
|
template<typename JointModel> |
95 |
|
✗ |
void operator()(const JointModelBase<JointModel> &) const |
96 |
|
|
{ |
97 |
|
✗ |
JointModel jmodel; |
98 |
|
✗ |
jmodel.setIndexes(0, 0, 0); |
99 |
|
|
|
100 |
|
✗ |
test_constraint_mimic(jmodel); |
101 |
|
|
} |
102 |
|
|
|
103 |
|
✗ |
void operator()(const JointModelBase<JointModelRevoluteUnaligned> &) const |
104 |
|
|
{ |
105 |
|
✗ |
JointModelRevoluteUnaligned jmodel(1.5, 1., 0.); |
106 |
|
✗ |
jmodel.setIndexes(0, 0, 0); |
107 |
|
|
|
108 |
|
✗ |
test_constraint_mimic(jmodel); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
✗ |
void operator()(const JointModelBase<JointModelPrismaticUnaligned> &) const |
112 |
|
|
{ |
113 |
|
✗ |
JointModelPrismaticUnaligned jmodel(1.5, 1., 0.); |
114 |
|
✗ |
jmodel.setIndexes(0, 0, 0); |
115 |
|
|
|
116 |
|
✗ |
test_constraint_mimic(jmodel); |
117 |
|
|
} |
118 |
|
|
}; |
119 |
|
|
|
120 |
|
✗ |
BOOST_AUTO_TEST_CASE(test_constraint) |
121 |
|
|
{ |
122 |
|
|
using namespace pinocchio; |
123 |
|
|
typedef boost::variant< |
124 |
|
|
JointModelRX, JointModelRY, JointModelRZ, JointModelRevoluteUnaligned, JointModelPX, |
125 |
|
|
JointModelPY, JointModelPZ, JointModelPrismaticUnaligned, JointModelRUBX, JointModelRUBY, |
126 |
|
|
JointModelRUBZ> |
127 |
|
|
Variant; |
128 |
|
|
|
129 |
|
✗ |
boost::mpl::for_each<Variant::types>(TestJointConstraint()); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
template<typename JointModel> |
133 |
|
✗ |
void test_joint_mimic(const JointModelBase<JointModel> & jmodel) |
134 |
|
|
{ |
135 |
|
|
typedef typename traits<JointModel>::JointDerived Joint; |
136 |
|
|
typedef typename traits<Joint>::JointDataDerived JointData; |
137 |
|
|
|
138 |
|
✗ |
JointData jdata = jmodel.createData(); |
139 |
|
|
|
140 |
|
✗ |
const double scaling_factor = 1.; |
141 |
|
✗ |
const double offset = 0.; |
142 |
|
|
|
143 |
|
|
typedef JointMimic<Joint> JointMimicType; |
144 |
|
|
typedef typename traits<JointMimicType>::JointModelDerived JointModelMimicType; |
145 |
|
|
typedef typename traits<JointMimicType>::JointDataDerived JointDataMimicType; |
146 |
|
|
|
147 |
|
|
// test constructor |
148 |
|
✗ |
JointModelMimicType jmodel_mimic(jmodel.derived(), scaling_factor, offset); |
149 |
|
✗ |
JointDataMimicType jdata_mimic = jmodel_mimic.createData(); |
150 |
|
|
|
151 |
|
✗ |
BOOST_CHECK(jmodel_mimic.nq() == 0); |
152 |
|
✗ |
BOOST_CHECK(jmodel_mimic.nv() == 0); |
153 |
|
|
|
154 |
|
✗ |
BOOST_CHECK(jmodel_mimic.idx_q() == jmodel.idx_q()); |
155 |
|
✗ |
BOOST_CHECK(jmodel_mimic.idx_v() == jmodel.idx_v()); |
156 |
|
|
|
157 |
|
✗ |
BOOST_CHECK(jmodel_mimic.idx_q() == 0); |
158 |
|
✗ |
BOOST_CHECK(jmodel_mimic.idx_v() == 0); |
159 |
|
|
|
160 |
|
|
typedef typename JointModelMimicType::ConfigVector_t ConfigVectorType; |
161 |
|
|
typedef typename LieGroup<JointModel>::type LieGroupType; |
162 |
|
✗ |
ConfigVectorType q0 = |
163 |
|
✗ |
LieGroupType().randomConfiguration(-ConfigVectorType::Ones(), ConfigVectorType::Ones()); |
164 |
|
|
|
165 |
|
✗ |
jmodel.calc(jdata, q0); |
166 |
|
✗ |
jmodel_mimic.calc(jdata_mimic, q0); |
167 |
|
|
|
168 |
|
✗ |
BOOST_CHECK(((SE3)jdata.M).isApprox((SE3)jdata_mimic.M())); |
169 |
|
✗ |
BOOST_CHECK(jdata.S.matrix().isApprox(jdata_mimic.S.matrix())); |
170 |
|
|
|
171 |
|
|
typedef typename JointModelMimicType::TangentVector_t TangentVectorType; |
172 |
|
|
|
173 |
|
✗ |
q0 = LieGroupType().randomConfiguration(-ConfigVectorType::Ones(), ConfigVectorType::Ones()); |
174 |
|
✗ |
TangentVectorType v0 = TangentVectorType::Random(); |
175 |
|
✗ |
jmodel.calc(jdata, q0, v0); |
176 |
|
✗ |
jmodel_mimic.calc(jdata_mimic, q0, v0); |
177 |
|
|
|
178 |
|
✗ |
BOOST_CHECK(((SE3)jdata.M).isApprox((SE3)jdata_mimic.M())); |
179 |
|
✗ |
BOOST_CHECK(jdata.S.matrix().isApprox(jdata_mimic.S.matrix())); |
180 |
|
✗ |
BOOST_CHECK(((Motion)jdata.v).isApprox((Motion)jdata_mimic.v())); |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
struct TestJointMimic |
184 |
|
|
{ |
185 |
|
|
|
186 |
|
|
template<typename JointModel> |
187 |
|
✗ |
void operator()(const JointModelBase<JointModel> &) const |
188 |
|
|
{ |
189 |
|
✗ |
JointModel jmodel; |
190 |
|
✗ |
jmodel.setIndexes(0, 0, 0); |
191 |
|
|
|
192 |
|
✗ |
test_joint_mimic(jmodel); |
193 |
|
|
} |
194 |
|
|
|
195 |
|
✗ |
void operator()(const JointModelBase<JointModelRevoluteUnaligned> &) const |
196 |
|
|
{ |
197 |
|
✗ |
JointModelRevoluteUnaligned jmodel(1.5, 1., 0.); |
198 |
|
✗ |
jmodel.setIndexes(0, 0, 0); |
199 |
|
|
|
200 |
|
✗ |
test_joint_mimic(jmodel); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
✗ |
void operator()(const JointModelBase<JointModelPrismaticUnaligned> &) const |
204 |
|
|
{ |
205 |
|
✗ |
JointModelPrismaticUnaligned jmodel(1.5, 1., 0.); |
206 |
|
✗ |
jmodel.setIndexes(0, 0, 0); |
207 |
|
|
|
208 |
|
✗ |
test_joint_mimic(jmodel); |
209 |
|
|
} |
210 |
|
|
}; |
211 |
|
|
|
212 |
|
✗ |
BOOST_AUTO_TEST_CASE(test_joint) |
213 |
|
|
{ |
214 |
|
|
using namespace pinocchio; |
215 |
|
|
typedef boost::variant< |
216 |
|
|
JointModelRX, JointModelRY, JointModelRZ, JointModelRevoluteUnaligned, JointModelPX, |
217 |
|
|
JointModelPY, JointModelPZ, JointModelPrismaticUnaligned, JointModelRUBX, JointModelRUBY, |
218 |
|
|
JointModelRUBZ> |
219 |
|
|
Variant; |
220 |
|
|
|
221 |
|
✗ |
boost::mpl::for_each<Variant::types>(TestJointMimic()); |
222 |
|
|
} |
223 |
|
|
|
224 |
|
✗ |
BOOST_AUTO_TEST_CASE(test_transform_linear_affine) |
225 |
|
|
{ |
226 |
|
|
typedef JointModelRX::ConfigVector_t ConfigVectorType; |
227 |
|
✗ |
double scaling = 1., offset = 0.; |
228 |
|
|
|
229 |
|
✗ |
ConfigVectorType q0 = ConfigVectorType::Random(); |
230 |
|
✗ |
ConfigVectorType q1; |
231 |
|
✗ |
LinearAffineTransform::run(q0, scaling, offset, q1); |
232 |
|
✗ |
BOOST_CHECK(q0 == q1); |
233 |
|
|
|
234 |
|
✗ |
offset = 2.; |
235 |
|
✗ |
LinearAffineTransform::run(ConfigVectorType::Zero(), scaling, offset, q1); |
236 |
|
✗ |
BOOST_CHECK(q1 == ConfigVectorType::Constant(offset)); |
237 |
|
|
} |
238 |
|
|
|
239 |
|
✗ |
BOOST_AUTO_TEST_CASE(test_transform_linear_revolute) |
240 |
|
|
{ |
241 |
|
|
typedef JointModelRUBX::ConfigVector_t ConfigVectorType; |
242 |
|
✗ |
double scaling = 1., offset = 0.; |
243 |
|
|
|
244 |
|
✗ |
ConfigVectorType q0 = ConfigVectorType::Random().normalized(); |
245 |
|
✗ |
ConfigVectorType q1; |
246 |
|
✗ |
UnboundedRevoluteAffineTransform::run(q0, scaling, offset, q1); |
247 |
|
✗ |
BOOST_CHECK(q0.isApprox(q1)); |
248 |
|
|
|
249 |
|
✗ |
offset = 2.; |
250 |
|
✗ |
UnboundedRevoluteAffineTransform::run(ConfigVectorType::Zero(), scaling, offset, q1); |
251 |
|
✗ |
BOOST_CHECK(q1 == ConfigVectorType(math::cos(offset), math::sin(offset))); |
252 |
|
|
} |
253 |
|
|
|
254 |
|
✗ |
BOOST_AUTO_TEST_CASE(test_joint_generic_cast) |
255 |
|
|
{ |
256 |
|
✗ |
JointModelRX jmodel_ref; |
257 |
|
✗ |
jmodel_ref.setIndexes(1, 2, 3); |
258 |
|
|
|
259 |
|
✗ |
JointModelMimic<JointModelRX> jmodel(jmodel_ref, 2., 1.); |
260 |
|
✗ |
jmodel.setIndexes(1, -1, -1); |
261 |
|
|
|
262 |
|
✗ |
BOOST_CHECK(jmodel.id() == jmodel_ref.id()); |
263 |
|
✗ |
BOOST_CHECK(jmodel.idx_q() == jmodel_ref.idx_q()); |
264 |
|
✗ |
BOOST_CHECK(jmodel.idx_v() == jmodel_ref.idx_v()); |
265 |
|
|
|
266 |
|
✗ |
JointModel jmodel_generic(jmodel); |
267 |
|
✗ |
jmodel_generic.setIndexes(1, -2, -2); |
268 |
|
|
|
269 |
|
✗ |
BOOST_CHECK(jmodel_generic.id() == jmodel_ref.id()); |
270 |
|
|
} |
271 |
|
|
BOOST_AUTO_TEST_SUITE_END() |
272 |
|
|
|