Expand description
The simulator in the browser: core, machines and analysis built for wasm32-unknown-unknown, behind a few C-ABI
functions that take and give UTF-8 text. web/index.html loads the module and runs a sizing check with it.
The page writes a request into memory from alloc, calls call(kind, ptr, len) and reads the answer, JSON, from
out_ptr() and out_len(). call returns 0 when the answer is a result and 1 when it is {"error": "..."}.
| kind | request lines | answer |
|---|---|---|
| 0 | language | [{"id", "name", "file"}], every machine |
| 1 | machine id | {"config"}, the machine’s default config (TOML) |
| 2 | machine id, language and options, a config (TOML) | the run’s load per motor and its verdicts |
| 3 | machine id, language and options, a config (TOML) | {"dt_s", "centre", "radius", "motors", "sample"}: the 3D view starts |
| 4 | file name, language, then a machine file (TOML) | {"id", "name", "config"}: the machine to use as an id |
| 5 | machine id, language and options, a config (TOML) | {"motor", "points"}: frequency response of one motor |
| 6 | machine id, language, a config, ---, a trace (CSV) | {"rows", "advice"}: masses and friction fitted to the trace |
| 7 | language, then translation keys, one a line | {key: text}: the page’s texts and those keys |
| 8 | machine id, language, a config (TOML) | {"params", "parts"}: the values the page’s form edits |
| 9 | machine id, language, a config, ---, path = value lines | {"config", "changed", "compact"}: the values set in the config’s own text |
| 10 | machine id, language, a config (TOML) | {"step_s", "time", "signals", "motors"}: the scopes of one pass of the cycle |
An empty config is the machine’s default one. Parts the config names ([parts]) come from the built-in catalogue,
as in every front end. WebAssembly starts no threads, so analyses that share the processors natively run one after
another here.
Options follow the language on its line, separated by spaces: path runs the path (format: sim_components::path)
that follows the config after a line --- instead of the cycle, timed within the axis limits or with
time-optimal as fast as the motors allow (kinds 2 and 3); motor=K, from=HZ, to=HZ, count=N and
amplitude=NM set the sweep of kind 5 as sim-cli sweep takes them. A line --- is never part of a TOML config.
Machines: the registered ones by their id, the machine files of machines/ built into the module as
file:<name>.toml, and a file the page hands in (kind 4) as upload:<name>.
The 3D view: kind 3 sets the machine at its start pose and starts its cycle or path; centre and radius are the
sphere round its scene there, to fit the camera to. Then the page calls frame(seconds), which runs the simulation
on by that many seconds and returns where frame_len() 32-bit floats lie, no JSON: a head of HEAD floats
(time_s, cycle_s, the tool’s x, y, z, the number of parts, of obstacles and of samples; NaN for what is not
known yet), RECORD floats per part and per obstacle, as record lays them out, and sample floats per sample as
Player::sample lays them out: the plots’ and the trail’s data since the last frame. A request that is not a
finite time from 0 to MAX_FRAME_S is refused: frame returns null and the error is the answer at out_ptr.
Constants§
- HEAD
- Floats in front of the parts in a frame.
- MAX_
FRAME_ S - The most simulated time one
frameruns, s: more is refused rather than left to hang the page. - MOTOR_
SIGNALS - Signals per motor in a sample, each as its lowest and highest value over the sample: torque, torque command, speed, speed command, following error.
- OBSTACLE_
MESH - The mesh number of an obstacle: a cube drawn see-through.
- RECORD
- Floats per part in a frame.
- SAMPLE_
HEAD - Floats of a sample in front of its motors: time, the tool’s x, y, z, and its distance from the plan.
- SAMPLE_
S - How long a sample spans, s: the plots get every peak, as the lowest and highest value within it.
- SCOPE_
ROWS - The most rows a scope answer has: one a millisecond up to a pass of 30 s.
- SCOPE_
SIGNALS - The signals of the scopes (kind 10), per motor, by the end of their id
motor.<id>.<signal>.
Functions§
- alloc
- Room for a request of
lenbytes, which the caller writes and hands tocall;callfrees it. - bounds
- The box with edges along the axes round every part of
records(RECORDfloats each): lowest and highest corner. - call⚠
- Safety
- frame
- Runs the 3D view’s machine on by
secondsand returns its frame (see the module’s documentation); null before kind 3 has set one up, and null with the error as the answer atout_ptrfor a time that is not finite, below 0 or overMAX_FRAME_S(an infinite one ran the steps’ count to the largest integer and hung the page). - frame_
len - How many floats the last frame has.
- handle
- The answer to a request as
callgets it, or the message of why there is none. - out_len
- How long the last answer is, in bytes.
- out_ptr
- Where the last answer is.
- record
- One part as the page draws it,
RECORDfloats: the mesh (0 a cube of side 1, 1 a cylinder of diameter and length 1 along y, both centred on the origin; turned asPart::flatsays), the matrix that takes the mesh to the part in scene coordinates (4 × 4, column by column, as WebGL takes it), and the colour (part_color, red, green, blue in 0..1). A segment is a cube stretched frompostoto,widthwide in the depth (y) and 4 mm thick, as in sim-app. - record_
obstacle - An obstacle as the page draws it,
RECORDfloats asrecordlays them out: meshOBSTACLE_MESH(the unit cube, drawn see-through), stretched to the obstacle’s box, grey, or red while a part of the machine touches it. - sample_
len - Floats per sample for a machine of
motorsmotors. - torque_
speed_ curve - The torque-speed curve of a motor’s drive (
DriveParams::torque_curve) as an outline of (speed rad/s, torque N m): the highest torque from the no-load speed backwards to the no-load speed forwards, then the lowest torque back, at the curve’s corners and 40 speeds between (a field-weakened curve bends). And the continuous (S1) rating as the app and the motor-s1 verdict have it (charts::torque_speed): its line for positive torque, then the one for negative torque back, closed.