class documentation

class ROS2ParameterMirrorMixin(ParameterSetMixin, ROS2EventsMixin):

Constructor: ROS2ParameterMirrorMixin(*args, **kwargs)

View In Hierarchy

Keeps a Component's ParameterSet in sync with the ROS2 nodes it declared.

Mixed in ahead of opensmi's own class. It extends the events mixin, because a node that stops answering is a BindingEvent.

Method __init__ Start out tuning nothing, and pass every argument to opensmi's constructor.
Property ros2_unconfirmed_parameters Return, per Binding name, the declared ROS2 parameter names not confirmed present.
Async Method _add_parameter Create one Parameter, with the access level its declaration asked for and its check.
Async Method _apply Take one look at one ROS2 parameter and make the Parameter say what it found.
Method _check_locally Refuse what the declaration and the node's descriptor already rule out, without a call.
Async Method _decide_write Decide one write to one Parameter: return to store it, raise to answer it with a code.
Async Method _emit Raise one BindingEvent, and never let the reporting itself be the fault.
Async Method _follow_parameters Mirror every change the node announces, for the names this Binding declared.
Async Method _init_parameter_mirror Create every declared Parameter, then start following the nodes they came from.
Async Method _look Read one name and its descriptor off the node and make its Parameter say what came back.
Method _lose_track Note that what the node holds for one name is unknown, so the refresh reads it again.
Async Method _open_parameters Create one Binding's Parameters and register interest in the node they live on.
Async Method _read_the_unconfirmed Read each name that is not confirmed present, one parameter per request.
Async Method _refresh_parameters Read every unconfirmed name, and keep reading until they are all confirmed.
Async Method _report Fire one BindingEvent about one Parameter, at most once per condition per name.
Async Method _report_once Fire one BindingEvent about a whole Binding, at most once per condition.
Method _require_parameter_runtime Return the Runtime this mirror was initialised with.
Async Method _send_parameter_write Ask the node to take one value, and answer with what it said.
Async Method _start_tuning Put the first status on one Binding's Parameters, and start its tasks.
Async Method _stop_parameter_mirror Stop following every ROS2-parameter Binding and close its watch. Idempotent.
Async Method _unreachable Say that a node did not answer, and take every one of its Parameters bad with it.
Method _write_check Return the async check opensmi awaits before it stores a value written to one Parameter.
Async Method _write_inward Write one Parameter's value and status, as an ordinary write through opensmi.
Instance Variable _parameter_runtime Undocumented
Instance Variable _tuned Undocumented
def __init__(self, *args: Any, **kwargs: Any):

Start out tuning nothing, and pass every argument to opensmi's constructor.

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

Return, per Binding name, the declared ROS2 parameter names not confirmed present.

Empty everywhere means every ROS2-parameter Binding is Satisfied. A name here is a typo in a declaration or a robot that is not answering; the BindingEvent says which.

async def _add_parameter(self, tuned: _Tuned, parameter: str, parameter_type: ParameterType) -> _Parameter:

Create one Parameter, with the access level its declaration asked for and its check.

Read-only is applied here because an access level cannot be moved after _init. A read-only Parameter still gets the write check, which answers a client's write BadNotWritable.

async def _apply(self, tuned: _Tuned, parameter: _Parameter, reading: ParameterReading):

Take one look at one ROS2 parameter and make the Parameter say what it found.

Runs under the Parameter's lock, so a client's write waiting on the node is answered first.

def _check_locally(self, parameter: _Parameter, value: object):

Refuse what the declaration and the node's descriptor already rule out, without a call.

Raises
UaStatusCodeErrorBadTypeMismatch, BadNotWritable or BadOutOfRange.
async def _decide_write(self, tuned: _Tuned, parameter: _Parameter, value: object):

Decide one write to one Parameter: return to store it, raise to answer it with a code.

The equality test comes first, because it needs no call. It only counts once ROS2 has said something: before that the Parameter holds a typed zero, and a client writing that zero goes to the node like any other write. Inward writes pass as the lock holder's own.

Raises
UaStatusCodeErrorWith the code the client is answered with.
async def _emit(self, binding: ROS2ParameterBinding, code: str, severity: Severity, text: str, parameter: str | None = None):

Raise one BindingEvent, and never let the reporting itself be the fault.

