mani_skill.envs.utils.randomization#
Submodules#
Attributes#
Classes#
Uniform placement sampler that lets you sequentially sample data such that the data is within given bounds and |
Functions#
|
Convert rotations given as Euler angles in radians to rotation matrices. |
|
Convert rotations given as rotation matrices to quaternions. |
|
Generates random quaternions by generating random euler angles uniformly, with each of |
|
Package Contents#
- class mani_skill.envs.utils.randomization.UniformPlacementSampler(bounds, batch_size, device=None)[source]#
Uniform placement sampler that lets you sequentially sample data such that the data is within given bounds and not too close to previously sampled data. This sampler is also batched so you can use this easily for GPU simulated tasks
- Parameters:
bounds (Tuple[list[float], list[float]]) – ((low1, low2, …), (high1, high2, …))
batch_size (int) – The number of points to sample with each call to sample(…)
device (mani_skill.utils.geometry.rotation_conversions.Device) –
- sample(radius, max_trials, append=True, verbose=False)[source]#
Sample a position.
- Parameters:
radius (float) – collision radius.
max_trials (int) – maximal trials to sample.
append (bool, optional) – whether to append the new sample to fixtures. Defaults to True.
verbose (bool, optional) – whether to print verbosely. Defaults to False.
- Returns:
a sampled position.
- Return type:
torch.Tensor
- _bounds#
- _ranges#
- batch_size#
- fixture_positions = None#
- fixtures_radii = None#
- mani_skill.envs.utils.randomization.euler_angles_to_matrix(euler_angles, convention)[source]#
Convert rotations given as Euler angles in radians to rotation matrices.
- Parameters:
euler_angles (torch.Tensor) – Euler angles in radians as tensor of shape (…, 3).
convention (str) – Convention string of three uppercase letters from {“X”, “Y”, and “Z”}.
- Returns:
Rotation matrices as tensor of shape (…, 3, 3).
- Return type:
torch.Tensor
- mani_skill.envs.utils.randomization.matrix_to_quaternion(matrix)[source]#
Convert rotations given as rotation matrices to quaternions.
- Parameters:
matrix (torch.Tensor) – Rotation matrices as tensor of shape (…, 3, 3).
- Returns:
quaternions with real part first, as tensor of shape (…, 4).
- Return type:
torch.Tensor
- mani_skill.envs.utils.randomization.random_quaternions(n, device=None, lock_x=False, lock_y=False, lock_z=False, bounds=(0, np.pi * 2))[source]#
Generates random quaternions by generating random euler angles uniformly, with each of the X, Y, Z angles ranging from bounds[0] to bounds[1] radians. Can optionally choose to fix X, Y, and/or Z euler angles to 0 via lock_x, lock_y, lock_z arguments
- Parameters:
n (int) –
device (mani_skill.utils.structs.types.Device) –
lock_x (bool) –
lock_y (bool) –
lock_z (bool) –
- mani_skill.envs.utils.randomization.uniform(low, high, size, device=None)[source]#
- Parameters:
low (Union[float, torch.Tensor]) –
high (Union[float, torch.Tensor]) –
size (Sequence) –
device (mani_skill.utils.structs.types.Device) –
- mani_skill.envs.utils.randomization.Device[source]#
The transformation matrices returned from the functions in this file assume the points on which the transformation will be applied are column vectors. i.e. the R matrix is structured as
- R = [
[Rxx, Rxy, Rxz], [Ryx, Ryy, Ryz], [Rzx, Rzy, Rzz],
] # (3, 3)
This matrix can be applied to column vectors by post multiplication by the points e.g.
points = [[0], [1], [2]] # (3 x 1) xyz coordinates of a point transformed_points = R * points
To apply the same matrix to points which are row vectors, the R matrix can be transposed and pre multiplied by the points:
- e.g.
points = [[0, 1, 2]] # (1 x 3) xyz coordinates of a point transformed_points = points * R.transpose(1, 0)