class documentation

class ROS2KeyedMirrorMixin(ROS2MutationMixin):

Constructor: ROS2KeyedMirrorMixin(*args, **kwargs)

View In Hierarchy

Keeps a machinery item's Keyed Bindings' members in sync with what arrives on their topics.

Mixed in ahead of opensmi's class. The mutation chokepoint it extends creates the nodes; this mixin decides which nodes there should be. It runs loops parallel to the inward mirror's (stream, publisher count, QoS) on purpose, since sharing them would need a callback at every step.

Method __init__ Start out with no Keyed Bindings, and pass every argument to opensmi.
Property ros2_keyed_presence Return, per Keyed Binding name, whether its topic has a publisher right now.
Property ros2_keyed_qos_provenance Return, per Keyed Binding name, what its subscription asks for and where it came from.
Property ros2_members Return, per Keyed Binding name, the browse name of each member it has created.
Async Method _create_aggregate Create the aggregate variable in the Binding's group, beside the members, at init.
Async Method _create_new_members Add every key this message names for the first time, in one mutation.
Async Method _follow_keyed Write every message of one Keyed Binding, until the subscription closes.
Async Method _follow_keyed_publishers Write the status code every time the topic gains or loses its publishers.
Async Method _follow_keyed_qos Raise one BindingEvent for every QoS incompatibility reported on this Binding's topic.
Async Method _init_keyed_mirror Open, shape and start every Keyed Binding, in declaration order.
Async Method _open_keyed Subscribe, shape the member plan, and create one Keyed Binding's aggregate.
Async Method _report_collision Say, as a BindingEvent, that a key has no member because its name is already taken.
Async Method _report_transition Fire the BindingEvent for a member's state change.
Method _report_unknown_keyed_name Log once per Binding a decoded name its shape never created.
Method _require_keyed_runtime Return the Runtime this mirror was initialised with.
Async Method _start_following_keyed Put the first status on what a Keyed Binding already has, then start its tasks.
Async Method _stop_keyed_mirror Stop following every Keyed Binding and close its subscription.
Async Method _write_aggregate Write the highest state any member holds, when this Binding has such a variable.
Async Method _write_keyed_message Give every element of one message its member, creating the ones that are new.
Async Method _write_keyed_status Re-write everything this Binding owns under the status its publishers now imply.
Async Method _write_member Decode one element onto its member's variables and return the state transition, if any.
Instance Variable _keyed Undocumented
Instance Variable _keyed_registry Undocumented
Instance Variable _keyed_runtime Undocumented
def __init__(self, *args: Any, **kwargs: Any):

Start out with no Keyed Bindings, and pass every argument to opensmi.

@property
ros2_keyed_presence: Mapping[str, bool] =

Return, per Keyed Binding name, whether its topic has a publisher right now.

Presence works as for a topic read into Monitoring and does not depend on membership: a Binding with a publisher but no member yet is a robot with nothing to report.

@property
ros2_keyed_qos_provenance: Mapping[str, BindingQoS] =

Return, per Keyed Binding name, what its subscription asks for and where it came from.

The counterpart of ~opensmi.ros2.server.mirror.ROS2InwardMirrorMixin.ros2_qos_provenance.

@property
ros2_members: Mapping[str, tuple[str, ...]] =

Return, per Keyed Binding name, the browse name of each member it has created.

In creation order. Members are append-only, so this only grows.

async def _create_aggregate(self, keyed: _Keyed):

Create the aggregate variable in the Binding's group, beside the members, at init.

async def _create_new_members(self, keyed: _Keyed, elements: Sequence[Message]):

Add every key this message names for the first time, in one mutation.

One chokepoint call gives one model-change event for the whole batch. A key that cannot have a member (its browse name is taken by another key or by something else on this Monitoring, or a cap closed the Binding) is reported once and remembered as refused, so a 10 Hz topic raises one event and not one per message.

async def _follow_keyed(self, keyed: _Keyed):

Write every message of one Keyed Binding, until the subscription closes.

async def _follow_keyed_publishers(self, keyed: _Keyed):

Write the status code every time the topic gains or loses its publishers.

async def _follow_keyed_qos(self, keyed: _Keyed):

Raise one BindingEvent for every QoS incompatibility reported on this Binding's topic.

Like the inward mirror's _follow_qos, with the same code.

async def _init_keyed_mirror(self, bindings: Iterable[KeyedBinding], *, runtime: RuntimeInterface, registry: ProjectionRegistry = DEFAULT_REGISTRY):

Open, shape and start every Keyed Binding, in declaration order.

Fatal at init on a bad declaration: a field that does not repeat a message, a key field that is not a scalar leaf, a state field the Projection never renders, an element type that is not installed. What a message carries is never fatal. Only the aggregate is created here; members appear with messages.

async def _open_keyed(self, binding: KeyedBinding) -> _Keyed:

Subscribe, shape the member plan, and create one Keyed Binding's aggregate.

async def _report_collision(self, keyed: _Keyed, key: tuple[str, ...], claimed: tuple[str, ...], browse: str):

Say, as a BindingEvent, that a key has no member because its name is already taken.

Parameters
keyed:_KeyedUndocumented
key:tuple[str, ...]Undocumented
claimed:tuple[str, ...]The key that holds the name, where one does. Empty when the name belongs to something that is not a member -- this Binding's own aggregate, say.
browse:strUndocumented
async def _report_transition(self, keyed: _Keyed, member: _Member, previous: object, current: object):

Fire the BindingEvent for a member's state change.

def _report_unknown_keyed_name(self, keyed: _Keyed, name: str):

Log once per Binding a decoded name its shape never created.

Unreachable with the shipped Projections; a curated one whose halves disagree only shows up with a message.

def _require_keyed_runtime(self) -> RuntimeInterface:

Return the Runtime this mirror was initialised with.

Raises
DeclarationErrorWhen there is none, which is a wiring fault and never a ROS2 condition.
async def _start_following_keyed(self, keyed: _Keyed):

Put the first status on what a Keyed Binding already has, then start its tasks.

async def _stop_keyed_mirror(self):

Stop following every Keyed Binding and close its subscription.

Idempotent. Runs before the Runtime is stopped, so a Component torn down on its own still stops reading.

async def _write_aggregate(self, keyed: _Keyed):

Write the highest state any member holds, when this Binding has such a variable.

async def _write_keyed_message(self, keyed: _Keyed, message: Message):

Give every element of one message its member, creating the ones that are new.

async def _write_keyed_status(self, keyed: _Keyed):

Re-write everything this Binding owns under the status its publishers now imply.

The value goes with it: a status written alone leaves the variant null.

async def _write_member(self, keyed: _Keyed, member: _Member, element: Message) -> tuple[_Member, object, object] | None:

Decode one element onto its member's variables and return the state transition, if any.

The caller reports it once the values are on their nodes.

_keyed: list[_Keyed] =

Undocumented

_keyed_registry: ProjectionRegistry =

Undocumented

_keyed_runtime: RuntimeInterface | None =

Undocumented