module documentation

Which frame belongs to which object, which folder it lands in, and what its Base points at.

The partition rules as pure functions of a frame tree (child frame to parent frame) and a set of declared head frames. There is no server, no asyncua node and no ROS2 here, so the rules can be tested without any of them.

Every other frame belongs to the nearest ancestor-or-self that is a declared head. A frame that is the TF parent of another object's head is an attach point; every other frame is an internal frame. A Location's Base is the node holding its TF parent, and a frame removed from the middle of a chain re-bases its children onto the nearest surviving ancestor. For the outward direction, rotation inverts angles, one_direction_per_frame checks the inward/outward rule across a Machine, and tree_roots finds the roots of the rendered tree.

Class FrameClash One frame that two declarations on a Machine both claim, and how each claims it.
Function angles Return a ROS2 quaternion as the A, B and C angles RSL wants, in degrees.
Function attach_points Return the frames that are attach points because another object's head hangs off them.
Function base_frame_of Return the frame whose node one Location's Base points at, or None for the world.
Function base_node_of Return the node one Location's Base points at, resolved through the frame-to-node index.
Function excluded Return whether one frame is removed by a declaration's exclusions.
Function folder_of Return which folder of its object's SpatialObject one frame lands in.
Function nearest_ancestor Return the closest frame at or above frame that is admitted, or None.
Function one_direction_per_frame Return the first frame two declarations on one Machine both claim, or None.
Function owner_of Return the head frame of the object one frame belongs to, or None if no object does.
Function owners Return every frame that some declared object owns, mapped to that object's head frame.
Function parents_of Return the frame tree as the partition reads it: each child frame mapped to its parent.
Function rotation Return the A, B and C angles RSL holds as the quaternion ROS2 wants.
Function tree_roots Return every frame that is somebody's parent and nobody's child, in sorted order.
Constant ALTERNATIVE_FRAMES The folder for a pose composed against some base other than the frame's own TF parent.
Constant ATTACH_POINTS The folder for a position another object can be attached at. Inferred, never declared.
Constant INTERNAL_FRAMES The folder for every other frame of an object.
Constant _DEGREES Radians to degrees. The RSL Orientation is in degrees.
Type Variable _Node Whatever a node is to the caller. This module never looks at one.
def angles(rotation: tuple[float, float, float, float]) -> tuple[float, float, float]:

Return a ROS2 quaternion as the A, B and C angles RSL wants, in degrees.

The convention is the nodeset's: fixed-axis roll-pitch-yaw (ISO 9787:2013), the same as tf2's getRPY. The unit is degrees because opensmi's Orientation carries °. A pitch at either pole is clamped, because floating-point drift can push the asin argument slightly past one.

Parameters
rotation:tuple[float, float, float, float]The quaternion as ROS2 orders it: x, y, z, w.
Returns
tuple[float, float, float]Undocumented
def attach_points(*, parents: Mapping[str, str], heads: Collection[str]) -> frozenset[str]:

Return the frames that are attach points because another object's head hangs off them.

A head whose parent is itself a head attaches to that object's PositionFrame, so nothing is filed for it.

def base_frame_of(frame: str, *, parents: Mapping[str, str], kept: Collection[str]) -> str | None:

Return the frame whose node one Location's Base points at, or None for the world.

The search starts strictly above frame. None means the walk left the tree without meeting a frame that has a node, which is the root of the TF tree, i.e. the list's World Frame. A frame excluded from the middle of a chain is not in kept, so its children walk past it.

def base_node_of(frame: str, *, parents: Mapping[str, str], index: Mapping[str, _Node], world: _Node) -> _Node:

Return the node one Location's Base points at, resolved through the frame-to-node index.

Walks up until a frame has a node and answers that node, or the World Frame when the walk leaves the index. Generic in what a node is: the caller's index holds NodeIds.

Parameters
frame:strThe frame whose Base is wanted.
parents:Mapping[str, str]Child frame to parent frame.
index:Mapping[str, _Node]Every frame that has a node, and the node it has.
world:_NodeWhat to answer when the walk leaves the index.
Returns
_NodeUndocumented
def excluded(frame: str, patterns: Iterable[str]) -> bool:

Return whether one frame is removed by a declaration's exclusions.

