15 #include <boost/test/unit_test.hpp>
16 #include <boost/utility/binary.hpp>
18 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
22 using namespace Eigen;
30 model.lowerPositionLimit.head<3>().
fill(-1.);
31 model.upperPositionLimit.head<3>().
fill(1.);
34 VectorXd
v(VectorXd::Random(
model.nv));
35 VectorXd
a(VectorXd::Random(
model.nv));
49 dtau2_dqdv, dtau2_dadq);
60 MatrixXd drnea_dq_plus(MatrixXd::Zero(
model.nv,
model.nv));
61 MatrixXd drnea_dv_plus(MatrixXd::Zero(
model.nv,
model.nv));
62 MatrixXd drnea_da_plus(MatrixXd::Zero(
model.nv,
model.nv));
64 MatrixXd temp1(MatrixXd::Zero(
model.nv,
model.nv));
65 MatrixXd temp2(MatrixXd::Zero(
model.nv,
model.nv));
67 VectorXd v_eps(VectorXd::Zero(
model.nv));
68 VectorXd q_plus(
model.nq);
69 VectorXd v_plus(
model.nv);
71 MatrixXd rnea_partial_dq(MatrixXd::Zero(
model.nv,
model.nv));
72 MatrixXd rnea_partial_dv(MatrixXd::Zero(
model.nv,
model.nv));
73 MatrixXd rnea_partial_da(MatrixXd::Zero(
model.nv,
model.nv));
77 rnea_partial_dv, rnea_partial_da);
79 const double alpha = 1e-7;
81 for (
int k = 0; k <
model.nv; ++k)
86 model, data_fd, q_plus, VectorXd::Zero(
model.nv), VectorXd::Zero(
model.nv), drnea_dq_plus,
87 drnea_dv_plus, drnea_da_plus);
88 temp1 = (drnea_dq_plus - rnea_partial_dq) /
alpha;
89 for (
int ii = 0; ii <
model.nv; ii++)
91 for (
int jj = 0; jj <
model.nv; jj++)
93 dtau2_dq_fd(jj, ii, k) = temp1(jj, ii);
99 Map<VectorXd> mq(dtau2_dq.
data(), dtau2_dq.
size());
100 Map<VectorXd> mq_fd(dtau2_dq_fd.
data(), dtau2_dq_fd.
size());
101 BOOST_CHECK(mq.isApprox(mq_fd, sqrt(
alpha)));
109 model,
data,
q, VectorXd::Zero(
model.nv),
a, dtau2_dq, dtau2_dv, dtau2_dqdv, dtau2_dadq);
111 rnea_partial_dq.setZero();
112 rnea_partial_dv.setZero();
113 rnea_partial_da.setZero();
122 model,
data,
q, VectorXd::Zero(
model.nv),
a, rnea_partial_dq, rnea_partial_dv, rnea_partial_da);
124 for (
int k = 0; k <
model.nv; ++k)
129 model, data_fd, q_plus, VectorXd::Zero(
model.nv),
a, drnea_dq_plus, drnea_dv_plus,
131 temp1 = (drnea_dq_plus - rnea_partial_dq) /
alpha;
132 temp2 = (drnea_da_plus - rnea_partial_da) /
alpha;
133 temp2.triangularView<Eigen::StrictlyLower>() =
134 temp2.transpose().triangularView<Eigen::StrictlyLower>();
135 for (
int ii = 0; ii <
model.nv; ii++)
137 for (
int jj = 0; jj <
model.nv; jj++)
139 dtau2_dq_fd(jj, ii, k) = temp1(jj, ii);
140 dtau2_dadq_fd(jj, ii, k) = temp2(jj, ii);
145 Map<VectorXd> maq(dtau2_dadq.
data(), dtau2_dadq.
size());
146 Map<VectorXd> maq_fd(dtau2_dadq_fd.
data(), dtau2_dadq_fd.
size());
148 BOOST_CHECK(mq.isApprox(mq_fd, sqrt(
alpha)));
149 BOOST_CHECK(maq.isApprox(maq_fd, sqrt(
alpha)));
157 model,
data,
q,
v,
a, dtau2_dq, dtau2_dv, dtau2_dqdv, dtau2_dadq);
159 rnea_partial_dq.setZero();
160 rnea_partial_dv.setZero();
161 rnea_partial_da.setZero();
170 for (
int k = 0; k <
model.nv; ++k)
175 model, data_fd, q_plus,
v,
a, drnea_dq_plus, drnea_dv_plus, drnea_da_plus);
176 temp1 = (drnea_dq_plus - rnea_partial_dq) /
alpha;
177 temp2 = (drnea_da_plus - rnea_partial_da) /
alpha;
178 temp2.triangularView<Eigen::StrictlyLower>() =
179 temp2.transpose().triangularView<Eigen::StrictlyLower>();
180 for (
int ii = 0; ii <
model.nv; ii++)
182 for (
int jj = 0; jj <
model.nv; jj++)
184 dtau2_dq_fd(jj, ii, k) = temp1(jj, ii);
185 dtau2_dadq_fd(jj, ii, k) = temp2(jj, ii);
192 for (
int k = 0; k <
model.nv; ++k)
197 model, data_fd,
q, v_plus,
a, drnea_dq_plus, drnea_dv_plus, drnea_da_plus);
198 temp1 = (drnea_dv_plus - rnea_partial_dv) /
alpha;
199 temp2 = (drnea_dq_plus - rnea_partial_dq) /
alpha;
200 for (
int ii = 0; ii <
model.nv; ii++)
202 for (
int jj = 0; jj <
model.nv; jj++)
204 dtau2_dv_fd(jj, ii, k) = temp1(jj, ii);
205 dtau2_dqdv_fd(jj, ii, k) = temp2(jj, ii);
210 Map<VectorXd> mv(dtau2_dv.
data(), dtau2_dv.
size());
211 Map<VectorXd> mv_fd(dtau2_dv_fd.
data(), dtau2_dv_fd.
size());
213 Map<VectorXd> mqv(dtau2_dqdv.
data(), dtau2_dqdv.
size());
214 Map<VectorXd> mqv_fd(dtau2_dqdv_fd.
data(), dtau2_dqdv_fd.
size());
216 BOOST_CHECK(mq.isApprox(mq_fd, sqrt(
alpha)));
217 BOOST_CHECK(maq.isApprox(maq_fd, sqrt(
alpha)));
218 BOOST_CHECK(mv.isApprox(mv_fd, sqrt(
alpha)));
219 BOOST_CHECK(mqv.isApprox(mqv_fd, sqrt(
alpha)));
229 BOOST_CHECK(mq.isApprox(mq2, sqrt(
alpha)));
230 BOOST_CHECK(mv.isApprox(mv2, sqrt(
alpha)));
231 BOOST_CHECK(mqv.isApprox(mqv2, sqrt(
alpha)));
232 BOOST_CHECK(maq.isApprox(maq2, sqrt(
alpha)));
235 BOOST_AUTO_TEST_SUITE_END()