diff --git a/agent_context/MAP.yaml b/agent_context/MAP.yaml index 8086c4a5f8..24734f43a8 100644 --- a/agent_context/MAP.yaml +++ b/agent_context/MAP.yaml @@ -11,7 +11,7 @@ topics: aliases: [simulation system, simulation manager, Newton physics backend, motion module, sim motion, camera attachment, 运动能力模块, 仿真系统, 仿真管理器] keywords: [SimulationManager, SimulationManagerCfg, RenderCfg, DLSSCfg, DLSS, frame_time_delta_ms, offscreen_dlss_enabled, explicit physics stepping, arena, DexSim, PhysicsBackendCfg, - DefaultPhysicsCfg, NewtonPhysicsCfg, AutoSolverCfg, DexUniSolverCfg, DexUni, runtime control, deformable, particle set, + DefaultPhysicsCfg, NewtonPhysicsCfg, AutoSolverCfg, DexUniSolverCfg, DexUni, MJVBDV2SolverCfg, mjvbd_v2, mjvbd2, runtime control, deformable, particle set, ArticulationJointKinematics, get_parent_joint_chain, asset_physics_mode, joint_drive_props, enable_gravity, fixed-cadence playback, quaternion, xyzw] paths: [topics/simulation-system/simulation-system.md] diff --git a/agent_context/topics/atomic-actions/atomic-actions.md b/agent_context/topics/atomic-actions/atomic-actions.md index 6cfc208ed7..5694c474a6 100644 --- a/agent_context/topics/atomic-actions/atomic-actions.md +++ b/agent_context/topics/atomic-actions/atomic-actions.md @@ -92,6 +92,35 @@ repeated-pick/open-drawer environment components carry the same Newton-only overlays, while their declared Default backend continues to consume only the portable fields. +For UR5 with `mjvbd_v2`, the paper-cup `move_held_object.py` tutorial opts into +VBD contact history with `latest` collision matching, sliding friction 4 on the +gripper alone, and a 0.0115 m candidate close target. Transport orientation +is not yet repeatably aligned. The native contact alpha and the cup +and ground materials are unchanged. `create_tutorial_simulation` accepts +`newton_solver_options`, and `add_tutorial_robot` accepts +`newton_gripper_friction` and optional `arm_damping`; these are authored before +model construction. This +calibration also applies to the UR5-only `pour.py` tutorial with its 0.013 m +cube close target. The UR5 plastic-tray `coordinated_pickment.py` tutorial uses +the same contact settings with a 0.023 m close target; the dual-arm helper +`add_dual_tutorial_robot` also accepts `newton_gripper_friction`. +The UR5 vertical-can `hand_over.py` tutorial uses those contact settings with +left/right close targets of 0.007/0.0055 m and retains its original arm drives. +Its replay callback holds the current targets for one second immediately before +the compiled `receive_release` segment so the receiving arm can settle before +opening. The wait uses segment metadata, not a fixed waypoint index, and is +scoped to that same profile. This scene-specific calibration does not promise +identical final poses or stability across initial-state changes. Horizontal +objects and other robot families retain their prior configuration. +The UR5 V2 `place.py` profile uses a 0.013 m close target, gripper friction 4, +contact history with `latest` matching, contact alpha 0.5, and arm damping 1000. +The lower arm damping reduces tracking lag when the fingers open; finger +drives and authored release waypoints remain unchanged. Complete cached +replays preserve the grasp to release, but landing orientation still varies; +this is a scoped improvement, not a claim of full solver equivalence. +These explicit scene choices do not change world defaults +or establish a generic object-width-to-gripper-target mapping. + ## Semantic integration boundary `semantics` contains: diff --git a/agent_context/topics/motion-planning/collision-worlds.md b/agent_context/topics/motion-planning/collision-worlds.md index ac240779fb..b380bc8898 100644 --- a/agent_context/topics/motion-planning/collision-worlds.md +++ b/agent_context/topics/motion-planning/collision-worlds.md @@ -17,7 +17,10 @@ mapping key is the authoritative logical/source obstacle ID used by the content-cache key, `collision_world_entity_ids`, generated obstacle-name prefix, dynamic update key, and registry validation. Scene generation reads physical collision descriptors through `RigidObject.get_collision_shapes()` and emits a -mixed tensor-backed cuRobo scene. A compound source expands to physical names +mixed tensor-backed cuRobo scene. Geometry snapshots retain authored collision +shapes even when physical contact response is disabled, matching native shape +queries; a moving planner obstacle can therefore avoid exerting impulses on +the robot. A compound source expands to physical names such as `registry_id__shape_0`; cache and full-world identity remain keyed by the unexpanded `registry_id`, and dynamic updates fan out through the physical shapes' local poses. A registry mapping whose source lacks physical collision diff --git a/agent_context/topics/simulation-system/simulation-system.md b/agent_context/topics/simulation-system/simulation-system.md index 04c0a74f5a..1f52ad696d 100644 --- a/agent_context/topics/simulation-system/simulation-system.md +++ b/agent_context/topics/simulation-system/simulation-system.md @@ -136,6 +136,8 @@ before closing the Spawn result, environment, and World. Default backends use the no-op hook. Newton synchronizes its resolved Warp CUDA device and clears its render bridge while Spawn still owns the parent skeletons, so cached link views cannot be destructed after their native parents. +Asset material and reset-baseline material caches are also cleared before +closing the Scene, so OptiX material wrappers cannot outlive the renderer. After backend materialization, dynamic `RigidObject`, `Articulation`, and `RigidObjectGroup` facades capture their resolved mass, inertia diagonal, and @@ -466,18 +468,59 @@ are both absent. Thus a config-backed launcher preserves the backend default, while an explicit CPU override remains authoritative even for Newton. Environment tensors derive from `sim.device`; do not introduce a second tensor-device selector. -Leaving `NewtonPhysicsCfg.solver_cfg=None` preserves DexSim's -`AutoSolverCfg` default. A DexSim build exporting `AutoSolverCfg` is required; -EmbodiChain does not substitute a concrete solver. DexSim resolves that -placeholder from the complete Spawn scene during finalization: rigid-only -scenes select XPBD, scenes with an articulation select MuJoCo Warp, and -supported particle families select their matching particle/deformable solver. -A mapping with `solver_type: auto` or -`class_type: AutoSolverCfg` is the explicit equivalent. Gradient mode must -still select `semi_implicit` explicitly because AutoSolver does not choose a -differentiable solver. Before finalization, EmbodiChain treats `auto` as -unresolved; after finalization, `NewtonPhysicsBackend.solver_type` reads the -concrete type from DexSim's World-owned backend. +`NewtonPhysicsCfg()` selects `mjvbd_v2` by default for rigid bodies and +articulations. V2 owns collision detection, so conversion omits the external +pipeline even when `collision_cfg` contains its default settings. Other +solvers retain the external pipeline unless explicitly disabled. +Explicit `solver_cfg=None`, `solver_type: auto`, or `class_type: AutoSolverCfg` +opts into DexSim's scene-aware selection: rigid-only scenes select XPBD, +articulation scenes select MuJoCo Warp, and supported particle families select +their matching solver. Gradient mode still requires explicit `semi_implicit`. +Before finalization, explicit `auto` is unresolved; after finalization, +`NewtonPhysicsBackend.solver_type` reads the concrete World-owned solver. +Explicit rigid/articulation V2 configurations select `mjvbd_v2` (aliases +`mjvbd2`, `mjvbdv2`, or `MJVBDV2SolverCfg`). Keep `joint_mode: dynamic` for +ordinary robot control, put existing MuJoCo options under `mujoco_options`, +and set `collision_cfg: null` because V2 owns collision detection. Joint +targets, state access, mimic compliance, and whole-world articulation reset +use the existing Scene/Batch path. V2's compact MuJoCo indices are translated +by DexSim for contact queries and by its index map for mimic equality rows. +Runtime FK updates only MuJoCo-owned articulation trees; replaying FK for +VBD-owned FREE joints would overwrite simulated rigid-body poses with stale +generalized coordinates. Reset completeness checks count Scene articulations, +not the internal FREE-joint trees used to represent standalone rigid bodies. +The pure MuJoCo branch exposes contact geometry, impulses, and friction on +CUDA. VBD contacts expose geometry without MuJoCo impulse reporting. + +V2 selects MuJoCo for articulations with active scalar joints and VBD for +unselected free rigid bodies. Its current mixed dynamic branch is one-way: +VBD contacts do not push back on the MuJoCo robot. The local, uncommitted DexSim +patch enables a second MuJoCo-Warp collision/contact pipeline by default; explicitly setting +`mujoco_options.disable_contacts=True` still disables them. The compact +MuJoCo view contains owned links and world-attached static shapes, but excludes +VBD-owned free bodies and independent kinematic bodies. A stationary fixture +declared kinematic therefore does not provide robot contact reaction in this +view; use static for fixtures that never move. The stationary tables in +`examples/sim/demo/grasp_cup_to_caffe.py` and +`scripts/tutorials/atomic_action/coordinated_placement.py` use this declaration. +Moving kinematic obstacles and +dynamic-object reaction remain separate limitations. Mixed contact queries +still lack equivalent impulse reporting, even when robot ground support is +restored. Explicit `mujoco_articulations` or +`mujoco_articulation_paths` can select complete joint trees; these are ownership +choices, not automatic EmbodiChain rewrites. This integration does not extend +deformable support. + +The UR5 `repeated_pick_place` and `open_drawer` deployments provide +`task.ur5.newton.yaml` and matching `env.newton.yaml` components using V2. They share the +existing embodiment, controller gains, and Task Programs, with the timed +`trajectory_open_loop_slow.yaml` execution policy (80 control points). The +40-point drawer reference allocates only five samples to pulling; at 25 Hz its +0.2-second pull is shorter than the time needed for 18 cm at the drawer's +authored 0.35 m/s speed limit. Evaluate measured lift, placement, and drawer +travel separately from projected Task Program completion; a completed program +alone is not evidence of physical success. + Explicit coupled articulation/deformable configurations use `dexuni` or `DexUniSolverCfg`. DexUni owns collision detection and its particle-shape contacts, so explicit configurations set `collision_cfg=None` instead of @@ -491,28 +534,43 @@ The `open_drawer.py` tutorial combines this option with 20 Newton substeps per 10 ms control step, while keeping its authored robot gains, collision geometry, pull trajectory, success criteria, and push trajectory identical to Default. Atomic-action tutorials configure their shared Newton simulation in -`scripts/tutorials/atomic_action/tutorial_utils.py` with 20 solver substeps -per 10 ms physics step (0.5 ms solver intervals). They select `mujoco_warp` with -`use_mujoco_contacts=True` and set the external `collision_cfg` to `None`. -MuJoCo-Warp then generates and solves contacts internally at every solver -substep; external-pipeline settings such as `update_interval`, contact -reduction, and the external `rigid_contact_max` do not apply. DexSim derives -the native per-world contact capacity from the finalized scene, avoiding the -oversized fixed buffers formerly inherited from external-pipeline examples. -The shared factory leaves the Default backend configuration unchanged. For -parallel-jaw manipulation, the tutorial and packaged task components add a -Newton-only contact overlay (`condim=4`, `ke=4e4`, `kd=4e2`, torsional friction -`0.1`, rolling friction `0.01`) to the gripper and directly manipulated object -contact links. `condim=4` activates torsional friction in MuJoCo-Warp; rolling -friction is retained for solvers/`condim=6` that support it. This is a scoped -contact/force-closure candidate profile, not a replacement for Newton's scene-aware -`AutoSolverCfg`; rigid-only scenes still resolve to XPBD and articulation -scenes to MuJoCo-Warp. Keep -backend-specific overlays sparse so the Default adapter continues to use its -existing portable contact envelope. -The package dependency must identify the exact DexSim dev build containing -this API; a base `==0.4.3` requirement also accepts older local-version wheels -that do not export `AutoSolverCfg` and is therefore insufficient. +`scripts/tutorials/atomic_action/tutorial_utils.py` with `mjvbd_v2`, retaining +20 solver substeps per 10 ms physics step (0.5 ms solver intervals) and the +existing articulation tuning under `mujoco_options`. The direct drawer +tutorial and rigid manipulation examples use the same native V2 ownership. +The shared factory leaves the Default backend configuration unchanged. +Parallel-jaw manipulation keeps its Newton-only contact overlay (`condim=4`, +`ke=4e4`, `kd=4e2`, torsional friction `0.1`, rolling friction `0.01`) on the +gripper and manipulated objects. MuJoCo options affect articulation-owned +contacts; free rigid-body contacts use VBD and need not have identical effects. +The UR5 `pickup.py` and `axis_align.py` tutorials use a 0.013 m +DH-gripper close target for their 5 cm cube under V2 +(`MJVBD_V2_CUBE_CLOSE_QPOS` in `tutorial_utils.py`). The old +0.036 m target relies on contact feedback to stop the fingers; V2's one-way +proxies instead reach that target and squeeze the cube out. This calibration +is specific to that object and gripper, not a general grasp-width mapping. +These two cube tutorials retain native VBD defaults. Their calibrated target +does not make the original oversized command compatible with one-way contact. +The UR5 `move_held_object.py` paper-cup tutorial uses a 0.0115 m candidate close target, +gripper-only sliding friction 4, VBD contact history, and collision matching +`latest`, retaining the native contact alpha. The shared simulation helper +accepts scene-specific `newton_solver_options`; robot creation accepts +`newton_gripper_friction` before spawning. The cup candidate has not achieved repeatable orientation alignment. These are explicit tutorial choices, +not world defaults, and leave the cup and ground materials unchanged. The UR5-only `pour.py` tutorial uses the same contact history and gripper +friction with a 0.013 m cube close target; its V2 initial height includes the +ground's 1 mm contact margin. Other robot selections and physics solvers keep +their existing targets and materials. +The UR5 V2 `place.py` tutorial additionally uses contact alpha 0.5 and arm +damping 1000 with the same cube target, gripper friction, and contact history. +`add_tutorial_robot(arm_damping=...)` authors this drive override before spawn; +other callers retain their configured gains. Release waypoints are unchanged, +and landing orientation remains sensitive to contact variation. +The `examples/sim/demo/scoop_ice.py` scene sets +`vbd_options.rigid_body_contact_buffer_size=256` for dense ice contacts. +This per-body VBD capacity is independent of MuJoCo's `nconmax`/`njmax`; +overflow truncates the contacts used by each affected VBD body. The larger +scene-specific capacity does not establish stable friction grasping. +Explicit cloth, softbody, and differentiable examples keep their selected solvers. Newton's `suppress_warp_kernel_logs=True` suppresses Warp's one-time runtime banner plus module compile/load chatter during manager startup, build, facade initialization, and physics updates, then restores the process-wide setting. @@ -521,6 +579,10 @@ information is controlled separately by `dexsim_startup_info`. EmbodiChain-authored Newton collision shapes use a default margin and gap of `0.001 m` each only when no portable or Newton-native envelope is authored. +The Pour tutorial starts its cube center at half its height. Under V2, Pour +and Place add 1 mm initial clearance for the default ground's contact margin, +avoiding penetration recovery before grasp planning. The global ground +configuration stays unchanged to preserve the pure-MuJoCo locomotion path. `CollisionPropertiesCfg.contact_offset/rest_offset` are portable: Default uses them directly, while the Spawn compiler maps `rest_offset → margin` and `contact_offset - rest_offset → gap`. Both values must be present to derive a @@ -721,6 +783,10 @@ only the generic `newton` and `default` alternatives are eligible; do not guess a solver-specific preset before DexSim has inspected the complete scene. This is the only robot preset selection boundary; do not add a second backend selector to robot configs. +For explicit `mjvbd_v2`, preset priority is `newton_mjvbd_v2`, then +`newton_mujoco_warp` / `newton_mjwarp`, then generic `newton` / `default`. +This preserves established articulation drive tuning while allowing a V2 +override. File-backed rigid objects and articulations share one source-independent physics policy: `asset_physics_mode="preserve"` keeps properties resolved from @@ -1021,3 +1087,15 @@ Default source-physics capture preserves each link's replication collision filter while filling mass/COM properties. Spawn articulation mass-property writes use the live handle's `set_link_inertia` and `set_link_com_pose`; native COM quaternions are converted from EmbodiChain `xyzw` to DexSim `wxyz`. + +## Current MJVBD V2 validation dependency + +The local mixed-scene validation uses an uncommitted DexSim patch that defaults +`mujoco_options.disable_contacts` to `False` while retaining +`use_mujoco_contacts=True`. This runs MuJoCo-Warp collision/contact solving for +its articulation/static compact view alongside Newton/VBD contacts. It differs +from native V2 mixed-mode contact configuration and is not an accepted final +architecture. Mixed locomotion alignment measurements depend on this patch; +they do not establish native single-pipeline mixed-mode equivalence. A second +local DexSim patch fixes convex mesh import coordinates. Neither patch is +contained in this EmbodiChain commit. diff --git a/embodichain/lab/sim/cfg/robot.py b/embodichain/lab/sim/cfg/robot.py index c26dac1325..13f63395d4 100644 --- a/embodichain/lab/sim/cfg/robot.py +++ b/embodichain/lab/sim/cfg/robot.py @@ -349,7 +349,7 @@ def resolve( solver_type = str( solver_cfg.get("solver_type") or solver_cfg.get("class_type") - or "auto" + or "mjvbd_v2" ) else: solver_type = str(getattr(solver_cfg, "solver_type")) @@ -357,6 +357,8 @@ def resolve( solver_candidates = [] if solver_type != "auto": solver_candidates.append(f"newton_{solver_type}") + if solver_type == "mjvbd_v2": + solver_candidates.extend(("newton_mujoco_warp", "newton_mjwarp")) if solver_type == "mujoco_warp": solver_candidates.append("newton_mjwarp") candidates = (*solver_candidates, "newton", "default") diff --git a/embodichain/lab/sim/cfg/simulation.py b/embodichain/lab/sim/cfg/simulation.py index cb0803e1f6..5ace2c3ed1 100644 --- a/embodichain/lab/sim/cfg/simulation.py +++ b/embodichain/lab/sim/cfg/simulation.py @@ -530,14 +530,16 @@ class NewtonPhysicsCfg(PhysicsBackendCfg): Genuine Newton/Warp warnings and errors are not suppressed. """ - solver_cfg: Mapping[str, Any] | NewtonSolverCfg | None = None + solver_cfg: Mapping[str, Any] | NewtonSolverCfg | None = field( + default_factory=lambda: {"solver_type": "mjvbd_v2"} + ) """Optional Newton solver configuration. A mapping is converted to the matching DexSim Newton solver config. Include ``solver_type`` or ``class_type`` to select the solver, then add any - parameters accepted by that DexSim solver config. If omitted, EmbodiChain - preserves DexSim's scene-aware ``AutoSolverCfg`` default. A DexSim build - exporting ``AutoSolverCfg`` is required; no concrete-solver fallback is used. + parameters accepted by that DexSim solver config. The default is + ``mjvbd_v2`` for rigid bodies and articulations. Explicit ``None`` or + ``solver_type="auto"`` preserves DexSim's scene-aware ``AutoSolverCfg``. """ collision_cfg: NewtonCollisionPipelineCfg | Mapping[str, Any] | None = field( @@ -545,10 +547,10 @@ class NewtonPhysicsCfg(PhysicsBackendCfg): ) """Optional external collision-pipeline configuration. - The default preserves external contact generation for ordinary rigid-body - scenes. Set to ``None`` to avoid constructing or executing the external - pipeline, for example when particle solvers use rigid shapes solely as - one-way SDF boundaries. + MJVBD V2 owns collision detection and does not construct this pipeline. + Other solvers use these settings unless explicitly set to ``None``, for + example when particle solvers use rigid shapes solely as one-way SDF + boundaries. """ def __post_init__(self) -> None: @@ -566,6 +568,7 @@ def to_dexsim_cfg( DexUniSolverCfg, FeatherstoneSolverCfg, MJWarpSolverCfg, + MJVBDV2SolverCfg, NewtonCfg, NewtonCollisionPipelineCfg as DexsimNewtonCollisionPipelineCfg, SemiImplicitSolverCfg, @@ -586,6 +589,7 @@ def to_dexsim_cfg( "auto": AutoSolverCfg, "dexuni": DexUniSolverCfg, "mujoco_warp": MJWarpSolverCfg, + "mjvbd_v2": MJVBDV2SolverCfg, "xpbd": XPBDSolverCfg, "semi_implicit": SemiImplicitSolverCfg, "featherstone": FeatherstoneSolverCfg, @@ -606,7 +610,9 @@ def to_dexsim_cfg( ) collision_pipeline_cfg = None - if self.collision_cfg is not None: + if self.collision_cfg is not None and ( + solver_cfg is None or solver_cfg.solver_type != "mjvbd_v2" + ): collision_values = { item.name: getattr(self.collision_cfg, item.name) for item in fields(self.collision_cfg) @@ -655,6 +661,10 @@ def _normalize_newton_solver_type(solver_type: str) -> str: "mujocowarp": "mujoco_warp", "mujocowarpsolver": "mujoco_warp", "mujocowarpsolvercfg": "mujoco_warp", + "mjvbd2": "mjvbd_v2", + "mjvbdv2": "mjvbd_v2", + "mjvbd_v2": "mjvbd_v2", + "mjvbdv2solvercfg": "mjvbd_v2", "dexuni": "dexuni", "dexunisolver": "dexuni", "dexunisolvercfg": "dexuni", @@ -677,7 +687,7 @@ def _normalize_newton_solver_type(solver_type: str) -> str: if key not in aliases: logger.log_error( f"Unsupported Newton solver type '{solver_type}'. " - "Expected one of 'auto', 'dexuni', 'mjwarp', 'xpbd', 'semi_implicit', " + "Expected one of 'auto', 'dexuni', 'mjwarp', 'mjvbd_v2', 'xpbd', 'semi_implicit', " "'featherstone', or 'vbd'." ) return aliases[key] @@ -703,7 +713,7 @@ def _newton_solver_cfg_to_dexsim( configured_solver_type = ( solver_cfg_data.pop("solver_type", None) or solver_cfg_data.pop("class_type", None) - or "auto" + or "mjvbd_v2" ) normalized_solver_type = _normalize_newton_solver_type(str(configured_solver_type)) solver_cfg_type = solver_cfg_map[normalized_solver_type] diff --git a/embodichain/lab/sim/objects/articulation.py b/embodichain/lab/sim/objects/articulation.py index 23c78fcefa..a960831d12 100644 --- a/embodichain/lab/sim/objects/articulation.py +++ b/embodichain/lab/sim/objects/articulation.py @@ -1021,7 +1021,7 @@ def root_link_name(self) -> str: Returns: str: The name of the root link. """ - return self.entities[0].get_root_link_name() + return self._entities[0].get_root_link_name() @cached_property def joint_names(self) -> List[str]: diff --git a/embodichain/lab/sim/objects/backends/collision.py b/embodichain/lab/sim/objects/backends/collision.py index a39a35775a..1f2889669e 100644 --- a/embodichain/lab/sim/objects/backends/collision.py +++ b/embodichain/lab/sim/objects/backends/collision.py @@ -184,9 +184,9 @@ def _from_descriptor(entity: object) -> list[CollisionShapeDesc] | None: dtype=torch.float32, ).reshape(3) shapes: list[CollisionShapeDesc] = [] + # Match native shape queries: disabling contact response keeps geometry + # available to planners, including moving obstacles that exert no impulses. for shape_idx, collision in enumerate(collisions): - if getattr(collision, "enable_collision", True) is False: - continue geometry_type = getattr(collision, "geometry_type", None) geometry_type = getattr(geometry_type, "value", geometry_type) local_pose = torch.as_tensor( diff --git a/embodichain/lab/sim/objects/backends/newton.py b/embodichain/lab/sim/objects/backends/newton.py index 33b1644044..e6a8b94f26 100644 --- a/embodichain/lab/sim/objects/backends/newton.py +++ b/embodichain/lab/sim/objects/backends/newton.py @@ -204,11 +204,14 @@ def _configure_newton_mimic_compliance( backend = get_newton_backend(result.world) if ( backend is None - or backend.solver_type != "mujoco_warp" + or backend.solver_type not in {"mujoco_warp", "mjvbd_v2"} or backend.cfg.requires_grad or (backend.model is not None and backend.model.requires_grad) ): return False + solver = backend.mujoco_solver + if solver is None: + return False relation_names = [ (state_joint_names[child_id], state_joint_names[parent_id]) @@ -284,13 +287,21 @@ def _configure_newton_mimic_compliance( f"Newton model has no mimic constraint for joint pair {error.args[0]}." ) from error - solver = runtime.solver mapping = getattr(solver, "mjc_eq_to_newton_mimic", None) mjw_model = getattr(solver, "mjw_model", None) if mapping is None or mjw_model is None: raise RuntimeError("MuJoCo-Warp did not materialize Newton mimic rows.") mapping_values = np.asarray(mapping.numpy()) + if backend.solver_type == "mjvbd_v2": + from newton import Model + + scene_rows = backend.get_mujoco_index_map( + Model.AttributeFrequency.CONSTRAINT_MIMIC + ).numpy() + mapping_values = mapping_values.copy() + valid = mapping_values >= 0 + mapping_values[valid] = scene_rows[mapping_values[valid]] selected = np.isin(mapping_values, constraint_rows) if int(selected.sum()) != len(constraint_rows): raise RuntimeError( diff --git a/embodichain/lab/sim/physics/newton.py b/embodichain/lab/sim/physics/newton.py index 786ce98fb1..9fb74a16c0 100644 --- a/embodichain/lab/sim/physics/newton.py +++ b/embodichain/lab/sim/physics/newton.py @@ -204,6 +204,6 @@ def supports_contact_sensor(self) -> bool: if runtime_device is None: runtime_device = str(getattr(self._manager, "device", "")) return not ( - solver_type.endswith("mujoco_warp") + solver_type in {"mujoco_warp", "mjvbd_v2"} and runtime_device.lower().startswith("cpu") ) diff --git a/embodichain/lab/sim/sim_manager.py b/embodichain/lab/sim/sim_manager.py index 19d68cf313..3f70fc9dfc 100644 --- a/embodichain/lab/sim/sim_manager.py +++ b/embodichain/lab/sim/sim_manager.py @@ -537,7 +537,7 @@ def __init__( self._requested_renderer = sim_config.render_cfg.renderer solver_cfg = getattr(sim_config.physics_cfg, "solver_cfg", None) self._requested_solver = str( - solver_cfg.get("solver_type", solver_cfg.get("class_type", "auto")) + solver_cfg.get("solver_type", solver_cfg.get("class_type", "mjvbd_v2")) if isinstance(solver_cfg, Mapping) else getattr(solver_cfg, "solver_type", "auto") ) @@ -4427,6 +4427,7 @@ def reset_objects_state( None, "auto", "mujoco_warp", + "mjvbd_v2", } if ( use_coordinated_newton_clear @@ -4531,6 +4532,9 @@ def export_usd(self, fpath: str) -> bool: bool: True if export is successful, False otherwise. """ try: + # The optional USD kit registers the export methods on DexSim Env. + import dexsim.kit.usd + self._env.export_to_usd_file(fpath) logger.log_info(f"Simulation scene exported to USD file: {fpath}") return True @@ -4647,6 +4651,14 @@ def _deferred_destroy(self) -> None: "_robots", ): for asset in getattr(self, registry_name, {}).values(): + # Parsed material wrappers must die before their native renderer. + for material_attr in ( + "_visual_material", + "_original_visual_material", + "_original_visual_material_inst", + ): + if hasattr(asset, material_attr): + setattr(asset, material_attr, []) if hasattr(asset, "_data"): asset._data = None if hasattr(asset, "_spawn_result"): diff --git a/embodichain/lab/sim/spawn/descriptors.py b/embodichain/lab/sim/spawn/descriptors.py index beba18ddbc..ac596a0d62 100644 --- a/embodichain/lab/sim/spawn/descriptors.py +++ b/embodichain/lab/sim/spawn/descriptors.py @@ -1168,9 +1168,13 @@ def _compile_joint_properties( if newton_solver_type is None else newton_solver_type.replace("-", "_").lower() ) - if normalized_solver not in {None, "auto", "mujoco_warp", "mjwarp"} and any( - mode == 1 for mode in joint_target_modes.values() - ): + if normalized_solver not in { + None, + "auto", + "mujoco_warp", + "mjwarp", + "mjvbd_v2", + } and any(mode == 1 for mode in joint_target_modes.values()): warnings.warn( f"Newton solver {newton_solver_type!r} does not consume " "joint_target_mode. POSITION is emulated with its configured " diff --git a/embodichain_tasks/configs/components/execution_policies/trajectory_open_loop_slow.yaml b/embodichain_tasks/configs/components/execution_policies/trajectory_open_loop_slow.yaml new file mode 100644 index 0000000000..3ab4ee0fa9 --- /dev/null +++ b/embodichain_tasks/configs/components/execution_policies/trajectory_open_loop_slow.yaml @@ -0,0 +1,29 @@ +policy_id: trajectory_open_loop_slow_v1 +preset_id: trajectory + +requires: + embodiment_contract: single_arm_parallel_gripper + +motion: + strategy: ik_interp + velocity_targets: auto + # Allow velocity-limited articulated objects to follow before releasing. + sample_count: 80 + dynamic_collision_mode: "off" + +tracking: + kind: timed + +recovery: + max_replans: 0 + max_action_retries: 0 + +workflow_recovery: + max_recovery_attempts: 0 + +runner: + minimum_cycle_time: 0.0 + hold_on_completion: false + hold_during_effect_verification: false + +effect_assurance: projected diff --git a/embodichain_tasks/configs/tasks/manipulation/open_drawer/env.newton.yaml b/embodichain_tasks/configs/tasks/manipulation/open_drawer/env.newton.yaml index 083537e0cc..fd5905b07c 100644 --- a/embodichain_tasks/configs/tasks/manipulation/open_drawer/env.newton.yaml +++ b/embodichain_tasks/configs/tasks/manipulation/open_drawer/env.newton.yaml @@ -13,15 +13,15 @@ physics_config: num_substeps: 20 collision_cfg: null solver_cfg: - solver_type: mujoco_warp - solver: newton - integrator: implicitfast - iterations: 20 - ls_iterations: 100 - cone: elliptic - impratio: 1000.0 - use_mujoco_contacts: true - enable_multiccd: true + solver_type: mjvbd_v2 + mujoco_options: + solver: newton + integrator: implicitfast + iterations: 20 + ls_iterations: 100 + cone: elliptic + impratio: 1000.0 + enable_multiccd: true simulation: light: diff --git a/embodichain_tasks/configs/tasks/manipulation/open_drawer/task.ur5.newton.yaml b/embodichain_tasks/configs/tasks/manipulation/open_drawer/task.ur5.newton.yaml index 9783c94c9f..c1890df4ba 100644 --- a/embodichain_tasks/configs/tasks/manipulation/open_drawer/task.ur5.newton.yaml +++ b/embodichain_tasks/configs/tasks/manipulation/open_drawer/task.ur5.newton.yaml @@ -6,7 +6,7 @@ environment: task_program: program: task_program/program.yaml integration: task_program/integration.yaml - execution_policy: ../../../components/execution_policies/trajectory_open_loop.yaml + execution_policy: ../../../components/execution_policies/trajectory_open_loop_slow.yaml embodiment: component: ../../../components/embodiments/ur5_dh_pgi_140_80.yaml diff --git a/embodichain_tasks/configs/tasks/manipulation/repeated_pick_place/env.newton.yaml b/embodichain_tasks/configs/tasks/manipulation/repeated_pick_place/env.newton.yaml index 2bf2375612..10209b420f 100644 --- a/embodichain_tasks/configs/tasks/manipulation/repeated_pick_place/env.newton.yaml +++ b/embodichain_tasks/configs/tasks/manipulation/repeated_pick_place/env.newton.yaml @@ -15,15 +15,15 @@ physics_config: num_substeps: 20 collision_cfg: null solver_cfg: - solver_type: mujoco_warp - solver: newton - integrator: implicitfast - iterations: 20 - ls_iterations: 100 - cone: elliptic - impratio: 1000.0 - use_mujoco_contacts: true - enable_multiccd: true + solver_type: mjvbd_v2 + mujoco_options: + solver: newton + integrator: implicitfast + iterations: 20 + ls_iterations: 100 + cone: elliptic + impratio: 1000.0 + enable_multiccd: true simulation: light: diff --git a/embodichain_tasks/configs/tasks/manipulation/repeated_pick_place/task.ur5.newton.yaml b/embodichain_tasks/configs/tasks/manipulation/repeated_pick_place/task.ur5.newton.yaml index 429264f5a1..166663208f 100644 --- a/embodichain_tasks/configs/tasks/manipulation/repeated_pick_place/task.ur5.newton.yaml +++ b/embodichain_tasks/configs/tasks/manipulation/repeated_pick_place/task.ur5.newton.yaml @@ -6,7 +6,7 @@ environment: task_program: program: task_program/program.yaml integration: task_program/integration.yaml - execution_policy: ../../../components/execution_policies/trajectory_open_loop.yaml + execution_policy: ../../../components/execution_policies/trajectory_open_loop_slow.yaml embodiment: component: ../../../components/embodiments/ur5_dh_pgi_140_80.yaml diff --git a/examples/sim/demo/grasp_cup_to_caffe.py b/examples/sim/demo/grasp_cup_to_caffe.py index aa3fff4636..7e07355534 100644 --- a/examples/sim/demo/grasp_cup_to_caffe.py +++ b/examples/sim/demo/grasp_cup_to_caffe.py @@ -92,13 +92,9 @@ def initialize_simulation(args) -> SimulationManager: """ physics_cfg = physics_cfg_for_backend(args.physics) if args.physics == "newton": - # This contact-heavy URDF scene needs Newton's collision pipeline; - # MuJoCo's native contact path is not reliable for these convex meshes. physics_cfg.solver_cfg = { - "solver_type": "mujoco_warp", - "use_mujoco_contacts": False, - "nconmax": 16384, - "njmax": 65536, + "solver_type": "mjvbd_v2", + "mujoco_options": {"nconmax": 16384, "njmax": 65536}, } config = SimulationManagerCfg( @@ -217,7 +213,8 @@ def create_table(sim: SimulationManager) -> RigidObject: attrs=RigidBodyPhysicsCfg( mass_props=MassPropertiesCfg(mass=0.5), ), - body_type="kinematic", + # This fixture never moves; static shapes also enter V2's MuJoCo view. + body_type="static", init_pos=[1.1, -0.5, 0.08], init_rot=[0.0, 0.0, 0.0], ) diff --git a/examples/sim/demo/scoop_ice.py b/examples/sim/demo/scoop_ice.py index 8b05f43a0e..0f972e38c1 100644 --- a/examples/sim/demo/scoop_ice.py +++ b/examples/sim/demo/scoop_ice.py @@ -79,9 +79,12 @@ def initialize_simulation(args): """ physics_cfg = physics_cfg_for_backend(args.physics) if args.physics == "newton": - # Hundreds of free bodies make dense Newton Hessian factorization - # expensive. CG avoids that factorization while retaining contacts. - physics_cfg.solver_cfg = {"solver_type": "mujoco_warp", "solver": "cg"} + physics_cfg.solver_cfg = { + "solver_type": "mjvbd_v2", + "mujoco_options": {"solver": "cg"}, + # Dense ice contacts exceed VBD's default per-body capacity of 64. + "vbd_options": {"rigid_body_contact_buffer_size": 256}, + } config = SimulationManagerCfg( headless=True, device=args.device, diff --git a/examples/sim/motion/planners/curobo_planner.py b/examples/sim/motion/planners/curobo_planner.py index 11b7e3f373..a983deb940 100644 --- a/examples/sim/motion/planners/curobo_planner.py +++ b/examples/sim/motion/planners/curobo_planner.py @@ -502,9 +502,9 @@ def _build_scene( init_rot=(0.0, 0.0, 0.0), ) ) + sim.prepare() finally: demo_block_mesh_path.unlink(missing_ok=True) - sim.prepare() if robot_type == "w1": # Keep the W1-specific IK diagnostic batched so it remains useful when @@ -861,7 +861,10 @@ def main(args: argparse.Namespace | None = None) -> None: binding, motion_policy, ), - ) + ), + context=engine.initial_context( + control_dt=sim.sim_config.physics_dt * args.step_repeat, + ), ) success = compiled.plan_success trajectory = compiled.trajectory.positions @@ -899,7 +902,10 @@ def main(args: argparse.Namespace | None = None) -> None: binding, motion_policy, ), - ) + ), + context=engine.initial_context( + control_dt=sim.sim_config.physics_dt * args.step_repeat, + ), ) success = compiled.plan_success trajectory = compiled.trajectory.positions diff --git a/examples/sim/motion/trajectory_velocity_tracking.py b/examples/sim/motion/trajectory_velocity_tracking.py index 9d1145ad12..8772c98f67 100644 --- a/examples/sim/motion/trajectory_velocity_tracking.py +++ b/examples/sim/motion/trajectory_velocity_tracking.py @@ -396,8 +396,7 @@ def main(args: argparse.Namespace | None = None) -> None: robot: Robot = sim.add_robot( FrankaPandaCfg.from_dict({"uid": "tracking_franka"}) ) - if sim.is_use_gpu_physics: - sim.init_gpu_physics() + sim.prepare() if not args.headless: sim.open_window() common_initial_qpos = robot.get_qpos().clone() diff --git a/outputs/validation/mjvbd_v2/MJVBDV2_issues.md b/outputs/validation/mjvbd_v2/MJVBDV2_issues.md new file mode 100644 index 0000000000..56245a63af --- /dev/null +++ b/outputs/validation/mjvbd_v2/MJVBDV2_issues.md @@ -0,0 +1,114 @@ +# MJVBDV2 接入问题记录 + +更新日期:2026-09-20 + +本文记录影响 MJVBDV2 替换现有 solver 的机制问题、证据和验证边界。布料、软体不在本次范围内。“对齐”指更换 solver 后行为接近,不等于程序正常退出,也不等于某个任务偶然成功。旧 solver 指 Newton 后端的 `mujoco_warp`;Default 后端的对照会单独注明。 + +**当前接入已打通主要接口和状态生命周期,但尚不能作为保持原有抓取控制方式不变的通用替代。最关键的限制是:VBD 物体的接触反力不回传给 articulation。** 针对物体标定夹爪目标可以改善部分任务,不能补齐这一机制。 + +## 1. 单向耦合改变了位置夹紧的工作方式 + +MJVBDV2 混合模式中,MuJoCo 推进机器人关节,VBD 推进自由刚体。机器人在 VBD 中是按给定姿态运动的碰撞代理,VBD 对物体计算的反力不会传回机器人。 + +在具有双向接触响应的系统中,夹爪位置驱动允许把目标设得比物体允许的开口更闭合。手指被物体挡住,位置误差继续产生驱动力,驱动力与接触反力形成平衡。因此,“没有到达夹爪目标”可以是正常夹紧状态,并非控制失败。 + +当前单向路径没有这个平衡:被抓取的 VBD 物体无法阻止手指闭合。手指仍受自身驱动、力矩限制和 MuJoCo 可见接触影响,但缺少这件物体的反力。当两指间隙小于物体尺寸时,VBD 只能尝试移动或转动物体,可能出现穿透、挤出、滑转或抖动。 + +已有直接证据:同一抓取命令下,旧 MuJoCo 的手指被物体挡在约 0.012 m,新路径则继续到约 0.036 m。这些数值是关节位置,不是夹口宽度。调小闭合目标后能够恢复部分抓取,但控制命令已经改变。 + +**影响与边界:** + +- 依赖“过闭合目标+接触反力”的位置夹紧控制,不能直接沿用;物体负载对机械臂的反作用也缺失。 +- 增加摩擦、迭代或减小步长,可以改善现有接触求解,无法产生缺失的反力回传。 +- 按尺寸标定闭合目标只是一种场景适配,会对几何、姿态、碰撞余量和控制误差敏感,不能视为通用闭合策略。 +- 若要求保留原有接触驱动的控制行为,需要让这类接触具有双向动力学响应,例如由同一求解器处理,或采用经过稳定性验证的双向耦合。简单延迟一帧回传力并不自动保证稳定。 +- 根据接触主动停止闭合属于另一种控制策略,也不能完整恢复物体对机械臂的负载反馈。 + +这是已确认的结构性限制,但不能据此把所有任务失败都归为同一个原因;场景几何和规划问题仍需独立排查。 + +## 2. 动态刚体的加入会改变 articulation 的接触路径 + +纯 articulation 与静态地面场景可以走纯 MuJoCo 分支。加入 VBD 动态刚体后,原生混合分支关闭 MuJoCo 接触,同时又不回传 VBD 反力,因此即使新增物体在远处,也可能让机器人失去地面支撑。这是求解路径变化,不是机器人控制参数突然失效。 + +本地实验补丁把混合模式的 `disable_contacts` 默认改为 `False`,保留 `use_mujoco_contacts=True`,恢复了 MuJoCo 紧凑模型内的机器人、静态环境及允许的 articulation 间接触。**它实际启用了 MuJoCo-Warp 和 Newton 两套碰撞管线,偏离原生 V2 混合模式的接触配置。** + +自由刚体仍不进入 MuJoCo 模型,VBD 侧机器人仍不接收反力,所以双管线不等于同一对接触重复施力,也没有解决第 1 节的夹紧限制。不过,两套管线带来的开销、参数差异和查询范围需要分别处理;本方案尚不是确认后的最终架构。 + +若要求只使用 Newton 碰撞,同时保留 articulation 的接触响应,需要把合适的接触映射给 MuJoCo 求解。当前 V2 尚未接通此路径,直接设 `use_mujoco_contacts=False` 会被拒绝。 + +另外,独立 kinematic 物体不会自动进入上述 MuJoCo 接触模型。固定设施可按真实用途声明为 static;真正运动的 kinematic 物体不能用这种替换来解决支持缺口。 + +## 3. 同名接触参数并不代表相同的物理作用 + +切换求解器后,必须核对参数实际被谁消费,不能只看配置值相同: + +| 参数或机制 | 当前差异及影响 | +| --- | --- | +| 接触余量 margin | MuJoCo 原生 NATIVECCD/MULTICCD 路径会把相关形状的非零 margin 清零,VBD 仍保留;接触建立和释放时机可能不同。启动警告反映真实参数变化,隐藏警告不等于修复。 | +| 扭转、滚动摩擦 | 当前 VBD 刚体接触不读取独立的扭转、滚动摩擦系数,不能照搬 MuJoCo 的相应约束。多个接触点的切向力仍可产生抗转力矩,不等于完全没有抗转能力。 | +| 滑动摩擦、刚度与阻尼 | VBD 接触对的滑动摩擦取几何平均,刚度和阻尼取算术平均;应比较最终接触对,而非只比较手指字段。 | +| 接触阻尼 kd | 当前硬接触中主要抵抗相互接近的法向运动,不是通用的切向止滑或角阻尼。 | +| friction_epsilon | 当前默认刚体硬接触路径不消费该项,修改它不会改变这条路径的摩擦。 | +| 刚体 linear_damping / angular_damping | 现有 Newton 路径中的这些旧属性只保留记录,没有等价施加到运动上;关节驱动 damping 则实际参与求解。此限制也影响旧 Newton MuJoCo,不能归为 V2 独有回归。 | + +这解释了为什么复制旧参数不能保证行为相同,但不意味着全部差异都能靠调参消除。尤其是摩擦和接触阻尼无法替代双向反力。 + +## 4. 接触观测尚未形成统一的力反馈接口 + +| 路径 | 已确认能力 | +| --- | --- | +| 纯 MuJoCo | 已适配形状编号映射,可查询接触几何、法向及摩擦冲量,并做过行走数值对照。 | +| 混合模式 | 可查询接触几何,但尚未统一合并 MuJoCo 与 VBD 接触,也未提供与纯分支等价的冲量、力反馈。占位零值不能解释为真实无力。 | + +“查到碰撞”不等于“有可用于控制或奖励的接触力”。冲量换算为力需要使用对应物理子步时长,不能使用策略更新间隔。即使未来能查询 VBD 接触力,查询接口本身也不会使它回传给 articulation。 + +另有两项观测限制: + +- 当前 Newton 的 `get_qf()` 在位置驱动下读的是直接输入的力矩命令,不包含 PD 实际输出。全零结果不能证明电机力矩一致,也不能直接用于能耗奖励;这不是 V2 独有问题。 +- 部分混合接触记录出现零法向且伴有非零约束乘子。这些条目不能用于推导穿透或物理力;尚未确定异常产生于碰撞生成、读取时机还是内部处理,也未证明它是任务失败的原因。 + +## 5. 接触容量与碰撞成本影响正确性和可用性 + +VBD 单刚体接触容量与 MuJoCo 的接触、约束容量是不同配置。容量不足会截断参与求解的接触,不只是降低性能;仅扩大 MuJoCo 缓冲区不能解决 VBD 溢出。密集接触验证已观察到单刚体需求超过默认 64,扩大到 256 后完整运行无溢出,但受载滑转仍存在。因此不能用发生截断的结果推断单向耦合的能力上限,也不能把扩容当作夹持问题的完整修复。 + +性能方面,在双臂、桌子和两个动态物体的初始场景中,关闭窗口、排除规划与录像并完成预热后,同样 20 个子步下,推进 0.08 秒仿真:旧 MuJoCo 约需 0.10 秒,V2 约需 0.38 秒。CUDA Graph 已启用。阶段测量显示主要瓶颈为 Newton 的 GJK/MPR 凸体精细碰撞,每个子步重复执行会放大成本。 + +这是特定场景的步进测量,不是全任务平均值或所有场景的固定倍率。优先方向是检查碰撞对过滤和凸体复杂度;降低子步数需要重新验证接触效果。本地已准备该 demo 从 20 降到 5 的改动,但尚未完成完整速度和效果复验,不在本次文档提交内。 + +## 6. 资产、规划与执行差异必须从 solver 差异中分离 + +已有对照发现以下问题会同时影响新旧 solver: + +- 单凸包重新读取 GLB 时采用了不同坐标约定,造成外观和碰撞几何不一致。本地导入补丁改为使用已导入顶点;仅检查画面不够,还需核对实际碰撞形状。 +- 初始穿透、物体尚未落稳就规划,以及目标姿态或路径与桌子相交,会改变抓取初态或阻挡机械臂。双臂同轨迹对照已确认新旧都出现桌子阻挡,不能把此类偏差全归为 VBD。 +- 缓存轨迹、重新规划、不同夹爪命令、释放等待和播放时序会改变实验条件。增加等待或改变目标后成功,是适配结果,不能宣称原控制命令直接替换已对齐。 + +因此验证应分别报告:相同输入下的物理差异、适配后的完整任务效果,以及重复运行或初态变化下的稳定性。两边都失败不代表自动对齐,一次成功也不代表稳定兼容。 + +## 已修复的接入问题 + +以下补丁解决了接口或状态同步错误,不改变单向耦合的基本性质: + +| 类别 | 已完成处理 | +| --- | --- | +| 内部 MuJoCo 访问与编号 | 接通内部 solver,适配 mimic、接触形状编号和 reset。 | +| 状态所有权 | 限制 FK 更新范围,避免旧关节状态覆盖 VBD 自由刚体位置;修正运动代理姿态保留。 | +| 历史状态 | 瞬移和 CUDA Graph 预热回滚时同步内部历史,避免物体异常续移。 | +| 接触缓冲区 | 关闭 MuJoCo 接触时保留必要的非零容量,避免特定摩擦路径除零;这与后续额外开启接触是两项不同改动。 | +| 场景生命周期 | 适配部分/全部 reset,以及同名资产删除重建,支持连续 episode。 | + +## 验证结论与未覆盖范围 + +- **行走:** ANYmal-C 与静态地面/平台已有正常行走和接触反馈对照,同动作关节位置最大差约 1.1e-6 rad,足端法向力分量最大差约 0.015 N,与旧 solver 自身重复差异同量级。纯 MuJoCo 路线与混合路线必须区分;混合地面支撑结果依赖额外开启 MuJoCo 原生接触,不能作为原生混合配置已对齐的证据。未验证 PPO 从零训练收敛、完整生产 reward/done 或复杂地形。 +- **操作:** 抓起、倾倒、放置和托盘搬运已有完整改善结果;纸杯搬运、装配、双臂放置、舀冰等仍未完成稳定对齐。剩余问题涉及夹持与释放机制、几何/路径和基线稳定性,不能概括为“几个 demo 参数没调好”。 +- **Default 对照:** Slide 采用两后端相同的有效关节阻尼后已通过用户效果验收;这不是旧 Newton MuJoCo 与 V2 的严格数值对照。 +- **暂未完成:** Twist 按要求跳过,其早期结果未严格固定完整动作序列;NeuralPlanner 缺少匹配模型。通用刚体约束和 USD 完整物理导出属于既有 Newton 支持缺口。 + +历史覆盖包括 15 项内置原子技能、18 个原子教程和 26 个其他 Newton 示例入口。不是所有入口都完成任务,也没有覆盖所有机器人、初态与规划器组合。后续补丁只做了针对性复测,不能把早期覆盖数量当作最新版本的全量通过率。 + +## 版本与复现依赖 + +- EmbodiChain:[draft PR #645](https://github.com/DexForce/EmbodiChain/pull/645)。本文整理截至 2026-09-20 的证据;本次文档更新不代表重新完成全部实验。 +- 已推送 DexSim 适配补丁:[MR !1345](http://192.168.3.16/Engine/dexsim/-/merge_requests/1345),`MJVBDV2` 分支提交 `f7d60c2a2`。 +- **后续验证另依赖两项仍未提交、未推送的 DexSim 本地代码补丁:混合模式开启 MuJoCo 原生接触,以及单凸包导入坐标修复。仅检出上述 DexSim 提交与 EmbodiChain PR,不能保证复现这些后续结果。** 这些代码已用于本地安装包,但不在 EmbodiChain 仓库提交范围内。 +- 没有新增仓库测试或 benchmark。历史参数筛选、测量和详细日志保存在本地 `outputs/validation/mjvbd_v2/` 下的 `report.md`、`locomotion_alignment/report.md` 和 `coupling_tuning/round2.md`;这些产物未随 PR 发布。本文保留综合结论,逐次实验历史仍可从本地记录与 Git 历史追溯。 diff --git a/scripts/tutorials/atomic_action/axis_align.py b/scripts/tutorials/atomic_action/axis_align.py index 912f73934d..c805e4d2fe 100644 --- a/scripts/tutorials/atomic_action/axis_align.py +++ b/scripts/tutorials/atomic_action/axis_align.py @@ -42,6 +42,8 @@ from embodichain.lab.sim.shapes import CubeCfg from embodichain.utils import logger from scripts.tutorials.atomic_action.tutorial_utils import ( + DEFAULT_GRIPPER_CLOSE_QPOS, + MJVBD_V2_CUBE_CLOSE_QPOS, add_ur5_gripper_robot, clone_local_pose_from_first_env, create_antipodal_semantics, @@ -149,7 +151,14 @@ def main() -> None: sim = create_tutorial_simulation(args) robot = add_ur5_gripper_robot(sim, tcp_z=0.15) obj = create_align_object(sim) - hand_open, hand_close = get_hand_open_close_qpos(robot) + hand_open, hand_close = get_hand_open_close_qpos( + robot, + close_qpos=( + MJVBD_V2_CUBE_CLOSE_QPOS + if args.robot == "ur5" and sim.physics.solver_type == "mjvbd_v2" + else DEFAULT_GRIPPER_CLOSE_QPOS + ), + ) initialize_pre_pick_robot_pose(robot, obj, hand_open) motion_gen = create_toppra_motion_generator( robot, diff --git a/scripts/tutorials/atomic_action/coordinated_pickment.py b/scripts/tutorials/atomic_action/coordinated_pickment.py index 33c62d5e03..9169edc36b 100644 --- a/scripts/tutorials/atomic_action/coordinated_pickment.py +++ b/scripts/tutorials/atomic_action/coordinated_pickment.py @@ -161,6 +161,8 @@ class PickmentObjectPreset: PICKMENT_HAND_INTERP_STEPS = 10 PICKMENT_HOLD_STEPS = 4 ROBOTIQ_2F_140_CLOSE_QPOS = 0.7 +# Calibrated for the plastic tray and UR5/DH PGI one-way contact. +MJVBD_V2_TRAY_CLOSE_QPOS = 0.023 TRAJECTORY_SIM_STEPS = 4 @@ -189,6 +191,8 @@ def parse_arguments() -> argparse.Namespace: def create_dual_robot( sim: SimulationManager, robot_type: TutorialRobot, + *, + newton_gripper_friction: float | None = None, ) -> Robot: """Create the selected dual-arm robot with its matching grippers.""" return add_dual_tutorial_robot( @@ -198,6 +202,7 @@ def create_dual_robot( urdf_name=f"dual_{robot_type}_coordinated_pickment", tcp_z=GRIPPER_TCP_Z, solver="pytorch", + newton_gripper_friction=newton_gripper_friction, ) @@ -395,6 +400,12 @@ def run_coordinated_pickment_demo( hand_close_qpos = ( ROBOTIQ_2F_140_CLOSE_QPOS if args.robot == "ur10" else preset.hand_close_qpos ) + if ( + args.robot == "ur5" + and args.object == "plastic_tray" + and sim.physics.solver_type == "mjvbd_v2" + ): + hand_close_qpos = MJVBD_V2_TRAY_CLOSE_QPOS left_open, left_close = get_hand_open_close_qpos( robot, hand_control_part="left_hand", @@ -527,8 +538,27 @@ def main() -> None: sim = create_tutorial_simulation( args, arena_space=3.0, + newton_solver_options=( + { + "vbd_options": {"rigid_contact_history": True}, + "collision_options": {"contact_matching": "latest"}, + } + if args.physics == "newton" + and args.robot == "ur5" + and args.object == "plastic_tray" + else None + ), + ) + use_vbd_grasp = ( + args.robot == "ur5" + and args.object == "plastic_tray" + and sim.physics.solver_type == "mjvbd_v2" + ) + robot = create_dual_robot( + sim, + args.robot, + newton_gripper_friction=4.0 if use_vbd_grasp else None, ) - robot = create_dual_robot(sim, args.robot) run_coordinated_pickment_demo(args, sim, robot) diff --git a/scripts/tutorials/atomic_action/coordinated_placement.py b/scripts/tutorials/atomic_action/coordinated_placement.py index 6bd7c08e3f..362ef304a3 100644 --- a/scripts/tutorials/atomic_action/coordinated_placement.py +++ b/scripts/tutorials/atomic_action/coordinated_placement.py @@ -235,7 +235,8 @@ def create_table(sim: SimulationManager) -> RigidObject: static_friction=0.95, restitution=0.01, ), - body_type="kinematic", + # This fixture never moves; static shapes also enter V2's MuJoCo view. + body_type="static", init_pos=list(TABLE_INIT_POS), init_rot=list(TABLE_INIT_ROT), ) diff --git a/scripts/tutorials/atomic_action/hand_over.py b/scripts/tutorials/atomic_action/hand_over.py index 8b06150de8..8a401fb1a6 100644 --- a/scripts/tutorials/atomic_action/hand_over.py +++ b/scripts/tutorials/atomic_action/hand_over.py @@ -19,6 +19,7 @@ from __future__ import annotations import argparse +import math import sys from pathlib import Path @@ -88,6 +89,9 @@ # --------------------------------------------------------------------------- HAND_CLOSE_QPOS = 0.04 +MJVBD_V2_CAN_LEFT_CLOSE_QPOS = 0.007 +MJVBD_V2_CAN_RIGHT_CLOSE_QPOS = 0.0055 +MJVBD_V2_RELEASE_SETTLE_DURATION = 1.0 HANDOVER_SAMPLE_INTERVAL = 220 HANDOVER_HAND_INTERP_STEPS = 10 HANDOVER_PRE_GRASP_DISTANCE = 0.08 @@ -119,6 +123,8 @@ def parse_arguments() -> argparse.Namespace: def create_dual_robot( sim: SimulationManager, robot_type: TutorialRobot, + *, + newton_gripper_friction: float | None = None, ) -> Robot: """Create the selected dual-arm robot with its matching grippers.""" return add_dual_tutorial_robot( @@ -131,6 +137,7 @@ def create_dual_robot( hand_stiffness=1e3, hand_damping=1e2, hand_max_effort=1e4, + newton_gripper_friction=newton_gripper_friction, ) @@ -204,11 +211,20 @@ def run_handover_demo( planner=getattr(args, "planner", "trapezoidal"), ) + use_vbd_grasp = ( + args.robot == "ur5" + and not args.is_horizontal + and sim.physics.solver_type == "mjvbd_v2" + ) left_open, left_close = get_hand_open_close_qpos( - robot, hand_control_part="left_hand", close_qpos=HAND_CLOSE_QPOS + robot, + hand_control_part="left_hand", + close_qpos=MJVBD_V2_CAN_LEFT_CLOSE_QPOS if use_vbd_grasp else HAND_CLOSE_QPOS, ) right_open, right_close = get_hand_open_close_qpos( - robot, hand_control_part="right_hand", close_qpos=HAND_CLOSE_QPOS + robot, + hand_control_part="right_hand", + close_qpos=MJVBD_V2_CAN_RIGHT_CLOSE_QPOS if use_vbd_grasp else HAND_CLOSE_QPOS, ) final_pose = torch.eye(4, dtype=torch.float32) @@ -285,6 +301,17 @@ def run_handover_demo( if wait_for_user: input("Press Enter to execute the handover...") + release_start = compiled.segment(0, "receive_release").start + + def settle_before_release(step_index: int, _total_steps: int) -> None: + if step_index == release_start - 1: + # Let the receiving arm stop before opening the gripper. + sim.update( + step=math.ceil( + MJVBD_V2_RELEASE_SETTLE_DURATION / sim.sim_config.physics_dt + ) + ) + replay_trajectory( sim, robot, @@ -293,6 +320,7 @@ def run_handover_demo( video_prefix="handover_auto_play", hold_steps=0, trajectory_sim_steps=TRAJECTORY_SIM_STEPS, + on_trajectory_step=settle_before_release if use_vbd_grasp else None, look_at=HANDOVER_RECORD_LOOK_AT, ) if wait_for_user: @@ -305,8 +333,27 @@ def main() -> None: sim = create_tutorial_simulation( args, arena_space=3.0, + newton_solver_options=( + { + "vbd_options": {"rigid_contact_history": True}, + "collision_options": {"contact_matching": "latest"}, + } + if args.physics == "newton" + and args.robot == "ur5" + and not args.is_horizontal + else None + ), + ) + use_vbd_grasp = ( + args.robot == "ur5" + and not args.is_horizontal + and sim.physics.solver_type == "mjvbd_v2" + ) + robot = create_dual_robot( + sim, + args.robot, + newton_gripper_friction=4.0 if use_vbd_grasp else None, ) - robot = create_dual_robot(sim, args.robot) run_handover_demo(args, sim, robot) serve_tutorial_scene(sim, args) diff --git a/scripts/tutorials/atomic_action/move_held_object.py b/scripts/tutorials/atomic_action/move_held_object.py index 4341110e04..9c164e630a 100644 --- a/scripts/tutorials/atomic_action/move_held_object.py +++ b/scripts/tutorials/atomic_action/move_held_object.py @@ -27,6 +27,7 @@ sys.path.insert(0, str(_REPO_ROOT)) import torch +import trimesh from embodichain.data import get_data_path from embodichain.lab.sim.atomic_actions import ( @@ -43,6 +44,7 @@ from embodichain.lab.sim.shapes import MeshCfg, MeshCollisionCfg from embodichain.utils import logger from scripts.tutorials.atomic_action.tutorial_utils import ( + DEFAULT_GRIPPER_CLOSE_QPOS, add_tutorial_robot, broadcast_pose_batch, clone_local_pose_from_first_env, @@ -69,6 +71,8 @@ MOVE_HELD_OBJECT_SAMPLE_INTERVAL = 120 HAND_INTERP_STEPS = 12 POST_TRAJECTORY_STEPS = 240 +# Candidate for this cup and UR5/DH PGI; transport orientation remains unaligned. +MJVBD_V2_CUP_CLOSE_QPOS = 0.0115 def parse_arguments() -> argparse.Namespace: @@ -82,11 +86,16 @@ def parse_arguments() -> argparse.Namespace: def create_pick_object(sim) -> RigidObject: """Create and settle the paper cup used by the tutorial.""" + mesh = trimesh.load_mesh(get_data_path(OBJECT_MESH_PATH), process=False) + # Author cup proportions in the mesh; physical body scale must be uniform. + mesh.apply_scale((0.75, 0.75, 1.0)) obj = sim.add_rigid_object( cfg=RigidObjectCfg( uid="paper_cup", shape=MeshCfg( - fpath=get_data_path(OBJECT_MESH_PATH), + vertices=mesh.vertices, + triangles=mesh.faces, + normals=mesh.vertex_normals, collision=MeshCollisionCfg( approximation="convex_decomposition", max_hulls=16, @@ -99,7 +108,6 @@ def create_pick_object(sim) -> RigidObject: newton_contact=sim.is_newton_backend, ), init_pos=[*OBJECT_XY, OBJECT_INITIAL_Z], - body_scale=(0.75, 0.75, 1.0), ) ) sim.prepare() @@ -124,15 +132,35 @@ def make_object_target_pose(device: torch.device) -> torch.Tensor: def main() -> None: """Plan MoveEndEffector -> PickUp -> MoveHeldObject.""" args = parse_arguments() - sim = create_tutorial_simulation(args) - robot = add_tutorial_robot(sim, args.robot) + sim = create_tutorial_simulation( + args, + newton_solver_options=( + { + "vbd_options": {"rigid_contact_history": True}, + "collision_options": {"contact_matching": "latest"}, + } + if args.physics == "newton" and args.robot == "ur5" + else None + ), + ) + use_vbd_grasp = args.robot == "ur5" and sim.physics.solver_type == "mjvbd_v2" + robot = add_tutorial_robot( + sim, + args.robot, + newton_gripper_friction=4.0 if use_vbd_grasp else None, + ) obj = create_pick_object(sim) sim.prepare() motion_gen = create_curobo_motion_generator( robot, planner=getattr(args, "planner", "trapezoidal"), ) - hand_open, hand_close = get_hand_open_close_qpos(robot) + hand_open, hand_close = get_hand_open_close_qpos( + robot, + close_qpos=( + MJVBD_V2_CUP_CLOSE_QPOS if use_vbd_grasp else DEFAULT_GRIPPER_CLOSE_QPOS + ), + ) engine = create_simulation_atomic_action_engine( motion_generator=motion_gen, diff --git a/scripts/tutorials/atomic_action/pickup.py b/scripts/tutorials/atomic_action/pickup.py index e35bc902a5..1313bd3cbe 100644 --- a/scripts/tutorials/atomic_action/pickup.py +++ b/scripts/tutorials/atomic_action/pickup.py @@ -40,6 +40,8 @@ from embodichain.lab.sim.shapes import CubeCfg from embodichain.utils import logger from scripts.tutorials.atomic_action.tutorial_utils import ( + DEFAULT_GRIPPER_CLOSE_QPOS, + MJVBD_V2_CUBE_CLOSE_QPOS, add_tutorial_robot, clone_local_pose_from_first_env, create_antipodal_semantics, @@ -130,7 +132,14 @@ def main() -> None: robot = add_tutorial_robot(sim, args.robot, tcp_z=0.15) obj = create_pick_object(sim) sim.prepare() - hand_open, hand_close = get_hand_open_close_qpos(robot) + hand_open, hand_close = get_hand_open_close_qpos( + robot, + close_qpos=( + MJVBD_V2_CUBE_CLOSE_QPOS + if args.robot == "ur5" and sim.physics.solver_type == "mjvbd_v2" + else DEFAULT_GRIPPER_CLOSE_QPOS + ), + ) initialize_pre_pick_robot_pose(robot, obj, hand_open) motion_gen = create_curobo_motion_generator( robot, diff --git a/scripts/tutorials/atomic_action/place.py b/scripts/tutorials/atomic_action/place.py index f943bd2e13..973d999657 100644 --- a/scripts/tutorials/atomic_action/place.py +++ b/scripts/tutorials/atomic_action/place.py @@ -42,6 +42,8 @@ from embodichain.lab.sim.shapes import CubeCfg from embodichain.utils import logger from scripts.tutorials.atomic_action.tutorial_utils import ( + DEFAULT_GRIPPER_CLOSE_QPOS, + MJVBD_V2_CUBE_CLOSE_QPOS, add_tutorial_robot, broadcast_pose_batch, broadcast_waypoint_pose_batch, @@ -81,6 +83,8 @@ def parse_arguments() -> argparse.Namespace: def create_pick_object(sim) -> RigidObject: """Create a settled cube for the PickUp and Place sequence.""" + # Start outside the default ground's 1 mm VBD contact margin. + ground_clearance = 0.001 if sim.physics.solver_type == "mjvbd_v2" else 0.0 obj = sim.add_rigid_object( cfg=RigidObjectCfg( uid="cube", @@ -93,7 +97,7 @@ def create_pick_object(sim) -> RigidObject: angular_damping=0.2, newton_contact=sim.is_newton_backend, ), - init_pos=[*OBJECT_XY, 0.5 * OBJECT_SIZE[2]], + init_pos=[*OBJECT_XY, 0.5 * OBJECT_SIZE[2] + ground_clearance], ) ) sim.prepare() @@ -125,15 +129,41 @@ def make_place_eef_poses(device: torch.device) -> torch.Tensor: def main() -> None: """Plan and replay PickUp followed by a multi-waypoint Place.""" args = parse_arguments() - sim = create_tutorial_simulation(args) - robot = add_tutorial_robot(sim, args.robot, tcp_z=0.15) + sim = create_tutorial_simulation( + args, + newton_solver_options=( + { + "vbd_options": { + "rigid_contact_history": True, + "rigid_avbd_contact_alpha": 0.5, + }, + "collision_options": {"contact_matching": "latest"}, + } + if args.physics == "newton" and args.robot == "ur5" + else None + ), + ) + use_vbd_grasp = sim.physics.solver_type == "mjvbd_v2" and args.robot == "ur5" + robot = add_tutorial_robot( + sim, + args.robot, + tcp_z=0.15, + newton_gripper_friction=4.0 if use_vbd_grasp else None, + # Reach the release waypoint before the fingers finish opening. + arm_damping=1000.0 if use_vbd_grasp else None, + ) obj = create_pick_object(sim) sim.prepare() motion_gen = create_curobo_motion_generator( robot, planner=getattr(args, "planner", "trapezoidal"), ) - hand_open, hand_close = get_hand_open_close_qpos(robot) + hand_open, hand_close = get_hand_open_close_qpos( + robot, + close_qpos=( + MJVBD_V2_CUBE_CLOSE_QPOS if use_vbd_grasp else DEFAULT_GRIPPER_CLOSE_QPOS + ), + ) initialize_pre_pick_robot_pose(robot, obj, hand_open) engine = create_simulation_atomic_action_engine( diff --git a/scripts/tutorials/atomic_action/pour.py b/scripts/tutorials/atomic_action/pour.py index 34c2ef0e4c..e70fbe0123 100644 --- a/scripts/tutorials/atomic_action/pour.py +++ b/scripts/tutorials/atomic_action/pour.py @@ -39,17 +39,19 @@ PourOptions, ) from embodichain.lab.sim.motion.planners import ( - TrapezoidalPlanOptions, ToppraPlanOptions, TrajectorySampleMethod, ) from embodichain.utils import logger from scripts.tutorials.atomic_action.axis_align import ( + OBJECT_SIZE, create_align_object, create_axis_align_semantics, ) from scripts.tutorials.atomic_action.tutorial_utils import ( - add_ur5_gripper_robot, + DEFAULT_GRIPPER_CLOSE_QPOS, + MJVBD_V2_CUBE_CLOSE_QPOS, + add_tutorial_robot, create_parallel_jaw_grasp_pose_generator, create_toppra_motion_generator, create_tutorial_argument_parser, @@ -71,7 +73,8 @@ HAND_INTERP_STEPS = 12 POST_TRAJECTORY_STEPS = 240 PICK_MOTION_SAMPLE_COUNT = PICK_SAMPLE_INTERVAL - HAND_INTERP_STEPS -OBJ_POSITION = (-0.5, 0.0, 0.0) +# Start above the ground so penetration recovery does not move the grasp target. +OBJ_POSITION = (-0.5, 0.0, 0.5 * OBJECT_SIZE[2]) RECORD_LOOK_AT = ( (-1.5, 0.2, 1.2), (-0.4, 0.0, 0.4), @@ -103,14 +106,9 @@ def _create_pick_motion_policy( sample_method=TrajectorySampleMethod.QUANTITY, sample_interval=PICK_MOTION_SAMPLE_COUNT, ) - elif planner == "trapezoidal": - plan_opts = TrapezoidalPlanOptions( - sample_method=TrajectorySampleMethod.QUANTITY, - sample_interval=PICK_MOTION_SAMPLE_COUNT, - ) - elif planner == "curobo": - # cuRobo owns its native sampling and does not use the joint-space - # sample-count options above. + elif planner in ("trapezoidal", "curobo"): + # Preserve native waypoints before PickUp resamples its two motion + # segments. A fixed quantity can be smaller than the Cartesian IK path. plan_opts = None else: raise ValueError(f"Unsupported tutorial planner {planner!r}.") @@ -124,13 +122,38 @@ def _create_pick_motion_policy( def main() -> None: """Plan and replay PickUp followed by Pour.""" args = parse_arguments() - sim = create_tutorial_simulation(args) - robot = add_ur5_gripper_robot(sim, tcp_z=0.15) + sim = create_tutorial_simulation( + args, + newton_solver_options=( + { + "vbd_options": {"rigid_contact_history": True}, + "collision_options": {"contact_matching": "latest"}, + } + if args.physics == "newton" + else None + ), + ) + use_vbd_grasp = sim.physics.solver_type == "mjvbd_v2" + robot = add_tutorial_robot( + sim, + "ur5", + tcp_z=0.15, + newton_gripper_friction=4.0 if use_vbd_grasp else None, + ) + obj_position = list(OBJ_POSITION) + if use_vbd_grasp: + # Start outside the default ground's 1 mm VBD contact margin. + obj_position[2] += 0.001 obj = create_align_object( sim, - obj_position=OBJ_POSITION, + obj_position=obj_position, + ) + hand_open, hand_close = get_hand_open_close_qpos( + robot, + close_qpos=( + MJVBD_V2_CUBE_CLOSE_QPOS if use_vbd_grasp else DEFAULT_GRIPPER_CLOSE_QPOS + ), ) - hand_open, hand_close = get_hand_open_close_qpos(robot) initialize_pre_pick_robot_pose(robot, obj, hand_open) planner = getattr(args, "planner", "trapezoidal") motion_gen = create_toppra_motion_generator(robot, planner=planner) diff --git a/scripts/tutorials/atomic_action/scenario_utils.py b/scripts/tutorials/atomic_action/scenario_utils.py index d52e6bd996..10cf327425 100644 --- a/scripts/tutorials/atomic_action/scenario_utils.py +++ b/scripts/tutorials/atomic_action/scenario_utils.py @@ -234,6 +234,7 @@ def add_dual_tutorial_robot( hand_stiffness: float = 1e3, hand_damping: float = 1e2, hand_max_effort: float = 1e4, + newton_gripper_friction: float | None = None, ) -> Robot: """Add a supported dual-arm tutorial robot to a simulation. @@ -254,6 +255,7 @@ def add_dual_tutorial_robot( hand_stiffness: Hand joint drive stiffness. hand_damping: Hand joint drive damping. hand_max_effort: Hand joint maximum effort. + newton_gripper_friction: Optional Newton gripper sliding friction. Returns: The added dual-arm robot instance. @@ -274,7 +276,7 @@ def add_dual_tutorial_robot( hand_damping=hand_damping, hand_max_effort=hand_max_effort, ) - configure_newton_gripper_contacts(sim, robot_cfg) + configure_newton_gripper_contacts(sim, robot_cfg, friction=newton_gripper_friction) return sim.add_robot(cfg=robot_cfg) diff --git a/scripts/tutorials/atomic_action/slide.py b/scripts/tutorials/atomic_action/slide.py index 2970504f70..ddba7af78b 100644 --- a/scripts/tutorials/atomic_action/slide.py +++ b/scripts/tutorials/atomic_action/slide.py @@ -95,10 +95,16 @@ def create_drawer( init_pos=DRAWER_POSITION, init_rot=DRAWER_ORIENTATION, init_qpos=(0.0,), - joint_drive_props=JointDrivePropertiesCfg(drive_type="none"), + joint_drive_props=JointDrivePropertiesCfg( + drive_type="force", + target_mode="velocity", + stiffness=0.0, + damping=5.0, + ), attrs=create_tutorial_rigid_body_physics( static_friction=1.0, dynamic_friction=1.0, + linear_damping=0.0, ), ) configure_newton_link_contacts( diff --git a/scripts/tutorials/atomic_action/tutorial_utils.py b/scripts/tutorials/atomic_action/tutorial_utils.py index 1167510b11..28fa6910c1 100644 --- a/scripts/tutorials/atomic_action/tutorial_utils.py +++ b/scripts/tutorials/atomic_action/tutorial_utils.py @@ -111,6 +111,9 @@ palm_depth=0.096, ) DEFAULT_GRIPPER_CLOSE_QPOS = 0.036 +# Calibrated for the UR5's DH-PGI gripper holding the tutorial's 5 cm cube. +# V2's one-way contacts cannot stop the fingers at an oversized close target. +MJVBD_V2_CUBE_CLOSE_QPOS = 0.013 NEWTON_GRASP_CONTACT_STIFFNESS = 4.0e4 NEWTON_GRASP_CONTACT_DAMPING = 4.0e2 # MuJoCo-Warp's default contact dimension (3) has no torsional friction. A @@ -267,10 +270,8 @@ def _tutorial_physics_cfg( ) -> PhysicsBackendCfg: """Build the shared physics configuration for atomic-action tutorials. - Newton tutorials intentionally use MuJoCo Warp's native collision path. - It generates contacts inside every solver substep, so an external Newton - collision pipeline would be unused and would only allocate unnecessary - contact buffers. + MJVBD V2 owns collision detection and retains MuJoCo articulation drives. + Free rigid bodies use VBD with the solver's native one-way coupling. """ physics_cfg = physics_cfg_for_backend(backend) if isinstance(physics_cfg, NewtonPhysicsCfg): @@ -279,20 +280,21 @@ def _tutorial_physics_cfg( # contacts and fast-changing manipulator loads. DexSim sizes # contact/constraint buffers from the finalized scene, including the # contact dimensions authored on gripper and object surfaces. - # MultiCCD retains up to four contacts per gripper-mesh/object pair, - # which prevents a marginal two-finger grasp from sliding away. + # Retain the existing MuJoCo articulation tuning. Free-body contacts + # remain VBD-owned and do not inherit these MuJoCo contact options. physics_cfg.num_substeps = 20 physics_cfg.collision_cfg = None physics_cfg.solver_cfg = { - "solver_type": "mujoco_warp", - "solver": "newton", - "integrator": "implicitfast", - "iterations": 20, - "ls_iterations": 100, - "cone": "elliptic", - "impratio": 1_000.0, - "use_mujoco_contacts": True, - "enable_multiccd": True, + "solver_type": "mjvbd_v2", + "mujoco_options": { + "solver": "newton", + "integrator": "implicitfast", + "iterations": 20, + "ls_iterations": 100, + "cone": "elliptic", + "impratio": 1_000.0, + "enable_multiccd": True, + }, } return physics_cfg @@ -302,6 +304,7 @@ def create_tutorial_simulation( *, arena_space: float = 2.5, sun_direction: Sequence[float] = DEFAULT_TUTORIAL_SUN_DIRECTION, + newton_solver_options: Mapping[str, object] | None = None, ) -> SimulationManager: """Create the shared simulation setup used by atomic-action tutorials. @@ -311,10 +314,17 @@ def create_tutorial_simulation( arena_space: Spacing between parallel simulation arenas in meters. sun_direction: Direction of the single global sun light. The vector points from the light toward the scene. + newton_solver_options: Scene-specific overrides for the Newton solver + configuration, such as VBD contact history and collision matching. Returns: A simulation manager with the tutorial key light configured. """ + physics_cfg = _tutorial_physics_cfg(getattr(args, "physics", "default")) + if newton_solver_options is not None: + if not isinstance(physics_cfg, NewtonPhysicsCfg): + raise ValueError("Newton solver options require the Newton backend.") + physics_cfg.solver_cfg = {**physics_cfg.solver_cfg, **newton_solver_options} sim = SimulationManager( SimulationManagerCfg( width=VIEWER_WIDTH, @@ -322,7 +332,7 @@ def create_tutorial_simulation( headless=True, num_envs=args.num_envs, device=args.device, - physics_cfg=_tutorial_physics_cfg(getattr(args, "physics", "default")), + physics_cfg=physics_cfg, render_cfg=RenderCfg(renderer=args.renderer), physics_dt=1.0 / 100.0, arena_space=arena_space, @@ -407,6 +417,9 @@ def add_tutorial_robot( robot_type: TutorialRobot, init_pos: Sequence[float] = (0.0, 0.0, 0.0), init_qpos: Sequence[float] | None = None, + *, + newton_gripper_friction: float | None = None, + arm_damping: float | None = None, **kwargs, ) -> Robot: """Add a selected tutorial robot with the shared PGI gripper. @@ -416,6 +429,9 @@ def add_tutorial_robot( robot_type: Tutorial robot family to construct. init_pos: Root position of the robot in its arena. init_qpos: Optional full robot joint configuration. + newton_gripper_friction: Optional sliding-friction coefficient for the + Newton gripper collision links; object materials are unaffected. + arm_damping: Optional drive damping for the arm control part. Returns: The added robot instance. @@ -429,7 +445,9 @@ def add_tutorial_robot( init_qpos=init_qpos, **kwargs, ) - configure_newton_gripper_contacts(sim, robot_cfg) + if arm_damping is not None: + robot_cfg.joint_drive_props.damping["arm"] = arm_damping + configure_newton_gripper_contacts(sim, robot_cfg, friction=newton_gripper_friction) return sim.add_robot(cfg=robot_cfg) @@ -618,9 +636,19 @@ def configure_newton_link_contacts( def configure_newton_gripper_contacts( sim: SimulationManager, robot_cfg: RobotCfg, + *, + friction: float | None = None, ) -> None: - """Configure Newton gripper contacts and recompute their source inertia.""" + """Configure Newton gripper contacts and recompute their source inertia. + + Args: + sim: Simulation manager that owns the robot. + robot_cfg: Robot configuration to update before spawning. + friction: Optional static and dynamic sliding-friction coefficient. + """ if not sim.is_newton_backend: + if friction is not None: + raise ValueError("Newton gripper friction requires the Newton backend.") return configure_newton_link_contacts( @@ -629,9 +657,11 @@ def configure_newton_gripper_contacts( group_name="newton_gripper_contacts", link_names_expr=[_GRIPPER_CONTACT_LINK_PATTERN], ) - robot_cfg.link_attrs["newton_gripper_contacts"].attrs.mass_props = ( - MassPropertiesCfg(recompute_inertia=True) - ) + attrs = robot_cfg.link_attrs["newton_gripper_contacts"].attrs + attrs.mass_props = MassPropertiesCfg(recompute_inertia=True) + if friction is not None: + attrs.material_props.static_friction = friction + attrs.material_props.dynamic_friction = friction def create_trapezoidal_motion_generator( @@ -1545,6 +1575,7 @@ def create_tutorial_robot_cfg( "DEFAULT_AXIS_LEN", "DEFAULT_AXIS_SIZE", "DEFAULT_GRIPPER_CLOSE_QPOS", + "MJVBD_V2_CUBE_CLOSE_QPOS", "DEFAULT_TUTORIAL_SUN_DIRECTION", "DEFAULT_TUTORIAL_SUN_INTENSITY", "GRIPPER_HAND_JOINT_PATTERN", diff --git a/scripts/tutorials/gym/modular_env.py b/scripts/tutorials/gym/modular_env.py index f7d33c5d75..e33bdc33c4 100644 --- a/scripts/tutorials/gym/modular_env.py +++ b/scripts/tutorials/gym/modular_env.py @@ -211,7 +211,7 @@ class ExampleCfg(EmbodiedEnvCfg): shape=MeshCfg( fpath=get_data_path("TableWare/tableware/fork/standard_fork_scale.ply"), ), - body_scale=(0.75, 0.75, 1.0), + body_scale=(0.75, 0.75, 0.75), init_pos=(0.8, 0, 1.0), ), ] diff --git a/scripts/tutorials/sim/open_drawer.py b/scripts/tutorials/sim/open_drawer.py index 58f893e342..99c0a55242 100644 --- a/scripts/tutorials/sim/open_drawer.py +++ b/scripts/tutorials/sim/open_drawer.py @@ -530,22 +530,21 @@ def _tutorial_physics_cfg( """Build the physics configuration used by this tutorial.""" physics_cfg = physics_cfg_for_backend(backend) if isinstance(physics_cfg, NewtonPhysicsCfg): - # Keep the same MuJoCo-Warp solver/contact profile as the atomic-action - # tutorial and packaged Newton task. The finer drawer substep cadence - # is intentional; per-world capacities remain auto-sized by DexSim - # from the finalized scene. + # Share the V2 articulation profile with the atomic-action tutorials. + # Keep the finer drawer substep cadence and native contact ownership. physics_cfg.num_substeps = 20 physics_cfg.collision_cfg = None physics_cfg.solver_cfg = { - "solver_type": "mujoco_warp", - "solver": "newton", - "integrator": "implicitfast", - "iterations": 20, - "ls_iterations": 100, - "cone": "elliptic", - "impratio": 1_000.0, - "use_mujoco_contacts": True, - "enable_multiccd": True, + "solver_type": "mjvbd_v2", + "mujoco_options": { + "solver": "newton", + "integrator": "implicitfast", + "iterations": 20, + "ls_iterations": 100, + "cone": "elliptic", + "impratio": 1_000.0, + "enable_multiccd": True, + }, } return physics_cfg diff --git a/tests/sim/atomic_actions/test_tutorial_utils.py b/tests/sim/atomic_actions/test_tutorial_utils.py index c967391725..1649196956 100644 --- a/tests/sim/atomic_actions/test_tutorial_utils.py +++ b/tests/sim/atomic_actions/test_tutorial_utils.py @@ -268,7 +268,7 @@ def _run_obstacle_animation(*, pace_wall_time: bool) -> tuple[MagicMock, MagicMo return obstacle, adapter -def test_atomic_action_tutorial_uses_native_mujoco_contact_settings() -> None: +def test_atomic_action_tutorial_uses_native_mjvbd_v2_settings() -> None: module = importlib.import_module("scripts.tutorials.atomic_action.tutorial_utils") default_cfg = module._tutorial_physics_cfg("default") @@ -279,29 +279,24 @@ def test_atomic_action_tutorial_uses_native_mujoco_contact_settings() -> None: assert newton_cfg.num_substeps == 20 assert newton_cfg.collision_cfg is None assert newton_cfg.solver_cfg == { - "solver_type": "mujoco_warp", - "solver": "newton", - "integrator": "implicitfast", - "iterations": 20, - "ls_iterations": 100, - "cone": "elliptic", - "impratio": 1_000.0, - "use_mujoco_contacts": True, - "enable_multiccd": True, + "solver_type": "mjvbd_v2", + "mujoco_options": { + "solver": "newton", + "integrator": "implicitfast", + "iterations": 20, + "ls_iterations": 100, + "cone": "elliptic", + "impratio": 1_000.0, + "enable_multiccd": True, + }, } dexsim_cfg = newton_cfg.to_dexsim_cfg(gpu_id=0) - assert dexsim_cfg.solver_cfg.solver_type == "mujoco_warp" - assert dexsim_cfg.solver_cfg.solver == "newton" - assert dexsim_cfg.solver_cfg.integrator == "implicitfast" - assert dexsim_cfg.solver_cfg.iterations == 20 - assert dexsim_cfg.solver_cfg.ls_iterations == 100 - assert dexsim_cfg.solver_cfg.nconmax is None - assert dexsim_cfg.solver_cfg.njmax is None - assert dexsim_cfg.solver_cfg.cone == "elliptic" - assert dexsim_cfg.solver_cfg.impratio == pytest.approx(1_000.0) - assert dexsim_cfg.solver_cfg.use_mujoco_contacts is True - assert dexsim_cfg.solver_cfg.enable_multiccd is True + assert dexsim_cfg.solver_cfg.solver_type == "mjvbd_v2" + assert ( + dexsim_cfg.solver_cfg.mujoco_options == newton_cfg.solver_cfg["mujoco_options"] + ) + assert dexsim_cfg.solver_cfg.vbd_options == {} assert dexsim_cfg.collision_pipeline_cfg is None @@ -1023,6 +1018,7 @@ def test_place_tutorial_registers_pick_object_with_simulation_engine_factory() - n_sample=1, no_vis_eef_axis=True, robot="ur5", + physics="default", ) sim = MagicMock() sim.device = torch.device("cpu") @@ -1316,9 +1312,13 @@ def test_pour_tutorial_uses_configured_pickup_and_local_rotation_axis() -> None: assert module.POUR_INTERNAL_AXIS == (1.0, 0.0, 0.0) pick_policy = module._create_pick_motion_policy() assert pick_policy.sample_count == module.PICK_SAMPLE_INTERVAL - assert isinstance(pick_policy.plan_opts, module.TrapezoidalPlanOptions) - assert pick_policy.plan_opts.sample_method is module.TrajectorySampleMethod.QUANTITY - assert pick_policy.plan_opts.sample_interval == module.PICK_MOTION_SAMPLE_COUNT + assert pick_policy.plan_opts is None + toppra_policy = module._create_pick_motion_policy("toppra") + assert isinstance(toppra_policy.plan_opts, module.ToppraPlanOptions) + assert ( + toppra_policy.plan_opts.sample_method is module.TrajectorySampleMethod.QUANTITY + ) + assert toppra_policy.plan_opts.sample_interval == module.PICK_MOTION_SAMPLE_COUNT def test_replay_timed_trajectory_uses_arrival_intervals() -> None: diff --git a/tests/sim/test_cfg.py b/tests/sim/test_cfg.py index 13d74f2f72..523e1b6ef8 100644 --- a/tests/sim/test_cfg.py +++ b/tests/sim/test_cfg.py @@ -529,7 +529,7 @@ def test_robot_preset_accepts_newton_solver_alias() -> None: preset = _NewtonSolverAliasRobotPresetCfg() assert preset.resolve(DefaultPhysicsCfg()).uid == "fallback" - assert preset.resolve(NewtonPhysicsCfg()).uid == "fallback" + assert preset.resolve(NewtonPhysicsCfg()).uid == "mjwarp" assert ( preset.resolve(NewtonPhysicsCfg(solver_cfg={"solver_type": "mjwarp"})).uid == "mjwarp" @@ -812,6 +812,7 @@ def test_robot_cfg_merge_preserves_grouped_overrides() -> None: def test_newton_physics_inherits_common_gravity_and_collision_config() -> None: cfg = NewtonPhysicsCfg( + solver_cfg=None, gravity=[0.0, 0.0, -1.5], collision_cfg=NewtonCollisionPipelineCfg( broad_phase="sap", diff --git a/tests/sim/test_sim_manager_cfg.py b/tests/sim/test_sim_manager_cfg.py index a96f8e93cf..d34f11f2d4 100644 --- a/tests/sim/test_sim_manager_cfg.py +++ b/tests/sim/test_sim_manager_cfg.py @@ -124,15 +124,15 @@ def test_newton_physics_cfg_uses_device() -> None: @pytest.mark.no_sim -def test_newton_physics_cfg_preserves_dexsim_auto_solver_default() -> None: - from dexsim.engine.newton_physics import AutoSolverCfg +def test_newton_physics_cfg_defaults_to_mjvbd_v2_solver() -> None: + from dexsim.engine.newton_physics import MJVBDV2SolverCfg cfg = NewtonPhysicsCfg() dexsim_cfg = cfg.to_dexsim_cfg(gpu_id=0) - assert isinstance(dexsim_cfg.solver_cfg, AutoSolverCfg) - assert dexsim_cfg.solver_cfg.solver_type == "auto" + assert isinstance(dexsim_cfg.solver_cfg, MJVBDV2SolverCfg) + assert dexsim_cfg.solver_cfg.solver_type == "mjvbd_v2" @pytest.mark.no_sim @@ -174,7 +174,7 @@ def test_newton_physics_cfg_requires_dexsim_auto_solver_api( @pytest.mark.no_sim def test_newton_gradient_mode_rejects_auto_solver() -> None: - cfg = NewtonPhysicsCfg(requires_grad=True) + cfg = NewtonPhysicsCfg(solver_cfg=None, requires_grad=True) with pytest.raises(RuntimeError, match="explicit.*semi_implicit"): cfg.to_dexsim_cfg(gpu_id=0) @@ -193,7 +193,9 @@ def test_newton_physics_cfg_passes_warp_log_suppression() -> None: def test_newton_physics_cfg_forwards_collision_pipeline_update_interval( update_interval: int | None, ) -> None: - cfg = NewtonPhysicsCfg(collision_cfg={"update_interval": update_interval}) + cfg = NewtonPhysicsCfg( + solver_cfg=None, collision_cfg={"update_interval": update_interval} + ) dexsim_cfg = cfg.to_dexsim_cfg(gpu_id=0) @@ -296,7 +298,7 @@ def test_newton_backend_reports_scene_resolved_auto_solver( manager = SimpleNamespace(_world=world) backend = NewtonPhysicsBackend(manager) world_config = SimpleNamespace(newton_cfg=None) - sim_config = SimulationManagerCfg(physics_cfg=NewtonPhysicsCfg()) + sim_config = SimulationManagerCfg(physics_cfg=NewtonPhysicsCfg(solver_cfg=None)) monkeypatch.setattr( "dexsim.engine.newton_physics.backend_registry.get_newton_backend", lambda candidate: native_backend if candidate is world else None,