The Projection engine: how one ROS2 type is rendered in OPC UA.
A Binding connects one ROS2 path to one OPC UA object. A Projection is about the type of what flows through it, is reused by every Binding whose messages carry that type, and applies wherever the type appears, at the root of a message or nested inside another. It has three pure functions:
- shape, run once at init, turns a message dataclass into a node plan of
PlanObjectandPlanVariable. The generic walk emits only variables, which nest as complex Variables; a repeated message becomes one variable holding an array of a structure derived from its type, and a plan that asks for an Object is refused where its nodes are made. - decode, run per message, turns a payload into a map from plan name to value.
- encode, run per write on the publishing side, turns that map back into a payload. An entry that
cannot run backwards has no
Projection.inverse. That is derived from the recipe and asked asProjection.inverts, of a type, because for some recipes it depends on the message too.
The generic field-walk is an ordinary registry entry that matches last, so turning curation off for
one type means naming the generic entry for it. Authors write recipes
(opensmi.ros2.server.recipes), not these functions. No step sees an rclpy object.
| Class | |
An enumeration DataType to mint into the server, and the values it lists. |
| Class | |
One inner level of a node path: a structure, or a group, that holds the nodes below it. |
| Class | |
One OPC UA Object to create, with its own entries below it. |
| Class | |
One OPC UA Variable to create, and the ROS2 field it reads. |
| Class | |
A DataType this project's own nodeset defines, named by its generated NodeId definition. |
| Class | |
How one ROS2 type is rendered, as the steps and the type they answer for. |
| Class | |
What a Projection needs besides the message in front of it. |
| Class | |
The ordered entries a Component renders its types through. |
| Class | |
A DataType OPC UA itself defines, named by its numeric identifier in namespace 0. |
| Function | browse |
Return the browse name of one field of the message the context is on. |
| Function | curated |
Return the naming of curated levels: the qualifier and the node path, joined with dots. |
| Function | element |
Return the structure one element of a repeated message renders as. |
| Function | flat |
Return node path parts as the one name a plan entry has in the decode and encode maps. |
| Function | generic |
Read one payload into the names generic_shape created for its type. |
| Function | generic |
Build one payload out of the names generic_shape created, and nothing else. |
| Function | generic |
Render a message type field by field, one flat variable per leaf. |
| Function | inner |
Return every structure a plan's variables sit in, by node path. |
| Function | join |
Return one field path below another, spelled the way the selection spells it. |
| Function | level |
Return the structure DataType of every level of a plan and of its root, by node path. |
| Function | level |
Return the instance of the structure of one level, from what a message decoded to. |
| Function | message |
Return the structure of a ROS2 message type, named by it, with the fields of its definition. |
| Function | narrowed |
Return a Component's context narrowed to what one surface's selection kept. |
| Function | require |
Refuse a declaration that writes a type into ROS2 through a Projection with no inverse. |
| Function | ros2 |
Return a value a client wrote in the shape a payload holds. |
| Function | shaped |
Return the nodes one message type becomes, through the context's registry. |
| Function | ua |
Return the value one modelled ROS2 field boots with, and the OPC UA type it carries. |
| Function | ua |
Return a decoded field value in the shape an OPC UA write wants. |
| Constant | ANY |
The type name of an entry that answers for every type; the generic walk carries it. |
| Type Alias | |
Run per message: a payload becomes a map from plan name to the value to write. |
| Type Alias | |
Run per publish: that same map becomes a payload again, where the recipe has an inverse. |
| Type Alias | |
How a level whose subtree is curated is named: from its node path and its ROS2 type. |
| Type Alias | |
The browse names from the top of a plan down to one node, such as ("Pose", "Position", "X"). |
| Type Alias | |
What a plan may say about a variable's DataType, resolved to a NodeId where the nodes are made. |
| Type Alias | |
The two verbs, and there is no third. |
| Type Alias | |
Run once at init: a message dataclass becomes a node plan. |
| Function | _annotated |
Return the annotation of a field and the length of its fixed-size array, from its boot value. |
| Function | _below |
Carry one entry up under the field that produced it, which becomes a level above it. |
| Function | _below |
Return the values belonging to one nested field, with its own name taken off the front. |
| Function | _decoded |
Return one repeated message field as the array of elements its variable carries. |
| Function | _display |
Return what a client is told the field is called: the new name, else the raw ROS2 name. |
| Function | _element |
Return the context the elements of a repeated message field are rendered in. |
| Function | _element |
Work out the structure of one element, which element_structure remembers. |
| Function | _element |
Return the OPC UA type of a scalar, or of what a container holds. |
| Function | _encoded |
Return the ROS2 sequence that the array of elements of one repeated message field describes. |
| Function | _instance |
Undocumented |
| Function | _leaf |
Return the field annotation of a leaf, and the length of its fixed-size array. |
| Function | _narrowed |
Return one scalar as exactly the Python type its ROS2 element type is, where it can be. |
| Function | _plan |
Return the variable a repeated message field becomes: one array of the element's structure. |
| Function | _plan |
Return the variable one modelled ROS2 field becomes under the generic walk. |
| Function | _refuse |
Refuse to build a message with a hole in it, naming the field and the reason. |
| Function | _repeats |
Return whether a field holds many of its type rather than one. |
| Function | _require |
Refuse a second entry for one type unless it says it is replacing the first. |
| Function | _selected |
Yield each field the selection kept, with its context and the message type it nests. |
| Function | _siblings |
Return the browse name of each of these sibling fields, refusing two that share one. |
| Function | _signature |
Return the fields of the structure of a ROS2 message type, as its definition has them. |
| Constant | _INTEGERS |
The primitive names whose Python type is int, taken from the guard's table. |
| Constant | _PACKABLE |
The OPC UA types a field of a structure can carry. |
| Constant | _VARIANT |
Undocumented |
| Constant | _ZEROS |
Undocumented |
Return the browse name of one field of the message the context is on.
The key a field has in the decode and encode maps, for a recipe that works one field out itself.
Return the naming of curated levels: the qualifier and the node path, joined with dots.
Platform.Odom names the root and Platform.Odom.Pose the level below it. The qualifier is the Component and the Binding, so a name does not depend on what else is declared.
Return the structure one element of a repeated message renders as.
Public because a recipe that repeats a message of its own needs it too. Its fields are the
element's plan, nested like the message. Memoised on the registry
(ProjectionRegistry.element_structures).
| Raises | |
UnprojectableFieldError | When the element's Projection emits an Object, or a field of it is of a type that has no place in a structure. |
Return node path parts as the one name a plan entry has in the decode and encode maps.
Empty parts are skipped: an entry named "" takes the name of whatever contains it, so a message rendered as one variable browses as the field it sits in. The decode and encode maps are keyed the same way, so this is the one place that spells that name. It is a key and not a BrowseName: the nodes nest.
Message, context: ProjectionContext, overrides: Mapping[ str, object] | None = None) -> Mapping[ str, object]:
¶
Read one payload into the names generic_shape created for its type.
| Parameters | |
message:Message | Undocumented |
context:ProjectionContext | Undocumented |
overrides:Mapping[ | What a field's variable reads instead of the field itself, by ROS2 field name. It pairs with the shape override of the same name. |
| Returns | |
Mapping[ | Undocumented |
type[ Message], values: Mapping[ str, object], context: ProjectionContext, overrides: Mapping[ str, object] | None = None) -> Message:
¶
Build one payload out of the names generic_shape created, and nothing else.
The inverse of generic_decode. A field the selection removed is not filled from a
default: a covariance of zeros means perfectly certain in ROS2, not unknown.
| Parameters | |
messagetype[ | Undocumented |
values:Mapping[ | Undocumented |
context:ProjectionContext | Undocumented |
overrides:Mapping[ | The ROS2 value of a field the caller has already worked out, by field name. |
| Returns | |
Message | Undocumented |
| Raises | |
NotInvertibleError | When a field of the message has no value, whether because the selection removed it or because the caller supplied none. |
type[ Message], context: ProjectionContext, overrides: Mapping[ str, PlanEntry] | None = None) -> tuple[ PlanEntry, ...]:
¶
Render a message type field by field, one flat variable per leaf.
Recursion runs through the registry, so a nested type with a curated Projection is rendered by that entry and its names are carried up under this field's name. A field that repeats a message is one variable holding an array of a structure.
| Parameters | |
messagetype[ | Undocumented |
context:ProjectionContext | Undocumented |
overrides:Mapping[ | What to emit for a field instead of walking it, by ROS2 field name. The blob and enum recipes are overrides and nothing else. An override of a field the selection removed is never reached. |
| Returns | |
tuple[ | Undocumented |
| Raises | |
UnprojectableFieldError | When a repeated message's element cannot render as a structure: its Projection emits an Object, or a field of it has a type no structure field can carry. |
Return every structure a plan's variables sit in, by node path.
These are the nodes that become complex Variables.
Iterable[ PlanVariable], root: type[ Message], naming: NodeLevelNaming) -> dict[ NodePath, type]:
¶
Return the structure DataType of every level of a plan and of its root, by node path.
A level whose rendered subtree is the one its ROS2 type has (no field excluded or renamed, no
leaf of another type) gets the class of that type, message_class. Any other gets a class
of the rendered shape, named by naming. A level is curated when anything below it is,
since its fields differ then. The root is ().
| Parameters | |
plan:Iterable[ | The variables of one message, as shaped returns them. |
root:type[ | The ROS2 type of the message. |
naming:NodeLevelNaming | Undocumented |
| Returns | |
dict[ | Undocumented |
| Raises | |
UnprojectableFieldError | When a leaf has a type no structure field can carry. |
Iterable[ PlanVariable], classes: Mapping[ NodePath, type], values: Mapping[ str, object], path: NodePath = ()) -> Any:
¶
Return the instance of the structure of one level, from what a message decoded to.
This is the value a level's complex Variable holds. values is what the Projection's decode returns for the message, keyed by flat name.
| Parameters | |
plan:Iterable[ | Undocumented |
classes:Mapping[ | The result of level_datatypes for the plan. |
values:Mapping[ | Undocumented |
path:NodePath | The level to build. The root by default. |
| Returns | |
Any | Undocumented |
| Raises | |
KeyError | When a leaf below the level has no value. |
Return the structure of a ROS2 message type, named by it, with the fields of its definition.
It is the DataType of a level whose subtree is not curated. Equal for equal types.
ProjectionContext, message_type: type[ Message], selection: FieldSelection) -> ProjectionContext:
¶
Return a Component's context narrowed to what one surface's selection kept.
A Binding with several surfaces (an action's goal, feedback and result; a service's request and response) narrows its context once per surface.
A type with no fields at all (a bare trigger goal, a ping request) skips the selector, since nothing was removed. A pattern written against such a type still reaches the selector and is refused by name.
| Raises | |
FieldSelectionError | When a pattern matches nothing, or the two leave no field. |
Refuse a declaration that writes a type into ROS2 through a Projection with no inverse.
A Binding that publishes is declarable only if every Projection reachable in its message type inverts. The error names the ROS2 type, the field path and the entry. An action's goal type is checked like a published topic's. Reachable means through the selection, so an excluded field is never asked.
| Raises | |
NotInvertibleError | When any reachable entry cannot run backwards. |
Return a value a client wrote in the shape a payload holds.
The mirror image of ua_value. It reads the modelled field, since [] alone does not
say whether a tuple or a list is wanted.
It also narrows a number to the exact Python type of its ROS2 field, because the guard that runs
next (opensmi.ros2.runtime.guard) tests exact types, and OPC UA's scalar types subclass
int, float and str (a Double node written with 1 hands back an integer). The
field decides the type. A value the field cannot hold is left as it came, for the guard to
refuse by name.
Return the value one modelled ROS2 field boots with, and the OPC UA type it carries.
Public because a declared ROS2 parameter type is shaped here too
(opensmi.ros2.runtime.parameters.ParameterType.field_type,
opensmi.ros2.server.parameters.ua_parameter_shape), so one table decides the mapping.
Return a decoded field value in the shape an OPC UA write wants.
A payload holds a tuple and the library builds an array from a list, so that is the one conversion.
Run per message: a payload becomes a map from plan name to the value to write.
| Value |
|
Run per publish: that same map becomes a payload again, where the recipe has an inverse.
| Value |
|
How a level whose subtree is curated is named: from its node path and its ROS2 type.
| Value |
|
The browse names from the top of a plan down to one node, such as ("Pose", "Position", "X").
| Value |
|
What a plan may say about a variable's DataType, resolved to a NodeId where the nodes are made.
A plan is a pure value, and the NodeId of one of our types depends on the server, while an
enumeration or a structure has no NodeId until it is minted (opensmi.ros2.server.mutation).
A type is the structure class that is the element type of an array of structures, which the
generic walk emits for a repeated message.
| Value |
|
Run once at init: a message dataclass becomes a node plan.
| Value |
|
object, element_type: type[ Message], context: ProjectionContext) -> list[ Mapping[ str, object]]:
¶
Return one repeated message field as the array of elements its variable carries.
Each element is decoded by the Projection covering its type into a map from its structure's field names to values. An empty sequence decodes to an empty list, which is a value.
The elements are plain maps, not ExtensionObjects: encoding one needs the server's namespace
and belongs to the variable being written (opensmi.ros2.server.mutation).
type[ Message], context: ProjectionContext) -> ProjectionContext:
¶
Return the context the elements of a repeated message field are rendered in.
The path goes back to empty, because an element's leaves are named from its own root. The
selection becomes the element type's whole field set: the selector treats a repeated message as
one leaf and never walks inside it (opensmi.ros2.runtime.selection), so an element is
never partial and can be rebuilt exactly. Fields keep their ROS2 names and no rename
applies, because they are the field names of a DataType. The registry is kept, so curated
Projections still apply to elements.
object, element_type: type[ Message], context: ProjectionContext) -> tuple[ Message, ...]:
¶
Return the ROS2 sequence that the array of elements of one repeated message field describes.
Each element is a map from the names its Projection knows to values, rebuilt by that Projection's own inverse. An element that lacks a field is refused by name, and an empty list builds an empty sequence.
| Raises | |
NotInvertibleError | When an element has no value for a field of its type. |
ValueError | When the value is not a list, or an element of it is not a map. This is a client's write, not a declaration fault. |
list[ PlanVariable], classes: Mapping[ NodePath, type], values: Mapping[ str, object], path: NodePath) -> Any:
¶
Undocumented
Return the field annotation of a leaf, and the length of its fixed-size array.
Only a structure class and a plain value can be a field. Any other DataType (an enumeration, a type from the nodeset or one OPC UA defines) is left to the built-in type, so Components that curate such a field differently still share one structure.
| Raises | |
UnprojectableFieldError | When the leaf is of a type no structure field can carry. |
FieldDescription, context: ProjectionContext, element_type: type[ Message], name: str, display: str) -> PlanVariable:
¶
Return the variable a repeated message field becomes: one array of the element's structure.
It boots as an empty array, a legal ROS2 value, so "nobody has written this yet" is told by the
StatusCode, BadWaitingForInitialData (opensmi.ros2.server.status).
| Raises | |
UnprojectableFieldError | When the element cannot render as a structure. |
FieldDescription, context: ProjectionContext, name: str, display: str) -> PlanVariable:
¶
Return the variable one modelled ROS2 field becomes under the generic walk.
type[ Message], context: ProjectionContext) -> Iterator[ tuple[ FieldDescription, ProjectionContext, type[ Message] | None]]:
¶
Yield each field the selection kept, with its context and the message type it nests.
The generic walk's steps share this route and differ only in what they do at each stop.
Return the browse name of each of these sibling fields, refusing two that share one.
| Raises | |
DuplicateVariableNameError | When two give one browse name, whether by conversion or by a rename. The error names both ROS2 names. |
The primitive names whose Python type is int, taken from the guard's table.
| Value |
|
The OPC UA types a field of a structure can carry.
| Value |
|
Undocumented
| Value |
|