@@ -21,7 +21,8 @@ class Robot:
21
21
The number of actuated (i.e., controlled) joints. This should never be
22
22
more than `num_joints`.
23
23
tool_idx : int
24
- The index of the tool joint.
24
+ The index of the tool joint. Note that this corresponds to the tool
25
+ link, since each link has the same index as its parent joint.
25
26
26
27
Parameters
27
28
----------
@@ -48,15 +49,19 @@ def __init__(
48
49
49
50
n = pyb .getNumJoints (uid )
50
51
51
- # first build a dict of the non-fixed joints' info
52
- self ._joint_indices = []
52
+ # build a dict of all joint info
53
53
joint_info = {}
54
54
for i in range (n ):
55
55
info = getJointInfo (uid , i , decode = "utf-8" )
56
+ joint_info [info .jointName ] = info
57
+
58
+ # record indices of all non-fixed joints
59
+ self ._joint_indices = []
60
+ for name in joint_info :
61
+ info = joint_info [name ]
56
62
if info .jointType == pyb .JOINT_FIXED :
57
63
continue
58
- joint_info [info .jointName ] = info
59
- self ._joint_indices .append (i )
64
+ self ._joint_indices .append (info .jointIndex )
60
65
self .num_joints = len (self ._joint_indices )
61
66
62
67
if actuated_joints is None :
@@ -173,7 +178,7 @@ def command_effort(self, u):
173
178
forces = list (u ),
174
179
)
175
180
176
- def get_link_com_pose (self , link_idx = None ):
181
+ def get_link_com_pose (self , link_idx = None , as_rotation_matrix = False ):
177
182
"""Get the pose of a link's center of mass.
178
183
179
184
The pose is computed about the link's center of mass with respect to
@@ -204,22 +209,29 @@ def get_link_com_pose(self, link_idx=None):
204
209
link_idx :
205
210
Index of the link to use. If not provided, defaults to the end
206
211
effector ``self.tool_idx``.
212
+ as_rotation_matrix : bool
213
+ Set to ``True`` to return the orientation as a rotation matrix,
214
+ ``False`` to return a quaternion.
207
215
208
216
Returns
209
217
-------
210
218
:
211
- A tuple containing the position and orientation quaternion of the
212
- link's center of mass in the world frame. The quaternion is
213
- represented in xyzw order.
219
+ A tuple containing the position and orientation of the link's
220
+ center of mass in the world frame. If ``as_rotation_matrix=True``,
221
+ then the orientation is represented as a :math:`3\\ times3` rotation
222
+ matrix. If ``False``, then it is represented as a quaternion in
223
+ xyzw order.
214
224
"""
215
225
if link_idx is None :
216
226
link_idx = self .tool_idx
217
227
state = getLinkState (self .uid , link_idx , computeForwardKinematics = True )
218
- return np .array (state .linkWorldPosition ), np .array (
219
- state .linkWorldOrientation
220
- )
228
+ position = np .array (state .linkWorldPosition )
229
+ orientation = np .array (state .linkWorldOrientation )
230
+ if as_rotation_matrix :
231
+ orientation = quaternion_to_matrix (orientation )
232
+ return position , orientation
221
233
222
- def get_link_frame_pose (self , link_idx = None ):
234
+ def get_link_frame_pose (self , link_idx = None , as_rotation_matrix = False ):
223
235
"""Get the pose of a link's URDF frame.
224
236
225
237
The pose is computed about the link's parent joint position, which is
@@ -230,20 +242,26 @@ def get_link_frame_pose(self, link_idx=None):
230
242
link_idx :
231
243
Index of the link to use. If not provided, defaults to the end
232
244
effector ``self.tool_idx``.
245
+ as_rotation_matrix : bool
246
+ Set to ``True`` to return the orientation as a rotation matrix,
247
+ ``False`` to return a quaternion.
233
248
234
249
Returns
235
250
-------
236
251
:
237
- A tuple containing the position and orientation quaternion of the
238
- link's frame with respect to the world. The quaternion is
239
- represented in xyzw order.
252
+ A tuple containing the position and orientation of the link's frame
253
+ with respect to the world. If ``as_rotation_matrix=True``, then the
254
+ orientation is represented as a :math:`3\\ times3` rotation matrix.
255
+ If ``False``, then it is represented as a quaternion in xyzw order.
240
256
"""
241
257
if link_idx is None :
242
258
link_idx = self .tool_idx
243
259
state = getLinkState (self .uid , link_idx , computeForwardKinematics = True )
244
- return np .array (state .worldLinkFramePosition ), np .array (
245
- state .worldLinkFrameOrientation
246
- )
260
+ position = np .array (state .worldLinkFramePosition )
261
+ orientation = np .array (state .worldLinkFrameOrientation )
262
+ if as_rotation_matrix :
263
+ orientation = quaternion_to_matrix (orientation )
264
+ return position , orientation
247
265
248
266
def get_link_com_velocity (self , link_idx = None ):
249
267
"""Get the velocity of a link's center of mass with respect to the world.
0 commit comments