code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def axis_angle_from_quat(quat: torch.Tensor, eps: float = 1.0e-6) -> torch.Tensor: """Convert rotations given as quaternions to axis/angle. Args: quat: The quaternion orientation in (w, x, y, z). Shape is (..., 4). eps: The tolerance for Taylor approximation. Defaults to 1.0e-6. Returns: ...
Convert rotations given as quaternions to axis/angle. Args: quat: The quaternion orientation in (w, x, y, z). Shape is (..., 4). eps: The tolerance for Taylor approximation. Defaults to 1.0e-6. Returns: Rotations given as a vector in axis angle form. Shape is (..., 3). The vect...
axis_angle_from_quat
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def quat_error_magnitude(q1: torch.Tensor, q2: torch.Tensor) -> torch.Tensor: """Computes the rotation difference between two quaternions. Args: q1: The first quaternion in (w, x, y, z). Shape is (..., 4). q2: The second quaternion in (w, x, y, z). Shape is (..., 4). Returns: Angul...
Computes the rotation difference between two quaternions. Args: q1: The first quaternion in (w, x, y, z). Shape is (..., 4). q2: The second quaternion in (w, x, y, z). Shape is (..., 4). Returns: Angular error between input quaternions in radians.
quat_error_magnitude
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def skew_symmetric_matrix(vec: torch.Tensor) -> torch.Tensor: """Computes the skew-symmetric matrix of a vector. Args: vec: The input vector. Shape is (3,) or (N, 3). Returns: The skew-symmetric matrix. Shape is (1, 3, 3) or (N, 3, 3). Raises: ValueError: If input tensor is no...
Computes the skew-symmetric matrix of a vector. Args: vec: The input vector. Shape is (3,) or (N, 3). Returns: The skew-symmetric matrix. Shape is (1, 3, 3) or (N, 3, 3). Raises: ValueError: If input tensor is not of shape (..., 3).
skew_symmetric_matrix
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def is_identity_pose(pos: torch.tensor, rot: torch.tensor) -> bool: """Checks if input poses are identity transforms. The function checks if the input position and orientation are close to zero and identity respectively using L2-norm. It does NOT check the error in the orientation. Args: pos: ...
Checks if input poses are identity transforms. The function checks if the input position and orientation are close to zero and identity respectively using L2-norm. It does NOT check the error in the orientation. Args: pos: The cartesian position. Shape is (N, 3). rot: The quaternion in (w,...
is_identity_pose
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def combine_frame_transforms( t01: torch.Tensor, q01: torch.Tensor, t12: torch.Tensor | None = None, q12: torch.Tensor | None = None ) -> tuple[torch.Tensor, torch.Tensor]: r"""Combine transformations between two reference frames into a stationary frame. It performs the following transformation operation: ...
Combine transformations between two reference frames into a stationary frame. It performs the following transformation operation: :math:`T_{02} = T_{01} \times T_{12}`, where :math:`T_{AB}` is the homogeneous transformation matrix from frame A to B. Args: t01: Position of frame 1 w.r.t. frame 0. S...
combine_frame_transforms
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def subtract_frame_transforms( t01: torch.Tensor, q01: torch.Tensor, t02: torch.Tensor | None = None, q02: torch.Tensor | None = None ) -> tuple[torch.Tensor, torch.Tensor]: r"""Subtract transformations between two reference frames into a stationary frame. It performs the following transformation operation...
Subtract transformations between two reference frames into a stationary frame. It performs the following transformation operation: :math:`T_{12} = T_{01}^{-1} \times T_{02}`, where :math:`T_{AB}` is the homogeneous transformation matrix from frame A to B. Args: t01: Position of frame 1 w.r.t. fram...
subtract_frame_transforms
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def compute_pose_error( t01: torch.Tensor, q01: torch.Tensor, t02: torch.Tensor, q02: torch.Tensor, rot_error_type: Literal["quat", "axis_angle"] = "axis_angle", ) -> tuple[torch.Tensor, torch.Tensor]: """Compute the position and orientation error between source and target frames. Args: ...
Compute the position and orientation error between source and target frames. Args: t01: Position of source frame. Shape is (N, 3). q01: Quaternion orientation of source frame in (w, x, y, z). Shape is (N, 4). t02: Position of target frame. Shape is (N, 3). q02: Quaternion orientatio...
compute_pose_error
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def apply_delta_pose( source_pos: torch.Tensor, source_rot: torch.Tensor, delta_pose: torch.Tensor, eps: float = 1.0e-6 ) -> tuple[torch.Tensor, torch.Tensor]: """Applies delta pose transformation on source pose. The first three elements of `delta_pose` are interpreted as cartesian position displacement. ...
Applies delta pose transformation on source pose. The first three elements of `delta_pose` are interpreted as cartesian position displacement. The remaining three elements of `delta_pose` are interpreted as orientation displacement in the angle-axis format. Args: source_pos: Position of source...
apply_delta_pose
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def transform_points( points: torch.Tensor, pos: torch.Tensor | None = None, quat: torch.Tensor | None = None ) -> torch.Tensor: r"""Transform input points in a given frame to a target frame. This function transform points from a source frame to a target frame. The transformation is defined by the posi...
Transform input points in a given frame to a target frame. This function transform points from a source frame to a target frame. The transformation is defined by the position :math:`t` and orientation :math:`R` of the target frame in the source frame. .. math:: p_{target} = R_{target} \times p_{so...
transform_points
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def orthogonalize_perspective_depth(depth: torch.Tensor, intrinsics: torch.Tensor) -> torch.Tensor: """Converts perspective depth image to orthogonal depth image. Perspective depth images contain distances measured from the camera's optical center. Meanwhile, orthogonal depth images provide the distance fr...
Converts perspective depth image to orthogonal depth image. Perspective depth images contain distances measured from the camera's optical center. Meanwhile, orthogonal depth images provide the distance from the camera's image plane. This method uses the camera geometry to convert perspective depth to ortho...
orthogonalize_perspective_depth
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def unproject_depth(depth: torch.Tensor, intrinsics: torch.Tensor, is_ortho: bool = True) -> torch.Tensor: r"""Un-project depth image into a pointcloud. This function converts orthogonal or perspective depth images into points given the calibration matrix of the camera. It uses the following transformation...
Un-project depth image into a pointcloud. This function converts orthogonal or perspective depth images into points given the calibration matrix of the camera. It uses the following transformation based on camera geometry: .. math:: p_{3D} = K^{-1} \times [u, v, 1]^T \times d where :math:`p_{...
unproject_depth
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def project_points(points: torch.Tensor, intrinsics: torch.Tensor) -> torch.Tensor: r"""Projects 3D points into 2D image plane. This project 3D points into a 2D image plane. The transformation is defined by the intrinsic matrix of the camera. .. math:: \begin{align} p &= K \times ...
Projects 3D points into 2D image plane. This project 3D points into a 2D image plane. The transformation is defined by the intrinsic matrix of the camera. .. math:: \begin{align} p &= K \times p_{3D} = \\ p_{2D} &= \begin{pmatrix} u \\ v \\ d \end{pmatrix} ...
project_points
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def default_orientation(num: int, device: str) -> torch.Tensor: """Returns identity rotation transform. Args: num: The number of rotations to sample. device: Device to create tensor on. Returns: Identity quaternion in (w, x, y, z). Shape is (num, 4). """ quat = torch.zeros(...
Returns identity rotation transform. Args: num: The number of rotations to sample. device: Device to create tensor on. Returns: Identity quaternion in (w, x, y, z). Shape is (num, 4).
default_orientation
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def random_orientation(num: int, device: str) -> torch.Tensor: """Returns sampled rotation in 3D as quaternion. Args: num: The number of rotations to sample. device: Device to create tensor on. Returns: Sampled quaternion in (w, x, y, z). Shape is (num, 4). Reference: ...
Returns sampled rotation in 3D as quaternion. Args: num: The number of rotations to sample. device: Device to create tensor on. Returns: Sampled quaternion in (w, x, y, z). Shape is (num, 4). Reference: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.tra...
random_orientation
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def random_yaw_orientation(num: int, device: str) -> torch.Tensor: """Returns sampled rotation around z-axis. Args: num: The number of rotations to sample. device: Device to create tensor on. Returns: Sampled quaternion in (w, x, y, z). Shape is (num, 4). """ roll = torch.z...
Returns sampled rotation around z-axis. Args: num: The number of rotations to sample. device: Device to create tensor on. Returns: Sampled quaternion in (w, x, y, z). Shape is (num, 4).
random_yaw_orientation
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def sample_triangle(lower: float, upper: float, size: int | tuple[int, ...], device: str) -> torch.Tensor: """Randomly samples tensor from a triangular distribution. Args: lower: The lower range of the sampled tensor. upper: The upper range of the sampled tensor. size: The shape of the ...
Randomly samples tensor from a triangular distribution. Args: lower: The lower range of the sampled tensor. upper: The upper range of the sampled tensor. size: The shape of the tensor. device: Device to create tensor on. Returns: Sampled tensor. Shape is based on :attr:...
sample_triangle
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def sample_uniform( lower: torch.Tensor | float, upper: torch.Tensor | float, size: int | tuple[int, ...], device: str ) -> torch.Tensor: """Sample uniformly within a range. Args: lower: Lower bound of uniform range. upper: Upper bound of uniform range. size: The shape of the tensor...
Sample uniformly within a range. Args: lower: Lower bound of uniform range. upper: Upper bound of uniform range. size: The shape of the tensor. device: Device to create tensor on. Returns: Sampled tensor. Shape is based on :attr:`size`.
sample_uniform
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def sample_log_uniform( lower: torch.Tensor | float, upper: torch.Tensor | float, size: int | tuple[int, ...], device: str ) -> torch.Tensor: r"""Sample using log-uniform distribution within a range. The log-uniform distribution is defined as a uniform distribution in the log-space. It is useful for sa...
Sample using log-uniform distribution within a range. The log-uniform distribution is defined as a uniform distribution in the log-space. It is useful for sampling values that span several orders of magnitude. The sampled values are uniformly distributed in the log-space and then exponentiated to get the f...
sample_log_uniform
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def sample_gaussian( mean: torch.Tensor | float, std: torch.Tensor | float, size: int | tuple[int, ...], device: str ) -> torch.Tensor: """Sample using gaussian distribution. Args: mean: Mean of the gaussian. std: Std of the gaussian. size: The shape of the tensor. device: D...
Sample using gaussian distribution. Args: mean: Mean of the gaussian. std: Std of the gaussian. size: The shape of the tensor. device: Device to create tensor on. Returns: Sampled tensor.
sample_gaussian
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def sample_cylinder( radius: float, h_range: tuple[float, float], size: int | tuple[int, ...], device: str ) -> torch.Tensor: """Sample 3D points uniformly on a cylinder's surface. The cylinder is centered at the origin and aligned with the z-axis. The height of the cylinder is sampled uniformly from t...
Sample 3D points uniformly on a cylinder's surface. The cylinder is centered at the origin and aligned with the z-axis. The height of the cylinder is sampled uniformly from the range :obj:`h_range`, while the radius is fixed to :obj:`radius`. The sampled points are returned as a tensor of shape :obj:`(*si...
sample_cylinder
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def convert_camera_frame_orientation_convention( orientation: torch.Tensor, origin: Literal["opengl", "ros", "world"] = "opengl", target: Literal["opengl", "ros", "world"] = "ros", ) -> torch.Tensor: r"""Converts a quaternion representing a rotation from one convention to another. In USD, the camer...
Converts a quaternion representing a rotation from one convention to another. In USD, the camera follows the ``"opengl"`` convention. Thus, it is always in **Y up** convention. This means that the camera is looking down the -Z axis with the +Y axis pointing up , and +X axis pointing right. However, in ROS,...
convert_camera_frame_orientation_convention
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def create_rotation_matrix_from_view( eyes: torch.Tensor, targets: torch.Tensor, up_axis: Literal["Y", "Z"] = "Z", device: str = "cpu", ) -> torch.Tensor: """Compute the rotation matrix from world to view coordinates. This function takes a vector ''eyes'' which specifies the location of the...
Compute the rotation matrix from world to view coordinates. This function takes a vector ''eyes'' which specifies the location of the camera in world coordinates and the vector ''targets'' which indicate the position of the object. The output is a rotation matrix representing the transformation fro...
create_rotation_matrix_from_view
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/math_utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/math_utils.py
Apache-2.0
def __init__( self, ref_motion: dict, body_ids: List[int] | None = None, joint_ids: List[int] | None = None, ): """Represents the state of a reference motion frame. Args: ref_motion (dict): Reference motion data at a specific point in time, loaded from th...
Represents the state of a reference motion frame. Args: ref_motion (dict): Reference motion data at a specific point in time, loaded from the dataset. body_ids (List[int] | None, optional): Desired ordering of the bodies. Defaults to None. joint_ids (List[int] | None, option...
__init__
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/reference_motion.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/reference_motion.py
Apache-2.0
def __init__( self, cfg: ReferenceMotionManagerCfg, device: torch.device, num_envs: int, random_sample: bool, extend_head: bool, dt: float, ): """Initializes a reference motion manager that loads and queries a motion dataset. Args: ...
Initializes a reference motion manager that loads and queries a motion dataset. Args: cfg (ReferenceMotionManagerCfg): Configuration that specifies dataset and skeleton paths. device (torch.device): Device to host tensors on. num_envs (int): Number of environments/instances....
__init__
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/reference_motion.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/reference_motion.py
Apache-2.0
def load_motions(self, random_sample: bool, start_idx: int): """Loads motions from the motion dataset.""" self._motion_lib.load_motions( skeleton_trees=self._skeleton_trees, gender_betas=[torch.zeros(17)] * self._num_envs, limb_weights=[np.zeros(10)] * self._num_envs,...
Loads motions from the motion dataset.
load_motions
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/reference_motion.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/reference_motion.py
Apache-2.0
def reset_motion_start_times(self, env_ids: torch.Tensor, sample: bool): """Resets the time at which the reference motions start playing.""" if sample: self._motion_start_times[env_ids] = self._motion_lib.sample_time(self._motion_ids[env_ids]) else: self._motion_start_tim...
Resets the time at which the reference motions start playing.
reset_motion_start_times
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/reference_motion.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/reference_motion.py
Apache-2.0
def episodes_exceed_motion_length( self, episode_times: torch.Tensor, env_ids: torch.Tensor | None = None ) -> torch.Tensor: """Checks if the reference motion has reached to the end.""" if env_ids is None: return (episode_times + self._motion_start_times) > self._motion_len ...
Checks if the reference motion has reached to the end.
episodes_exceed_motion_length
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/reference_motion.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/reference_motion.py
Apache-2.0
def get_state_from_motion_lib_cache( self, episode_length_buf: torch.Tensor, terrain_heights: torch.Tensor | None = None, offset: torch.Tensor | None = None, quaternion_is_xyzw=True, ) -> ReferenceMotionState: """Query a reference motion frame from motion lib.""" ...
Query a reference motion frame from motion lib.
get_state_from_motion_lib_cache
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/reference_motion.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/reference_motion.py
Apache-2.0
def check_termination_conditions( training_mode: bool, projected_gravity: torch.Tensor, gravity_x_threshold: float, gravity_y_threshold: float, ref_motion_mgr: ReferenceMotionManager, episode_times: torch.Tensor, body_state: BodyState, ref_motion_state: ReferenceMotionState, max_ref_...
Evaluates termination conditions. This function checks various termination conditions and returns a boolean tensor of shape (num_env,) indicating whether any condition has been met. Additionally, it provides a dictionary mapping each condition's name to its activation state, with each state represente...
check_termination_conditions
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/termination.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/termination.py
Apache-2.0
def terminate_by_gravity( projected_gravity: torch.Tensor, gravity_x_threshold: float, gravity_y_threshold: float, ) -> torch.Tensor: """ Checks termination condition based on robot balance. This function evaluates whether the robot is unbalanced due to gravity and returns a boolean tensor ...
Checks termination condition based on robot balance. This function evaluates whether the robot is unbalanced due to gravity and returns a boolean tensor of shape (num_env, 1). Each element in the tensor indicates whether the unbalanced condition is active for the corresponding environment. Return...
terminate_by_gravity
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/termination.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/termination.py
Apache-2.0
def terminate_by_undesired_contact( net_contact_forces: torch.Tensor, undesired_contact_body_ids: torch.Tensor ) -> torch.Tensor: """ Checks termination condition based on contact forces. This function evaluates whether undesired bodies of the robot are in contact and returns a boolean tensor of sh...
Checks termination condition based on contact forces. This function evaluates whether undesired bodies of the robot are in contact and returns a boolean tensor of shape (num_env, 1). Each element in the tensor indicates whether the contact termination condition is active for the corresponding environm...
terminate_by_undesired_contact
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/termination.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/termination.py
Apache-2.0
def terminate_by_reference_motion_length( ref_motion_mgr: ReferenceMotionManager, episode_times: torch.Tensor ) -> torch.Tensor: """Checks if the reference motion has ended for each environment. This function returns a boolean tensor of shape (num_env, 1), where each element indicates whether the refer...
Checks if the reference motion has ended for each environment. This function returns a boolean tensor of shape (num_env, 1), where each element indicates whether the reference motion has ended for the corresponding environment. Returns: torch.tensor: A boolean tensor of shape (num_env, 1) where `T...
terminate_by_reference_motion_length
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/termination.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/termination.py
Apache-2.0
def terminate_by_reference_motion_distance( training_mode: bool, body_state: BodyState, ref_motion_state: ReferenceMotionState, max_ref_motion_dist: float, in_recovery: torch.Tensor | None, mask: torch.Tensor, ) -> torch.Tensor: """ Determines if the distance between current body positio...
Determines if the distance between current body positions and reference motion positions exceeds the allowed threshold. Args: is_training (bool): Flag indicating if the system is in training mode. body_state (BodyState): Current state of the humanoid bodies. ref_motion_state (Reference...
terminate_by_reference_motion_distance
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/termination.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/termination.py
Apache-2.0
def assert_equal(lhs: any, rhs: any, name: str): """Assert that 2 values are equal and provide a useful error if not. Args: lhs: First value to compare rhs: Second value to compare name: Description of what is being compared, used in error messages """ # Handle dictionary compar...
Assert that 2 values are equal and provide a useful error if not. Args: lhs: First value to compare rhs: Second value to compare name: Description of what is being compared, used in error messages
assert_equal
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/util.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/util.py
Apache-2.0
def _assert_dicts_equal(lhs: dict, rhs: dict, name: str): """Compare two dictionaries and raise assertion error with details if not equal.""" lhs_keys = set(lhs.keys()) rhs_keys = set(rhs.keys()) # Check for missing keys only_in_lhs = lhs_keys - rhs_keys only_in_rhs = rhs_keys - lhs_keys #...
Compare two dictionaries and raise assertion error with details if not equal.
_assert_dicts_equal
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/util.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/util.py
Apache-2.0
def _get_differing_values(lhs: dict, rhs: dict, common_keys: set) -> dict: """Compare values for common keys between two dicts, return dict of differences.""" diff_values = {} for key in common_keys: if isinstance(lhs[key], (int, float)) and isinstance(rhs[key], (int, float)): if abs(lhs...
Compare values for common keys between two dicts, return dict of differences.
_get_differing_values
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/util.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/util.py
Apache-2.0
def _assert_numbers_equal(lhs: float, rhs: float, name: str): """Assert that two numbers are equal within a small tolerance.""" if abs(lhs - rhs) >= 1e-6: raise AssertionError(f"{name}: Values are not equal within tolerance: {lhs} != {rhs}")
Assert that two numbers are equal within a small tolerance.
_assert_numbers_equal
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/util.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/util.py
Apache-2.0
def _assert_values_equal(lhs: any, rhs: any, name: str): """Assert that two non-numeric values are exactly equal.""" if lhs != rhs: raise AssertionError(f"{name}: Values are not equal: {lhs} != {rhs}")
Assert that two non-numeric values are exactly equal.
_assert_values_equal
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/util.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/util.py
Apache-2.0
def get_matching_indices(patterns: list[str], values: list[str], allow_empty: bool = False) -> list[int]: """Get indices of all elements in values that match any of the regex patterns.""" all_indices = set() for pattern in patterns: regex = re.compile(pattern) indices = [i for i, v in enumer...
Get indices of all elements in values that match any of the regex patterns.
get_matching_indices
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/util.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/util.py
Apache-2.0
def create_dummy_warp_module(): """Creates a dummy 'warp' module with necessary attributes and submodules. This function is created because the 'warp' module can only be properly imported when Isaac Sim is also launched, which is not always required when running unit tests or simulations with other sim...
Creates a dummy 'warp' module with necessary attributes and submodules. This function is created because the 'warp' module can only be properly imported when Isaac Sim is also launched, which is not always required when running unit tests or simulations with other simulators. By creating a dummy module, we...
create_dummy_warp_module
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/__init__.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/__init__.py
Apache-2.0
def __init__(self, num_envs: int, device: torch.device, entry_length: int, max_entries: int): """ Args: env (EnvironmentWrapper): An instance of the environment wrapper. entry_length (int): The length of a single entry. max_entries (int): The maximum number of entries...
Args: env (EnvironmentWrapper): An instance of the environment wrapper. entry_length (int): The length of a single entry. max_entries (int): The maximum number of entries to keep in the history.
__init__
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/student_history.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/student_history.py
Apache-2.0
def update(self, obs_dict: dict[str, torch.Tensor]): """Updates the history with a new entry. Args: obs_dict (dict[str, torch.Tensor]): A dictionary containing the latest student observations. Expected keys are "distilled_robot_state" and "distilled_last_action". Ra...
Updates the history with a new entry. Args: obs_dict (dict[str, torch.Tensor]): A dictionary containing the latest student observations. Expected keys are "distilled_robot_state" and "distilled_last_action". Raises: AssertionError: If the new entry does not matc...
update
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/student_history.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/student_history.py
Apache-2.0
def reset(self, env_ids: torch.Tensor | None): """Resets the history for specified environments. Args: env_ids (torch.Tensor | None): A tensor containing the IDs of the environments to reset. If None, all environments are reset. Example: ...
Resets the history for specified environments. Args: env_ids (torch.Tensor | None): A tensor containing the IDs of the environments to reset. If None, all environments are reset. Example: history.reset(None) # Resets history for all e...
reset
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/student_history.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/student_history.py
Apache-2.0
def compute_distilled_imitation_observations( ref_motion_state: ReferenceMotionState, body_state: BodyState, mask: torch.Tensor, ref_episodic_offset: torch.Tensor | None, ) -> torch.Tensor: """Computes the reference goal state used in the observation of the student.""" # First we get all referen...
Computes the reference goal state used in the observation of the student.
compute_distilled_imitation_observations
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/student_observations.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/student_observations.py
Apache-2.0
def compute_kinematic_command( ref_motion_state: ReferenceMotionState, body_state: BodyState, ref_episodic_offset: torch.Tensor | None, ) -> torch.Tensor: """ Compute the link position command used in the observation of the student. The link position command consists of: - the delta between...
Compute the link position command used in the observation of the student. The link position command consists of: - the delta between the current root position and the target link positions
compute_kinematic_command
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/student_observations.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/student_observations.py
Apache-2.0
def compute_joint_command(ref_motion_state: ReferenceMotionState, body_state: BodyState) -> torch.Tensor: """ Compute the joint command used in the observation of the student. The joint reference is the delta between the current joint position/velocity and the target joint position/velocity. """ ...
Compute the joint command used in the observation of the student. The joint reference is the delta between the current joint position/velocity and the target joint position/velocity.
compute_joint_command
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/student_observations.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/student_observations.py
Apache-2.0
def compute_root_command(ref_motion_state: ReferenceMotionState, body_state: BodyState) -> torch.Tensor: """ Compute the root command used in the observation of the student. The root command consists of - the target root velocity (in the root frame) - the target root roll and pitch - the delta ...
Compute the root command used in the observation of the student. The root command consists of - the target root velocity (in the root frame) - the target root roll and pitch - the delta between the current root yaw and the target root yaw - the root height.
compute_root_command
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/student_observations.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/student_observations.py
Apache-2.0
def compute_distilled_robot_state_observation( body_state: BodyState, base_id: int, projected_gravity: torch.Tensor, local_base_ang_velocity: torch.Tensor | None = None, ) -> torch.Tensor: """Root body state in the robot root frame.""" # for normalization joint_pos = body_state.joint_pos.clo...
Root body state in the robot root frame.
compute_distilled_robot_state_observation
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/student_observations.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/student_observations.py
Apache-2.0
def compute_teacher_observations( body_state: BodyState, ref_motion_state: ReferenceMotionState, tracked_body_ids: list[int], last_actions: torch.Tensor, ref_episodic_offset: torch.Tensor | None = None, ) -> tuple[torch.Tensor, dict[str, torch.Tensor]]: """Computes the observations for the teach...
Computes the observations for the teacher model based on the current body state, reference motion state, and other relevant parameters. Args: body_state (BodyState): The current state of the humanoid bodies. ref_motion_state (ReferenceMotionState): The reference motion state for the humanoid to...
compute_teacher_observations
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/teacher_observations.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/teacher_observations.py
Apache-2.0
def compute_robot_state_observation( body_state: BodyState, ) -> torch.Tensor: """Computes the robot state observation in the robot root frame. Args: body_state (BodyState): The current state of the humanoid bodies. """ # for normalization root_pos = body_state.body_pos_extend[:, 0, :]....
Computes the robot state observation in the robot root frame. Args: body_state (BodyState): The current state of the humanoid bodies.
compute_robot_state_observation
python
NVlabs/HOVER
neural_wbc/core/neural_wbc/core/observations/teacher_observations.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/neural_wbc/core/observations/teacher_observations.py
Apache-2.0
def test_zero_metrics(self): """ Test the metrics when all bodies have zero error. """ ( success_ids, episode, episode_gt, ) = self._create_data() self.metrics.update( success_ids=success_ids, episode=episode, ...
Test the metrics when all bodies have zero error.
test_zero_metrics
python
NVlabs/HOVER
neural_wbc/core/tests/test_evaluator.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/tests/test_evaluator.py
Apache-2.0
def test_offset_metrics(self): """ Test the metrics when all bodies have only a translation error to GT. Then we expect the global error to b the translation, the local error should be 0. """ ( success_ids, episode, episode_gt, ) = sel...
Test the metrics when all bodies have only a translation error to GT. Then we expect the global error to b the translation, the local error should be 0.
test_offset_metrics
python
NVlabs/HOVER
neural_wbc/core/tests/test_evaluator.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/tests/test_evaluator.py
Apache-2.0
def test_masked_metrics(self): """ Test the metrics when only the masked bodies have an offset. We expect the masked error to be greater than the unmasked error. """ ( success_ids, episode, episode_gt, ) = self._create_data() o...
Test the metrics when only the masked bodies have an offset. We expect the masked error to be greater than the unmasked error.
test_masked_metrics
python
NVlabs/HOVER
neural_wbc/core/tests/test_evaluator.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/core/tests/test_evaluator.py
Apache-2.0
def get_data_path(rel_path: str) -> str: """ Get the absolute path to a data file located in the 'neural_wbc/data/data' directory. Args: rel_path (str): The relative path to the data file from the data directory. Returns: str: The absolute path to the data file. Raises: Fi...
Get the absolute path to a data file located in the 'neural_wbc/data/data' directory. Args: rel_path (str): The relative path to the data file from the data directory. Returns: str: The absolute path to the data file. Raises: FileNotFoundError: If the specified file does not ...
get_data_path
python
NVlabs/HOVER
neural_wbc/data/neural_wbc/data/__init__.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/data/neural_wbc/data/__init__.py
Apache-2.0
def __init__( self, cfg: Any, ) -> None: """Initializes a new instance of the H1SDKWrapper class. Args: cfg (Any): The configuration object. """ self.cfg = cfg self._low_cmd = unitree_go_msg_dds__LowCmd_() self._low_cmd_lock = RLock() ...
Initializes a new instance of the H1SDKWrapper class. Args: cfg (Any): The configuration object.
__init__
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
Apache-2.0
def _cmd_publisher(self): """Publishes the low-level command to the SDK.""" with self._low_cmd_lock: if not self._cmd_received: return self._lowcmd_publisher.Write(self._low_cmd)
Publishes the low-level command to the SDK.
_cmd_publisher
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
Apache-2.0
def _init_sdk(self): """Initializes the SDK for the H1 robot. This function initializes the SDK using the required configuration. Args: None """ ChannelFactoryInitialize(0, self.cfg.network_interface) # Create publisher self._lowcmd_publisher = Chann...
Initializes the SDK for the H1 robot. This function initializes the SDK using the required configuration. Args: None
_init_sdk
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
Apache-2.0
def publish_joint_position_cmd(self, cmd_joint_positions: np.ndarray): """Publishes joint position commands to the low-level command publisher. Args: cmd_joint_positions (np.ndarray): An array of joint positions to be published. """ with self._low_cmd_lock: for j...
Publishes joint position commands to the low-level command publisher. Args: cmd_joint_positions (np.ndarray): An array of joint positions to be published.
publish_joint_position_cmd
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
Apache-2.0
def publish_joint_torque_cmd(self, cmd_joint_torques: np.ndarray): """Publishes joint torque commands to the low-level command publisher. Args: cmd_joint_torques (np.ndarray): An array of joint torques to be published. """ with self._low_cmd_lock: for joint_idx i...
Publishes joint torque commands to the low-level command publisher. Args: cmd_joint_torques (np.ndarray): An array of joint torques to be published.
publish_joint_torque_cmd
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
Apache-2.0
def reset(self, desired_joint_positions: np.ndarray | None = None) -> None: """Resets the robot to the given joint positions. Args: desired_joint_positions (np.ndarray | None, optional): An array of desired joint positions. Defaults to None: The robot will be reset to the 0 ...
Resets the robot to the given joint positions. Args: desired_joint_positions (np.ndarray | None, optional): An array of desired joint positions. Defaults to None: The robot will be reset to the 0 initial pose.
reset
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
Apache-2.0
def _init_cmd(self): """Initializes the low-level command. This function sets the values of the low-level command based on the configuration. """ self._low_cmd.head[0] = self.cfg.head0 self._low_cmd.head[1] = self.cfg.head1 self._low_cmd.level_flag = self.cfg.level_flag ...
Initializes the low-level command. This function sets the values of the low-level command based on the configuration.
_init_cmd
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
Apache-2.0
def state_handler(self, msg: LowState_): """ Update the joint positions and velocities based on the low state message. Saves them as per the joint sequence of isaac lab and mujoco. Args: msg (LowState_): The low state message containing the motor states. """ ...
Update the joint positions and velocities based on the low state message. Saves them as per the joint sequence of isaac lab and mujoco. Args: msg (LowState_): The low state message containing the motor states.
state_handler
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/h1_sdk_wrapper.py
Apache-2.0
def update(self, obs_dict: dict[str, torch.Tensor]) -> None: """Update the underlying model based on the observations from the environment/real robot. Args: obs_dict (dict[str, torch.Tensor]): A dictionary containing the latest robot observations. """ # TODO (pulkitg): Chang...
Update the underlying model based on the observations from the environment/real robot. Args: obs_dict (dict[str, torch.Tensor]): A dictionary containing the latest robot observations.
update
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/unitree_h1.py
Apache-2.0
def reset(self, **kwargs) -> None: """Resets the wrapper Args: kwargs (dict[str, Any], optional): key-word arguments to pass to underlying models. Defaults to None. """ qpos = kwargs.get("qpos") qvel = kwargs.get("qvel") self._kinematic_model.reset(qpos=qpos,...
Resets the wrapper Args: kwargs (dict[str, Any], optional): key-word arguments to pass to underlying models. Defaults to None.
reset
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/unitree_h1.py
Apache-2.0
def get_joint_ids(self, joint_names: list[str] | None = None) -> dict[str, int]: """Get the IDs of all joints in the model, indexed after removing the free joint. Args: joint_names (list[str] | None, optional): Names of the joints. Defaults to None. Returns: dict[str, i...
Get the IDs of all joints in the model, indexed after removing the free joint. Args: joint_names (list[str] | None, optional): Names of the joints. Defaults to None. Returns: dict[str, int]: Mapping from joint name to joint id.
get_joint_ids
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/unitree_h1.py
Apache-2.0
def get_base_projected_gravity(self, base_name: str = "torso_link") -> torch.Tensor: """Get the projection of the gravity vector to the base frame Args: base_name (str, optional): Name of the base. Defaults to 'torso_link'. Returns: torch.Tensor: Projection of the gravi...
Get the projection of the gravity vector to the base frame Args: base_name (str, optional): Name of the base. Defaults to 'torso_link'. Returns: torch.Tensor: Projection of the gravity vector to the base frame
get_base_projected_gravity
python
NVlabs/HOVER
neural_wbc/hw_wrappers/hw_wrappers/unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/hw_wrappers/unitree_h1.py
Apache-2.0
def test_get_base_projected_gravity_upright(self): """Test gravity projection when robot is upright""" # Set upright orientation (identity quaternion) self.robot._h1_sdk.torso_orientation = np.array([1.0, 0.0, 0.0, 0.0]) # Call the function gravity = self.robot.get_base_projecte...
Test gravity projection when robot is upright
test_get_base_projected_gravity_upright
python
NVlabs/HOVER
neural_wbc/hw_wrappers/tests/test_unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/tests/test_unitree_h1.py
Apache-2.0
def test_get_base_projected_gravity_rotated_90x(self): """Test gravity projection when robot is rotated 90 degrees around x-axis""" # Create quaternion for 90-degree rotation around x-axis quat = R.from_euler("x", 90, degrees=True).as_quat(scalar_first=True) # Convert to scalar-first for...
Test gravity projection when robot is rotated 90 degrees around x-axis
test_get_base_projected_gravity_rotated_90x
python
NVlabs/HOVER
neural_wbc/hw_wrappers/tests/test_unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/tests/test_unitree_h1.py
Apache-2.0
def test_get_base_projected_gravity_rotated_45y(self): """Test gravity projection when robot is rotated 45 degrees around y-axis""" # Create quaternion for 45-degree rotation around y-axis quat = R.from_euler("y", 45, degrees=True).as_quat(scalar_first=True) # Convert to scalar-first for...
Test gravity projection when robot is rotated 45 degrees around y-axis
test_get_base_projected_gravity_rotated_45y
python
NVlabs/HOVER
neural_wbc/hw_wrappers/tests/test_unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/tests/test_unitree_h1.py
Apache-2.0
def test_get_base_projected_gravity_inverted(self): """Test gravity projection when robot is completely inverted""" # Create quaternion for 180-degree rotation around x-axis quat = R.from_euler("x", 180, degrees=True).as_quat(scalar_first=True) self.robot._h1_sdk.torso_orientation = quat...
Test gravity projection when robot is completely inverted
test_get_base_projected_gravity_inverted
python
NVlabs/HOVER
neural_wbc/hw_wrappers/tests/test_unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/tests/test_unitree_h1.py
Apache-2.0
def test_get_base_projected_gravity_rotated_90z(self): """Test gravity projection when robot is rotated 90 degrees around z-axis""" # Create quaternion for 90-degree rotation around z-axis quat = R.from_euler("z", 90, degrees=True).as_quat(scalar_first=True) self.robot._h1_sdk.torso_orie...
Test gravity projection when robot is rotated 90 degrees around z-axis
test_get_base_projected_gravity_rotated_90z
python
NVlabs/HOVER
neural_wbc/hw_wrappers/tests/test_unitree_h1.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/hw_wrappers/tests/test_unitree_h1.py
Apache-2.0
def __init__( self, args_cli: argparse.Namespace, env_cfg: NeuralWBCEnvCfg, custom_config: dict[str, Any] | None = None, demo_mode: bool = False, ): """ Args: args_cli: command line arguments custom_config: custom configuration for the ...
Args: args_cli: command line arguments custom_config: custom configuration for the environment demo_mode (bool): whether to run in demo mode, without need for student policy Note: The *demo_mode* allows setting of joint manually for e.g. debugging purpos...
__init__
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/deployment_player.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/deployment_player.py
Apache-2.0
def play_once(self, ext_actions: torch.Tensor | None = None): """Advances the environment one time step after generating observations""" obs = self.env.get_observations() with torch.inference_mode(): if ext_actions is not None: actions = ext_actions else: ...
Advances the environment one time step after generating observations
play_once
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/deployment_player.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/deployment_player.py
Apache-2.0
def _update_env_cfg(self, env_cfg, custom_config: dict[str, Any]): """Update the default environment config if user provides a custom config. See readme for detailed usage.""" for key, value in custom_config.items(): obj = env_cfg attrs = key.split(".") try: ...
Update the default environment config if user provides a custom config. See readme for detailed usage.
_update_env_cfg
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/deployment_player.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/deployment_player.py
Apache-2.0
def __init__( self, cfg: NeuralWBCEnvCfg, render_mode: str | None = None, device=torch.device("cuda" if torch.cuda.is_available() else "cpu"), ) -> None: """Initializes the environment. Args: cfg (NeuralWBCEnvCfgH1): Environment configuration. ...
Initializes the environment. Args: cfg (NeuralWBCEnvCfgH1): Environment configuration. render_mode (str | None, optional): Render mode. Defaults to None. device (torch.device, optional): torch device to use. Defaults to 'cuda'.
__init__
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def step(self, actions: torch.Tensor) -> tuple[dict, torch.Tensor, torch.Tensor, dict]: """Performs one step of simulation. Args: actions (torch.Tensor): Actions of shape (num_envs, num_actions) Returns: * Observations as a dict or an object. * Rewards of sh...
Performs one step of simulation. Args: actions (torch.Tensor): Actions of shape (num_envs, num_actions) Returns: * Observations as a dict or an object. * Rewards of shape (num_envs,) * "Dones": a boolean tensor representing termination of an episode in e...
step
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def _pre_physics_step(self, actions: torch.Tensor): """Prepares the robot for the next physics step. Args: actions (torch.Tensor): Actions of shape (num_envs, num_actions) """ # update history if self.cfg.mode.is_distill_mode(): obs_dic = self._compute_ob...
Prepares the robot for the next physics step. Args: actions (torch.Tensor): Actions of shape (num_envs, num_actions)
_pre_physics_step
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def reset(self, env_ids: list | torch.Tensor | None = None): """Resets environment specified by env_ids. Args: env_ids (list | torch.Tensor | None, optional): Environment ids. Defaults to None. """ env_ids = self._env_ids if env_ids is None else env_ids self._reset_...
Resets environment specified by env_ids. Args: env_ids (list | torch.Tensor | None, optional): Environment ids. Defaults to None.
reset
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def _reset_robot_state_and_motion(self, env_ids: list | torch.Tensor | None = None): """Resets the robot state and the reference motion. Args: env_ids (list | torch.Tensor | None, optional): Environment ids. Defaults to None. """ env_ids = env_ids if env_ids is not None else...
Resets the robot state and the reference motion. Args: env_ids (list | torch.Tensor | None, optional): Environment ids. Defaults to None.
_reset_robot_state_and_motion
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def _update_robot_default_state(self): """Loads the default initial state of the robot.""" # Read the default values from the mujoco data first. robot_init_state = self.cfg.robot_init_state state_update_dict = {} root_pos_offset = 3 if "base_pos" in robot_init_state: ...
Loads the default initial state of the robot.
_update_robot_default_state
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def _apply_action(self): """Applies the current action to the robot.""" actions_scaled = self.actions * self.cfg.action_scale + self.default_joint_pos self._processed_action = self._control_fn(self, actions_scaled) self._processed_action = self._apply_limits(self._processed_action) ...
Applies the current action to the robot.
_apply_action
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def _compose_body_state( self, extend_body_pos: torch.Tensor | None = None, extend_body_parent_ids: list[int] | None = None ) -> BodyState: """Compose the Body state from the robot/articulation data. Args: extend_body_pos (torch.Tensor | None, optional): Extended body positions....
Compose the Body state from the robot/articulation data. Args: extend_body_pos (torch.Tensor | None, optional): Extended body positions. Defaults to None. extend_body_parent_ids (list[int] | None, optional): Extended body parent ids. Defaults to None. Returns: BodyS...
_compose_body_state
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def _compute_observations(self): """Compute the observations Returns: dict: Observations """ self._robot.update({}) # NOTE: not including the privileged observations so far obs_dict = {} ref_motion_state = self.reference_motion_manager.get_state_from...
Compute the observations Returns: dict: Observations
_compute_observations
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def _get_dones(self) -> tuple[torch.Tensor, torch.Tensor]: """Get the done flags. Returns: tuple[torch.Tensor, torch.Tensor]: Should terminate flags and time out flags """ time_out = self.episode_length_buf >= self.max_episode_length - 1 ref_motion_state = self.refe...
Get the done flags. Returns: tuple[torch.Tensor, torch.Tensor]: Should terminate flags and time out flags
_get_dones
python
NVlabs/HOVER
neural_wbc/inference_env/inference_env/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/inference_env/inference_env/neural_wbc_env.py
Apache-2.0
def build_body_state( data: ArticulationData, root_id: int, body_ids: list[int] | None = None, joint_ids: list[int] | None = None, extend_body_pos: torch.Tensor | None = None, extend_body_parent_ids: list[int] | None = None, ) -> BodyState: """Creates a body state from Isaac Lab articulation...
Creates a body state from Isaac Lab articulation data. Args: data (ArticulationData): Articulation data containing robot's body and joint states. body_ids (list[int] | None, optional): The desired order of bodies. If not, the order in body states is preserved. ...
build_body_state
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/body_state.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/body_state.py
Apache-2.0
def _reset_mask(self, env_ids: torch.Tensor | None = None): """ Reset the mask used to select which parts of the reference state should be tracked. Every environment uses a different mask. """ if self.cfg.mode.is_distill_mode() or self.cfg.mode.is_distill_test_mode(): ...
Reset the mask used to select which parts of the reference state should be tracked. Every environment uses a different mask.
_reset_mask
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/neural_wbc_env.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/neural_wbc_env.py
Apache-2.0
def convert_tensors_and_slices_to_serializable(d): """Recursively convert torch tensors to lists and handle slice objects in a nested dictionary, including lists and tuples.""" if isinstance(d, dict): return {k: convert_tensors_and_slices_to_serializable(v) for k, v in d.items()} elif isinstance(d, ...
Recursively convert torch tensors to lists and handle slice objects in a nested dictionary, including lists and tuples.
convert_tensors_and_slices_to_serializable
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/utils.py
Apache-2.0
def convert_serializable_to_tensors_and_slices(d): """Recursively convert lists back to torch tensors and dictionaries back to slice objects.""" if isinstance(d, dict): if "__type__" in d: if d["__type__"] == "tensor": return torch.tensor(d["data"]) elif d["__type...
Recursively convert lists back to torch tensors and dictionaries back to slice objects.
convert_serializable_to_tensors_and_slices
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/utils.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/utils.py
Apache-2.0
def randomize_body_com( env: NeuralWBCEnv, env_ids: torch.Tensor | None, asset_cfg: SceneEntityCfg, distribution_params: tuple[float, float] | tuple[torch.Tensor, torch.Tensor], operation: Literal["add", "abs", "scale"], distribution: Literal["uniform", "log_uniform", "gaussian"] = "uniform", ):...
Randomize the com of the bodies by adding, scaling or setting random values. This function allows randomizing the center of mass of the bodies of the asset. The function samples random values from the given distribution parameters and adds, scales or sets the values into the physics simulation based on the ope...
randomize_body_com
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
Apache-2.0
def randomize_pd_scale( env: NeuralWBCEnv, env_ids: torch.Tensor | None, distribution_params: tuple[float, float], operation: Literal["add", "abs", "scale"], distribution: Literal["uniform", "log_uniform", "gaussian"] = "uniform", ): """Randomize the scale of the pd gains by adding, scaling or s...
Randomize the scale of the pd gains by adding, scaling or setting random values. This function allows randomizing the scale of the pd gain. The function samples random values from the given distribution parameters and adds, or sets the values into the simulation based on the operation.
randomize_pd_scale
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
Apache-2.0
def randomize_action_noise_range( env: NeuralWBCEnv, env_ids: torch.Tensor | None, distribution_params: tuple[float, float], operation: Literal["add", "abs", "scale"], distribution: Literal["uniform", "log_uniform", "gaussian"] = "uniform", ): """Randomize the sample range of the added action no...
Randomize the sample range of the added action noise by adding, scaling or setting random values. This function allows randomizing the scale of the sample range of the added action noise. The function samples random values from the given distribution parameters and adds, scales or sets the values into the ...
randomize_action_noise_range
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
Apache-2.0
def randomize_motion_ref_xyz( env: NeuralWBCEnv, env_ids: torch.Tensor | None, distribution_params: tuple[float, float] | tuple[torch.Tensor, torch.Tensor], operation: Literal["add", "abs", "scale"], distribution: Literal["uniform", "log_uniform", "gaussian"] = "uniform", ): """Randomize the mot...
Randomize the motion reference x,y,z offset by adding, scaling or setting random values. This function allows randomizing the motion reference x,y,z offset. The function samples random values from the given distribution parameters and adds, scales or sets the values into the simulation based on the operati...
randomize_motion_ref_xyz
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
Apache-2.0
def push_by_setting_velocity_with_recovery( env: NeuralWBCEnv, env_ids: torch.Tensor, velocity_range: dict[str, tuple[float, float]], asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"), ): """Push the asset by setting the root velocity to a random value within the given ranges. This creates an...
Push the asset by setting the root velocity to a random value within the given ranges. This creates an effect similar to pushing the asset with a random impulse that changes the asset's velocity. It samples the root velocity from the given ranges and sets the velocity into the physics simulation. The func...
push_by_setting_velocity_with_recovery
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
Apache-2.0
def reset_robot_state_and_motion( env: NeuralWBCEnv, env_ids: torch.Tensor, asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"), ): """Reset the robot and reference motion. The full reset percess is: 1. Reset the robot root state to the origin position of its terrain. 2. Reset motion refere...
Reset the robot and reference motion. The full reset percess is: 1. Reset the robot root state to the origin position of its terrain. 2. Reset motion reference to random time step. 3. Moving the motion reference trajectory to the current robot position. 4. Reset the robot joint to reference motion'...
reset_robot_state_and_motion
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
Apache-2.0
def update_curriculum( env: NeuralWBCEnv, env_ids: torch.Tensor | None, penalty_level_down_threshold: float, penalty_level_up_threshold: float, penalty_level_degree: float, min_penalty_scale: float, max_penalty_scale: float, num_compute_average_epl: float, ): """ Update average e...
Update average episode length and in turn penalty curriculum. This function is rewritten from update_average_episode_length of legged_gym. When the policy is not able to track the motions, we reduce the penalty to help it explore more actions. When the policy is able to track the motions, we increase...
update_curriculum
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/events/events.py
Apache-2.0
def compute_reward( self, articulation_data: ArticulationData, body_state: BodyState, ref_motion_state: ReferenceMotionState, previous_actions: torch.Tensor, actions: torch.Tensor, reset_buf: torch.Tensor, timeout_buf: torch.Tensor, penalty_scale: ...
Computes the total reward for the given environment and reference motion state. This function calculates the weighted sum of individual rewards specified in the environment's reward configuration. Each reward is computed using a corresponding reward function defined within the class. T...
compute_reward
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
Apache-2.0
def reward_track_joint_positions( self, body_state: BodyState, ref_motion_state: ReferenceMotionState, **kwargs, ) -> torch.Tensor: """ Computes the reward for tracking the joint positions of the reference motion. This function is rewritten from _reward_teleo...
Computes the reward for tracking the joint positions of the reference motion. This function is rewritten from _reward_teleop_selected_joint_position of legged_gym. Returns: torch.Tensor: A float tensor of shape (num_envs) representing the computed reward for each environment. ...
reward_track_joint_positions
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
Apache-2.0
def reward_track_joint_velocities( self, body_state: BodyState, ref_motion_state: ReferenceMotionState, **kwargs, ) -> torch.Tensor: """ Computes the reward for tracking the joint velocities of the reference motion. This function is rewritten from _reward_tel...
Computes the reward for tracking the joint velocities of the reference motion. This function is rewritten from _reward_teleop_selected_joint_vel of legged_gym. Returns: torch.Tensor: A float tensor of shape (num_envs) representing the computed reward for each environment.
reward_track_joint_velocities
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
Apache-2.0
def reward_track_body_velocities( self, body_state: BodyState, ref_motion_state: ReferenceMotionState, **kwargs, ) -> torch.Tensor: """ Computes a reward based on the difference between the body's velocity and the reference motion's velocity. This function is...
Computes a reward based on the difference between the body's velocity and the reference motion's velocity. This function is rewritten from _reward_teleop_body_vel of legged_gym. Returns: torch.Tensor: A float tensor of shape (num_envs) representing the computed reward for each env...
reward_track_body_velocities
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
Apache-2.0
def reward_track_body_angular_velocities( self, body_state: BodyState, ref_motion_state: ReferenceMotionState, **kwargs, ) -> torch.Tensor: """ Computes a reward based on the difference between the body's angular velocity and the reference motion's angular vel...
Computes a reward based on the difference between the body's angular velocity and the reference motion's angular velocity. This function is rewritten from _reward_teleop_body_ang_vel of legged_gym. Returns: torch.Tensor: A float tensor of shape (num_envs) representing the ...
reward_track_body_angular_velocities
python
NVlabs/HOVER
neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
https://github.com/NVlabs/HOVER/blob/master/neural_wbc/isaac_lab_wrapper/neural_wbc/isaac_lab_wrapper/rewards/rewards.py
Apache-2.0