Quickstart¶
This goes beyond the minimal Getting started manual and shows the main ways to run a world.
Standalone¶
# windowed, real time
.venv/bin/roqsim sim <world.yaml>
# headless, as fast as possible, stop after N steps, print timing
.venv/bin/roqsim sim <world.yaml> --headless --pacing asap --steps 1000 --profile
# scaled real time (4x)
.venv/bin/roqsim sim <world.yaml> --pacing 4.0
# reproducible noise, recorded, rendered to video afterwards
.venv/bin/roqsim sim <world.yaml> --seed 7 --record run.mcap --video run.webm
The target is a world YAML, an MJCF scene, or a <pkg>:<name> reference resolved from an installed
package (roqsim sim roqsim_mobile:turtlebot4_demo).
Pacing is realtime (default), a numeric factor, or asap. It is what the run asks for and
not what it gets: the achieved factor is a property of the host’s load, a step that is already late
is never made up, and the runner warns at the end of a run it could not pace. So a duration a trial
must actually get is counted on simulated time — the recording’s t, or /clock for a node —
and never on a wall clock, which buys a varying amount of it. Headless works anywhere, offscreen
sensors included: import roqsim picks a backend that exists on this machine (the one
PYOPENGL_PLATFORM names, else egl where there is a render device and osmesa where there
is not), so MUJOCO_GL need not be set by hand — set it only to override that choice. To record
a run, add --record — see Recording a run below.
A running simulation prints control: <uri> and serves its endpoints and run control there:
roqsim endpoints, roqsim read, roqsim call and roqsim ctl pause|resume|step N from
another shell reach it with no ROS – see Talking to a running simulation. --control none serves nothing.
Note
Windowed GL defaults. On many Linux + GL-driver combinations the windowed launch aborts with
gladLoadGL error. When opening a window the runner applies two overridable defaults before any
GL loads:
Preloads ``libGLEW`` for the viewer. The passive viewer always opens its window via glfw, and that context is what needs libGLEW in the global symbol namespace. The runner locates it portably (via
ldconfig— no arch-specific path) and re-exec’s itself once withLD_PRELOADset, so no manualexport LD_PRELOAD=…is needed. No-op headless, with noDISPLAY, when the environment already preloads GLEW, or when GLEW is absent. Opt out withROQSIM_NO_GL_PRELOAD=1.Defaults ``MUJOCO_GL=egl`` — but only the offscreen (camera) renderer.
MUJOCO_GLdoes not affect the viewer window (always glfw); it selects the backend cameras render with. Forcing the cameras onto glfw too is what clashes with the window’s glfw context and producesgladLoadGL erroron camera worlds; giving cameras their own egl context avoids it. Override by settingMUJOCO_GLyourself (e.g.MUJOCO_GL=glfw). In practiceimport roqsimhas already chosen (see “Choosing a GL backend” in Interfaces), and it has to: by the time the runner’smainruns, mujoco is imported and the backend is bound. This default only still decides the windowed case underROQSIM_NO_GL_SELECT.
Because the runner preloads libGLEW itself, do not also export LD_PRELOAD=…libGLEW by hand.
A stale libGLEW preload lingering in the shell, combined with the egl default, drags GLX into
the same process as MuJoCo’s PyOpenGL EGL backend and crashes import mujoco with
undefined symbol: eglQueryString. If you see that, clear it with export -n LD_PRELOAD.
Keys in the window¶
F1 lists the keys roqsim adds to the window, and leaves the list up until F1 comes again. MuJoCo’s own help opens with it, in the opposite corner, listing Simulate’s keys rather than these.
Moving the camera¶
The window has two navigation modes and F10 switches between them. The mode is named in the lower-left corner for a couple of seconds whenever it changes, and once when the window opens.
Mouse (the mode a run opens in) is MuJoCo’s viewer exactly as it ships: drag to orbit, right-drag to pan, wheel to zoom. Nothing of roqsim’s is in the way, so all three keep their full reach — which is what an inspection driven by the mouse alone needs.
Flight is what F10 opts into, for getting inside a building-sized world rather than circling it
from outside. The arrow keys fly the free camera: ↑/↓ travel along the direction you are looking
(look down and you descend), ←/→ strafe level, Page Up/Down rise and drop, and holding Shift
flies three times faster. It applies to the free camera only — a track\ ed camera (below) owns
its own pose.
The drag stays MuJoCo’s own orbit in flight too, but it turns about a point held ~1.5 m in front of
the eye rather than wherever the world framed its camera, so it reads as looking around rather than
circling the room. That is done by re-spelling the camera — a free camera’s lookat and
distance are just how its eye position is written down, so pulling them in renders the identical
image and only moves the pivot, which is not drawn. The cost is that MuJoCo’s pan and zoom scale with
distance and therefore cover much less ground per drag; in flight the arrow keys are the way to
travel, and F10 hands the reach back. Because the pivot is only a re-spelling, neither switch moves
the picture: you come out of flight looking at exactly what you were looking at.
Not WASD, which would be the obvious choice: MuJoCo’s Simulate binds W, A, S, D,
E and Q to visualization flags (wireframe, static bodies, select point, …), so those keys
would toggle rendering as they moved. Its arrow bindings only step the physics while it is paused,
which leaves them free during a run. (The scene-review window of roqsim_scene_builder is not
MuJoCo’s window and does use WASD.)
Initial view¶
A world can set how the interactive viewer’s camera opens via an optional sim.view block
(windowed runs only; ignored when headless). Give any subset — omitted keys keep MuJoCo’s
model-derived default:
sim:
view:
lookat: [0.0, 0.4, 0.95] # point the camera orbits (world metres)
distance: 3.4 # metres from lookat
azimuth: 130 # degrees around +z
elevation: -20 # degrees; negative looks down
A fixed manipulation cell, for instance, sets these for a 3/4 view of the arm at its working height.
sim.view is the camera and nothing else: an unknown key there is an error, not a no-op.
Simulate’s two side panels are hidden by default and are not world config — which camera a world wants is part of the scene, whereas wanting the panels is a property of one interactive session, so they are run-level flags:
roqsim sim world.yaml --left-ui --right-ui
Either way Tab / Shift+Tab still toggle them at runtime.
Driving the robot by hand¶
The right panel’s sliders write data.ctrl — but a world’s controller plugin normally rewrites it
every tick, so a slider drag is undone before you see it. --manual-control stands every
controller down for the run and leaves ctrl to you:
roqsim sim world.yaml --manual-control # implies --right-ui, where the sliders are
It is a run-level switch, not world config: which controller a world wires up is part of the
experiment, whereas driving it by hand is a property of one interactive session. It applies to
every controller in the world (diff_drive, omni_drive, arm_controller,
spot_locomotion, g1_locomotion) — they keep serving their endpoints and tracking odometry, they just stop
stamping ctrl. Each still seeds ctrl once at reset, so the sliders open at the robot’s home
pose rather than at zero.
What the sliders mean is the actuator’s own units: wheel velocity for a diff_drive base, joint
position for an arm or Spot’s legs, and torque for the G1’s leg motors — a G1 left at zero torque
simply folds. Manual control needs the window, so it is refused under --headless.
Following a mobile robot¶
A static camera is fine for a fixed cell or a fixed arm, but a mobile robot drives out of frame. Add
track to attach the camera to it — MuJoCo’s tracking camera keeps the named body centred while
distance / elevation / azimuth stay yours to orbit and zoom with the mouse:
sim:
view:
track: robot # an entity name (as spawned) or a raw MJCF body name
follow_heading: true # chase cam: stay behind the robot as it turns
azimuth: 180 # with follow_heading, an offset from the robot's yaw
elevation: -20
distance: 3.4
track on its own keeps the azimuth world-fixed: the robot stays centred but spins in view as it
turns. follow_heading: true re-aims the camera at the robot’s heading each frame, so it rides
behind the robot; azimuth is then an offset (180 = directly behind, 0 = head-on). Orbiting
with the mouse still works under follow_heading — the new angle is folded into the offset, so it
holds relative to the robot rather than being overwritten on the next frame. lookat is ignored
while tracking (MuJoCo drives it).
The name given to track is resolved against the entity registry first, so you write the robot’s
name from its spawn plugin (track: robot) rather than its MJCF body prefix; any body name in the
compiled model also works. This works under both drivers — the standalone runner and the
scenario-execution adapter’s viewer window.
Saving the view you framed¶
Framing is done with the eye, not with numbers — so rather than transcribing a pose into sim.view
by hand, fly the camera until the shot is right and press F8. A dialog shows the values and the
world YAML they would go into; confirm, and that world’s sim.view block is rewritten:
Save the current camera view to
/…/roqsim_scenes/src/roqsim_scenes/worlds/depot.yaml
lookat: [3.2, -1.05, 0.9]
distance: 6.414
azimuth: 142.5
elevation: -21.0
This replaces the world's sim.view block.
Only that block is touched. The world is edited as text, not reparsed and dumped, so comments,
key order and one-line view: {…} styling all survive — a save shows up as a diff on the four value
lines and nothing else. The result is re-parsed and compared before it is written, so a bad edit is an
error rather than a mangled world.
A tracking view saves what it can mean: track and follow_heading are carried over,
lookat is dropped (MuJoCo drives it), and under follow_heading the saved azimuth is the
offset behind the robot rather than the live world-frame angle — which is the half a world can state,
and the half that still means the same thing after the robot turns.
Two things to know. A saved free-camera distance is usually ~1.5 m, because the arrow-key walk
holds the mouse pivot that far in front of the eye (above): the pair lookat/distance still
names the same eye position and renders the identical image, it just no longer reads as “how far back
from the scene”. And F8 needs a world YAML to write into — a run started from an MJCF scene or a bare
model reference has none, and says so rather than picking a file.
Checking a world before running it¶
roqsim check loads a world as far as it goes and reports every problem it found, in the order
the loader would hit them – so a world with three bad keys reports three, and a mount that does not
exist is named rather than discovered by a run that dies quietly:
roqsim check world.yaml
roqsim check roqsim_mobile:husky_demo --json # the same report, for a script
roqsim check world.yaml --override run.overrides.yaml --set sim.timestep=0.001
--set and --override are roqsim sim’s own options, applied by the same loader, so the
world checked is the one a run with those overrides builds – a campaign’s obstacles and plugin
settings included. An override addressing a component the world does not have is a config
problem, as it is when a run loads it. The report names the merged overrides (overrides in
--json, {} for none), so a caller can tell which world was checked; an override file that
cannot be read exits 2 with no report.
It runs six stages – resolve, inputs, config, build, configure, reset –
and says which one it reached, because “the config is wrong” and “the config is fine and the model
refused the name a plugin asked for” send a reader to different files. reset runs every plugin’s
on_reset and leaves the state a trial starts from. A transport plugin (one that declares
transport_only: the ROS bridge, an autopilot link) has its config checked and is not started,
since its configure connects to a process a check does not run; a transport warning names
it. It does not step the simulation: a world that passes can still behave wrongly, but it cannot
fail to start, which is the failure worth catching before a campaign queues a thousand of them.
Warnings do not clear ok and do not change the exit code; --json lists them under
warnings as {"check", "message", "hint"}. interpenetration is one: the reset state puts
two bodies inside one another deeper than the contact’s tolerance – an arm’s home that buries
its tool in the table, a prop spawned into another – which the contact solver would resolve on the
first steps by flinging them apart. It names both sides, the entity each belongs to, and the depth:
WARN [interpenetration] geom 'table_top' (entity 'table') and geom 'crate' (entity 'crate')
interpenetrate by 30.0 mm at reset (tolerance 5.0 mm, 4 contacts)
A run logs the same finding as a WARNING at every reset. An overlap that is meant is excluded from
collision (contype/conaffinity or an <exclude>), and is then not reported.
config-key names the config keys a plugin without a schema does not document (see
Available plugins), and rate an output the physics step publishes more than 1 % away from the rate
it asks for – a publish lands on a step, so 30 Hz on a 2 ms step is 29.41 Hz, every 17 steps. Each
endpoint in the inventory carries requested_hz, realised_hz and every_steps, the
transport’s rates: included, so the rate a run publishes at is readable before the run.
realised lists, per plugin, the values it runs with where they bound a run – a drive’s speed
caps, which clip any faster command, and a diff drive’s odometry with no error drawn – each with
whether the world or the plugin’s default set it. A plugin declares them in REALISED
(roqsim.plugin.Plugin.realised()).
friction-cone is another warning a plain world can get: it carries an arm or an object
entity – something grasped, pushed or carried – while its friction cone is MuJoCo’s pyramidal
default, which quantises the direction of the tangential contact force to the pyramid’s facets.
sim: {cone: elliptic} is the cone such a world wants, and saying either silences it.
With no problems it prints the inventory instead: the entities that registered, the endpoints they
publish with their topics and types, and the model’s totals. That is what the next thing gets written
against – a scenario that drives robot, a bridge that expects scan – without opening the
world file and its manifests to work out what is in there.
A world with a flex (MuJoCo’s <flexcomp>) gets two more things: what each flex compiled into, and
what it will do – worked out from the compiled model, before any step:
world: world.yaml
ok loads, compiles, every component resolved, and it resets
WARN [flex-damping] flex 'blk': numerical damping is 100% of its damping (zeta_1 = 0.036, of which 0.036 is the discrete integrator's timestep * omega / 2), so its ringing changes with sim.timestep
hint: state <elasticity damping> (a time, s) and keep sim.timestep at or below it: zeta_i = (damping + timestep) * omega_i / 2, with omega_1 = 71.92 rad/s
model: 38 bodies, 0 geoms, 108 joints, 0 actuators, 0 sensors, 0 cameras
timestep 0.001s, integrator discrete (auto: flex 'blk' (elasticity))
flexes (1):
blk dim 3, 45 vertices, 96 elements, dof full, 9 pinned, on holder; elastic, no passive contact
modes 11.4, 13, 22.4 Hz; damping ratio 0.036, 0.0407, 0.0703 at damping 0 s (numerical share 100% at timestep 0.001 s)
contact solref 0.02 1 (flex), floor 0.00102598 s
The modes are the flex’s lowest elastic frequencies with everything else held, from a
finite-difference stiffness and the mass matrix (roqsim.flex_modes.first_modes()); they match
a free-vibration measurement within 1 %. The damping ratio of mode i under the discrete
integrator (the one sim.integrator: auto picks for an elastic flex) is (damping + timestep) *
omega_i / 2: the integrator damps as if <elasticity damping> were one timestep larger, so with
no stated damping all of it is numerical and changes with sim.timestep, and the integrator’s
share is at most half exactly when sim.timestep is at or below the damping. That ratio, and the
frequency, hold while the timestep resolves the mode: at omega_i * timestep up to 0.3 a mode
damped at a ratio up to 0.3 rings within 5 % of both. Beyond it the run damps the mode less and
rings it slower than reported – with the damping one timestep, by 11 % and 9 % at 0.5, and at 0.85
a reported ratio of 0.85 rings down at 0.65 – so the report stars that mode’s figures
(resolved: false in --json) and warns. The contact floor is the time constant MuJoCo
raises a stiffer solref to: two timesteps under every integrator but discrete; under
discrete it caps the stiffness instead, which is timestep * sqrt(solimp[1]) / (solimp[1] *
dampratio) at the default solimp – about 1.03 steps at a damping ratio of 1. These rules were
measured on MuJoCo 4.0; the damping and the resolution are stated in
roqsim.flex_modes.explain_flex(), the floor in roqsim.solref.solref_floor(), which
sim.contact_override is held to as well; Deformable bodies in Available plugins measures them
and says where each stops holding.
The same block at a 4 ms step, with the damping raised to match it:
world: world.yaml
ok loads, compiles, every component resolved, and it resets
WARN [flex-timestep] flex 'blk': mode 2 (13 Hz) is under-resolved by the timestep (omega * timestep = 0.33, above 0.3), and so is mode 3; the damping ratio and frequency reported for them are not the ones that run: the discrete integrator distorts their dynamics, damping them less and ringing them slower than stated
hint: set sim.timestep <= 0.00213 s to bring omega * timestep to 0.3 or below for every reported mode, or lower the frequencies with a softer material (omega scales with the square root of <elasticity young>)
model: 38 bodies, 0 geoms, 108 joints, 0 actuators, 0 sensors, 0 cameras
timestep 0.004s, integrator discrete (auto: flex 'blk' (elasticity))
flexes (1):
blk dim 3, 45 vertices, 96 elements, dof full, 9 pinned, on holder; elastic, no passive contact
modes 11.4, 13*, 22.4* Hz; damping ratio 0.288, 0.326*, 0.562* at damping 0.004 s (numerical share 50% at timestep 0.004 s)
* under-resolved (omega * timestep above 0.3): a run damps and rings a starred mode differently -- see the flex-timestep warning
contact solref 0.02 1 (flex), floor 0.00410392 s
A WARN line names something a world that loads will do and its author probably did not mean –
damping that is mostly the integrator’s (flex-damping), a mode the timestep under-resolves
(flex-timestep, whose hint names the sim.timestep that resolves every reported mode), a
solref below the floor (flex-solref) – and never makes the check fail. In --json they are the warnings list,
each {"check", "message", "hint"} plus the flex it is about; the modes are under
derived.flexes, and the inventory under world.flexes. The modes are the one costly thing check computes (two
passive-force evaluations per flex degree of freedom and an eigen solve: seconds at most); a flex
above 2400 degrees of freedom is listed without them, with a hint – a coarser grid, or
dof="quadratic"/"trilinear", which reduce a flex to 27 or 8 nodes.
Recording a run¶
--record samples MuJoCo state while the run proceeds, so a run can be looked at afterwards —
from any camera, at any resolution, as a still or a video — without re-running it:
roqsim sim world.yaml --record run.mcap
roqsim sim world.yaml --record run.mcap --capture-fps 10 # a slower rate, a smaller file
roqsim render --state run.mcap --out last.png # where it ended up
roqsim render --state run.mcap --at 12.5 --out t.png # one moment
roqsim render --state run.mcap --out run.webm # the whole run as video
roqsim render --state run.mcap --renderer my_renderer --out run.mp4 # drawn through another renderer
roqsim render world.yaml --views views.yaml --out views/ # real cameras: a pose and intrinsics each (see rendering)
A recording is rebuilt from the world it ran in, so an override changes only how it is drawn: the
camera (sim.view) and the renderer with its settings (--renderer, sim.renderers.<name>).
Any other --set is refused, naming the key, since it could not change what was recorded.
A recording target is a file path ending in ``.mcap``, whether it comes from --record or
ROQSIM_RECORD. Anything else – another suffix, no suffix, a directory – is refused before the
world compiles, with exit status 2 and the target named (a recording is an .mcap file; got
'run.npz'); it is never renamed. --video without --record records beside the video, under the
video’s name with .mcap.
With nothing said about the camera, a recording is shown as the whole scene from above: every
geom in the world except the parked ones (below roqsim.presence.PARKED_BELOW_Z), angled rather
than top-down, as close as the field of view allows – and with the ceiling removed where the world
had one, since a view from above would otherwise be a view of a roof. That is the video you get with
no flags at all. A --view, --focus or --camera frames it otherwise and keeps the world
as it is (--no-ceiling is then yours to add), and a recording made in a window keeps the camera
the person watched it through.
Those three commands name no world, and that is not a shorthand: a recording carries the resolved
component tree rather than a recipe, so it rebuilds from itself and needs only the model packages it
referred to. What ran is recorded outright — including the actuator table, which says what control
law and gains every joint ran under and whether each value came from the model or from the world’s
actuators: block, so a result can state its gains without anyone reopening the MJCF. So is
which entities were present at each sample: presence is a model field the state cannot hold, so
the recording notes each change (presence in its provenance) and a replay applies it, and an
entity a trial brought in or took away appears and disappears in the render as it did in the run.
Without --at you get the last sample, and the command says so on stderr along with the sample’s
time — that is a choice you did not make, so it is not made silently. A video render reports progress the
same way: one line rewritten in place at a terminal, and a handful of lines when the output is a log.
Starting where the run starts moving¶
A run recorded from a live stack opens with the robot standing still while its nodes come up, a map
arrives and a plan is computed. --from onset skips that, and roqsim state --onset reports it
as JSON without drawing anything:
roqsim render --state run.mcap --from onset --out clip.mp4
roqsim state --state run.mcap --onset
The hard part is not the threshold, it is which velocity to read. A robot is spawned a little above
the floor and drops onto it, so something is moving at t=0 in almost every recording — and the drop is
sometimes faster than the drive that follows, so ranking motion by speed picks the fall. What separates
them is direction: a robot that falls moves along z and rocks about x/y, while a robot that
drives moves along x/y and turns about z.
So the signal is chosen by what the robot is, and the fall is not in it at all:
- A mobile base
is read by the planar motion of its base —
vx,vyand yaw rate. The fall isvzand the settle is roll and pitch, so none of it is in the signal.- A fixed base
is read by the velocity of its actuated joints. A bolted-down arm does not fall.
Which one a recording gets is read off the model rather than off any name: a robot is mobile iff the kinematic root of its actuated joints carries a free joint. Reaching the base through the actuators is what makes a world with props work — a parcel on a conveyor is a free body too, but it is the root of no actuated joint, so it is never mistaken for a base.
--onset-select overrides the choice with planar, actuated, a comma-separated list of joint
names, or any. any reads every velocity and needs no world rebuild, which is what lets it
answer for a recording whose world can no longer be built — at the cost of seeing the spawn drop, so
it reports kind: any to say the answer is the weaker one.
A run that never moved says so rather than reporting a time. moved means a sustained crossing
was found, not that the peak was high: a single sample of motion — a contact tick, a teleport — is not
a run in which anything drove, and reading the peak alone would clip a stationary robot.
onset is a moment, and a moment goes anywhere a time does: --from onset-1, --to onset+20,
--at onset+5 all resolve against the same table, found once.
Moving the camera: chase, path, and a person flying it¶
Three ways to say where the camera is during a clip, and they compose.
A chase camera is the world’s own track view, stated on the command line:
roqsim render --state run.mcap --from onset --no-ceiling \
--view track=robot follow_heading=true distance=2.5 elevation=-20 azimuth=180 --out clip.mp4
track attaches lookat to the robot’s body; follow_heading re-aims the camera each frame so
azimuth is an angle behind the robot (180 is directly behind) rather than a compass bearing.
A camera path moves it along keyframes, from a file or inline as JSON:
# orbit.yaml -- one orbit around the driving robot, then settle behind it
ease: smoothstep # linear | smoothstep
wrap: false # let azimuth sweep past 180 (a full orbit)
keyframes: # t: seconds, `onset`, or `onset+N`
- {t: onset, azimuth: 180, distance: 2.5}
- {t: onset+8, azimuth: 540, distance: 4.5, elevation: -35}
- {t: onset+11, azimuth: 540, distance: 2.5, elevation: -20}
roqsim render --state run.mcap --from onset --view track=robot follow_heading=true \
--camera-path orbit.yaml --out clip.mp4
Each key – lookat, distance, azimuth, elevation – is its own track: it interpolates
between the keyframes that state it and holds beyond them, and a key no keyframe states is never
written, so the base camera keeps it. That is what lets an azimuth-only path orbit a chase camera
while the robot’s own turning still counts: under follow_heading the path animates the angle
behind the robot, not a bearing. A keyframe may instead say where to stand and where to look, in
metres – {t: 0, eye: [9, -6, 5], target: [4, 2, 0.5]} – which converts to the orbit keys at
load. Azimuth takes the shortest arc between keyframes unless wrap: false. near: 0.02 draws
the path with its own near clip plane, for a camera closer than the model’s (visual/map znear
times the world’s extent, which a body parked far below the floor stretches to a metre): a close
shot of a hand.
Checking a path costs a still, not a clip. --at with --camera-path draws the frame the
clip would have at that moment, --check prints the resolved keyframes without drawing, and
roqsim state --state run.mcap --at T says where the robot is when choosing an eye:
roqsim render --state run.mcap --camera-path orbit.yaml --check
roqsim render --state run.mcap --camera-path orbit.yaml --at onset+4 --out look.png
That loop – where is the robot, write keyframes, look, adjust – is what makes a path something an agent can author as readily as a person.
A camera take is a person as the camera operator. In the replay window (below), Shift+F9 starts a take; play, fly the camera with the mouse and the flight keys;
Shift+F9 ends it. What lands is a clip in the shots file – from/to spanning the take and a
camera_path file beside the shots file holding the flown camera, one keyframe per frame – so
roqsim render reproduces the flight exactly as it was flown. Scrubbing back and playing again
overwrites that stretch rather than doubling it, and a take that never played is dropped and says so.
Drawing on the frames¶
--overlay paints an inset on every frame after the scene is rendered: clock puts the simulated
time in a corner, and installed packages add their own – a navigation package’s costmap, say –
under the roqsim.render_overlays entry-point group (see Interfaces). A bare name takes the
defaults; options ride along as JSON, anchor, width and margin being the ones every
overlay shares:
roqsim render --state run.mcap --overlay clock --out clip.mp4
roqsim render --state run.mcap --overlay '{"clock": {"anchor": "bottom-left", "format": "{t:.1f} s"}}' --out clip.mp4
roqsim render --overlay list
An overlay that nothing installed registers is refused before the world is built, naming what is available.
Rendering fewer frames than the recording holds¶
roqsim render draws one frame per sample and never decimates, so every frame in a video is a state
the simulation actually had. A recording captured at 250 Hz therefore draws eight frames for every one
that survives to a 30 fps video. --decimate drops them first instead:
roqsim state --state run.mcap --decimate 8 --out thin.mcap
The rows that remain are untouched, so the invariant holds; what changes is how many there are and the declared rate that says so. That rate stays exact because it is a numerator and a denominator — 250 Hz by 8 is 31.25 fps, not a rounded 31.
F9 records a take, in any windowed run — with or without --record. Press it once to start
and again to stop; the window title carries [REC] while one is running, and takes are numbered
(run.mcap, run-2.mcap, …) beside the --record path, or beside the default when the run was
started without one. It is the way to capture the interesting minute of a long run rather than all
of it, and what a take holds is what --record holds, so roqsim render --state reads it the
same way.
Replaying a run¶
Hand roqsim sim a recording instead of a world and it plays the run back, in the window a live run
uses — the same free camera, the same flight keys, the same visualization toggles. Nothing is
simulated: every frame is a state restored out of the file, so what the window shows is what happened.
roqsim sim run.mcap # from the start
roqsim sim run.mcap --at 12.5 # open at one moment
roqsim sim run.mcap --no-transport-window
roqsim sim run.mcap --world cell/world.yaml # a world that loaded files from beside itself
The extension is what selects it, as it does for a mesh target and for roqsim render’s output.
Options that drive a live simulation — --record, --steps, --pacing, --ros and their
kind — are refused by name rather than ignored, and a time outside the recording is refused the way
roqsim render --at refuses one. A recording rebuilds its world from its own provenance; where
that world loaded a plugin or a model by path from beside itself and those files are not beside the
recording, --world names the world to rebuild from, as roqsim render’s target does. The
provenance check still refuses one that does not match, and a shot taken in such a replay names the
world too, so its render rebuilds the same way.
A replay opens two windows. MuJoCo’s own takes a key callback and nothing else — no mouse
callback, no way to add a widget — so the slider, the timestamp box and the buttons are a small
window beside it, which is also what drives the replay. Without a display for that window, or with
--no-transport-window, the overlay bar and the keys carry it on their own: F11/F12 scrub (hold
Shift to jump), F8 plays and pauses, F9 writes a shot, Shift+F9 starts and ends a camera
take (Moving the camera: chase, path, and a person flying it). F1 lists what the run actually has.
A shot is why a replay exists. A figure needs one moment of one run seen from one place, and
neither half can be guessed at a command line: --at is a number nobody knows until they have
watched the run, and a camera is a pose nobody writes by hand. Pressing Add shot appends a document
to a shots file naming the sample, the camera, and the recording it came from — which
roqsim render draws later, at whatever size the figure wants:
roqsim sim run.mcap --shots shots.yaml --render-size 1920x1080
python3 -c "import yaml,subprocess as s;from roqsim.shots import read_shots,render_args
[s.run(['roqsim','render',*render_args(d)]) for d in read_shots('shots.yaml')]"
roqsim.shots.render_args() is the one place those flags are built, so the picture the window’s
Add + PNG button draws and the picture a figure script draws are the same command. Two of its rules
matter to anyone reading a shot: the render names no world (a recording rebuilds from its own
resolved tree only while no target is passed), and a shot framed by hand in a world whose sim.view
tracks the robot carries track: null and follow_heading: false, because --view merges over
that view and tracking would otherwise quietly ignore the lookat that was chosen.
A clip is a shot with a range where a shot has a moment: from/to instead of at, and
video instead of png. It carries the same state, view, size and source, plus
two keys a still has no use for – camera_path (a file, or the keyframe document inline) and
overlays (a list, in drawing order) – and roqsim.shots.render_args() turns both into the
flags above. A camera take writes one; so can a person or an agent.
--capture-fps is samples per simulated second, so a recording plays back at 1× sim time
whatever pacing the run used. Samples can only be taken on a physics step, so the rate is snapped onto
the world’s step grid and the command says so if that moved it noticeably; a fraction like 500/17
is accepted, which is what makes any rate it suggests something you can type back.
Recording costs the run almost nothing, which is why nothing is drawn while the loop runs. Measured over
30 s of sim with --pacing asap (so wall time is the loop cost): the default 25 fps is
indistinguishable from not recording; 500 fps — every single step on a 0.002 timestep — costs about
5.5%. A rendered frame, by contrast, is 2–6 ms depending on how much of the world is in shot (it is
scene-geometry bound, so resolution barely matters), against ~0.001 ms for a state sample: three orders
of magnitude, which is the whole reason the picture is made afterwards.
It costs the run almost no memory either, which is why an hour-long recording is a disk question and not a “will this fit” one: the file is written chunk by chunk as the run goes, and a chunk is closed and flushed at least once per wall second (and at 256 KiB). The rate is otherwise a disk decision: at 25 fps a mobile manipulator produces about 0.25 MB of state per simulated minute, and the chunks are zstd-compressed by a factor that depends on the world, because a state vector repeats: most of a world stands still, so most of a sample is the sample before it.
The file is one mcap (https://mcap.dev), profile roqsim, so any mcap tool can open it, and the
state channel is the primary artifact: one message per sample holding both clocks – t is
simulated seconds and w is wall seconds elapsed since the recording started
(wall_clock_origin in the metadata names that zero) – followed by the MuJoCo state vector as
float32, and the viewer camera when one was tracked. w is deliberately not a Unix timestamp – it
is monotonic, so an NTP step mid-run cannot make it go backwards, and it keeps nanosecond resolution
that a float64 holding 1.7e9 does not. Both are kept because neither is derivable from the other: their
ratio is the run’s real-time factor, which is exactly what varies. Use t to ask what the physics did
and w to ask what the run cost – a stall on a slow sensor, or the gap where a viewer sat paused,
exists only in w. For arbitrary computations over a run, use roqsim.recording:
from roqsim.recording import open_recording
with open_recording("run.mcap") as rec:
rec.real_time_factor # simulated seconds per real second, over the whole recording
for sample in rec.range(8.0, 20.0):
sample.sim_time, sample.wall_time, sample.index, sample.data
... # any numpy/mujoco computation over a real restored state
The with closes the rebuilt world’s plugins on the way out (rec.close() does the same): a
replayed camera holds an offscreen renderer exactly as a live one does, and only its shutdown releases it.
--record is for a run you launch yourself. A run launched for you — an orchestrator starting this
world through a ROS launch file, where the command line belongs to that file — asks for the same thing
through the environment, which both drivers honour:
export ROQSIM_RECORD=run.mcap # same as --record, and an explicit flag still wins
export ROQSIM_CAPTURE_FPS=25 # same as --capture-fps
export ROQSIM_RECORD_TRACKS='robot/**' # same as --record-tracks (below)
export ROQSIM_RECORD_EXCLUDE='shelf' # same as --record-exclude
A ROQSIM_* variable that roqsim does not read is refused when a run starts, by roqsim sim
and by the scenario adapter alike, as an unknown parameter: the run exits 2 naming it and
listing the ones roqsim reads (roqsim.env is that list). A misspelt or unread variable would
otherwise be ignored, and the run would look configured.
What the recording holds¶
Beside the state channel the file carries JSON channels a reader without the model can
use – roqsim health is one, a campaign’s ingest is another – poses, joints and clock
with one message per sample and events with one per event, each stamped log_time = simulated
time and publish_time = wall clock (epoch), and its schema in the
file:
poses{"t", "w", "bodies": {name: [x, y, z, qx, qy, qz, qw, vx, vy, vz, wx, wy, wz]}}– every recorded named body – robot bases, links, wheels, attached tools and workpieces, props and walkers – with the world pose as a quaternion and the world twist read from the solver viamj_objectVelocity. Every named body, and not only the ones parented to the world, because what a trial is judged on is often welded below a robot – a tool on a flange, a workpiece in a gripper – and a reader cannot know in advance which. Sites and unnamed bodies have no entry (the run log counts the unnamed ones and names their parents); thestatechannel is the complete state, from which those are derivable.joints{"t", "w", "q": {joint: value}}– every recorded hinge and slide joint, in radians or metres.clock{"wall_ts", "sim_ts"}– the pair a reader outside the process relates its own stamps to.events{"t", "run", "source", "event", ...}– not one per sample but one per event a plugin emitted (ctx.events.emit(source, event, **fields),roqsim.events): a machine starting a stroke, a controller beginning a move. Itslog_timeis the event’s own simulated time, so an event between two samples keeps its exact time;Recording.eventsreads them back in order.
And two metadata records, each a JSON document under the key json: roqsim.recording, the
provenance (world, overrides, the resolved component tree, actuator gains, endpoint rates, package
versions, the state layout, the seed and the run (together the key of every draw the run made),
and presence: from which sample on which entities were
absent), written at the start, again whenever the absent set changes, and again at close; and
roqsim.entities, the roster of what the pose entries are – each entity’s name, kind,
body and whether it is currently present, from the registry. A body name does not say whether
it is a robot, a prop or a walker, and nothing recovers that from the model, so the roster is written
again whenever it changes, and a reader takes the last one: a trial that spawns an obstacle mid-run
is described by it rather than by the world it started in.
The bodies a flex creates for its vertices or nodes (block_0, block_1, … of a
<flexcomp>) have no poses entry either: one each per sample that no success rule reads by name. The run log names each
flex left out; the body it is declared in keeps its entry, and the state channel carries the rest.
Two reasons the pose channel exists rather than leaving callers to difference the state. A velocity obtained by differencing positions is only ever as good as the interval it is divided by, and a consumer reading poses off a transport is dividing by arrival times – quantised by whatever gates the clock, jittered by delivery – so a constant speed comes out alternating. And a stepped run publishes nothing at all, so this is the only pose series it has.
t is exact simulated seconds. One convention worth knowing: mj_step integrates qpos and
leaves xpos holding the pose from before that integration, so an entry is a coherent snapshot
of t - dt carrying the label t – deliberately the same one-step lag the core pose endpoints
(sim/entities/<name>/pose) read with, so the two describe the same instant. It cancels in every
derivative.
Narrowing what the decoded channels carry. A manipulator world writes an entry per sample for
every link, which is more than most trials read. --record-tracks (ROQSIM_RECORD_TRACKS)
keeps only what its patterns select and --record-exclude (ROQSIM_RECORD_EXCLUDE) removes
what its patterns select, an exclude winning; both are comma-separated. A pattern is
<entity>/<body-or-joint> in the entity’s own words (its spawn prefix removed) – robot/** is
everything of that entity, robot/* one name segment – or a bare name as the compiled model
spells it, which selects the body and the joint of that name alike. A pattern that matches nothing
fails the run’s start, naming the entities, bodies and joints that exist: a typo must not record
a run that looks complete and lacks the one track the trial is judged on. The state and clock
channels are never narrowed.
A relative path is anchored to RUN_OUTPUT_DIR (this run’s own result directory) or, failing that,
OUTPUT_DIR (the job’s), so a run’s artifacts land beside its other results instead of
wherever the launch left the working directory; otherwise it resolves against the working directory as
usual. Deliberately not SCENARIO_OUTPUT_DIR: that is the root shared by every run of a batch, so
anchoring a per-run file there gives one path that each run of a sweep overwrites in turn. Recording stays a session
concern either way — the same footing as --headless, which a world YAML has no key for — so
there is no route to it through the world.
A run stopped any of the normal ways finishes its recording on the way out: closing the viewer
window, one Ctrl+C, or a SIGTERM – which is how a supervised run ends, whether that is docker
stop, a container teardown, a scheduler eviction or a supervisor’s timeout. Finishing writes the
file’s summary section, which is what marks a run that ended on purpose. SIGKILL skips it and
costs at most the open chunk – under a second of the run – because every chunk closed before the
kill is already on disk: roqsim.recording.open_recording() reads such a file with the chunks it
has, and its missing summary remains the signal that the run did not end on purpose.
Exporting a world as glTF¶
roqsim export gltf writes a world as one binary glTF 2.0 file (.glb), the standard format for 3D
scenes that three.js, Blender and every engine load. It compiles the world through the same build
pipeline a run uses, and what the scene contains is decided once, by the walk in
roqsim.scene_content. A browser viewer is best served with
--meshopt --texture-format webp (see Size below):
roqsim export gltf --world worlds/warehouse.yaml --out warehouse.glb
roqsim export gltf --mjcf model.xml --out model.glb
roqsim export gltf --world w.yaml --set sim.view.distance=8 --settle-steps 200 --out w.glb
The frame. glTF is Y-up and a roqsim world is Z-up. The file’s root node is named world and
carries the turn between the two (-90 degrees about x), so a point in the frame of node world
is a point in roqsim world coordinates: the world point (x, y, z) is the scene point
(x, z, -y). A viewer that reports a clicked point in the frame of world reports it in the
world’s own coordinates, with nothing to convert.
Bodies. Every body is a node, in MuJoCo’s body tree, named exactly as the body is, so a viewer can
name what was clicked and move a body by its name. A node’s extras repeat the name as body,
with body_id: three.js rewrites node names containing ., :, / or brackets, and the
exact name then survives in the object’s userData. A body sits where the exported state puts it
relative to its parent – a free body where the world placed it, a jointed link at its configured
value – since glTF has no joints to apply one.
Joints. The joints glTF has no place for ride in extras: a body node’s joints list each
joint’s name, type, axis, anchor pos and, for a hinge or a slide, ref; the
scene’s extras give initialJoints, the values the nodes are posed at, beside format and
version (roqsim.scene, 1) and the world’s authored view. That is enough for a viewer to
move an arm or a wheel from recorded joint values exactly as MuJoCo does: it takes each body back to
its pose at ref and turns or slides it by value - ref (roqsim.export_gltf).
Geoms. A drawn geom is an unnamed child node of its body’s node, holding one mesh; its extras
carry geom (its name, where it has one), body and geom_id. Primitives are tessellated
(--segments, by default the model’s own visual/quality numslices), meshes keep MuJoCo’s
normals, and an infinite plane becomes a square of the model’s extent. A surface MuJoCo shades with
its faces’ own normals – a box, a triangulated STL or OBJ – is written without normals, which glTF
draws flat, and with one vertex per corner position. Collision-only geometry
(group 3) is left out. A MuJoCo skin, and a flex, are glTF skinned
meshes whose joints are their bone bodies’ nodes, so moving the bodies deforms them; a
dof="quadratic" flex loses its negative weights (glTF allows none), exact at rest and approximate
under deformation, and the export says so.
What it looks like. Colours are MuJoCo’s resolved colours, converted to the linear space glTF
states them in, and textures its compiled pixels, embedded in the file. A texture lands where MuJoCo draws it: a primitive carries MuJoCo’s own
texture coordinates for it, and a mesh without coordinates gets the ones MuJoCo generates, so a
UV-less wall is tiled as in the simulator; texrepeat and texuniform scale them as MuJoCo
does. A tint above 1 is multiplied into the image, since glTF’s colour stops at 1. A cube or skybox
texture on a drawn geom is refused, naming the material. Every light fixed to its body is a
KHR_lights_punctual light on its body’s node (used, not required: a viewer without the extension
brings its own); a light that tracks a body, the headlight and the skybox are not exported. A world’s
sim.view becomes a camera named in extras as {"roqsim": "view"}, outside world.
Sensor cameras. Every camera sensor in the world (an RGB or RGB-D camera plugin) is a glTF
perspective camera on a node of its own, the child of the node of the body it is mounted on, at its
mount pose, so it follows that body when a viewer moves it. The node and the camera are named after
the sensor’s address (robot.oakd.oakd_camera), the projection is the one the sensor publishes
(yfov and aspectRatio from its intrinsics, znear/zfar the clip planes the sensor
renders with: its render_near and the model’s far plane), and the node’s extras carry
sensor (the address), kind (rgb, or depth for a device that publishes depth and no
colour) and the image’s width and height. A viewer renders the scene from that node to see
what the sensor saw, with no image stored.
Size. By default only core glTF is written, which every loader reads. --max-tex-dim caps
every image’s longest side (default 1024, 0 keeps them whole). --texture-format jpeg stores
opaque images as JPEG and webp every image as WebP (EXT_texture_webp), at
--texture-quality (default 85), several times smaller than PNG for photographic textures.
--meshopt compresses vertex and index data with EXT_meshopt_compression, which three.js
decodes with GLTFLoader.setMeshoptDecoder; it stores positions to 16 bits below each mesh’s
extent and normals and texture coordinates to fixed steps, and is meant to be gzipped on top. The
bundled warehouse (depot) is several megabytes at the defaults and about a fifth of that with
--meshopt --texture-format webp, the file a browser viewer is best served.
The export is checked with the Khronos glTF Validator: make test-gltf validates an export of every
bundled world (see Developer guide).
From Python. The compile is public, for a script that needs the model a world builds rather than a
file: roqsim.scene_source.compile_from_world() returns (model, data, view), and
roqsim.scene_source.compile_world() the same with the sensor cameras the world’s plugins declare.
Both take the world YAML, a set of plugin names or refs to drop, the overrides to merge in, a logger
and settle_steps, and return the state after reset():
import logging
from roqsim.scene_source import compile_from_world
model, data, view = compile_from_world("world.yaml", set(), {}, logging.getLogger(__name__))
Exporting a model as one mesh¶
export gltf, export urdf, export srdf and export moveit all keep a model as a body tree,
because their consumers animate or plan it. A second class of consumer wants the opposite – one rigid
mesh and nothing else. A model-based 6D pose estimator takes a single mesh and returns the pose of that
mesh’s frame; a CAD tool imports one body and knows nothing about joints:
roqsim export mesh --model turtlebot4 --out robot.obj --sidecar robot.json
roqsim export mesh --model turtlebot4 --out robot.3mf --units mm # for CAD
roqsim export mesh --world w.yaml --prefix ur10e_ --out arm.ply # one robot out of a world
The output’s extension picks the format – .stl, .obj, .ply, .3mf – and --format
overrides it, which is also the only way to ask for ASCII STL, since both STL flavours share an
extension. An extension nothing recognises is a usage error rather than a guess.
The frame is the contract. Vertices come out in the frame of one body – --frame, defaulting to
the root of the selection, which for a mobile base is its own base_link because the wheels hang off
it – so a pose estimated against the mesh IS the pose of that body, with nothing to compose onto it.
Every geom transform is composed back through the body tree from the compiled model rather than read
from the world, so exporting a robot from a bare model and from a world that spawns it somewhere odd
gives the same file.
Group 3 is excluded by default: the convention here is that group-3 geometry is collision-only, and a
chassis-swallowing collision cylinder is not a shape the robot has. --groups 3 asks for exactly
that envelope instead, which is the small clean solid to design a mount against.
Formats differ in what they can carry, and it matters:
Format |
Colour |
Structure |
Good for |
|---|---|---|---|
|
none |
one merged mesh |
the universally readable lowest common denominator; states no unit anywhere |
|
|
one merged mesh |
an estimator or renderer that matches on appearance (keep the |
|
per-vertex RGB |
one merged mesh |
the same, in one self-contained file with no sidecar to lose |
|
base materials |
one named object per geom |
CAD: parts stay separable and named, and the unit is stated in the file |
3MF is the one to hand a CAD tool. It is an OPC package (a zip of three XML members, written with the
standard library – no dependency), and unlike the others it does not merge the selection: each geom
becomes a named, coloured <object> assembled into one build item, so left_wheel_cylinder is
something a designer can select and hide rather than anonymous triangles inside a lump. It also
declares unit="millimeter", which removes the guess that makes a 0.35 m robot import 0.35 mm tall.
One caveat: 3MF’s specification wants manifold objects, and packaging does not make a non-watertight
source mesh manifold – consumers repair it, a strict conformance checker will complain.
Units are metres by default, MuJoCo’s own; --units mm is the CAD convention. Since an STL states no
unit anywhere, the choice is always recorded in the JSON summary (and in the file’s header or unit
attribute where the format has one).
Watertightness is reported, not claimed. A merged robot mesh is usually not a closed solid: shipped
visual meshes may have boundary or non-manifold edges, and two geoms that touch do not fuse. That is
fine for rendering and for pose estimation, which need a silhouette and an appearance; a CAD tool may
need a repair pass before mesh -> solid. So the summary counts boundary and non-manifold edges per
geom rather than asserting a solid, and --weld (default 1e-6 m) first merges vertices that are
merely duplicated, which is the common reason a mesh that looks closed is not.
Checking a run is healthy¶
Four things can go wrong with a run and raise no error anywhere: the simulation never starts
stepping, it stops stepping, it steps far slower than realtime, or a robot stands still for the whole
trial. The process is up, the log is quiet and the exit status is 0, and the run produced nothing
worth analysing. roqsim health is the check for exactly those four, and nothing else — everything
else a run can get wrong already reports itself.
roqsim health <run-dir> # judge the record as it stands
roqsim health <run-dir> --watch # follow a live run until something is wrong
roqsim health <run-dir> --json # one document: findings, skips, and state
It is a separate process that reads the recording above, and it changes nothing about a run. A
check that lived inside the simulator would share the simulator’s failure modes, and one that spoke
over the ROS bridge could not diagnose a broken bridge; this reads a file, so it can also say something
true about a run that is wedged or already dead. The clock channel answers checks 2, 3 and 4, and
the poses channel answers check 1; it follows the file as the recorder closes chunks, without
needing the summary a finished file ends with.
# |
slug |
check |
level |
|---|---|---|---|
1 |
|
every watched robot moves ≥ 1 cm per 60 s of sim time |
warn |
2 |
|
sim time starts advancing within 60 s |
error |
3 |
|
sim time advances again within max(60 s, 10× its row cadence) |
error |
4 |
|
sim time advances ≥ 5 s per 60 s of wall time (0.083x) |
warn |
Check 1 is only a warning because a robot standing still is often correct — waiting on a pedestrian, a perception-only run, a manipulator-only phase — and a channel that interrupts healthy runs is one nobody reads. Check 4 is a warning for the same reason: slow is not stopped. A clock row is written per recorder sample on the simulated-time grid, so an expensive world — a deformable body at a sub-millisecond timestep — keeps writing rows at a few percent of realtime, just further apart, while a frozen one writes none. Check 3 reads the silence, measured against the run’s own cadence so that a world whose rows are seconds apart is not failed for its ordinary pace; check 4 reads the pace.
Exit status is 0 when nothing is wrong (warnings are still printed), 5 on an error-level
finding, and 2 when the checks could not run at all (Exit status). Exiting on a finding is
the point: a backgrounded command’s output is invisible until it exits.
Which of those bodies is a robot comes from the roster. The poses channel names every
recorded body and cannot say which is which, so the recorder writes the roqsim.entities metadata
from the entity registry – name, kind, body, present – and check 1 watches the entities of
kind robot that are currently there. That is what makes one command correct for every world:
a check whose names have to be passed per world is a check that is absent from the run that needed
it. --robot remains as an override, for a run with no roster and for watching something the
registry does not call a robot.
An absent entity is deliberately not watched: its body stays in the compiled model, so the
recorder still writes rows for it, and a robot the trial has not brought in yet is standing still
entirely correctly. With no roster and no --robot, check 1 reports itself skipped and says
which of the two reasons applies — and it warns about a named robot that never appears in the record,
rather than passing one it never looked at.
The same roster is what lets --json’s state block carry a kind per entity, which the pose
record cannot: “the robot has not moved” and “the furniture has not moved” are different readings of
the same row.
The precondition. The recording exists only while a run is recording, so a run without
ROQSIM_RECORD cannot be checked. That is reported and exits 2; it never reads as health.
Who runs it, when a supervisor does. A run harness executes this command itself, in the running
container, on a bounded interval while somebody is watching the run — and reads --json: the
findings, and level in particular, are the contract it acts on. An error-level finding
is what such a supervisor ends a run on. So the exit code (Exit status) and the document are
a public interface, and check slugs are names other software matches on rather than prints.
Nothing is pushed from inside the run and nothing is written into a run’s output by this: it is read
on demand and answered.
What one check costs does not grow with the run. Every check judges the newest minute, so the file is entered at the newest chunks that cover that window and the chunks before them are never decompressed; only what arrives afterwards is read incrementally, and the report notes how much of a long record was left unread. That is what makes it safe to run as a fresh process on every poll, inside the simulator’s own container and memory budget: a reader that parsed a whole record each time would cost more on every poll for as long as the run lasted. A verdict is accordingly about the run now – a robot that stood still earlier and has moved since is not reported.
Silence means different things live and after the fact, which is why the two modes differ. Both
channels are sampled on simulated-time boundaries, so a frozen simulation writes nothing at all and
the only evidence of a stall is that nothing arrives. --watch is watching a run it expects to
continue, so that gap counts against it – and it stops without complaint when the recording gains its
summary section, since that is written by close() and so means the run ended rather than stopped. A one-shot
check has no such premise: it judges the span the record covers, because what happened after the last
row is not in the file. Without that split, every finished run would be reported as a stall a minute
after it ended. The cost is that a one-shot check cannot see a run that stopped — its rows simply
end — so check 3 fires there only on rows that arrived without advancing sim time, which the recorder
never writes. A supervisor polling a live run that has to catch a stop runs
roqsim health <run-dir> --watch --for <seconds> --json: its first poll is judged against the wall
clock, and --for bounds it to one pass or a few.
Exit status¶
Every roqsim tool exits with a status from one table (roqsim.exit_status), so a script
treats “the input I named is not there” the same way whichever tool it ran. Each tool’s --help
ends with the statuses it can return, generated from that table:
code |
meaning |
|---|---|
|
success |
|
an unexpected error (a crash, with its traceback on stderr) |
|
bad input or a wrong request |
|
no GL context (set MUJOCO_GL=egl or osmesa, or give a window a display) |
|
a recording that cannot be read or rebuilt |
|
a check or health verdict that failed |
|
a run that ended before its scene did |
2 is anything the caller can fix by asking differently: a world, model, recording or file that
does not exist or does not load, a flag or value that cannot be honoured. 4 is a recording that
exists and cannot be read (a file that is not mcap, or a format version this reader does not
know) or whose world cannot be rebuilt from its provenance; a recording path that names nothing, or
does not end in .mcap, is a 2. 5 is a verdict:
roqsim check finding a problem in a world it resolved, an error-level roqsim health finding,
an exporter’s --check finding its output off its source, an asset check (roqsim assets
collision, inspect-prop) failing a prop. 6 is roqsim sim ending – at --seconds or
--steps, on a signal, by its window closing, at a plugin’s or a quit’s asking – while a scene of the world (a Python scenario or an
OpenSCENARIO file) was still running: the scene neither passed nor failed, so the run is no pass. A
scene that ended exits 0, one that failed stops the run with its error, and a world without a
scene is unaffected. make smoke holds every shipped world with a scene to ending it within its
run (Developer guide). 1 is never returned on purpose, so it always means
the tool itself broke. Every other status comes with its reason: a line on stderr
naming the command, or the report the tool prints (check, health).
The scene-builder windows (roqsim builder) are the one exception: they return a person’s verdict
on what they were shown, and Scene builder (human 2D floorplan + 3D review) gives their statuses. Interrupting a command
(Ctrl-C) exits 130 (roqsim.exit_status.INTERRUPTED), as a shell’s convention has it.
Getting numbers out of a run¶
roqsim state reads the same recording as numbers rather than pixels — poses, joint values, contacts,
sensors:
roqsim state --state run.mcap --check # what does this recording offer?
roqsim state --state run.mcap --at 12.5 --body base_link # one moment -> JSON
roqsim state --state run.mcap --body base_link --out b.csv # whole run -> CSV
roqsim state --state run.mcap --joint 'arm_*' --from 8 --to 20 --out arm.csv
roqsim state --state run.mcap --sensor front --out scan.npz # the world's own lidar, re-run
--contacts lists every contact at that moment with its two sides — geom1/geom2 for a
geom, flex1/flex2 with vert1/vert2 or elem1/elem2 for a flex — its position
and its normal force.
--at snaps to the nearest recorded sample and tells you which one it used, so you can see it landed a
few milliseconds off rather than assume it did not. Names accept globs, and a selector that matches
nothing is an error naming the near misses — never an empty column.
Every row leads with both of the recording’s clocks — sim_time and wall_time (elapsed seconds
from the start of the recording, with its origin restated in the CSV header) — so “what was this run
doing when it slowed down?” is answerable from the same file as “where was the robot at t = 12.5”.
An .npz of array series carries them as the times and wall_times members.
--sensor re-runs a sensor the world declares, configured exactly as the world configured it, so
--check is how you see what is on offer. Its output shape decides the file: a few values become CSV
columns, a scan becomes an .npz array, and an image is refused with a pointer to
roqsim render --camera. A sensor’s columns are named <endpoint>.<field path>.<index>: a number
is <endpoint> alone, a vector <endpoint>.<index>, and a payload type <endpoint>.<field> per
field in declaration order, with a nested type’s fields under its field’s name and .<index> per
element of a vector field — an odometry endpoint gives odom.position.0 to odom.angular.2, a
wrench wrench.force.0 to wrench.torque.2. Text fields (joint names) have no column, and a
vector field wider than 32 values is refused; --joint reads joints from the state instead.
A re-run sensor is deterministic and gets the noise that moment would have had
(the recording carries the run’s seed and its name), but it is not bit-identical to what the live run published at
that timestamp — live, the sensor fires between recorded samples, so the value published then was
computed a moment earlier.
A selected sensor whose plugin raises while re-running on a sample is refused, naming it and the
error, rather than written with the value it held from the sample before; another plugin that raises
is logged as a warning and does not stop the rest.
Rebuilding a run’s sensor streams¶
A camera’s frames, its depth and a lidar’s scans are a function of the recorded state, so a run need
not produce or keep them: roqsim rebuild produces them afterwards from roqsim sim --record,
through each sensor’s own code – its intrinsics, resolution, frame ids, depth encoding and its noise,
drawn from the run’s seed – as the ROS 2 messages the bridge publishes, on the topics it publishes
them on:
roqsim rebuild --state run.mcap --list # the streams, rendering nothing
roqsim rebuild --state run.mcap --sensor robot/oakd --at 12.5 # one moment, nothing kept
roqsim rebuild --state run.mcap --from 8 --to 20 --rate 5 --output sensors.mcap
The primary interface is the Python iterator (python -m pydoc roqsim.rebuild): it opens the
recording once, renders only the frames asked for, restores each moment directly from its sample, and
keeps nothing. --output is one sink over it, an mcap file (ros2 profile, zstd chunks, the
manifest as roqsim.rebuild metadata). A moment is served by the nearest recorded sample, never an
interpolated one, and a --rate is the recording’s rate divided by a whole number – one above it,
or one that does not divide it, is refused with the rates it holds. Record at a multiple of the
sensors’ rates (--capture-fps 30 for a 10 Hz camera) to rebuild them at their own.
Which world endpoints a rebuild can produce is in roqsim check --json’s endpoints, before any
run: rebuildable, cost (render, raycast or null) and lazy.
Rendering a picture¶
roqsim render writes an image of a world without opening a window, so it works over SSH, in a
container, and from a script. It takes the same targets roqsim sim does — a world YAML, a baked
.xml scene, a model reference — plus a raw mesh:
roqsim render world.yaml --out shot.png
roqsim render roqsim_assets:industrial_table --out table.png # one model, auto-framed
roqsim render prop.obj --out prop.png # a mesh, before it is a model
The camera is the world’s own sim.view (above). --view overrides it one key at a time, so you
can re-aim without editing the world; the keys are exactly the ones sim.view accepts:
roqsim render world.yaml --out top.png --view elevation=-85 distance=45
roqsim render world.yaml --out eye.png --view lookat=-3.2,-1.3,1.9 azimuth=200
roqsim render world.yaml --out robot.png --focus robot # find an unblocked angle for me
roqsim render indoor.yaml --out room.png --no-ceiling # see into a roofed world
roqsim render world.yaml --out shot.png --size 1920x1080 --show
--focus searches for a viewpoint with a clear line of sight, which is what you want indoors where
a wall is usually between the default camera and the thing you care about. --show opens the result.
Rendering needs an offscreen GL backend, which import roqsim already selected for this machine;
override it with MUJOCO_GL=egl (GPU) or MUJOCO_GL=osmesa (CPU). If mujoco was somehow
imported before roqsim — the one case that selection cannot reach — roqsim render says exactly
that rather than failing obscurely.
A vector value takes either spelling — lookat=-3.2,-1.3,1.9 or lookat="-3.2 -1.3 1.9", MJCF’s
— so a pose can be pasted back in whichever form you have it.
The command prints one line of JSON describing what it rendered, including the camera it used — in the
same vocabulary --view takes, so you can copy it back to reproduce a shot exactly.
From scenario-execution¶
roqsim implements scenario-execution’s SimulationInterface. Point the world file at it via an
environment variable and load the adapter by module:Class:
export ROQSIM_WORLD=roqsim_mobile/src/roqsim_mobile/worlds/turtlebot4_demo.yaml
scenario_execution --simulation roqsim.scenario_adapter:MujocoSim <scenario.osc>
scenario-execution owns the loop and calls dt / setup / reset / step / shutdown;
one behavior-tree tick advances one mj_step.
By default the adapter runs headless. To show the interactive viewer window, pass a headless
scenario parameter set to "False". This needs a display (the viewer window is always glfw,
independent of MUJOCO_GL); with no DISPLAY set, reset() raises a clear DisplayError
instead of crashing in the native viewer init. Unlike the standalone runner, the adapter does not
apply the runner’s windowed GL defaults (the libGLEW preload and its re-exec); set them yourself if
a windowed adapter run hits gladLoadGL error on a camera world. The offscreen backend is not
among them — that one is chosen by import roqsim, so the adapter gets it like everything else,
which is what makes a stepped run able to render at all.
The adapter can also leave the scene next to the run: set ROQSIM_SCENE_EXPORT_DIR and every
(re)built world is exported as scene.glb into that directory after reset() — the file
roqsim export gltf writes with its default options, but of the exact simulated world
(world_overrides included), captured at its true initial pose. A relative path is anchored to
the scenario’s own directory when scenario-execution hands one to reset() (its output_dir
argument), else to RUN_OUTPUT_DIR when it is set, else to the output_dir scenario-execution
passes to setup(), else to the process working directory.
It records on the same environment contract the standalone runner uses (ROQSIM_RECORD,
ROQSIM_CAPTURE_FPS, ROQSIM_RECORD_TRACKS, ROQSIM_RECORD_EXCLUDE – see
Recording a run), with a relative path anchored the same way. A parameter file that runs
several scenarios in one process hands reset() a directory per scenario, and the recording
and the scene export roll with it: the scenario before is finished, with its summary, and the next
one records and exports its scene into its own directory, with the engine kept rather than rebuilt. That is what turns a run into
something replayable: the scene above is the world’s geometry, and the recording is what moved
in it.
What a scenario can ask the simulation¶
scenario_execution_roqsim ships the substrate’s own OSC actions — import osc.roqsim:
entity_moved(entities: ['parcel'], threshold: 0.05, mode: displacement_mode!z, dwell: 8.0)
entity_rotated(entities: ['crate'], angle: 0.5)
entity_monitor(entity: 'ur5e', value: 'force_limit.tripped', target_variable: tripped)
entity_call(entity: 'grip_fault', command: 'override', value: 'true') # 'false' restores it
entity_near(entity: 'robot', target: 'shelf', distance: 0.6)
entity_in_region(entity: 'robot', region: [position_3d(x: 2m, y: 0m), position_3d(x: 3m, y: 1m)])
entity_moved / entity_rotated succeed once the named entities have been displaced (or turned)
from where they were when the action started — net displacement, not path length, unlike
osc.ros’s odometry_distance_traveled. entity_call sends any command a plugin declares –
here a model_override fault (§9.2) – and fails the trial when the command’s confirmation reports
that it changed nothing, so a run cannot record an unfaulted outcome under a faulted label.
entity_monitor keeps a scenario variable equal to a value a plugin publishes about an entity –
<endpoint>.<field>, as the world names it – on every tick, as osc.ros’s topic_monitor
does for a topic. It never succeeds on its own, so it runs in a parallel branch, and every
condition is plain OpenSCENARIO over the variable:
scenario trial:
timeout(120s)
min_clearance: float = 0.3
var tripped: bool = false
var clearance: float = 10.0
do parallel:
entity_monitor(entity: 'ur5e', value: 'force_limit.tripped', target_variable: tripped)
entity_monitor(entity: 'robot', value: 'clearance.current', target_variable: clearance)
serial:
wait tripped == true
emit end
serial:
wait clearance < 0.2
emit fail
pattern |
how it reads |
|---|---|
end the run on an outcome |
|
threshold |
|
assertion: fail if it ever goes bad |
a parallel branch: |
bound an action |
|
combined conditions |
|
comparison with a parameter |
|
event and condition |
|
A flag is compared explicitly (tripped == true): a condition is a comparison or a logical
expression, not a bare variable. Until the first reading arrives the variable keeps its declared
default, so declare one the condition does not hold for. A condition that must hold for a length of
time is composed in the language itself; scenario-execution’s language documentation describes that
pattern. An entity, endpoint or field that does not exist, and a field that is not a single number,
flag or string, are refused with the same text on both transports.
Where an entity is – near something, inside an area – is geometry, which an expression cannot compute, so actions state it; each succeeds on the first tick its condition holds:
entity_near(entity: 'robot', target: 'shelf', distance: 0.6)
entity_near_position(entity: 'robot', position: position_3d(x: 4m, y: 2m), distance: 0.3)
entity_near(entity: 'gripper', target: 'parcel', distance: 0.05, mode: distance_mode!spatial)
entity_in_region(entity: 'robot', region: [position_3d(x: 2m, y: 0m), position_3d(x: 3m, y: 1m)])
entity_in_region(entity: 'person', outside: true, region: [p1, p2, p3, p4]) # a polygon
The distance is between reference points – the origins of the entities’ bodies, from the core’s
sim/entities/<name>/pose – and measured in the floor plane unless distance_mode!spatial asks
for 3D, since “the robot reached the shelf” is a statement about the floor plan. A region is an area
of the floor plan: two points are a box’s opposite corners, three or more a polygon’s vertices; z is
ignored and the boundary counts as inside. Neither action fails on its own: timeout() bounds one
that must hold in time, and “must never enter” is a branch that fails the trial, bounded by until
for as long as the rule applies:
do parallel:
serial:
entity_navigate(entity: 'robot', goal_poses: [...])
emit end
serial:
entity_in_region(entity: 'robot', region: [position_3d(x: 2m, y: 0m),
position_3d(x: 3m, y: 1m)])
emit fail
with:
until @door_open
Every entity_* condition (entity_moved, entity_rotated and these) reads the core’s
sim/entities/<name>/pose on both transports, so it names entities, not bodies. An entity that
exists but is absent (deleted, or not spawned yet) is nowhere, so the condition waits for it and says
so; a name the world never had is refused at once, naming the closest names, with the same text on
both transports. entity_moved and entity_rotated also refuse an entity welded to the world
(the pose endpoint’s movable: false), whose pose can never change.
Each works in a stepped run and against a simulator in another process, unedited: the transport is
chosen from what the runner offered. In-process they read MujocoSim.context (entity poses,
commands and reports through the world’s endpoints, writes queued on the physics
thread); otherwise they reach roqsim sim’s control socket (Talking to a running simulation) – the same endpoints,
found by the same entity and endpoint names, which is what makes one scenario serve both. None of them
can run under remote(): a remote server is handed no simulation.
ROS 2 bridge¶
source /opt/ros/jazzy/setup.bash
source ros2_ws/install/setup.bash
.venv/bin/python -m roqsim_ros_bridge.run_bridge \
--world ros2_ws/src/roqsim_ros_bridge/worlds/turtlebot_ros2.yaml
# in another sourced shell:
ros2 topic pub /cmd_vel geometry_msgs/msg/Twist '{linear: {x: 0.2}, angular: {z: 0.3}}'
ros2 topic echo /odom
ros2 topic echo /scan
ros2 service call /get_simulator_features simulation_interfaces/srv/GetSimulatorFeatures
The bridge publishes /clock; run other nodes with use_sim_time:=true. See
nav2 example for a full navigation stack.
Log lines for an aggregator¶
roqsim’s commands log LEVEL logger: message, which suits a terminal. Where roqsim is one
producer in an aggregated log, ROQSIM_LOG_FORMAT=stamped switches to
[LEVEL] [epoch] [logger]: message – the shape ROS tooling writes, stamped with the time the
event happened. plain is the default; any other value is an error rather than a fallback.