Parameters
binding:ROS2ParameterBindingUndocumented
code:strUndocumented
severity:SeverityUndocumented
text:strUndocumented
parameter:str | NoneThe ROS2 parameter this is about, when it is about one rather than the whole node. It is joined onto the event's ROS2Path.
async def _follow_parameters(self, tuned: _Tuned):

Mirror every change the node announces, for the names this Binding declared.

Events caused by a client's write are applied like any other, since the node just confirmed the value. Other names are skipped.

async def _init_parameter_mirror(self, bindings: Iterable[ROS2ParameterBinding], *, runtime: RuntimeInterface):

Create every declared Parameter, then start following the nodes they came from.

Fatal on anything wrong with a declaration, such as a name written twice; what was opened is closed again first. No ROS2 call happens here, so the endpoint opens before anything waits for a robot.

async def _look(self, tuned: _Tuned, parameter: _Parameter) -> bool:

Read one name and its descriptor off the node and make its Parameter say what came back.

Returns
boolWhether the node answered at all. False is about the whole Binding, so a caller working through several names stops.
def _lose_track(self, tuned: _Tuned, parameter: _Parameter):

Note that what the node holds for one name is unknown, so the refresh reads it again.

async def _open_parameters(self, binding: ROS2ParameterBinding, runtime: RuntimeInterface) -> _Tuned:

Create one Binding's Parameters and register interest in the node they live on.

Raises
DuplicateVariableNameErrorWhen a name is already taken on this ParameterSet.
async def _read_the_unconfirmed(self, tuned: _Tuned):

Read each name that is not confirmed present, one parameter per request.

One request per name, since the batch call answers with an empty list when any one name is undeclared, which would blank every value on one typo. A transport failure ends the pass, as the remaining names would time out for the same reason.

async def _refresh_parameters(self, tuned: _Tuned):

Read every unconfirmed name, and keep reading until they are all confirmed.

It is self-disabling: while every name is confirmed it waits on an event and makes no calls. A name going unconfirmed (absent node, timed-out write, deleted parameter) sets the event. Without this, a node that was off at boot and comes up silently would never be seen.

async def _report(self, tuned: _Tuned, parameter: _Parameter, code: str, severity: Severity, text: str):

Fire one BindingEvent about one Parameter, at most once per condition per name.

The latch is cleared when the name reads well again. The parameter goes in the event's path (the node plus the dotted name), not in the text.

async def _report_once(self, tuned: _Tuned, code: str, severity: Severity, text: str):

Fire one BindingEvent about a whole Binding, at most once per condition.

The latch lives on the Parameters, because every one of them clears it when it reads well.

def _require_parameter_runtime(self) -> RuntimeInterface:

Return the Runtime this mirror was initialised with.

Raises
DeclarationErrorWhen there is none, which is a wiring fault.
async def _send_parameter_write(self, tuned: _Tuned, parameter: _Parameter, value: object):

Ask the node to take one value, and answer with what it said.

Called with the Parameter's lock held. Returning means the node took the value.

Raises
UaStatusCodeErrorBadTypeMismatch or BadOutOfRange when the guard behind the seam refused to put the value in a message; BadOutOfRange or BadInvalidArgument when the node refused it; BadTimeout when the node did not answer in time.
async def _start_tuning(self, tuned: _Tuned):

Put the first status on one Binding's Parameters, and start its tasks.

The status is written here so that a Parameter says BadNoCommunication from the moment it exists, whatever order the tasks run in.

async def _stop_parameter_mirror(self):

Stop following every ROS2-parameter Binding and close its watch. Idempotent.

It runs before the Runtime is stopped, for a Component torn down while the process goes on serving.

async def _unreachable(self, tuned: _Tuned, text: str):

Say that a node did not answer, and take every one of its Parameters bad with it.

Reported once per Binding, since the fact is about the node.

def _write_check(self, tuned: _Tuned, parameter: _Parameter) -> Callable[[Any], Awaitable[None]]:

Return the async check opensmi awaits before it stores a value written to one Parameter.

async def _write_inward(self, parameter: _Parameter):

Write one Parameter's value and status, as an ordinary write through opensmi.

Called with the Parameter's lock held, and the write passes the check as the holder's own. The value always travels with the status, because a status alone leaves the variant null.

_parameter_runtime: RuntimeInterface | None =

Undocumented

_tuned: list[_Tuned] =

Undocumented