Skip to main content
GymAdapter exposes the simulator as a Gym-style reset() / step() loop, the natural interface for driving a robot from a policy. It speaks ActionCall in and Observation out.
import cadenza_lab as cadenza
from cadenza_lab import ActionCall

env = cadenza.GymAdapter(robot="go1", headless=True)
obs = env.reset()

for _ in range(20):
    obs, info = env.step(ActionCall("walk_forward", distance_m=0.5))
    if not env.is_open:           # property, not a method
        break

env.close()

Constructor

GymAdapter(robot, *, xml_path=None, scene=None, headless=False,
           render_camera=False, cam_distance=0.0, cam_elevation=-15.0,
           cam_azimuth=270.0, max_action_seconds=30.0)
ParamDescription
robot"go1" or "g1".
sceneAn optional Scene.
headlessTrue to run without a viewer (CI-safe).
render_cameraPopulate Observation.camera each step.
max_action_secondsPer-action wall-clock cap.

Methods

MethodReturnsDescription
reset()ObservationReset to the start state.
step(call)(Observation, info: dict)Execute one ActionCall.
add_box / add_slope / add_sphere(...)GymAdapterAdd geometry before reset() (same args as Scene).
clear_scene()NoneRemove added geometry.
is_openboolProperty. Whether the viewer/sim is still open.
close()NoneShut down the sim/viewer.
Scene geometry is baked at reset(). Add boxes/slopes/spheres before the first reset() (or call reset() again after changing the scene).
GymAdapter.step() returns (Observation, info), not the 5-tuple Gym returns. For the standard (obs, reward, terminated, truncated, info) loop tied to a CLI mission, use CustomEnv.

ActionCall

The action passed to step(). Parameterizes a named action.
ActionCall(action_name, speed=1.0, extension=1.0, repeat=1,
           distance_m=0.0, rotation_rad=0.0, duration_s=0.0,
           speed_override=0.0, height_override=0.0)
FieldDescription
action_nameA base action, e.g. "walk_forward" (see Actions).
distance_mTarget distance for locomotion actions.
rotation_radTarget rotation for turn actions.
speed, extension, repeatGait/scale modifiers.
duration_s, speed_override, height_overrideFine-grained overrides.

Observation

Returned by reset() / step().
AttributeDescription
pos, rpy, body_heightBase pose (numpy arrays / float).
qpos, qvelFull generalized position / velocity.
foot_contactsTuple of per-foot ground contact bools.
terrain_ahead, obstacles_aheadRaycast sensing dicts (see Simulation).
cameraRGB frame, shape (224, 224, 3) (when render_camera=True).
depthDepth frame.
to_dict()Serialize the observation to a plain dict.

Demo: drive a scene through a Gym loop

"""demo_gym.py: headless reset/step loop with obstacles + camera (CI-safe)."""
import cadenza_lab as cadenza
from cadenza_lab import ActionCall

env = cadenza.GymAdapter(robot="go1", headless=True, render_camera=True)
env.add_box(position=(-1.2, 0.0, 0.08), size=(0.15, 0.15, 0.08))
env.add_slope(position=(-2.5, 0.0, 0.0), size=(0.6, 0.6, 0.05), angle_deg=12)

obs = env.reset()
print("start:", obs.pos.round(2), "camera:", obs.camera.shape)

plan = [
    ActionCall("walk_forward", distance_m=0.6),
    ActionCall("turn_left", rotation_rad=0.8),
    ActionCall("walk_forward", distance_m=0.6),
    ActionCall("sit"),
]
for call in plan:
    obs, info = env.step(call)
    print(f"{call.action_name:<14} moved={info['moved_m']:.2f}  ok={info['ok']}")
    if not env.is_open:
        break

env.close()
python demo_gym.py