Repository navigation
Expand file tree
/
Copy pathPose.py
More file actions
278 lines (214 loc) · 10.9 KB
/
Copy pathPose.py
File metadata and controls
278 lines (214 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import Feature as f
import numpy as np
from math import cos, sin
class Pose(np.ndarray):
"""
Definition of a robot pose interface from where all the particular poses of different DOF inherit.
This class defines a robot pose AxB as the pose of the B-Frame expressed in the A-Frame coordinates.
"""
def oplus(AxB, BxC):
"""
Given a Pose object *AxB* (the self object) and a Pose object *BxC*, it returns the compounded Pose object *AxC*.
The operation is defined as:
.. math::
\\mathbf{{^A}x_C} = \\mathbf{{^A}x_B} \\oplus \\mathbf{{^B}x_C}
:label: eq-oplus
**This is a pure virtual method that must be implemented by a child class.**
:param BxC: C-Frame pose expressed in B-Frame coordinates
:returns: C-Frame pose expressed in A-Frame coordinates
"""
pass
def J_1oplus(AxB, BxC):
"""
Jacobian of the pose compounding operation (eq. :eq:`eq-oplus`) with respect to the first pose:
.. math::
J_{1\\oplus}=\\frac{\\partial ^Ax_B \\oplus ^Bx_C}{\\partial ^Ax_B}
:label: eq-J1oplus
The method returns a numerical matrix containing the evaluation of the Jacobian for the pose *AxB* (the self object) and the :math:`2^{nd}` pose *BxC*.
**This is a pure virtual method that must be implemented by a child class.**
:param BxC: 2nd pose
:returns: Evaluation of the :math:`J_{1\\oplus}` Jacobian of the pose compounding operation with respect to the first pose (eq. :eq:`eq-J1oplus`)
"""
pass
def J_2oplus(AxB):
"""
Jacobian of the pose compounding operation (:eq:`eq-oplus`) with respect to the second pose:
.. math::
J_{2\\oplus}=\\frac{\\partial ^Ax_B \\oplus ^Bx_C}{\\partial ^Bx_C}
:label: eq-J2oplus
The method returns a numerical matrix containing the evaluation of the Jacobian for the :math:`1^{st}` pose *AxB* (the self object).
**This is a pure virtual method that must be implemented by a child class.**
:returns: Evaluation of the :math:`J_{2\\oplus}` Jacobian of the pose compounding operation with respect to the second pose (eq. :eq:`eq-J2oplus`)
"""
pass
def ominus(AxB):
"""
Inverse pose compounding of the *AxB* pose (the self object):
.. math::
^Bx_A = \\ominus ^Ax_B
:label: eq-ominus
**This is a pure virtual method that must be implemented by a child class.**
:returns: A-Frame pose expressed in B-Frame coordinates (eq. :eq:`eq-ominus`)
"""
pass
def J_ominus(AxB):
"""
Jacobian of the inverse pose compounding operation (:eq:`eq-oplus`) with respect the pose *AxB* (the self object):
.. math::
J_{\\ominus}=\\frac{\\partial \\ominus ^Ax_B}{\\partial ^Ax_B}
:label: eq-Jominus
Returns the numerical matrix containing the evaluation of the Jacobian for the pose *AxB* (the self object).
**This is a pure virtual method that must be implemented by a child class.**
:returns: Evaluation of the :math:`J_{\\ominus}` Jacobian of the inverse pose compounding operation with respect to the pose (eq. :eq:`eq-Jominus3dof`)
"""
pass
def boxplus(NxB, BxF):
"""
Given a Pose object *NxB* (the self object) and a Feature object *BxF*, it returns the Feature object *NxF*
providing the same feature but now expresend in the N-Frame.
:param BxF: Feature object expressed in the B-Frame
:return: NxF Feature object expressed in the N-Frame
"""
assert isinstance(BxF,f.Feature), "BxF is not a Feature"
assert isinstance(NxB,Pose), "NxB is not a Pose"
return BxF.boxplus(NxB)
def J_1boxplus(NxB, BxF):
"""
Jacobian of the pose-feature compounding operation (eq. :eq:`eq-boxplus`) with respect to the robot pose:
.. math::
J_{1\\boxplus}=\\frac{\\partial ^Nx_B \\boxplus ^Bx_F}{\\partial ^Nx_B}
:label: eq-J1boxplus
:param BxF: Feature object expressed in the B-Frame
:return: :math:`J_{1\\boxplus}` Jacobian of the feature compounding operation with respect to the robot pose (eq. :eq:`eq-J1boxplus`)
"""
assert isinstance(BxF,f.Feature), "BxF is not a Feature"
assert isinstance(NxB,Pose), "NxB is not a Pose"
return BxF.J_1boxplus(NxB)
def J_2boxplus(NxB, BxF):
"""
Jacobian of the pose-feature compounding operation (eq. :eq:`eq-boxplus`) with respect to the feature:
.. math::
J_{2\\boxplus}=\\frac{\\partial ^Nx_B \\boxplus ^Bx_F}{\\partial ^Bx_F}
:label: eq-J2boxplus
:param BxF: Feature object expressed in the B-Frame
:return: :math:`J_{2\\boxplus}` Jacobian of the feature compounding operation with respect to the feature (eq. :eq:`eq-J2boxplus`)
"""
assert isinstance(BxF,f.Feature), "BxF is not a Feature"
assert isinstance(NxB,Pose), "NxB is not a Pose"
return BxF.J_2boxplus(NxB)
class Pose3D(Pose):
"""
Definition of a robot pose in 3 DOF (x, y, yaw). The class inherits from a ndarray.
This class extends the ndarray with the :math:`oplus` and :math:`ominus` operators and the corresponding Jacobians.
"""
# def __new__(cls, input_array):
# """
# Constructor of the class. It is called when the class is instantiated. It is required to extend the ndarray numpy class.
#
# :param input_array: array used to initialize the class
# :returns: the instance of a Pose3D class object
# """
# assert input_array.shape == (3, 1), "mean must be a 3x1 vector"
#
# # Input array is an already formed ndarray instance
# # We first cast to be our class type
# obj = np.asarray(input_array).view(cls)
# # Finally, we must return the newly created object:
# return obj
def __new__(cls, input_array=np.array([[0.0, 0.0, 0.0]]).T):
"""
Constructor of the class. It is called when the class is instantiated. It is required to extend the ndarry numpy class.
:param input_array: array used to initialize the class
:returns: the instance of a Pose4D class object
"""
# Input array is an already formed ndarray instance
# We first cast to be our class type
obj = np.asarray(input_array).view(cls)
# Finally, we must return the newly created object:
return obj
def __init__(self, input_array=np.array([[0.0, 0.0, 0.0]]).T):
assert input_array.shape == (3, 1), "mean must be a 3x1 vector"
def oplus(AxB, BxC):
"""
Given a Pose3D object *AxB* (the self object) and a Pose3D object *BxC*, it returns the Pose3D object *AxC*.
.. math::
\\mathbf{{^A}x_B} &= \\begin{bmatrix} ^Ax_B & ^Ay_B & ^A\\psi_B \\end{bmatrix}^T \\\\
\\mathbf{{^B}x_C} &= \\begin{bmatrix} ^Bx_C & ^By_C & & ^B\\psi_C \\end{bmatrix}^T \\\\
The operation is defined as:
.. math::
\\mathbf{{^A}x_C} &= \\mathbf{{^A}x_B} \\oplus \\mathbf{{^B}x_C} =
\\begin{bmatrix}
^Ax_B + ^Bx_C \\cos(^A\\psi_B) - ^By_C \\sin(^A\\psi_B) \\\\
^Ay_B + ^Bx_C \\sin(^A\\psi_B) + ^By_C \\cos(^A\\psi_B) \\\\
^A\\psi_B + ^B\\psi_C
\\end{bmatrix}
:label: eq-oplus3dof
:param BxC: C-Frame pose expressed in B-Frame coordinates
:returns: C-Frame pose expressed in A-Frame coordinates
"""
# TODO: To be completed by the student
return AxC
def J_1oplus(AxB, BxC):
"""
Jacobian of the pose compounding operation (eq. :eq:`eq-oplus3dof`) with respect to the first pose:
.. math::
J_{1\\oplus}=\\frac{\\partial ^Ax_B \\oplus ^Bx_C}{\\partial ^Ax_B} =
\\begin{bmatrix}
1 & 0 & -^Bx_C \\sin(^A\\psi_B) - ^By_C \\cos(^A\\psi_B) \\\\
0 & 1 & ^Bx_C \\cos(^A\\psi_B) - ^By_C \\sin(^A\\psi_B) \\\\
0 & 0 & 1
\\end{bmatrix}
:label: eq-J1oplus3dof
The method returns a numerical matrix containing the evaluation of the Jacobian for the pose *AxB* (the self object) and the :math:`2^{nd}` posepose *BxC*.
:param BxC: 2nd pose
:returns: Evaluation of the :math:`J_{1\\oplus}` Jacobian of the pose compounding operation with respect to the first pose (eq. :eq:`eq-J1oplus3dof`)
"""
# TODO: To be completed by the student
return J1
def J_2oplus(AxB):
"""
Jacobian of the pose compounding operation (:eq:`eq-oplus3dof`) with respect to the second pose:
.. math::
J_{2\\oplus}=\\frac{\\partial ^Ax_B \\oplus ^Bx_C}{\\partial ^Bx_C} =
\\begin{bmatrix}
\\cos(^A\\psi_B) & -\\sin(^A\\psi_B) & 0 \\\\
\\sin(^A\\psi_B) & \\cos(^A\\psi_B) & 0 \\\\
0 & 0 & 1
\\end{bmatrix}
:label: eq-J2oplus3dof
The method returns a numerical matrix containing the evaluation of the Jacobian for the :math:`1^{st} posepose *AxB* (the self object).
:returns: Evaluation of the :math:`J_{2\\oplus}` Jacobian of the pose compounding operation with respect to the second pose (eq. :eq:`eq-J2oplus3dof`)
"""
# TODO: To be completed by the student
return J2
def ominus(AxB):
"""
Inverse pose compounding of the *AxB* pose (the self objetc):
.. math::
^Bx_A = \\ominus ^Ax_B =
\\begin{bmatrix}
-^Ax_B \\cos(^A\\psi_B) - ^Ay_B \\sin(^A\\psi_B) \\\\
^Ax_B \\sin(^A\\psi_B) - ^Ay_B \\cos(^A\\psi_B) \\\\
-^A\\psi_B
\\end{bmatrix}
:label: eq-ominus3dof
:returns: A-Frame pose expressed in B-Frame coordinates (eq. :eq:`eq-ominus3dof`)
"""
# TODO: To be completed by the student
return BxA
def J_ominus(AxB):
"""
Jacobian of the inverse pose compounding operation (:eq:`eq-oplus3dof`) with respect the pose *AxB* (the self object):
.. math::
J_{\\ominus}=\\frac{\\partial \\ominus ^Ax_B}{\\partial ^Ax_B} =
\\begin{bmatrix}
-\\cos(^A\\psi_B) & -\\sin(^A\\psi_B) & ^Ax_B \\sin(^A\\psi_B) - ^Ay_B \\cos(^A\\psi_B) \\\\
\\sin(^A\\psi_B) & -\\cos(^A\\psi_B) & ^Ax_B \\cos(^A\\psi_B) + ^Ay_B \\sin(^A\\psi_B) \\\\
0 & 0 & -1
\\end{bmatrix}
:label: eq-Jominus3dof
Returns the numerical matrix containing the evaluation of the Jacobian for the pose *AxB* (the self object).
:returns: Evaluation of the :math:`J_{\\ominus}` Jacobian of the inverse pose compounding operation with respect to the pose (eq. :eq:`eq-Jominus3dof`)
"""
# TODO: To be completed by the student
return J