Files
chenlin c32df70326
Checks / Layout, translation and Colab checks (push) Has been cancelled
Checks / Ruff (push) Has been cancelled
Checks / Framework tests (native backend, CPU) (push) Has been cancelled
Checks / Portable Rust controller (push) Has been cancelled
release: v0.1 generic robot training and application platform
2026-11-05 11:05:01 +08:00

79 lines
3.3 KiB
Python

"""Wet-ice friction preset with explicit ground-contact priority.
The terrain uses priority=2 and friction=(0.03, 0.00025, 0.00025).
MuJoCo selects the whole contact parameter set from the higher-priority geom;
therefore this preset dominates foot geoms with lower priority, but not robots
whose foot priority is higher. Inspect the compiled contact model for each asset.
The helper preserves the terrain's existing solref and solimp unless explicitly
provided. It does not infer robot contact stiffness or a universal foot material.
These coefficients are illustrative scene parameters, not measurements of an
imported robot. Foot-friction randomization is ineffective wherever the terrain
has higher priority. Randomize the terrain when that variation is required.
"""
from __future__ import annotations
from typing import Any
from .registry import GROUND, Headlight, Scene, set_ground_contact
#: Illustrative sliding friction; calibrate for the target surface.
ICE_SLIDING = 0.03
#: Illustrative torsional and rolling friction.
ICE_TORSIONAL = 0.00025
ICE_ROLLING = 0.00025
def _make_it_ice(spec: Any) -> None:
"""Apply the preset while preserving authored terrain stiffness."""
set_ground_contact(
spec, "ice", friction=(ICE_SLIDING, ICE_TORSIONAL, ICE_ROLLING)
)
def scene() -> Scene:
from mjlab.utils import spec_config as sc
return Scene(
# Low ambient and one hard low sun. Ice reads as ice through its
# specular highlight and the long shadow across it; a bright overhead
# ambient washes both out and leaves a flat pale floor that could be
# anything. The same reasoning as `beach.py`'s note on the headlight.
headlight=Headlight(ambient=(0.13, 0.14, 0.16), diffuse=(0.30, 0.32, 0.36)),
textures=(
# Faint, large-scale mottling rather than a checker: refrozen ice has
# cloudy patches where air is trapped, and the pattern has to be much
# larger than a foot or it reads as texture on a floor instead of as
# depth within a slab. Two blues a hair apart -- any more contrast and
# it looks like tiling.
sc.TextureCfg(
name="ice_floor", type="2d", builtin="checker",
rgb1=(0.74, 0.82, 0.88), rgb2=(0.70, 0.79, 0.86),
width=512, height=512,
),
sc.TextureCfg(
name="ice_sky", type="skybox", builtin="gradient",
rgb1=(0.62, 0.72, 0.82), rgb2=(0.82, 0.88, 0.92),
width=256, height=256,
),
),
materials=(
# **`reflectance` is the whole visual trick.** A wet surface is
# defined by what it mirrors, not by its colour, and 0.4 is high
# enough to pick up the sky and the robot without turning the floor
# into a mirror the gait cannot be read against. `texrepeat` is low
# so the mottling stays large.
sc.MaterialCfg(
name="ice_floor", texture="ice_floor", texuniform=True,
texrepeat=(3.0, 3.0), reflectance=0.4, geom_names_expr=GROUND,
),
),
lights=(
sc.LightCfg(name="sun", type="directional", pos=(-3.0, -2.0, 2.0),
dir=(0.6, 0.4, -1.0), diffuse=(0.85, 0.87, 0.92)),
),
decorate=_make_it_ice,
)