motornet.js

A dependency-free JavaScript port of MotorNet โ€” simulate biomechanically realistic muscled arms and point masses, and run PyTorch-trained neural control policies, entirely in your browser.

๐Ÿค– Developed with the help of Claude
Zero dependencies Pure ES modules Validated vs. PyTorch MIT licensed
Launch interactive demo โ†’ View on GitHub

Live demo

Watch a trained policy reach โ€” right here
motornet.js ยท interactive demo

Click inside the canvas to set a reach target. A GRU policy trained in PyTorch drives the point-mass muscles to reach it โ€” running here in plain JavaScript. Open the demo full-screen โ†—

What it does

A faithful re-implementation of MotorNet's simulation engine

Effectors & muscles

Point masses and two-joint arms driven by Hill-type, Thelen, MuJoCo, and ReLU muscle models โ€” the same biomechanics as the Python toolbox.

Gym-style environments

A RandomTargetReach environment with the familiar reset / step / obs / reward loop for closed-loop control.

Run trained policies

Export a PolicyGRU from PyTorch and run inference in the browser โ€” no Python, no server, no WebAssembly.

Numerically validated

Trajectories are checked against the PyTorch reference across seven effector/muscle configurations plus the GRU policy.

Quick start

Simulate an arm in a handful of lines
import { RigidTendonArm26, RigidTendonHillMuscle } from 'motornetjs';

const effector = new RigidTendonArm26({ muscle: new RigidTendonHillMuscle() });
effector.reset({ jointState: [0.5, 1.0] });        // shoulder, elbow (radians)

const action = [0.3, 0.0, 0.6, 0.0, 0.2, 0.1];      // 6 muscle excitations in [0,1]
for (let t = 0; t < 50; t++) effector.step(action);

console.log(effector.states.fingertip);  // [x, y] endpoint position

See the README for environments, trained-policy inference, and the full API.