unilab.envs.locomotion.common.height_scan

Shared height-scan and terrain-bound helpers for rough locomotion envs.

These functions and the HeightScanConfig dataclass are consumed by Go2, Go2W, Go1, and G1 rough environments — anywhere the policy / critic ingests a forward-looking height grid sampled from a procedural heightfield.

Each helper mirrors the original implementation that lived inline in go2/rough.py so that behavior is bit-for-bit identical; the only change is the host: env classes import these instead of redefining them.

Functions

base_height_from_scan(env[, num_obs])

Estimate base-relative height by averaging the heightfield samples below the body.

configured_height_scan_dim(scan_cfg)

height_scan_obs(env, scan_cfg, num_obs)

Clipped, scaled height observation matching the Go2 rough format.

height_scan_offsets(points_x, points_y)

Build a contiguous (P, 2) array of (x, y) sampling offsets in body frame.

init_height_scan_sensor(env, scan_cfg, ...)

Wire a yaw-aligned heightfield scanner onto env.

raw_height_scan_obs(env, num_obs)

Return (raw_heights (N, P), base_pos (N, 3)) or (None, None) if sensor not ready.

terrain_num_cols(terrain_cfg)

terrain_out_of_bounds(env, terrain_cfg, ...)

Boolean mask: True when the body's (x, y) is outside the terrain footprint.

Classes

HeightScanConfig

HeightScanConfig(enabled: 'bool' = True, hfield_name: 'str' = 'terrain_hfield', geom_name: 'str' = 'floor', measured_points_x: 'list[float]' = <factory>, measured_points_y: 'list[float]' = <factory>, vertical_offset: 'float' = 0.5, scale: 'float' = 5.0)

class unilab.envs.locomotion.common.height_scan.HeightScanConfig[source]

Bases: object

HeightScanConfig(enabled: ‘bool’ = True, hfield_name: ‘str’ = ‘terrain_hfield’, geom_name: ‘str’ = ‘floor’, measured_points_x: ‘list[float]’ = <factory>, measured_points_y: ‘list[float]’ = <factory>, vertical_offset: ‘float’ = 0.5, scale: ‘float’ = 5.0)

Parameters:
enabled: bool = True
hfield_name: str = 'terrain_hfield'
geom_name: str = 'floor'
measured_points_x: list[float]
measured_points_y: list[float]
vertical_offset: float = 0.5
scale: float = 5.0
__init__(enabled=True, hfield_name='terrain_hfield', geom_name='floor', measured_points_x=<factory>, measured_points_y=<factory>, vertical_offset=0.5, scale=5.0)
Parameters:
unilab.envs.locomotion.common.height_scan.height_scan_offsets(points_x, points_y)[source]

Build a contiguous (P, 2) array of (x, y) sampling offsets in body frame.

Parameters:
Return type:

ndarray

unilab.envs.locomotion.common.height_scan.configured_height_scan_dim(scan_cfg)[source]
Parameters:

scan_cfg (HeightScanConfig)

Return type:

int

unilab.envs.locomotion.common.height_scan.init_height_scan_sensor(env, scan_cfg, base_body_name)[source]

Wire a yaw-aligned heightfield scanner onto env.

Sets the following attributes on env:

_height_scan_dim, _height_scan_hfield_geom_id, _height_scan_frame_body_id, _height_scan_offsets, _height_scan_sensor.

Parameters:
Return type:

None

unilab.envs.locomotion.common.height_scan.raw_height_scan_obs(env, num_obs)[source]

Return (raw_heights (N, P), base_pos (N, 3)) or (None, None) if sensor not ready.

Parameters:
Return type:

tuple[ndarray | None, ndarray | None]

unilab.envs.locomotion.common.height_scan.height_scan_obs(env, scan_cfg, num_obs)[source]

Clipped, scaled height observation matching the Go2 rough format.

Parameters:
Return type:

ndarray

unilab.envs.locomotion.common.height_scan.base_height_from_scan(env, num_obs=None)[source]

Estimate base-relative height by averaging the heightfield samples below the body.

Parameters:
Return type:

ndarray

unilab.envs.locomotion.common.height_scan.terrain_num_cols(terrain_cfg)[source]
Parameters:

terrain_cfg (Any)

Return type:

int

unilab.envs.locomotion.common.height_scan.terrain_out_of_bounds(env, terrain_cfg, distance_buffer)[source]

Boolean mask: True when the body’s (x, y) is outside the terrain footprint.

Parameters:
Return type:

ndarray