rlightning.humanoid.utils.lafan_vendor.utils

rlightning.humanoid.utils.lafan_vendor.utils.angle_axis_to_quat(angle, axis)[source]

Converts from and angle-axis representation to a quaternion representation

Parameters:
  • angle – angles tensor

  • axis – axis tensor

Returns:

quaternion tensor

rlightning.humanoid.utils.lafan_vendor.utils.euler_to_quat(e, order='zyx')[source]

Converts from an euler representation to a quaternion representation

Parameters:
  • e – euler tensor

  • order – order of euler rotations

Returns:

quaternion tensor

rlightning.humanoid.utils.lafan_vendor.utils.extract_feet_contacts(pos, lfoot_idx, rfoot_idx, velfactor=0.02)[source]

Extracts binary tensors of feet contacts

Parameters:
  • pos – tensor of global positions of shape (Timesteps, Joints, 3)

  • lfoot_idx – indices list of left foot joints

  • rfoot_idx – indices list of right foot joints

  • velfactor – velocity threshold to consider a joint moving or not

Returns:

binary tensors of left foot contacts and right foot contacts

rlightning.humanoid.utils.lafan_vendor.utils.interpolate_local(lcl_r_mb, lcl_q_mb, n_past, n_future)[source]

Performs interpolation between 2 frames of an animation sequence.

The 2 frames are indirectly specified through n_past and n_future. SLERP is performed on the quaternions LERP is performed on the root’s positions.

Parameters:
  • lcl_r_mb – Local/Global root positions (B, T, 1, 3)

  • lcl_q_mb – Local quaternions (B, T, J, 4)

  • n_past – Number of frames of past context

  • n_future – Number of frames of future context

Returns:

Interpolated root and quats

rlightning.humanoid.utils.lafan_vendor.utils.length(x, axis=-1, keepdims=True)[source]

Computes vector norm along a tensor axis(axes)

Parameters:
  • x – tensor

  • axis – axis(axes) along which to compute the norm

  • keepdims – indicates if the dimension(s) on axis should be kept

Returns:

The length or vector of lengths.

rlightning.humanoid.utils.lafan_vendor.utils.normalize(x, axis=-1, eps=1e-08)[source]

Normalizes a tensor over some axis (axes)

Parameters:
  • x – data tensor

  • axis – axis(axes) along which to compute the norm

  • eps – epsilon to prevent numerical instabilities

Returns:

The normalized tensor

rlightning.humanoid.utils.lafan_vendor.utils.quat_between(x, y)[source]

Quaternion rotations between two 3D-vector arrays

Parameters:
  • x – tensor of 3D vectors

  • y – tensor of 3D vetcors

Returns:

tensor of quaternions

rlightning.humanoid.utils.lafan_vendor.utils.quat_fk(lrot, lpos, parents)[source]

Performs Forward Kinematics (FK) on local quaternions and local positions to retrieve global representations

Parameters:
  • lrot – tensor of local quaternions with shape (…, Nb of joints, 4)

  • lpos – tensor of local positions with shape (…, Nb of joints, 3)

  • parents – list of parents indices

Returns:

tuple of tensors of global quaternion, global positions

rlightning.humanoid.utils.lafan_vendor.utils.quat_ik(grot, gpos, parents)[source]

Performs Inverse Kinematics (IK) on global quaternions and global positions to retrieve local representations

Parameters:
  • grot – tensor of global quaternions with shape (…, Nb of joints, 4)

  • gpos – tensor of global positions with shape (…, Nb of joints, 3)

  • parents – list of parents indices

Returns:

tuple of tensors of local quaternion, local positions

rlightning.humanoid.utils.lafan_vendor.utils.quat_inv(q)[source]

Inverts a tensor of quaternions

Parameters:

q – quaternion tensor

Returns:

tensor of inverted quaternions

rlightning.humanoid.utils.lafan_vendor.utils.quat_mul(x, y)[source]

Performs quaternion multiplication on arrays of quaternions

Parameters:
  • x – tensor of quaternions of shape (…, Nb of joints, 4)

  • y – tensor of quaternions of shape (…, Nb of joints, 4)

Returns:

The resulting quaternions

rlightning.humanoid.utils.lafan_vendor.utils.quat_mul_np(x, y)[source]

Performs quaternion multiplication on arrays of quaternions

Parameters:
  • x – tensor of quaternions of shape (…, Nb of joints, 4)

  • y – tensor of quaternions of shape (…, Nb of joints, 4)

Returns:

The resulting quaternions

rlightning.humanoid.utils.lafan_vendor.utils.quat_mul_vec(q, x)[source]

Performs multiplication of an array of 3D vectors by an array of quaternions (rotation).

Parameters:
  • q – tensor of quaternions of shape (…, Nb of joints, 4)

  • x – tensor of vectors of shape (…, Nb of joints, 3)

Returns:

the resulting array of rotated vectors

rlightning.humanoid.utils.lafan_vendor.utils.quat_normalize(x, eps=1e-08)[source]

Normalizes a quaternion tensor

Parameters:
  • x – data tensor

  • eps – epsilon to prevent numerical instabilities

Returns:

The normalized quaternions tensor

rlightning.humanoid.utils.lafan_vendor.utils.quat_slerp(x, y, a)[source]

Performs spherical linear interpolation (SLERP) between x and y, with proportion a

Parameters:
  • x – quaternion tensor

  • y – quaternion tensor

  • a – indicator (between 0 and 1) of completion of the interpolation.

Returns:

tensor of interpolation results

rlightning.humanoid.utils.lafan_vendor.utils.remove_quat_discontinuities(rotations)[source]

Removing quat discontinuities on the time dimension (removing flips)

Parameters:

rotations – Array of quaternions of shape (T, J, 4)

Returns:

The processed array without quaternion inversion.

rlightning.humanoid.utils.lafan_vendor.utils.rotate_at_frame(X, Q, parents, n_past=10)[source]

Re-orients the animation data according to the last frame of past context.

Parameters:
  • X – tensor of local positions of shape (Batchsize, Timesteps, Joints, 3)

  • Q – tensor of local quaternions (Batchsize, Timesteps, Joints, 4)

  • parents – list of parents’ indices

  • n_past – number of frames in the past context

Returns:

The rotated positions X and quaternions Q