Start a Machine from one TOML file, with no code of the deployer's.
[machine] name = "Robot" [machine.identification] serial_number = "example-0001" manufacturer = "Example Manufacturer" product_instance_uri = "urn:example:opensmi-ros2:robot" [ros2] domain_id = 42 [[component]] name = "Platform" [[component.monitoring]] name = "Odom" path = "/odom" message_type = "nav_msgs/msg/Odometry" [[component]] name = "Arm" parent = "Platform"
The function load_machine reads the file and returns a Machine ready for opensmi's
Server.add_machine.
The whole file is checked before anything is built. Every mistake is collected with the path to its
place (component[1].monitoring[2].message_type) and raised together as one
~opensmi.ros2.server.errors.FileDeclarationError. The checks reuse the Binding declarations' own
validation and the loader of opensmi.ros2.server.config, so a new rule on a Binding applies to the
file at once. The Runtime comes from runtime_factory and is made only once the file has passed.
An optional [server] config = "server.toml" is resolved against the file's directory, must exist,
and is carried as ConfiguredMachine.server_config for the caller that builds the Server, as
opensmi.ros2.cli does. Without it, opensmi's defaults apply.
A Component names its parent with parent (default: the Machine), and a parent comes before its children in the file. A Binding file can be included with bindings_toml.
[[component.projection]] and [[machine.projection]] hold one Projection entry each: recipe
(one of RECIPES), type, and the recipe's own parameters. The keys of a recipe are derived
from its dataclass, minus fields with no TOML spelling (callables) and minus the functions recipe,
which is only callables. Entries register through
~opensmi.ros2.server.projection.ProjectionRegistry.extended in the same layers as in Python
(Component, then Machine, then the shipped catalogue), so a second entry for one type is an error
unless it says override = true. Every recipe takes override and type_hash. scalar also
takes variant_type (a name such as Float, or its number) and datatype (a namespace 0
DataType number), blob takes field and datatype, enum takes fields (a table per
field name of number to label) and drop takes fields (a list of field paths):
[[component.projection]] recipe = "drop" type = "nav_msgs/msg/Odometry" fields = ["pose/covariance", "twist/covariance"] [[component.projection]] recipe = "enum" type = "sensor_msgs/msg/BatteryState" [component.projection.fields.power_supply_status] 0 = "Unknown" 1 = "Charging" [[component.projection]] recipe = "scalar" type = "std_msgs/msg/Float64" variant_type = "Float"
A file may name the deployer's own classes by import path (package.module.Name or package.module:Name, the colon reaching a nested name): machine_class and component_class, startup_skill_type, driver_type inside a lifecycle table, and the callables of a projection table (recipe = "functions"). Without a key the stock class applies. Importing runs that module's code, so a machine file is trusted configuration. Nothing is imported until the whole file has passed the structural checks. Import errors and classes of the wrong kind are reported at their key.
[machine] name = "Robot" machine_class = "my_robot.cell:Cell" startup_skill_type = "my_robot.cell:CellStartup" [[component]] name = "Platform" component_class = "my_robot.cell:Platform" [[component.lifecycle]] name = "Navigation" path = "/lifecycle_manager" driver_type = "my_robot.cell:NavigationDriver" [[component.projection]] recipe = "functions" type = "my_msgs/msg/Pose" shaped_by = "my_robot.curation:pose_shape" decoded_by = "my_robot.curation:pose_decode" encode = "my_robot.curation:pose_encode"
machine_class must subclass ConfiguredMachine and component_class
ConfiguredComponent; a class with its own __init__ passes unknown keywords on to the base.
startup_skill_type must subclass the stock StartupSkill (the lifecycle one on a Component with
lifecycle Bindings) and driver_type LifecycleDriver. The functions recipe takes one key per
callable (shaped_by, decoded_by and the optional encode); the encode of a blob is
named the same way.
Anything beyond Bindings, Projections, identification and these classes stays Python, such as the Skill, Method or goal classes and the message functions of a Binding, and logic between declarations (adding Components in a loop), which belongs in a machine_class.
From Python:
async with Server() as server: await server.add_machine(load_machine("machine.toml")) await server.start(blocking=True)
| Class | |
The stock Component a machine file declares: Bindings, identification and children. |
| Class | |
The stock Machine a machine file declares: identification, TF Bindings and Components. |
| Class | |
The identification block of a Machine or Component, as a file gives it. |
| Function | load |
Read a machine file and return the Machine it declares, ready for Server.add_machine. |
| Constant | RECIPES |
The recipes a projection table can name. A test fails when a recipe of opensmi.ros2.server.recipes is missing from it. |
| Class | _ |
What the [machine] table declares. |
| Class | _ |
A file that has passed every check. |
| Class | _ |
The mistakes found so far, in the order the file reaches them, and what waits for an import. |
| Class | _ |
A class or callable the file names by import path, resolved only after the structure passed. |
| Class | _ |
One Component as the file declares it, before anything is built. |
| Class | _ |
A frozen declaration built with stand-ins, rebuilt with the imported objects. |
| Function | _arrange |
Place each Component under its parent, or report why it cannot be. |
| Function | _build |
Construct a Component with its children, which are constructed first. |
| Function | _callable |
Return what is wrong with an imported object that has to be called, if anything. |
| Function | _check |
Report each key the table has that the model does not know, at the key. |
| Function | _component |
Read one [[component]] table. Where it sits in the tree is decided afterwards. |
| Function | _declare |
Build one Binding from its table through the declaration's own checks. |
| Function | _declare |
Build the Bindings the kind tables of one component or machine declare, in file order. |
| Function | _identification |
Read an identification table. opensmi refuses to start an item that leaves an entry empty. |
| Function | _import |
Import the object an import path names. |
| Function | _include |
Read the Binding file a component includes, relative to the machine file. |
| Function | _join |
Undocumented |
| Function | _layered |
Read the projection tables of a Machine or Component and register them over a registry. |
| Function | _machine |
Read the [machine] table. |
| Function | _misplaced |
Say why a Component's parent is not a place it can go. |
| Function | _projection |
Build one Projection from its table, through the recipe's own dataclass. |
| Function | _real |
Build the real Runtime. Imported here, as rclpy is needed to import it. |
| Function | _recipe |
Return the keys a recipe's table takes; a callable field is spelled as an import path. |
| Function | _recipe |
Report each key the recipe does not take and each it needs and lacks, and say whether none. |
| Function | _reference |
Read a key that names a class or callable by import path, checking only its shape. |
| Function | _required |
Return the keys a recipe's table must carry: its fields that have no default. |
| Function | _resolve |
Import everything the file names, report what fails, and rebuild the stand-in declarations. |
| Function | _ros2 |
Read the [ros2] table into the settings the Runtime and the Machine share. |
| Function | _server |
Read the [server] table: the opensmi server configuration the file points at, which must exist. |
| Function | _stand |
Stand for a callable a file names until it is imported. |
| Function | _string |
Return a non-empty string value, or report a wrong one at its path (an absent key is silent). |
| Function | _subclass |
Return the check that an imported object is a class derived from base. |
| Function | _swapped |
Replace each stand-in declaration by its real one. |
| Function | _table |
Return the value if it is a table, else report it at the path. |
| Function | _unique |
Check no two Bindings share a name, with the rule a Component applies at init. |
| Function | _validate |
Read and check the whole file, and raise every mistake in it at once. |
| Async Function | _write |
Write what the file gave into the item's identification block. |
| Constant | _COMPONENT |
A Component's identification block has no product URI; only a Machine's does. |
| Constant | _COMPONENT |
Undocumented |
| Constant | _LOCALE |
The locale of the manufacturer's text; a file carries one string. |
| Constant | _MACHINE |
Undocumented |
| Constant | _MACHINE |
Undocumented |
| Constant | _PATH |
An import path: dotted names, with an optional : before the attribute (which may be dotted). |
| Constant | _TOP |
Undocumented |
| Constant | _TYPE |
The key a table spells a recipe's type_name with. |
| Type Variable | _T |
Undocumented |
str | Path, *, runtime_factory: Callable[ [ ROS2Config], RuntimeInterface] | None = None) -> ConfiguredMachine:
¶
Read a machine file and return the Machine it declares, ready for Server.add_machine.
| Parameters | |
path:str | Path | The TOML file. A relative bindings_toml or [server] config in it is relative to this file. |
runtimeCallable[ | How to make the Runtime from the file's [ros2] settings, called once and only after the file has passed. None builds the real Runtime, which needs rclpy; a test passes a function returning its fake. |
| Returns | |
ConfiguredMachine | Undocumented |
| Raises | |
FileDeclarationError | When the file has any mistake, with all of them and the path to each. Nothing has been constructed by then. |
OSError | When the file cannot be read. |
The recipes a projection table can name. A test fails when a recipe of
opensmi.ros2.server.recipes is missing from it.
| Value |
|
Mapping[ str, Any], allowed: Iterable[ str], path: str, problems: _Problems):
¶
Report each key the table has that the model does not know, at the key.
int, raw: Any, base: Path, machine: ProjectionRegistry, problems: _Problems) -> _Spec | None:
¶
Read one [[component]] table. Where it sits in the tree is decided afterwards.
Mapping[ str, Any], kinds: Iterable[ str], path: str, problems: _Problems) -> list[ Binding]:
¶
Build the Bindings the kind tables of one component or machine declare, in file order.
Any, path: str, problems: _Problems, *, machine: bool) -> Identification:
¶
Read an identification table. opensmi refuses to start an item that leaves an entry empty.
Import the object an import path names.
| Raises | |
LookupError | With what went wrong, when the module does not import or lacks the attribute. |
Mapping[ str, Any], path: str, base: Path, problems: _Problems) -> list[ Binding]:
¶
Read the Binding file a component includes, relative to the machine file.
Mapping[ str, Any], path: str, below: ProjectionRegistry, problems: _Problems) -> tuple[ tuple[ Projection, ...], ProjectionRegistry]:
¶
Read the projection tables of a Machine or Component and register them over a registry.
| Returns | |
tuple[ | The entries that registered, and the registry they extend. |
Mapping[ str, Any], name: str, path: str, problems: _Problems) -> bool:
¶
Report each key the recipe does not take and each it needs and lacks, and say whether none.
Mapping[ str, Any], key: str, path: str, problems: _Problems, complaint: Callable[ [ Any], str | None]) -> _Ref | None:
¶
Read a key that names a class or callable by import path, checking only its shape.
Import everything the file names, report what fails, and rebuild the stand-in declarations.
| Returns | |
dict[ | The real declaration for each stand-in, by the stand-in's id. |
A Component's identification block has no product URI; only a Machine's does.
| Value |
|
Undocumented
| Value |
|
Undocumented
| Value |
|
An import path: dotted names, with an optional : before the attribute (which may be dotted).
| Value |
|