| 8 | const double jacobianTolerance = 1.0e-3; |
| 9 | |
| 10 | TEST(okvisTestSuite, JacobianTest) { |
| 11 | // initialize random number generator |
| 12 | srand((unsigned int)time(0)); // disabled: make unit tests deterministic... |
| 13 | |
| 14 | OKVIS_DEFINE_EXCEPTION(Exception, std::runtime_error); |
| 15 | |
| 16 | okvis::kinematics::Transformation T_WS; |
| 17 | T_WS.setRandom(); |
| 18 | okvis::Time time(0.1); |
| 19 | okvis::ceres::PoseParameterBlock poseParameterBlock(T_WS, 0, time); // ground truth |
| 20 | |
| 21 | double* x = poseParameterBlock.parameters(); |
| 22 | |
| 23 | Eigen::Matrix<double, 7, 6, Eigen::RowMajor> Jplus; |
| 24 | Eigen::Matrix<double, 7, 6, Eigen::RowMajor> Jplus_numDiff; |
| 25 | |
| 26 | okvis::ceres::PoseManifold::plusJacobian(x, Jplus.data()); |
| 27 | |
| 28 | double dx = 1e-9; |
| 29 | |
| 30 | for (size_t i = 0; i < 6; ++i) { |
| 31 | Eigen::Matrix<double, 7, 1> xp; |
| 32 | Eigen::Matrix<double, 7, 1> xm; |
| 33 | Eigen::Matrix<double, 6, 1> delta; |
| 34 | delta.setZero(); |
| 35 | delta[i] = dx; |
| 36 | okvis::ceres::PoseManifold::plus(x, delta.data(), xp.data()); |
| 37 | delta[i] = -dx; |
| 38 | okvis::ceres::PoseManifold::plus(x, delta.data(), xm.data()); |
| 39 | Jplus_numDiff.col(i) = (xp - xm) / (2 * dx); |
| 40 | } |
| 41 | |
| 42 | okvis::ceres::PoseManifold pose_manifold; |
| 43 | OKVIS_ASSERT_TRUE(Exception, pose_manifold.verify(x, 1e-6), "Pose manifold verification failed."); |
| 44 | |
| 45 | // x = poseParameterBlock.parameters(); |
| 46 | Eigen::Matrix<double, 6, 7, Eigen::RowMajor> Jminus; |
| 47 | Eigen::Matrix<double, 6, 7, Eigen::RowMajor> Jminus_numDiff; |
| 48 | |
| 49 | okvis::ceres::PoseManifold::minusJacobian(x, Jminus.data()); |
| 50 | |
| 51 | Eigen::Matrix<double, 7, 1> xp, xm, x_vec(x); |
| 52 | |
| 53 | for (size_t i = 0; i < 7; ++i) { |
| 54 | Eigen::Matrix<double, 6, 1> delta_p, delta_m; |
| 55 | |
| 56 | xp = x_vec; |
| 57 | xm = x_vec; |
| 58 | xp[i] = x[i] + dx; |
| 59 | xm[i] = x[i] - dx; |
| 60 | |
| 61 | okvis::ceres::PoseManifold::minus(xp.data(), x, delta_p.data()); |
| 62 | okvis::ceres::PoseManifold::minus(xm.data(), x, delta_m.data()); |
| 63 | Jminus_numDiff.col(i) = (delta_p - delta_m) / (2 * dx); |
| 64 | } |
| 65 | |
| 66 | OKVIS_ASSERT_TRUE(Exception, |
| 67 | (Jminus - Jminus_numDiff).norm() < jacobianTolerance, |
nothing calls this directly
no test coverage detected