Cables, hoses and wire harnesses show up in many real assembly and household tasks, and they are awkward to simulate: a cable has to bend, twist and sag like its material, and it has to sit in the same scene as the robot that grabs it. This walkthrough simulates a clamped cable in a few lines of Python with Alloy, an open-source physics engine for robot learning built on MuJoCo Warp and Newton.
pip install alloy-engine
1. Clamp a cable and let it sag
import alloy
scene = alloy.Scene(dt=0.01)
scene.add_rod("cable", length=0.4, radius=0.003, pos=(0, 0, 0.5), direction=(1, 0, 0), segments=16,
clamp="start", route="chain") # held horizontal at z = 0.5, then released to sag
sim = alloy.build(scene, device="cpu")
print(sim.routes()["cable"]["route"])
chain
A rod is a chain of segments that bends, twists and stretches like the material you give it. clamp="start" welds the first segment where it is built, and route="chain" keeps the clamped cable on a fast chain of rigid segments, stepped in MuJoCo together with any robot in the scene.
2. Run it and read the centre line
sim.run(2.0)
points = sim.state(["cable"], world=0)["cable.points"]
print(points.shape, points[-1][[0, 2]].round(2)) # the free end's x and z
print(sim.check()["ok"])
(17, 3) [0.35 0.31]
True
cable.points holds one row per segment end, 17 points for 16 segments, as a NumPy array you can feed to a policy or a reward. The free end hangs at x = 0.35 m and z = 0.31 m, below the clamp at 0.5 m. sim.check() grades the world, so a run that blew up is caught before it reaches training.
3. Materials and robots
- A cable that yields, such as a
copper_c110wire, keeps a bend after you release it; it steps on the slower elastic-rod solver. - A robot grips the cable in the same scene; the docs' Robots guide shows how.
- Many copies of the scene run as parallel worlds on one GPU for reinforcement learning.
Keep in mind
- A clamped cable steps on the slower solver unless you pass
route="chain", and the slower solver is expensive beside a robot on a CPU. - A chain held by a robot slowly loses its twist; clamp a cable that must hold a twist for a long time.
- A cable that needs more than 40 segments (long or soft) also uses the slower solver. The full list of limits is in the docs.
Links
- Docs page this is based on: https://alloy.argonrobotics.ai/docs/how-to/cable-or-wire/
- Code: https://github.com/argonrobotics-ai/alloy
- Paper: https://arxiv.org/abs/2611.16312
Top comments (0)