gtsam/python/gtsam/tests/test_Scenario.py

57 lines
1.4 KiB
Python
Raw Normal View History

2019-03-10 02:06:31 +08:00
"""
GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
Atlanta, Georgia 30332-0415
All Rights Reserved
See LICENSE for the license information
2019-03-21 05:35:53 +08:00
Scenario unit tests.
2019-03-10 02:06:31 +08:00
Author: Frank Dellaert & Duy Nguyen Ta (Python)
"""
from __future__ import print_function
2018-10-17 05:01:47 +08:00
import math
import unittest
2019-03-10 02:06:31 +08:00
2018-10-17 05:01:47 +08:00
import numpy as np
import gtsam
2019-03-21 05:35:53 +08:00
from gtsam.utils.test_case import GtsamTestCase
# pylint: disable=invalid-name, E1101
2018-10-17 05:01:47 +08:00
2019-03-21 05:35:53 +08:00
class TestScenario(GtsamTestCase):
2018-10-17 05:01:47 +08:00
def setUp(self):
pass
def test_loop(self):
# Forward velocity 2m/s
# Pitch up with angular velocity 6 degree/sec (negative in FLU)
v = 2
w = math.radians(6)
W = np.array([0, -w, 0])
V = np.array([v, 0, 0])
scenario = gtsam.ConstantTwistScenario(W, V)
T = 30
np.testing.assert_almost_equal(W, scenario.omega_b(T))
np.testing.assert_almost_equal(V, scenario.velocity_b(T))
np.testing.assert_almost_equal(
np.cross(W, V), scenario.acceleration_b(T))
# R = v/w, so test if loop crests at 2*R
R = v / w
T30 = scenario.pose(T)
2020-08-18 23:02:35 +08:00
xyz = T30.rotation().xyz()
if xyz[0] < 0:
xyz = -xyz
2018-10-17 05:01:47 +08:00
np.testing.assert_almost_equal(
2020-08-18 23:02:35 +08:00
np.array([math.pi, 0, math.pi]), xyz)
2019-03-21 05:35:53 +08:00
self.gtsamAssertEquals(gtsam.Point3(
0, 0, 2.0 * R), T30.translation(), 1e-9)
2018-10-17 05:01:47 +08:00
if __name__ == '__main__':
unittest.main()