9 """ 3 dimensional group of rigid body transformations """
12 """ internally represented by a unit quaternion q and a translation
15 assert isinstance(t, sympy.Matrix)
16 assert t.shape == (3, 1), t.shape
23 """ exponential map """
25 omega = sophus.Vector3(v[3], v[4], v[5])
26 so3 = sophus.So3.exp(omega)
27 Omega = sophus.So3.hat(omega)
28 Omega_sq = Omega * Omega
29 theta = sympy.sqrt(sophus.squared_norm(omega))
30 V = (sympy.Matrix.eye(3) +
31 (1 - sympy.cos(theta)) / (theta**2) * Omega +
32 (theta - sympy.sin(theta)) / (theta**3) * Omega_sq)
33 return Se3(so3, V * upsilon)
38 theta = sympy.sqrt(sophus.squared_norm(omega))
39 Omega = sophus.So3.hat(omega)
41 half_theta = 0.5 * theta
43 V_inv = sympy.Matrix.eye(3) - 0.5 * Omega + (1 - theta * sympy.cos(
44 half_theta) / (2 * sympy.sin(half_theta))) / (theta * theta) *\
46 upsilon = V_inv * self.
t
47 return upsilon.col_join(omega)
50 return "Se3: [" + repr(self.
so3) +
" " + repr(self.
t)
54 return Se3(invR, invR * (-1 * self.
t))
59 """ returns 4x4-matrix representation ``Omega`` """
60 upsilon = sophus.Vector3(v[0], v[1], v[2])
61 omega = sophus.Vector3(v[3], v[4], v[5])
62 return sophus.So3.hat(omega).\
64 col_join(sympy.Matrix.zeros(1, 4))
69 """ returns 6-vector representation of Lie algebra """
70 """ This is the inverse of the hat-operator """
72 head = sophus.Vector3(Omega[0,3], Omega[1,3], Omega[2,3])
73 tail = sophus.So3.vee(Omega[0:3,0:3])
75 sophus.Vector6(head[0], head[1], head[2], tail[0], tail[1], tail[2])
80 """ returns matrix representation """
82 return (R.row_join(self.
t)).col_join(sympy.Matrix(1, 4, [0, 0, 0, 1]))
85 """ left-multiplication
86 either rotation concatenation or point-transform """
87 if isinstance(right, sympy.Matrix):
88 assert right.shape == (3, 1), right.shape
89 return self.
so3 * right + self.
t
90 elif isinstance(right, Se3):
91 r = self.
so3 * right.so3
92 t = self.
t + self.
so3 * right.t
94 assert False,
"unsupported type: {0}".format(type(right))
97 """ We use the following convention [q0, q1, q2, q3, t0, t1, t2] """
98 assert (key >= 0
and key < 7)
102 return self.
t[key - 4]
106 return sympy.Matrix(7, 6,
lambda r, c:
107 sympy.diff(Se3.exp(x)[r], x[c]))
111 return sympy.Matrix([[0.0, 0.0, 0.0, 0.5, 0.0, 0.0],
112 [0.0, 0.0, 0.0, 0.0, 0.5, 0.0],
113 [0.0, 0.0, 0.0, 0.0, 0.0, 0.5],
114 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
115 [1.0, 0.0, 0.0, 0.0, 0.0, 0.0],
116 [0.0, 1.0, 0.0, 0.0, 0.0, 0.0],
117 [0.0, 0.0, 1.0, 0.0, 0.0, 0.0]])
121 return sympy.Matrix(7, 6,
lambda r, c:
122 sympy.diff((self * Se3.exp(x))[r], x[c])). \
123 subs(x[0], 0).subs(x[1], 0).subs(x[2], 0).\
124 subs(x[3], 0).subs(x[4], 0).limit(x[5], 0)
128 return Se3.calc_Dx_exp_x(x).subs(x[0], 0).subs(x[1], 0).subs(x[2], 0).\
129 subs(x[3], 0).subs(x[4], 0).limit(x[5], 0)
134 return sophus.So3.Dxi_x_matrix(x, i).\
135 row_join(sympy.Matrix.zeros(3, 1)).\
136 col_join(sympy.Matrix.zeros(1, 4))
137 M = sympy.Matrix.zeros(4, 4)
143 return sympy.Matrix(4, 4,
lambda r, c:
144 sympy.diff(x.matrix()[r, c], x[i]))
149 Dx_exp_x = Se3.calc_Dx_exp_x(x)
150 l = [Dx_exp_x[j, i] * Se3.Dxi_x_matrix(T, j)
for j
in range(0, 7)]
151 return functools.reduce((
lambda a, b: a + b), l)
155 return sympy.Matrix(4, 4,
lambda r, c:
156 sympy.diff(Se3.exp(x).
matrix()[r, c], x[i]))
160 v = sophus.ZeroVector6()
166 return sympy.Matrix(4, 4,
lambda r, c:
167 sympy.diff(Se3.exp(x).
matrix()[r, c], x[i])
168 ).subs(x[0], 0).subs(x[1], 0).subs(x[2], 0).\
169 subs(x[3], 0).subs(x[4], 0).limit(x[5], 0)
174 upsilon0, upsilon1, upsilon2, omega0, omega1, omega2 = sympy.symbols(
175 'upsilon[0], upsilon[1], upsilon[2], omega[0], omega[1], omega[2]',
177 x, v0, v1, v2 = sympy.symbols(
'q.w() q.x() q.y() q.z()', real=
True)
178 p0, p1, p2 = sympy.symbols(
'p0 p1 p2', real=
True)
179 t0, t1, t2 = sympy.symbols(
't[0] t[1] t[2]', real=
True)
180 v = sophus.Vector3(v0, v1, v2)
182 upsilon0, upsilon1, upsilon2, omega0, omega1, omega2)
183 self.
t = sophus.Vector3(t0, t1, t2)
185 self.
p = sophus.Vector3(p0, p1, p2)
188 for v
in [sophus.Vector6(0., 1, 0.5, 2., 1, 0.5),
189 sophus.Vector6(0.1, 0.1, 0.1, 0., 1, 0.5),
190 sophus.Vector6(0.01, 0.2, 0.03, 0.01, 0.2, 0.03)]:
192 for i
in range(0, 3):
193 self.assertAlmostEqual(v[i], w[i])
197 Tmat_foo_bar = T_foo_bar.matrix()
199 p1_foo = T_foo_bar * point_bar
200 p2_foo = sophus.proj(Tmat_foo_bar * sophus.unproj(point_bar))
201 self.assertEqual(sympy.simplify(p1_foo - p2_foo),
202 sophus.ZeroVector3())
205 self.assertEqual(sympy.simplify(
207 Se3.Dx_exp_x_at_0()),
208 sympy.Matrix.zeros(7, 6))
210 for i
in range(0, 7):
211 self.assertEqual(sympy.simplify(Se3.calc_Dxi_x_matrix(self.
a, i) -
212 Se3.Dxi_x_matrix(self.
a, i)),
213 sympy.Matrix.zeros(4, 4))
214 for i
in range(0, 6):
215 self.assertEqual(sympy.simplify(
218 sympy.Matrix.zeros(4, 4))
219 self.assertEqual(sympy.simplify(
220 Se3.Dxi_exp_x_matrix_at_0(i) -
222 sympy.Matrix.zeros(4, 4))
226 filename =
"cpp_gencode/Se3_Dx_exp_x.cpp"
229 file = open(filename,
"w")
234 file = open(filename,
"r")
235 file_lines = file.readlines()
236 for i, line
in enumerate(stream):
237 self.assertEqual(line, file_lines[i])
243 filename =
"cpp_gencode/Se3_Dx_this_mul_exp_x_at_0.cpp"
246 file = open(filename,
"w")
251 file = open(filename,
"r")
252 file_lines = file.readlines()
253 for i, line
in enumerate(stream):
254 self.assertEqual(line, file_lines[i])
259 if __name__ ==
'__main__':