Physics-Based RL Environment ← Projects

Physics-Based RL Environment

rigidRL

C++PythonPyBind11Physics SimulationRL

rigidRL is a custom 2D rigid body physics engine written in C++ and exposed to Python via PyBind11, intended as a lightweight alternative to MuJoCo or Box2D for reinforcement learning research. It supports articulated agents constructed from rigid links connected by joint constraints, making it suitable for locomotion and manipulation tasks where the physical fidelity of a general-purpose engine is unnecessary overhead.

Motivation

Existing RL physics environments often carry significant setup complexity or licensing constraints. rigidRL was built to provide a minimal, hackable simulation backend where every physical assumption is explicit and the step function can be called from Python at RL training speeds without spawning a subprocess or serializing state across a socket.

Technical Approach

The engine implements impulse-based rigid body dynamics with iterative constraint solving for joint connections. Bodies are represented as convex polygons with mass and moment of inertia computed analytically. The PyBind11 bridge provides zero-copy access to state arrays as NumPy buffers, so the Python training loop can read observations without any memory allocation on the hot path. The simulation step is fixed-timestep with sub-stepping for stability at large time deltas.

Results

rigidRL runs several thousand simulation steps per second on a single CPU core, which is sufficient for policy gradient training on simple locomotion tasks. The articulated agent abstraction correctly handles multi-link chains with joint limits, and the PyBind11 interface integrates cleanly with standard RL libraries that expect a Gym-compatible step signature.