Esempio n. 1
0
    def test_constructor(self):
        """Test that a ``PoseR2`` instance can be created.

        """
        r2a = PoseR2([1, 2])
        r2b = PoseR2(np.array([3, 4]))
        self.assertIsInstance(r2a, PoseR2)
        self.assertIsInstance(r2b, PoseR2)
Esempio n. 2
0
    def test_sub(self):
        """Test that the overloaded ``__sub__`` method works as expected.

        """
        r2a = PoseR2([1, 2])
        r2b = PoseR2([3, 4])

        expected = PoseR2([2, 2])
        self.assertAlmostEqual(
            np.linalg.norm((r2b - r2a).to_array() - expected), 0.)
Esempio n. 3
0
    def test_add(self):
        """Test that the overloaded ``__add__`` method works as expected.

        """
        r2a = PoseR2([1, 2])
        r2b = PoseR2([3, 4])

        expected = PoseR2([4, 6])
        self.assertAlmostEqual(
            np.linalg.norm((r2a + r2b).to_array() - expected), 0.)

        r2a += r2b
        self.assertAlmostEqual(np.linalg.norm(r2a.to_array() - expected), 0.)
Esempio n. 4
0
    def test_orientation(self):
        """Test that the ``orientation`` property works as expected.

        """
        r2 = PoseR2([1, 2])

        self.assertEqual(r2.orientation, 0.)
Esempio n. 5
0
    def test_calc_jacobians(self):
        """Test that the ``calc_jacobians`` method works as expected.

        """
        p1 = PoseR2([1, 2])
        p2 = PoseR2([3, 4])
        estimate = PoseR2([0, 0])

        v1 = Vertex(1, p1)
        v2 = Vertex(2, p2)

        e = EdgeOdometry([1, 2], np.eye(2), estimate, [v1, v2])

        jacobians = e.calc_jacobians()

        self.assertAlmostEqual(np.linalg.norm(jacobians[0] - np.eye(2)), 0.)
        self.assertAlmostEqual(np.linalg.norm(jacobians[1] + np.eye(2)), 0.)
Esempio n. 6
0
    def test_copy(self):
        """Test that the ``copy`` method works as expected.

        """
        p1 = PoseR2([1, 2])
        p2 = p1.copy()

        p2[0] = 0
        self.assertEqual(p1[0], 1)
Esempio n. 7
0
    def test_inverse(self):
        """Test that the ``inverse`` property works as expected.

        """
        r2 = PoseR2([1, 2])

        true_inv = np.array([-1, -2])

        self.assertAlmostEqual(
            np.linalg.norm(r2.inverse.to_array() - true_inv), 0.)
Esempio n. 8
0
    def test_to_compact(self):
        """Test that the ``to_compact`` method works as expected.

        """
        r2 = PoseR2([1, 2])
        arr = r2.to_compact()

        self.assertIsInstance(arr, np.ndarray)
        self.assertNotIsInstance(arr, PoseR2)
        self.assertAlmostEqual(np.linalg.norm(arr - np.array([1, 2])), 0.)
Esempio n. 9
0
    def setUp(self):
        r"""Setup a simple ``Graph`` in :math:`\mathbb{R}^2`.

        """
        np.random.seed(0)

        p1 = PoseR2(np.random.random_sample(2))
        p2 = PoseR2(np.random.random_sample(2))
        p3 = PoseR2(np.random.random_sample(2))
        estimate = PoseR2([0, 0])

        v1 = Vertex(1, p1)
        v2 = Vertex(2, p2)
        v3 = Vertex(3, p3)

        e1 = EdgeOdometry([1, 2], np.eye(2), estimate, [v1, v2])
        e2 = EdgeOdometry([3, 2], 2 * np.eye(2), estimate, [v3, v2])

        self.g = Graph([e1, e2], [v1, v2, v3])