The patterns are fnmatch globs over the whole frame id (see opensmi.ros2.runtime.selection): *_wheel_link removes four frames on a differential-drive base, and a bare frame id removes one.

def folder_of(frame: str, *, head: str, attach: Collection[str]) -> str | None:

Return which folder of its object's SpatialObject one frame lands in.

None for the object's own head frame, which is the PositionFrame and in no folder.

def nearest_ancestor(frame: str, *, parents: Mapping[str, str], admitted: Collection[str], include_self: bool = True) -> str | None:

Return the closest frame at or above frame that is admitted, or None.

Both the partition and the re-basing walk up until something qualifies. A cycle (which tf2 forbids and a misbehaving publisher can still produce) ends the walk and answers None, so a poll never hangs.

Parameters
frame:strWhere to start.
parents:Mapping[str, str]Child frame to parent frame.
admitted:Collection[str]The frames that qualify.
include_self:boolWhether frame itself may be the answer.
Returns
str | NoneUndocumented
def one_direction_per_frame(*, heads: Mapping[str, str], published: Mapping[str, Collection[str]]) -> FrameClash | None:

Return the first frame two declarations on one Machine both claim, or None.

This is the cross-object half of the rule that a frame is inward or outward and never both. One declaration contradicting itself is caught by ~opensmi.ros2.server.bindings.TFBinding. Two cases are caught here: a frame one object publishes and another declares as its head (the two would fight over one Location's pose), and a frame two objects publish (tf2 would keep whichever transform arrived last). The result is deterministic: the caller's order over the objects, then alphabetical over the frames.

Parameters
heads:Mapping[str, str]Binding name to the head frame that Binding declares.
published:Mapping[str, Collection[str]]Binding name to the frames that Binding publishes outward.
Returns
FrameClash | NoneUndocumented
def owner_of(frame: str, *, parents: Mapping[str, str], heads: Collection[str]) -> str | None:

Return the head frame of the object one frame belongs to, or None if no object does.

A head frame owns itself, which makes it the object's PositionFrame. Frames above every declared head (a map, say) belong to no object and are rendered by nobody.

def owners(*, parents: Mapping[str, str], heads: Collection[str]) -> Mapping[str, str]:

Return every frame that some declared object owns, mapped to that object's head frame.

TF has one parent per frame, so no frame can be under two heads.

def parents_of(frames: Mapping[str, FrameLink]) -> Mapping[str, str]:

Return the frame tree as the partition reads it: each child frame mapped to its parent.

This is the one place the module reads a ~opensmi.ros2.runtime.tf.FrameLink. Everything else takes a plain mapping of names, which tests can write by hand.

def rotation(degrees: tuple[float, float, float]) -> tuple[float, float, float, float]:

Return the A, B and C angles RSL holds as the quaternion ROS2 wants.

The exact inverse of angles, used when a pose a client writes goes out on /tf. Three angles always name one rotation, so no clamping is needed.

Parameters
degrees:tuple[float, float, float]A, B and C in degrees: roll about X, pitch about Y, yaw about Z.
Returns
tuple[float, float, float, float]The quaternion as ROS2 orders it: x, y, z, w.
def tree_roots(parents: Mapping[str, str]) -> tuple[str, ...]:

Return every frame that is somebody's parent and nobody's child, in sorted order.

Like ~opensmi.ros2.runtime.tf.roots_of but over the rendered tree, not the facet's raw record: what a Machine broadcasts comes back through its own subscription, so the raw record would report its own outward declarations as a second coordinate system. A well-formed tree has one root, which OPC 10000-210 calls the World Frame.

ALTERNATIVE_FRAMES: str =

The folder for a pose composed against some base other than the frame's own TF parent.

Value
'AlternativeFrames'
ATTACH_POINTS: str =

The folder for a position another object can be attached at. Inferred, never declared.

Value
'AttachPoints'
INTERNAL_FRAMES: str =

The folder for every other frame of an object.

Where nearly every TF frame lands. 6.1.1 says an internal frame may not be used as an attach point, so filing a wheel link under ATTACH_POINTS would assert something false.

Value
'InternalFrames'
_DEGREES =

Radians to degrees. The RSL Orientation is in degrees.

Value
180.0 / math.pi
_Node =

Whatever a node is to the caller. This module never looks at one.

Value
TypeVar('_Node')