9 #include <boost/variant.hpp>
11 #include <boost/test/unit_test.hpp>
12 #include <boost/utility/binary.hpp>
14 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
18 double r =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
19 double p =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / M_PI)) - (M_PI / 2);
20 double y =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
25 (Eigen::AngleAxisd(
y, Eigen::Vector3d::UnitZ()) * Eigen::AngleAxisd(
p, Eigen::Vector3d::UnitY())
26 * Eigen::AngleAxisd(
r, Eigen::Vector3d::UnitX()))
29 BOOST_CHECK(
R.isApprox(Raa));
36 BOOST_CHECK(Rv.isApprox(Raa));
37 BOOST_CHECK(Rv.isApprox(
R));
47 for (
int k = 0; k <
n; ++k)
49 Eigen::Quaterniond
quat;
51 const Eigen::Matrix3d
R =
quat.toRotationMatrix();
56 BOOST_CHECK(Rprime.isApprox(
R));
57 BOOST_CHECK(-M_PI <=
v[0] &&
v[0] <= M_PI);
58 BOOST_CHECK(-M_PI / 2 <=
v[1] &&
v[1] <= M_PI / 2);
59 BOOST_CHECK(-M_PI <=
v[2] &&
v[2] <= M_PI);
69 for (
int k = 0; k < n2; ++k)
71 double r =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
72 double y =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
74 Rp << 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, -1.0, 0.0, 0.0;
75 const Eigen::Matrix3d
R = Eigen::AngleAxisd(
y, Eigen::Vector3d::UnitZ()).toRotationMatrix() * Rp
76 * Eigen::AngleAxisd(
r, Eigen::Vector3d::UnitX()).toRotationMatrix();
81 BOOST_CHECK(Rprime.isApprox(
R));
82 BOOST_CHECK(-M_PI <=
v[0] &&
v[0] <= M_PI);
83 BOOST_CHECK(-M_PI / 2 <=
v[1] &&
v[1] <= M_PI / 2);
84 BOOST_CHECK(-M_PI <=
v[2] &&
v[2] <= M_PI);
88 for (
int k = 0; k < n2; ++k)
90 double r =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
91 double y =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
93 Rp << 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0;
94 const Eigen::Matrix3d
R = Eigen::AngleAxisd(
y, Eigen::Vector3d::UnitZ()).toRotationMatrix() * Rp
95 * Eigen::AngleAxisd(
r, Eigen::Vector3d::UnitX()).toRotationMatrix();
100 BOOST_CHECK(Rprime.isApprox(
R));
101 BOOST_CHECK(-M_PI <=
v[0] &&
v[0] <= M_PI);
102 BOOST_CHECK(-M_PI / 2 <=
v[1] &&
v[1] <= M_PI / 2);
103 BOOST_CHECK(-M_PI <=
v[2] &&
v[2] <= M_PI);
110 Eigen::Vector3d
rpy(Eigen::Vector3d::Zero());
112 BOOST_CHECK(j0.isIdentity());
114 BOOST_CHECK(jL.isIdentity());
116 BOOST_CHECK(jW.isIdentity());
118 BOOST_CHECK(jA.isIdentity());
121 double r =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
122 double p =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / M_PI)) - (M_PI / 2);
123 double y =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
124 rpy = Eigen::Vector3d(
r,
p,
y);
130 BOOST_CHECK(j0 == jL);
131 BOOST_CHECK(jW == jA);
132 BOOST_CHECK(jW.isApprox(
R * jL));
135 Eigen::Vector3d jL0Expected = Eigen::Vector3d::UnitX();
136 Eigen::Vector3d jL1Expected =
137 Eigen::AngleAxisd(
r, Eigen::Vector3d::UnitX()).toRotationMatrix().transpose().col(1);
138 Eigen::Vector3d jL2Expected = (Eigen::AngleAxisd(
p, Eigen::Vector3d::UnitY())
139 * Eigen::AngleAxisd(
r, Eigen::Vector3d::UnitX()))
143 BOOST_CHECK(jL.col(0).isApprox(jL0Expected));
144 BOOST_CHECK(jL.col(1).isApprox(jL1Expected));
145 BOOST_CHECK(jL.col(2).isApprox(jL2Expected));
147 Eigen::Vector3d jW0Expected = (Eigen::AngleAxisd(
y, Eigen::Vector3d::UnitZ())
148 * Eigen::AngleAxisd(
p, Eigen::Vector3d::UnitY()))
151 Eigen::Vector3d jW1Expected =
152 Eigen::AngleAxisd(
y, Eigen::Vector3d::UnitZ()).toRotationMatrix().col(1);
153 Eigen::Vector3d jW2Expected = Eigen::Vector3d::UnitZ();
154 BOOST_CHECK(jW.col(0).isApprox(jW0Expected));
155 BOOST_CHECK(jW.col(1).isApprox(jW1Expected));
156 BOOST_CHECK(jW.col(2).isApprox(jW2Expected));
159 Eigen::Vector3d rpydot = Eigen::Vector3d::Random();
160 double const eps = 1e-7;
161 double const tol = 1e-5;
166 Eigen::Matrix3d Rdot = dRdr * rpydot[0] + dRdp * rpydot[1] + dRdy * rpydot[2];
168 Eigen::Vector3d omegaL = jL * rpydot;
171 Eigen::Vector3d omegaW = jW * rpydot;
178 double r =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
179 double p =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / M_PI)) - (M_PI / 2);
181 double y =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
182 Eigen::Vector3d
rpy(
r,
p,
y);
186 BOOST_CHECK(j0inv.isApprox(j0.inverse()));
190 BOOST_CHECK(jLinv.isApprox(jL.inverse()));
194 BOOST_CHECK(jWinv.isApprox(jW.inverse()));
197 Eigen::Matrix3d jAinv =
199 BOOST_CHECK(jAinv.isApprox(jA.inverse()));
205 double r =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
206 double p =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / M_PI)) - (M_PI / 2);
207 double y =
static_cast<double>(
rand()) / (
static_cast<double>(RAND_MAX / (2 * M_PI))) - M_PI;
208 Eigen::Vector3d
rpy(
r,
p,
y);
209 Eigen::Vector3d rpydot(Eigen::Vector3d::Zero());
211 BOOST_CHECK(dj0.isZero());
212 Eigen::Matrix3d djL =
214 BOOST_CHECK(djL.isZero());
215 Eigen::Matrix3d djW =
217 BOOST_CHECK(djW.isZero());
218 Eigen::Matrix3d djA =
220 BOOST_CHECK(djA.isZero());
223 rpydot = Eigen::Vector3d::Random();
229 BOOST_CHECK(dj0 == djL);
230 BOOST_CHECK(djW == djA);
235 Eigen::Vector3d omegaL = jL * rpydot;
236 Eigen::Vector3d omegaW = jW * rpydot;
237 BOOST_CHECK(omegaW.isApprox(
R * omegaL));
242 double const eps = 1e-7;
243 double const tol = 1e-5;
244 Eigen::Vector3d rpyEps =
rpy;
255 Eigen::Matrix3d djLf = djLdr * rpydot[0] + djLdp * rpydot[1] + djLdy * rpydot[2];
256 BOOST_CHECK(djL.isApprox(djLf, tol));
267 Eigen::Matrix3d djWf = djWdr * rpydot[0] + djWdp * rpydot[1] + djWdy * rpydot[2];
268 BOOST_CHECK(djW.isApprox(djWf, tol));
271 BOOST_AUTO_TEST_SUITE_END()