@@ -116,74 +116,72 @@ def _rotate_vector_by_quaternion(q: np.ndarray, v: List[float]) -> List[float]:
116
116
return rotated_vq [1 :].tolist ()
117
117
118
118
119
- def get_pose_target_in_reference_frame (
120
- reference_pose : PoseData , target_pose : PoseData
121
- ) -> PoseData :
119
+ def _transform_pose (pose : PoseData , reference_pose : PoseData ) -> PoseData :
122
120
"""
123
- Computes a target pose with respect to the frame (coordinate system) defined by a reference.
124
- target and reference should be given first in a common frame
125
-
126
- :param reference_pose: Pose of reference frame in a common frame
127
- :type reference_pose: PoseData
128
- :param target_pose: Pose of target frame in a common frame
129
- :type target_pose: PoseData
121
+ Transforms a pose from a local frame to a global frame using a reference pose.
122
+ Equivalent to: global_pose = reference_pose * local_pose
130
123
131
- :return: The pose of target in the reference frame
132
- :rtype: PoseData
124
+ :param pose: PoseData in local frame
125
+ :type pose: PoseData
126
+ :param reference_pose: PoseData of local frame in global frame
127
+ :type reference_pose: PoseData
128
+ :return: PoseData in global frame
129
+ :rtype: PoseData
133
130
"""
134
- position_target = target_pose .get_position ()
135
- orientation_target = target_pose .get_orientation ()
136
-
137
- reference_position = reference_pose .get_position ()
138
- reference_rotation = reference_pose .get_orientation ()
139
-
140
- orientation_target_in_ref = (
141
- _np_quaternion_conjugate (reference_rotation ) * orientation_target
142
- )
131
+ rotated_position = _rotate_vector_by_quaternion (reference_pose .get_orientation (), pose .get_position ().tolist ())
132
+ translated_position = reference_pose .get_position () + np .array (rotated_position )
143
133
144
- position_target_in_ref = _rotate_vector_by_quaternion (
145
- _np_quaternion_conjugate (reference_rotation ),
146
- (position_target - reference_position ).tolist (),
147
- )
134
+ combined_orientation = _np_quaternion_multiply (reference_pose .get_orientation (), pose .get_orientation ())
148
135
149
- target_pose_in_ref = PoseData ()
150
- target_pose_in_ref .set_pose (
151
- x = position_target_in_ref [0 ],
152
- y = position_target_in_ref [1 ],
153
- z = position_target_in_ref [2 ],
154
- qw = orientation_target_in_ref [0 ],
155
- qx = orientation_target_in_ref [1 ],
156
- qy = orientation_target_in_ref [2 ],
157
- qz = orientation_target_in_ref [3 ],
136
+ result = PoseData ()
137
+ result .set_pose (
138
+ * translated_position ,
139
+ * combined_orientation
158
140
)
141
+ return result
159
142
160
- return target_pose_in_ref
161
143
144
+ def _inverse_pose (pose : PoseData ) -> PoseData :
145
+ """
146
+ Computes the inverse of a pose (converts pose_in_frame to frame_in_pose)
162
147
163
- def from_frame1_to_frame2 (
164
- pose_1_in_2 : PoseData , pose_target_in_1 : PoseData
165
- ) -> PoseData :
148
+ :param pose: PoseData to invert
149
+ :type pose: PoseData
150
+ :return: Inverse pose
151
+ :rtype: PoseData
166
152
"""
167
- get the pose of a target in frame 2 instead of frame 1
153
+ inv_orientation = _np_quaternion_conjugate (pose .get_orientation ())
154
+ inv_position = _rotate_vector_by_quaternion (inv_orientation , (- pose .get_position ()).tolist ())
155
+
156
+ result = PoseData ()
157
+ result .set_pose (
158
+ * inv_position ,
159
+ * inv_orientation
160
+ )
161
+ return result
168
162
169
- :param pose_1_in_2: pose of frame 1 in frame 2
170
- :type pose_1_in_2: PoseData
171
- :param pose_target_in_1: pose of target in frame 1
172
- :type pose_target_in_1: PoseData
163
+ def transform_point_from_local_to_global (point_pose_in_local : PoseData , robot_pose_in_global : PoseData ) -> PoseData :
164
+ """Transforms a point from the robot frame to the global frame.
173
165
174
- :return: pose of target in frame 2
175
- :rtype: PoseData
166
+ :param point_pose_in_local: Target point in robot frame
167
+ :type point_pose_in_local: PoseData
168
+ :param robot_pose_in_global: Robot pose in global frame
169
+ :type robot_pose_in_global: PoseData
170
+ :return: Target point in global frame
171
+ :rtype: PoseData
176
172
"""
177
- pose_2_origin = PoseData ()
178
- pose_2_in_1 = get_pose_target_in_reference_frame (
179
- reference_pose = pose_1_in_2 , target_pose = pose_2_origin
180
- )
173
+ return _transform_pose (point_pose_in_local , robot_pose_in_global )
181
174
182
- pose_target_in_2 = get_pose_target_in_reference_frame (
183
- reference_pose = pose_2_in_1 , target_pose = pose_target_in_1
184
- )
175
+ def get_relative_pose ( pose_1_in_ref : PoseData , pose_2_in_ref : PoseData ) -> PoseData :
176
+ """
177
+ Computes the pose of pose_2 in the coordinate frame of pose_1.
185
178
186
- return pose_target_in_2
179
+ :param pose_1_in_ref: PoseData of frame 1 in reference frame
180
+ :param pose_2_in_ref: PoseData of frame 2 in reference frame
181
+ :return: PoseData of pose_2 in frame 1
182
+ """
183
+ pose_ref_in_1 = _inverse_pose (pose_1_in_ref )
184
+ return _transform_pose (pose_2_in_ref , pose_ref_in_1 )
187
185
188
186
189
187
def from_euler_to_quaternion (yaw : float , pitch : float , roll : float ) -> np .ndarray :
@@ -275,7 +273,7 @@ def from_frame1_to_frame2_2d(
275
273
)
276
274
277
275
# Get transformd pose
278
- pose_target_in_2 : PoseData = from_frame1_to_frame2 (pose_1_in_2 , pose_target_in_1 )
276
+ pose_target_in_2 : PoseData = get_relative_pose (pose_1_in_2 , pose_target_in_1 )
279
277
280
278
return pose_target_in_2
281
279
0 commit comments