Simulator
The [sim] extra ships a MuJoCo-backed physics simulator, so you can
develop robot programs without a hub on the desk:
$ pipx install 'openbricks[sim]'
$ openbricks sim run examples/full_robot.py --viewer
The sim runs the same script you’d push to the hub — a driver shim
maps the openbricks API onto simulated motors and sensors, so
ST3032Motor, DriveBase, color sensors, and distance sensors behave
like their hardware counterparts.
Commands
$ openbricks sim preview [--world WORLD] [--x X] [--y Y] [--headless] [--duration S] [--seed N]
Loads the named world (an alias or a path to an MJCF file), splices in
the default chassis, and opens the MuJoCo viewer so you can inspect the
scene. --headless steps the physics for --duration seconds without
opening a window — useful as a smoke test.
$ openbricks sim run SCRIPT [--world WORLD] [--chassis FILE] [--x X] [--y Y] [--yaw DEG] [--viewer] [--no-shim] [--seed N]
Loads the world plus the chassis and executes SCRIPT against the
simulated robot. --viewer opens the interactive MuJoCo window;
without it the sim runs headless (CI-friendly). --seed makes
randomized worlds reproducible.
Run openbricks sim --help for the full, always-current option list.
Describing your robot
The default chassis is a 60 mm-wheel, 150 mm-axle box with every
down-facing sensor 60 mm ahead of the axle. A real robot differs, and
those differences decide whether a mission script’s numbers work:
--chassis FILE loads a JSON object of ChassisSpec fields (metres,
kilograms, degrees) that describe the robot the script was written
for. Fields not given keep the defaults.
{
"wheel_radius": 0.0432, "axle_length": 0.135,
"body_length": 0.16, "body_width": 0.12,
"line_sensor_x": 0.06,
"color_sensor_x": 0.06, "color_sensor_y": 0.184,
"pos_x": -0.547, "pos_y": -0.15, "yaw_deg": 90
}
wheel_radius/axle_lengthsize the chassis at load time. TheDriveBase(wheel_diameter_mm=…, axle_track_mm=…)in the script resizes it again at adoption, so the script’s geometry always wins — set them here so apreviewshows the same robot.line_sensor_xplaces the reflectance-array site (chassis_line) ahead of the axle;color_sensor_x/color_sensor_yplace the centre down camera (chassis_cam_down, the no-muxTCS34725), and the left/right camera pair rides 18 mm either side of it.pos_x/pos_y/yaw_degare the spawn pose;--x/--y/--yawon the command line override them one at a time.yaw_degis counter-clockwise from +X seen from above (0 = facing +X).
What the shim simulates
Firmware class |
Sim binding |
|---|---|
|
The first two servo ids become the chassis wheels, the third and fourth kinematic task shafts (a gripper motor that turns but pushes nothing). A |
|
The firmware engine over an emulated |
|
Ground-truth chassis heading; the ICM’s bias estimator reports calibrated at once. |
|
One downward ray from the centre camera (no mux) or the left/right pair (mux channels 1 / 0); prop colours and mat texels resolve to what the sensor would see. |
|
The firmware driver over a reflectance model: one element per array position, spread left-to-right from the |
Distance sensors |
A forward ray from the |
Nothing above has a load: task motors don’t grip, and a prop is only pushed when the chassis body drives into it.
Notes
The sim needs the
[sim]extra (mujoco,numpy). Without it,openbricks sim …prints an install hint instead of crashing.Firmware-only users never need the simulator — it’s strictly host-side tooling.