2 GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
3 Atlanta, Georgia 30332-0415
6 See LICENSE for the license information
17 from gtsam
import Pose2, Rot2, Similarity2
21 """Test selected Sim2 methods."""
24 """Test Align of list of Pose2Pair.
28 same scale (no gauge ambiguity)
29 world frame has poses rotated about 180 degrees.
30 world and egovehicle frame translated by 15 meters w.r.t. each other
32 R180 = Rot2.fromDegrees(180)
40 eToi_list = [eTo0, eTo1, eTo2]
44 wTo0 =
Pose2(R180, np.array([-10, 0]))
45 wTo1 =
Pose2(R180, np.array([-5, 0]))
46 wTo2 =
Pose2(R180, np.array([0, 0]))
48 wToi_list = [wTo0, wTo1, wTo2]
50 we_pairs =
list(zip(wToi_list, eToi_list))
53 wSe = Similarity2.Align(we_pairs)
55 for wToi, eToi
in zip(wToi_list, eToi_list):
59 """Test if Pose2 Align method can account for gauge ambiguity.
63 with gauge ambiguity (2x scale)
64 world frame has poses rotated by 90 degrees.
65 world and egovehicle frame translated by 11 meters w.r.t. each other
67 R90 = Rot2.fromDegrees(90)
75 eToi_list = [eTo0, eTo1, eTo2]
79 wTo0 =
Pose2(R90, np.array([0, 12]))
80 wTo1 =
Pose2(R90, np.array([0, 14]))
81 wTo2 =
Pose2(R90, np.array([0, 18]))
83 wToi_list = [wTo0, wTo1, wTo2]
85 we_pairs =
list(zip(wToi_list, eToi_list))
88 wSe = Similarity2.Align(we_pairs)
90 for wToi, eToi
in zip(wToi_list, eToi_list):
94 """Test if Align method can account for gauge ambiguity.
96 Make sure a big and small square can be aligned.
97 The u's represent a big square (10x10), and v's represents a small square (4x4).
101 with gauge ambiguity (2.5x scale)
104 R0 = Rot2.fromDegrees(0)
105 R90 = Rot2.fromDegrees(90)
106 R180 = Rot2.fromDegrees(180)
107 R270 = Rot2.fromDegrees(270)
109 aTi0 =
Pose2(R0, np.array([2, 3]))
110 aTi1 =
Pose2(R90, np.array([12, 3]))
111 aTi2 =
Pose2(R180, np.array([12, 13]))
112 aTi3 =
Pose2(R270, np.array([2, 13]))
114 aTi_list = [aTi0, aTi1, aTi2, aTi3]
116 bTi0 =
Pose2(R0, np.array([4, 3]))
117 bTi1 =
Pose2(R90, np.array([8, 3]))
118 bTi2 =
Pose2(R180, np.array([8, 7]))
119 bTi3 =
Pose2(R270, np.array([4, 7]))
121 bTi_list = [bTi0, bTi1, bTi2, bTi3]
123 ab_pairs =
list(zip(aTi_list, bTi_list))
126 aSb = Similarity2.Align(ab_pairs)
128 for aTi, bTi
in zip(aTi_list, bTi_list):
132 """Sim(2) to perform p_b = bSa * p_a"""
134 bta = np.array([1, 2])
137 self.assertIsInstance(bSa, Similarity2)
138 np.testing.assert_allclose(bSa.rotation().
matrix(), bRa.matrix())
139 np.testing.assert_allclose(bSa.translation(), bta)
140 np.testing.assert_allclose(bSa.scale(), bsa)
143 """Ensure object equality works properly (are equal)."""
149 """Ensure object equality works properly (not equal translation)."""
152 self.assertNotEqual(bSa, bSa_)
155 """Ensure object equality works properly (not equal rotation)."""
157 bSa_ =
Similarity2(R=Rot2.fromDegrees(180), t=np.array([2.0, 1.0]), s=3)
158 self.assertNotEqual(bSa, bSa_)
161 """Ensure object equality works properly (not equal scale)."""
164 self.assertNotEqual(bSa, bSa_)
167 """Ensure rotation component is returned properly."""
168 R = Rot2.fromDegrees(90)
173 expected_R = Rot2.fromDegrees(90)
174 np.testing.assert_allclose(expected_R.matrix(), bSa.rotation().
matrix())
177 """Ensure translation component is returned properly."""
178 R = Rot2.fromDegrees(90)
182 expected_t = np.array([1, 2])
183 np.testing.assert_allclose(expected_t, bSa.translation())
186 """Ensure the scale factor is returned properly."""
188 bta = np.array([1, 2])
191 self.assertEqual(bSa.scale(), 3.0)
194 if __name__ ==
"__main__":