17 #include <boost/test/unit_test.hpp>
18 #include <boost/utility/binary.hpp>
20 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
24 using namespace Eigen;
33 model.lowerPositionLimit.head<7>().
fill(-1.);
34 model.upperPositionLimit.head<7>().
fill(1.);
43 const double eps = 1e-8;
51 Data::Matrix6x kinematic_regressor_LWA_fd(Data::Matrix6x::Zero(6, 6 * (
model.njoints - 1)));
60 Data data_plus(model_plus);
64 for (
int i = 1;
i <
model.njoints; ++
i)
66 Motion::Vector6
v = Motion::Vector6::Zero();
69 for (Eigen::DenseIndex k = 0; k < 6; ++k)
76 const Motion diff_L =
log6(oMi.actInv(oMi_plus));
77 kinematic_regressor_L_fd.middleCols<6>(6 * (
i - 1)).col(k) = diff_L.toVector() /
eps;
78 const Motion diff_LWA = Mi_LWA.act(diff_L);
79 kinematic_regressor_LWA_fd.middleCols<6>(6 * (
i - 1)).col(k) = diff_LWA.toVector() /
eps;
80 const Motion diff_W = oMi.act(diff_L);
81 kinematic_regressor_W_fd.middleCols<6>(6 * (
i - 1)).col(k) = diff_W.toVector() /
eps;
85 M_placement_plus = M_placement;
88 BOOST_CHECK(kinematic_regressor_L.isApprox(kinematic_regressor_L_fd, sqrt(
eps)));
89 BOOST_CHECK(kinematic_regressor_LWA.isApprox(kinematic_regressor_LWA_fd, sqrt(
eps)));
90 BOOST_CHECK(kinematic_regressor_W.isApprox(kinematic_regressor_W_fd, sqrt(
eps)));
96 using namespace Eigen;
105 model.lowerPositionLimit.head<7>().
fill(-1.);
106 model.upperPositionLimit.head<7>().
fill(1.);
126 Data::Matrix6x kinematic_regressor_L_ref(Data::Matrix6x::Zero(6, 6 * (
model.njoints - 1)));
127 Data::Matrix6x kinematic_regressor_LWA_ref(Data::Matrix6x::Zero(6, 6 * (
model.njoints - 1)));
128 Data::Matrix6x kinematic_regressor_W_ref(Data::Matrix6x::Zero(6, 6 * (
model.njoints - 1)));
135 BOOST_CHECK(kinematic_regressor_L.isApprox(kinematic_regressor_L_ref));
136 BOOST_CHECK(kinematic_regressor_LWA.isApprox(kinematic_regressor_LWA_ref));
137 BOOST_CHECK(kinematic_regressor_W.isApprox(kinematic_regressor_W_ref));
143 using namespace Eigen;
149 model.lowerPositionLimit.head<7>().
fill(-1.);
150 model.upperPositionLimit.head<7>().
fill(1.);
154 model.addBodyFrame(
"test_body",
joint_id, SE3::Random(), -1);
165 const double eps = 1e-8;
179 Data::Matrix6x kinematic_regressor_L_ref(Data::Matrix6x::Zero(6, 6 * (
model.njoints - 1)));
180 Data::Matrix6x kinematic_regressor_LWA_ref(Data::Matrix6x::Zero(6, 6 * (
model.njoints - 1)));
181 Data::Matrix6x kinematic_regressor_W_ref(Data::Matrix6x::Zero(6, 6 * (
model.njoints - 1)));
187 kinematic_regressor_LWA_ref);
191 BOOST_CHECK(kinematic_regressor_L.isApprox(kinematic_regressor_L_ref));
192 BOOST_CHECK(kinematic_regressor_LWA.isApprox(kinematic_regressor_LWA_ref));
193 BOOST_CHECK(kinematic_regressor_W.isApprox(kinematic_regressor_W_ref));
196 Data::Matrix6x kinematic_regressor_LWA_fd(Data::Matrix6x::Zero(6, 6 * (
model.njoints - 1)));
200 Data data_plus(model_plus);
204 for (
int i = 1;
i <
model.njoints; ++
i)
206 Motion::Vector6
v = Motion::Vector6::Zero();
209 for (Eigen::DenseIndex k = 0; k < 6; ++k)
217 const Motion diff_L =
log6(oMf.actInv(oMf_plus));
218 kinematic_regressor_L_fd.middleCols<6>(6 * (
i - 1)).col(k) = diff_L.toVector() /
eps;
219 const Motion diff_LWA = Mf_LWA.act(diff_L);
220 kinematic_regressor_LWA_fd.middleCols<6>(6 * (
i - 1)).col(k) = diff_LWA.toVector() /
eps;
221 const Motion diff_W = oMf.act(diff_L);
222 kinematic_regressor_W_fd.middleCols<6>(6 * (
i - 1)).col(k) = diff_W.toVector() /
eps;
226 M_placement_plus = M_placement;
229 BOOST_CHECK(kinematic_regressor_L.isApprox(kinematic_regressor_L_fd, sqrt(
eps)));
230 BOOST_CHECK(kinematic_regressor_LWA.isApprox(kinematic_regressor_LWA_fd, sqrt(
eps)));
231 BOOST_CHECK(kinematic_regressor_W.isApprox(kinematic_regressor_W_fd, sqrt(
eps)));
237 using namespace Eigen;
246 model.lowerPositionLimit.head<7>().
fill(-1.);
247 model.upperPositionLimit.head<7>().
fill(1.);
252 VectorXd phi(4 * (
model.njoints - 1));
253 for (
int k = 1; k <
model.njoints; ++k)
256 phi.segment<4>(4 * (k - 1)) <<
Y.mass(),
Y.mass() *
Y.lever();
260 Vector3d static_com_ref;
261 static_com_ref <<
com;
263 Vector3d static_com =
data.staticRegressor * phi;
265 BOOST_CHECK(static_com.isApprox(static_com_ref));
270 using namespace Eigen;
281 BOOST_CHECK(f_regressor.isApprox(
f.toVector()));
286 using namespace Eigen;
296 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
297 VectorXd
a = Eigen::VectorXd::Random(
model.nv);
303 Inertia::Vector6 f_regressor =
306 BOOST_CHECK(f_regressor.isApprox(
f.toVector()));
311 using namespace Eigen;
319 const SE3 & framePlacement = SE3::Random();
325 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
326 VectorXd
a = Eigen::VectorXd::Random(
model.nv);
333 Inertia::Vector6 f_regressor =
336 BOOST_CHECK(f_regressor.isApprox(
f.toVector()));
341 using namespace Eigen;
347 model.lowerPositionLimit.head<7>().
fill(-1.);
348 model.upperPositionLimit.head<7>().
fill(1.);
354 VectorXd
v = Eigen::VectorXd::Random(
model.nv);
355 VectorXd
a = Eigen::VectorXd::Random(
model.nv);
359 Eigen::VectorXd params(10 * (
model.njoints - 1));
361 params.segment<10>((int)((
i - 1) * 10)) =
model.inertias[
i].toDynamicParameters();
365 Eigen::VectorXd tau_regressor =
data.jointTorqueRegressor * params;
367 BOOST_CHECK(tau_regressor.isApprox(data_ref.
tau));
372 using namespace Eigen;
378 model.lowerPositionLimit.head<7>().
fill(-1.);
379 model.upperPositionLimit.head<7>().
fill(1.);
385 const VectorXd
v = Eigen::VectorXd::Random(
model.nv);
390 const auto regressor = computeKineticEnergyRegressor(
model,
data,
q,
v);
392 Eigen::VectorXd params(10 * (
model.njoints - 1));
394 params.segment<10>(Eigen::DenseIndex((
i - 1) * 10)) =
model.inertias[
i].toDynamicParameters();
396 const double kinetic_energy_regressor =
data.kineticEnergyRegressor * params;
398 BOOST_CHECK_CLOSE(kinetic_energy_regressor, target_energy, 1e-12);
403 using namespace Eigen;
409 model.lowerPositionLimit.head<7>().
fill(-1.);
410 model.upperPositionLimit.head<7>().
fill(1.);
416 const VectorXd
v = Eigen::VectorXd::Random(
model.nv);
421 Eigen::VectorXd params(10 * (
model.njoints - 1));
423 params.segment<10>(Eigen::DenseIndex((
i - 1) * 10)) =
model.inertias[
i].toDynamicParameters();
426 const double potential_energy_regressor =
data.potentialEnergyRegressor * params;
428 BOOST_CHECK_CLOSE(potential_energy_regressor, target_energy, 1e-12);
431 BOOST_AUTO_TEST_SUITE_END()