Skip to main content

Crate sim_fmi

Crate sim_fmi 

Source
Expand description

FMI export: a machine as an FMI 2.0 or FMI 3.0 Co-Simulation FMU, for Simulink, OpenModelica, Dymola and other tools.

One binary serves both versions: the fmi2* functions are in api, the fmi3* ones in api3, and both drive the same api::Instance. Model Exchange is not offered (docs/fmi.md says why: the controller is a sampled controller whose internal states the importer’s integrator cannot see). An FMU state holds a snapshot of the simulation, which setting it restores at once, serialized or not (api). The directional derivatives of the outputs with respect to the inputs are exactly zero, because an input acts on the outputs only through the next communication step.

The FMU carries one generic binary (sim_fmi.dll, sim_fmi.so) for every machine; which machine and which config it runs come from its resources (resources/model.txt: machine id and language; resources/config.toml). A machine from a machine file (docs/machine-files.md) is not registered: its file goes along as resources/machine.toml, and the FMU builds the machine from it when it is instantiated. The model description is generated from the machine’s signal list and config, never written per machine:

variabletypecausalitymeaning
timeRealindependentsimulated time, s (Real in 2.0 is Float64 in 3.0)
every other signal idRealoutputevery signal of the simulation, with its unit
command.setpoint.<axis>Realinputposition setpoint, interpolated as from a PLC
command.enableBooleaninputfalse switches the drives off (brakes on)
command.stop_categoryStringinputhow false stops them: “0” (off), “1” or “2”
command.cycleBooleaninputtrue starts the configured cycle, false stops it
command.target.<axis>Realinputthe target of a move
command.moveBooleaninputturning true moves to the targets
command.pathStringinputa path as the text of a path file
command.path_fileStringinputa path file, used instead of command.path
command.trajectory_fileStringinputposes at times, run instead of a path where not empty
command.run_pathBooleaninputturning true plans the path from here and runs it
command.mode.<motor>Stringinputthe drive’s mode: “position”, “velocity” or “torque”
command.torque.<motor>Realinputtorque setpoint in torque mode, N m (N if linear)
command.velocity.<motor>Realinputspeed setpoint in velocity mode, rad/s (m/s if linear)
time_optimalBooleanparameterpaths timed as fast as the motors allow
machineStringparameterthe machine of the registry
config_fileStringparametera config file to use instead of the one in the FMU
effects.<name>Booleanparameterthe effect switches, overriding the config’s

The value reference of a variable is its place in the list, unique across types. The names are the signal ids as CSV columns and OPC UA nodes have them; the naming convention is “flat”, since ids such as belt.1.tension are not identifiers of the “structured” one. A position setpoint goes to the controller as Command::Setpoint whenever it differs from the one the controller follows; the controller interpolates towards it over profile.setpoint_interval_s, so the communication step should be that interval (the model description’s default step). fmi2DoStep and fmi3DoStep run whole base steps (sim.dt_s) and refuse a communication step that is not a whole multiple of it. The triggers (command.cycle, command.move, command.run_path) act at the communication point where they have changed since the last one; a setpoint input, once set, takes the axes over whenever it differs from the setpoint the controller follows, so an importer drives the machine either by setpoints or by cycle, moves and paths. A motor whose command.mode.<motor> is “velocity” or “torque” takes command.velocity.<motor> or command.torque.<motor> as it stands at each communication point, held over the step, in place of the controller’s plan (sim_components::DriveMode): the importer’s own controller closes the loop. The mode changes at the communication point where the input differs from the drive’s.

Modules§

api
The FMI 2.0 Co-Simulation C functions, and the instance both FMI versions drive (api3 has the FMI 3.0 ones). The type definitions follow the FMI 2.0 headers (fmi2TypesPlatform.h, fmi2FunctionTypes.h; Copyright Modelica Association Project “FMI”, BSD-2-Clause licence), written out in Rust.
api3
The FMI 3.0 Co-Simulation C functions, on the same instance as the FMI 2.0 ones (api::Instance). The type definitions follow the FMI 3.0 headers (fmi3PlatformTypes.h, fmi3FunctionTypes.h; Copyright Modelica Association Project “FMI”, BSD-2-Clause licence), written out in Rust.

Structs§

Model
An FMU’s content apart from its binaries: the machine, the config as text, and the model description generated from them.
Variable

Enums§

Kind
What a variable stands for.

Constants§

LOG_CATEGORIES
The log categories of the model description, with their descriptions’ keys: the commands the inputs gave and the states set, warnings, errors; logAll stands for all of them (fmi2SetDebugLogging, fmi3SetDebugLogging).
MODEL_IDENTIFIER
The name of the binary in the FMU and of the C functions’ library.

Statics§

I18N
(language code, translation file contents) for the export’s own labels and messages.

Functions§

binary_path
Where a binary goes in the FMU, from its file name: binaries/<platform>/sim_fmi.<extension>.
binary_path3
Where a binary goes in an FMI 3.0 FMU: binaries/<architecture>-<system>/sim_fmi.<extension>, the system from the extension and the architecture (x86_64 or aarch64) from the binary’s header (PE, ELF or a thin 64-bit Mach-O). None for anything else, a universal Mach-O among it: FMI 3.0 wants one folder per architecture.
crc32
The CRC-32 a zip archive carries per file.
is_registered
Whether entry is one of sim_machines::MACHINES, not a machine from a file.
machine_of
The machine of an FMU’s resources: from machine.toml where it carries a machine file, else the registered one of that id.
texts
Every label the FMU shows, in one language: machines, components and the export’s own.
zip
A zip archive of the files, stored without compression: an FMU is a zip, and stored entries need no library.