Skip to content

Loop dr testmech

Looped linkages

The DR TestMech in many worlds on Kamino.

0.00 s
The steel preset (the default), recordedon an NVIDIA RTX PRO 6000 Blackwell.

Run it

Terminal window
cd examples
# the default preset (steel), then the others
uv run shelf play loop_dr_testmech
uv run shelf play loop_dr_testmech --solver kamino
# change solver settings live
uv run shelf tune loop_dr_testmech

Source: examples/shelf/05_looped_linkages/loop_dr_testmech/ ยท ported from newton/examples/kamino/example_kamino_basic_dr_testmech.py @ skild-ai/newton 7565a26b1

Presets

PresetSolverStatusChecked
kaminokaminoworks2026-10-28, newton 7565a26b1, NVIDIA RTX A6000

Solvers with no row are untested on this example. The full settings are inpresets.toml.

Code

examples/shelf/05_looped_linkages/loop_dr_testmech/example.py
# SPDX-FileCopyrightText: Copyright (c) 2025 The Newton Developers
# SPDX-License-Identifier: Apache-2.0
# Modified for Steel Shelf: preset-driven execution and shared runner integration.
###########################################################################
# Example for basic DR TestMech system
#
# Shows how to simulate DR TestMech with multiple worlds using SolverKamino.
#
# Command: python -m shelf run loop_dr_testmech --world-count 16
#
###########################################################################
import warp as wp
import newton
import newton.examples
from common import presets
class Example:
def __init__(self, viewer: newton.viewer.ViewerBase, args=None):
self.preset = presets.load(__file__)
# Set simulation run-time configurations
self.fps = self.preset.fps
self.frame_dt = 1.0 / self.fps
self.sim_substeps = self.preset.substeps
self.sim_dt = self.frame_dt / self.sim_substeps
self.sim_time = 0.0
self.world_count = args.world_count if args else 1
self.viewer = viewer
self.device = wp.get_device()
# Create a single-robot model builder and register the Kamino-specific custom attributes
robot_builder = newton.ModelBuilder(up_axis=newton.Axis.Z)
if self.preset.name == "kamino":
newton.solvers.SolverKamino.register_custom_attributes(robot_builder)
robot_builder.default_shape_cfg.margin = 1e-6
robot_builder.default_shape_cfg.gap = 0.01
# Load the DR TestMech USD and add it to the builder
asset_path = newton.utils.download_asset("disneyresearch")
asset_file = str(asset_path / "dr_testmech/usd" / "dr_testmech.usda")
robot_builder.add_usd(
asset_file,
# Kamino keeps the file's joint order; reduced-coordinate solvers (Steel) need a parent-first tree
joint_ordering=None if self.preset.name == "kamino" else "dfs",
force_show_colliders=True,
force_position_velocity_actuation=False,
collapse_fixed_joints=False,
enable_self_collisions=False,
hide_collision_shapes=True,
)
# Create the multi-world model by duplicating the single-robot
# builder for the specified number of worlds
builder = newton.ModelBuilder(up_axis=newton.Axis.Z)
builder.num_rigid_contacts_per_world = 2048
for _ in range(self.world_count):
builder.add_world(robot_builder)
# Create the model from the builder
self.model = builder.finalize(skip_validation_joints=True)
# Create the Kamino solver for the given model
self.build_solver()
# Create state and control data containers
self.state_0 = self.model.state()
self.state_1 = self.model.state()
self.control = self.model.control()
# Attach the model to the viewer for visualization
self.viewer.set_model(self.model)
# Capture the simulation graph if running on CUDA
# NOTE: This only has an effect on GPU devices
self.capture()
# If only a single-world is created, set initial
# camera position for better view of the system
if self.world_count == 1 and hasattr(self.viewer, "set_camera"):
camera_pos = wp.vec3(0.2, 0.2, 0.15)
pitch = -20.0
yaw = 215.0
self.viewer.set_camera(camera_pos, pitch, yaw)
def build_solver(self):
"""Build the solver and everything bound to its instance; the tuner calls this again to swap it."""
if self.preset.name == "kamino":
self.config = self.preset.make_config(self.model)
self.solver = newton.solvers.SolverKamino(self.model, config=self.config)
else:
self.solver = self.preset.make_solver(self.model)
def capture(self):
self.graph = None
if self.device.is_cuda and not wp.config.verify_cuda:
with wp.ScopedCapture() as capture:
self.simulate()
self.graph = capture.graph
# simulate() performs one frame's worth of updates
def simulate(self):
for substep in range(self.sim_substeps):
self.state_0.clear_forces()
self.viewer.apply_forces(self.state_0)
self.solver.step(self.state_0, self.state_1, self.control, None, self.sim_dt)
if self.sim_substeps % 2 == 1 and substep == self.sim_substeps - 1:
# an odd count under graph capture: copy the last result into state_0 instead of swapping,
# so every replay of the captured graph starts from the newest state
self.state_0.assign(self.state_1)
else:
self.state_0, self.state_1 = self.state_1, self.state_0
def step(self):
if self.graph:
wp.capture_launch(self.graph)
else:
self.simulate()
self.sim_time += self.frame_dt
def render(self):
self.viewer.begin_frame(self.sim_time)
self.viewer.log_state(self.state_0)
self.viewer.end_frame()
def test_final(self):
pass # TODO: Add some assertions here once we have a more meaningful test scenario
@staticmethod
def create_parser():
parser = newton.examples.create_parser()
newton.examples.add_world_count_arg(parser)
parser.set_defaults(world_count=1)
return parser
if __name__ == "__main__":
parser = Example.create_parser()
viewer, args = newton.examples.init(parser)
newton.examples.run(Example(viewer, args), args)