mani_skill.utils.structs.pose#

Classes#

Pose

Wrapper around sapien.Pose that supports managing a batch of Poses and flexible creation of them from a variety of

Functions#

add_batch_dim(x)

to_batched_tensor(x[, device])

to_sapien_pose(pose)

Maps several formats to a sapien Pose

vectorize_pose(pose[, device])

Maps several formats of Pose representation to the appropriate tensor representation

Module Contents#

class mani_skill.utils.structs.pose.Pose[source]#

Wrapper around sapien.Pose that supports managing a batch of Poses and flexible creation of them from a variety of sources (list, numpy array, sapien.Pose). This pose object will also return information with a batch dimension, even if it is just holding a single position and quaternion.

As a result pose.p and pose.q will return shapes (N, 3) and (N, 4) respectively for N poses being stored. pose.raw_pose stores all the pose data as a single 2D array of shape (N, 7).

All sapien.Pose API are re-implemented in batch mode here to support GPU simulation. E.g. pose multiplication and inverse with pose_1.inv() * pose_2, or creating transformation matrices with pose_1.to_transformation_matrix() are suppported they same way they are in sapien.Pose.

Pose Creation#

To create a batched pose with a given position p and/or quaternion q, you run:

pose = Pose.create_from_pq(p=p, q=q)

p and q can be a torch tensor, numpy array, and/or list, or None.

If p or q have only 1 value/not batched, then we automatically repeat the value to the batch size of the other given value. For example, if p has a batch dimension of size > 1, and q has a batch dimension of size 1 or is a flat list, then the code automatically repeats the q value to the batch size of p. Likewise in the reverse direction the same repeating occurs.

If p and q have the same batch size, they are stored as so.

If p and q have no batch dimensions, one is automatically added (e.g. p having shape (3,) now becomes (1, 3))

If p is None, it is auto filled with zeros.

If q is None, it is auto filled with the [1, 0, 0, 0] quaternion.

If you have a sapien.Pose, another Pose object, or a raw pose tensor of shape (N, 7) or (7,) called x, you can create this Pose object with:

pose = Pose.create(x)

If you want a sapien.Pose object instead of this batched Pose, you can do pose.sp to get the sapien.Pose version (which is not batched). Note that this is only permitted if this Pose has a batch size of 1.

Pose Indexing#

You can index into a Pose object like numpy/torch arrays to get a new Pose object with the indexed data.

For example if pose has a batch size of 4, then pose[0] will be a Pose object with batch size of 1, and pose[1:3] will be a Pose object with batch size of 2.

__getitem__(i)[source]#
__len__()[source]#
__mul__(arg0)[source]#

Multiply two poses. Supports multiplying singular poses like sapien.Pose or Pose object with batch size of 1 with Pose objects with batch size > 1.

Parameters:

arg0 (Union[Pose, sapien.Pose]) –

Return type:

Pose

classmethod create(pose, device=None)[source]#

Creates a Pose object from a given pose, which can be a torch tensor, sapien.Pose, list of sapien.Pose, or Pose

Parameters:
  • pose (Union[torch.Tensor, sapien.Pose, list[sapien.Pose], Pose]) –

  • device (Optional[mani_skill.utils.structs.types.Device]) –

Return type:

Pose

classmethod create_from_pq(p=None, q=None, device=None)[source]#

Creates a Pose object from a given position p and/or quaternion q

Parameters:
  • p (Optional[torch.Tensor]) –

  • q (Optional[torch.Tensor]) –

  • device (Optional[mani_skill.utils.structs.types.Device]) –

get_p()[source]#

Returns self.p, the position

get_q()[source]#

Returns self.q, the quaternion

inv()[source]#

Returns the inverse of this pose

set_p(p)[source]#

Sets the position of this pose

Parameters:

p (torch.Tensor) –

Return type:

None

set_q(q)[source]#

Sets the quaternion of this pose

Parameters:

q (torch.Tensor) –

Return type:

None

to(device)[source]#

Move the Pose object to a different device

Parameters:

device (mani_skill.utils.structs.types.Device) –

to_transformation_matrix()[source]#

Returns the (N, 4, 4) shaped transformation matrix equivalent to this pose

property device: mani_skill.utils.structs.types.Device[source]#

Torch Device the Pose object is on

Return type:

mani_skill.utils.structs.types.Device

property p[source]#

The position of this pose

property q[source]#

The quaternion of this pose

raw_pose: torch.Tensor[source]#
property shape: torch.Size[source]#

Shape of the Pose object

Return type:

torch.Size

property sp[source]#

Returns the equivalent sapien pose. Note that this is only permitted if this Pose has a batch size of 1.

mani_skill.utils.structs.pose.add_batch_dim(x)[source]#
mani_skill.utils.structs.pose.to_batched_tensor(x, device=None)[source]#
Parameters:
  • x (Union[list, mani_skill.utils.structs.types.Array]) –

  • device (Optional[mani_skill.utils.structs.types.Device]) –

mani_skill.utils.structs.pose.to_sapien_pose(pose)[source]#

Maps several formats to a sapien Pose

Parameters:

pose (Union[torch.Tensor, sapien.Pose, Pose]) –

Return type:

sapien.Pose

mani_skill.utils.structs.pose.vectorize_pose(pose, device=None)[source]#

Maps several formats of Pose representation to the appropriate tensor representation

Parameters:
  • pose (Union[sapien.Pose, Pose, mani_skill.utils.structs.types.Array]) –

  • device (Optional[mani_skill.utils.structs.types.Device]) –

Return type:

torch.Tensor