Esempio n. 10
0
    def test_position(self):
        """Test that the ``position`` property works as expected.

        """
        r2 = PoseR2([1, 2])
        pos = r2.position

        true_pos = np.array([1, 2])
        self.assertIsInstance(pos, np.ndarray)
        self.assertNotIsInstance(pos, PoseR2)
        self.assertAlmostEqual(np.linalg.norm(true_pos - pos), 0.)
Esempio n. 11
0
    def test_jacobian_self_ominus_other_compact(self):
        """Test that the ``jacobian_self_ominus_other_wrt_self_compact`` and ``jacobian_self_ominus_other_wrt_other_compact`` methods are correctly implemented.

        """
        np.random.seed(0)

        for _ in range(10):
            p1 = PoseR2(np.random.random_sample(2))
            p2 = PoseR2(np.random.random_sample(2))

            v1 = Vertex(1, p1)
            v2 = Vertex(2, p2)

            e = EdgeOMinusCompact([1, 2], np.eye(2), np.zeros(2), [v1, v2])

            numerical_jacobians = BaseEdge.calc_jacobians(e)

            analytical_jacobians = e.calc_jacobians()

            self.assertEqual(len(numerical_jacobians),
                             len(analytical_jacobians))
            for n, a in zip(numerical_jacobians, analytical_jacobians):
                self.assertAlmostEqual(np.linalg.norm(n - a), 0.)
Esempio n. 12
0
    def test_calc_chi2_gradient_hessian(self):
        """Test that the ``calc_chi2_gradient_hessian`` method works as expected.

        """
        p1 = PoseR2([1, 3])
        p2 = PoseR2([2, 4])
        estimate = PoseR2([0, 0])

        v1 = Vertex(0, p1, 0)
        v2 = Vertex(1, p2, 1)

        e = EdgeOdometry([0, 1], np.eye(2), estimate, [v1, v2])

        chi2, gradient, hessian = e.calc_chi2_gradient_hessian()

        self.assertEqual(chi2, 2.)

        self.assertAlmostEqual(np.linalg.norm(gradient[0] + np.ones(2)), 0.)
        self.assertAlmostEqual(np.linalg.norm(gradient[1] - np.ones(2)), 0.)

        self.assertAlmostEqual(np.linalg.norm(hessian[(0, 0)] - np.eye(2)), 0.)
        self.assertAlmostEqual(np.linalg.norm(hessian[(0, 1)] + np.eye(2)), 0.)
        self.assertAlmostEqual(np.linalg.norm(hessian[(1, 1)] - np.eye(2)), 0.)
Esempio n. 13
0
    def test_plot(self):
        """Test that the ``plot`` method is not implemented.

        """
        v_none = Vertex(0, None)
        v_r2 = Vertex(1, PoseR2([1, 2]))
        v_se2 = Vertex(2, PoseSE2([1, 2], 3))
        v_r3 = Vertex(3, PoseR3([1, 2, 3]))
        v_se3 = Vertex(4, PoseSE3([1, 2, 3], [0.5, 0.5, 0.5, 0.5]))

        with self.assertRaises(NotImplementedError):
            e = EdgeOdometry(0, 1, 0, [v_none, v_none])
            e.plot()

        for v in [v_r2, v_se2, v_r3, v_se3]:
            e = EdgeOdometry(0, 1, 0, [v, v])
            e.plot()
Esempio n. 14
0
    def test_plot(self):
        """Test that a ``Vertex`` can be plotted.

        """
        v_none = Vertex(0, None)
        v_r2 = Vertex(1, PoseR2([1, 2]))
        v_se2 = Vertex(2, PoseSE2([1, 2], 3))
        v_r3 = Vertex(3, PoseR3([1, 2, 3]))
        v_se3 = Vertex(4, PoseSE3([1, 2, 3], [0.5, 0.5, 0.5, 0.5]))

        with self.assertRaises(NotImplementedError):
            v_none.plot()

        for v in [v_r2, v_se2, v_r3, v_se3]:
            fig = plt.figure()
            if len(v.pose.position) == 3:
                fig.add_subplot(111, projection='3d')
            v.plot()