Skip to content

sim/mujoco: MjSpec stage 3 - single-robot attach via spec.attach() (#121) #122

@cagataycali

Description

@cagataycali

Part of #121. See IDEA.md stage 3 for the full context.

Goal

Replace part of scene_ops.inject_robot_into_scene with spec.attach(robot_spec, prefix=..., frame=...) when STRANDS_SIM_USE_MJSPEC=1.

Current code (after mj_spec flag lands):

  • inject_robot_into_scene loads robot XML, parses, prefixes names, merges with scene XML, reloads. ~100 lines of ElementTree + name-mangling.

Target:

robot_spec = mujoco.MjSpec.from_file(robot.urdf_path)
frame = scene_spec.worldbody.add_frame(pos=robot.position, quat=robot.orientation)
scene_spec.attach(robot_spec, prefix=f'{robot.name}_', frame=frame)
world._model, world._data = scene_spec.recompile(world._model, world._data)

attach() handles name prefixing across bodies, joints, geoms, actuators, sensors, sites; default-class namespacing; asset deduplication; keyframe merging.

Acceptance

  • When STRANDS_SIM_USE_MJSPEC=1, single-robot add_robot uses spec.attach().
  • Joint/actuator ID discovery (_discover_* helpers) still works - they read from the compiled MjModel.
  • Legacy path untouched. Feature flag still default-off.
  • New tests in test_spec_builder.py for attach semantics (prefix applied, assets dedup'd).

Non-goals

  • Don't delete _save_and_patch_xml yet - multi-robot still needs it until Stage 4.
  • Don't change public API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions