class documentation

All ROS2 access for one Machine, which is the unit of one Domain ID.

Method __init__ Describe a Runtime without starting anything; construction touches no ROS2.
Method __repr__ Return a representation naming the node and its Domain ID.
Async Method advertise Advertise a ROS2 topic, and return the handle that owns the publisher.
Async Method call_service Call one ROS2 service and return the response it answered with.
Method default_message Return a message of a type as its generated ROS2 class constructs it, with no arguments.
Method describe_action Return the goal, feedback and result message dataclasses of a ROS2 action type.
Method describe_message Return the message dataclass of a ROS2 message type.
Method describe_service Return the request and response message dataclasses of a ROS2 service type.
Method publishers_on Return what every publisher on a topic offers, as the QoS resolver takes it.
Async Method send_goal Send one goal to a ROS2 action server, and return the handle that owns it.
Async Method start Bring up the Context, the Node and the executor thread on the running loop, which stays the Runtime's.
Async Method stop Close every open endpoint, then tear down the thread, the Node and the Context.
Async Method subscribe Subscribe to a ROS2 topic, and return the handle that owns the subscription.
Property domain_id Return the ROS2 Domain ID this Runtime is confined to.
Property graph Return the facet answering what is on the ROS2 graph (it reads nothing until watched).
Property node_name Return the name of the single rclpy Node this Runtime owns.
Property parameters Return the facet for the parameters of ROS2 nodes (/parameter_events only while watched).
Property started Return whether the Context, Node and executor thread are up.
Property tf Return the facet answering where a TF frame sits (/tf is subscribed once a Binding asks).
Async Method _await_acceptance Send the goal, wait for the server's answer, and build the handle around it.
Async Method _call_parameter_service Call one parameter service of a ROS2 node.
Method _close Tear the ROS2 objects down (blocking, so called off the loop), collecting faults.
Async Method _describe_parameter Ask one ROS2 node about one parameter (one name per call: a batch with an undeclared name answers empty).
Method _destroy Destroy one rclpy subscription, publisher or client, and wake the executor.
Method _destroy_action_client Destroy one rclpy action client and wake the executor so its wait set is rebuilt.
Method _feed_transforms Put every transform of one message into the buffer, on the loop that received it.
Async Method _follow_parameter_events Yield every parameter change on the graph from one /parameter_events subscription.
Async Method _list_parameters Ask one ROS2 node what parameters it declares, recursively.
Method _lookup_transform Return where one frame sits in another, out of what the buffer already holds.
Method _open Create and spin the ROS2 objects (blocking, so called off the loop).
Async Method _read_graph Read every name on the graph once, off the loop; this is what graph polls with.
Async Method _read_parameter Read one parameter of one ROS2 node (one name per call, see ParameterFacet).
Method _report_type_hash_mismatches Compare every publisher's type hash against our own, and warn about each new one.
Method _require_loop Return the Runtime's loop, or refuse because this is not it.
Method _require_started Return the node, or refuse because there is none.
Method _ros2_clock Return the Node's clock (not the wall clock, so right under use_sim_time) as seconds and nanoseconds.
Method _wake Wake the executor so its wait set is rebuilt after an endpoint went away.
Async Method _write_parameters Write a batch of parameters to one ROS2 node, with one outcome per parameter.
Instance Variable _buffer Undocumented
Instance Variable _context Undocumented
Instance Variable _domain_id Undocumented
Instance Variable _executor Undocumented
Instance Variable _goals Undocumented
Instance Variable _graph Undocumented
Instance Variable _loop Undocumented
Instance Variable _namespace Undocumented
Instance Variable _node Undocumented
Instance Variable _node_name Undocumented
Instance Variable _parameters Undocumented
Instance Variable _publishers Undocumented
Instance Variable _stop_timeout Undocumented
Instance Variable _subscriptions Undocumented
Instance Variable _tf Undocumented
Instance Variable _thread Undocumented
Instance Variable _transform_cache Undocumented
def __init__(self, *, domain_id: int, node_name: str = 'opensmi_ros2', namespace: str | None = None, stop_timeout: float = 5.0, graph_poll_interval: float = POLL_INTERVAL, transform_cache: float = TRANSFORM_CACHE):

Describe a Runtime without starting anything; construction touches no ROS2.

Parameters
domain_id:intThe ROS2 Domain ID this Runtime's Context is confined to.
node_name:strThe name of the single rclpy Node this Runtime owns.
namespace:str | NoneThe ROS2 namespace for that node, or None for the root.
stop_timeout:floatSeconds stop waits for the executor thread.
graph_poll_interval:floatSeconds between graph reads while the graph facet is watched.
transform_cache:floatSeconds of transform history the TF buffer keeps.
def __repr__(self) -> str:

Return a representation naming the node and its Domain ID.

async def advertise(self, *, topic: str, message_type: str | type[Message], depth: int = 10, qos: QoSProfile | None = None) -> Publisher:

Advertise a ROS2 topic, and return the handle that owns the publisher.

Nothing goes on the wire until ~opensmi.ros2.runtime.publisher.Publisher.publish. The profile is declared or defaulted, never discovered or adapted, since this call is how a publisher on the topic comes to exist.

Parameters
topic:strThe ROS2 topic name.
message_type:str | type[Message]The ROS2 type name (package/Name or package/kind/Name) or an already-resolved message dataclass.
depth:intThe ROS2 queue depth.
qos:QoSProfile | NoneThe profile to offer, or None for ~opensmi.ros2.runtime.qos.DEFAULT_PROFILE.
Returns
PublisherUndocumented
Raises
RuntimeNotStartedErrorWhen the Runtime is not up.
LoopAffinityErrorWhen awaited on a loop other than the Runtime's.
MissingInterfacePackageErrorWhen the type's interface package is not installed.
async def call_service(self, *, service: str, service_type: str | ServiceTypes, request: Message, server_timeout: float = 10.0, call_timeout: float = 30.0) -> Message:

Call one ROS2 service and return the response it answered with.

A refusal is in the response message. Only two cases raise: nobody serving the path, and a server that took the request and never answered. They have separate timeouts so that "the robot is off" and "the robot is stuck" stay distinguishable.

Parameters
service:strThe ROS2 service name.
service_type:str | ServiceTypesThe service type (package/srv/Name) or the already-resolved pair of message dataclasses.
request:MessageThe request, as an instance of the service's request message dataclass.
server_timeout:floatSeconds to wait for a service server to appear on the path.
call_timeout:floatSeconds to wait for the answer once the request has gone.
Returns
MessageUndocumented
Raises
RuntimeNotStartedErrorWhen the Runtime is not up.
LoopAffinityErrorWhen awaited on a loop other than the Runtime's.
FieldTypeMismatchErrorWhen a field of the request holds a value of the wrong Python type. Refused here because rclpy aborts the process.
FieldValueOutOfRangeErrorWhen a field of the request is past its width or bound.
ServiceUnavailableErrorWhen no service server answers on the path.
ServiceCallTimeoutErrorWhen the request went and no answer came back in time.
MissingInterfacePackageErrorWhen the service's interface package is absent.
def default_message(self, message_type: type[Message]) -> Message:

Return a message of a type as its generated ROS2 class constructs it, with no arguments.

Every field holds the default its interface definition declares, or its type's zero. Usable before start.

Parameters
message_type:type[Message]A message dataclass, as describe_message returns it.
Returns
MessageUndocumented
def describe_action(self, action_type: str) -> ActionTypes:

Return the goal, feedback and result message dataclasses of a ROS2 action type.

Usable before start, so a missing interface package fails while a Component is constructed. It lives on the Runtime so that tests can substitute a double.

Parameters
action_type:strpackage/action/Name.
Returns
ActionTypesUndocumented
Raises
InvalidMessageTypeNameErrorWhen the name is not a three-part action name.
MissingInterfacePackageErrorWhen the interface package is not installed.
UnusableMessageTypeErrorWhen the package has no such action.
def describe_message(self, message_type: str) -> type[Message]:

Return the message dataclass of a ROS2 message type.

Usable before start.

Parameters
message_type:strpackage/Name or package/msg/Name.
Returns
type[Message]Undocumented
Raises
InvalidMessageTypeNameErrorWhen the name is not a message name.
MissingInterfacePackageErrorWhen the interface package is not installed.
UnusableMessageTypeErrorWhen the package has no such message.
def describe_service(self, service_type: str) -> ServiceTypes:

Return the request and response message dataclasses of a ROS2 service type.

Usable before start, like describe_action.

Parameters
service_type:strpackage/srv/Name.
Returns
ServiceTypesUndocumented
Raises
InvalidMessageTypeNameErrorWhen the name is not a three-part service name.
MissingInterfacePackageErrorWhen the interface package is not installed.
UnusableMessageTypeErrorWhen the package has no such service.
def publishers_on(self, topic: str) -> tuple[EndpointInfo, ...]:

Return what every publisher on a topic offers, as the QoS resolver takes it.

This reads the node's local graph cache on the loop: callers decide synchronously whether to adapt, and an await in between would let two match events spend the one bootstrap tightening twice. Returns an empty tuple when the Runtime is not up, because middleware callbacks call it during teardown.

async def send_goal(self, *, action: str, action_type: str | ActionTypes, goal: Message, depth: int = 10, server_timeout: float = 10.0) -> Goal:

Send one goal to a ROS2 action server, and return the handle that owns it.

The handle is returned once the server has answered the goal request. A refusal comes back as an already settled handle; only a path nobody serves raises.

Parameters
action:strThe ROS2 action name.
action_type:str | ActionTypesThe action type (package/action/Name) or the already-resolved trio of message dataclasses.
goal:MessageThe goal, as an instance of the action's goal message dataclass.
depth:intHow many feedback messages the handle buffers.
server_timeout:floatSeconds to wait for an action server to appear on the path.
Returns
GoalUndocumented
Raises
RuntimeNotStartedErrorWhen the Runtime is not up.
LoopAffinityErrorWhen awaited on a loop other than the Runtime's.
FieldTypeMismatchErrorWhen a field of the goal holds a value of the wrong Python type. Refused here because rclpy aborts the process instead of raising.
FieldValueOutOfRangeErrorWhen a field of the goal is past its width or bound.
ActionServerUnavailableErrorWhen no action server answers on the path.
MissingInterfacePackageErrorWhen the action's interface package is absent.
async def start(self):

Bring up the Context, the Node and the executor thread on the running loop, which stays the Runtime's.

Raises
RuntimeAlreadyStartedErrorWhen the Runtime is already up.
async def stop(self) -> StopOutcome:

Close every open endpoint, then tear down the thread, the Node and the Context.

Teardown faults are returned in the outcome, not raised: the Runtime is stopped either way.

Raises
RuntimeNotStartedErrorWhen the Runtime was never started, or is already stopped.
LoopAffinityErrorWhen awaited on a loop other than the Runtime's.
async def subscribe(self, *, topic: str, message_type: str | type[Message], depth: int = 10, qos: QoSProfile | None = None) -> Subscription:

Subscribe to a ROS2 topic, and return the handle that owns the subscription.

A declared profile is honoured exactly; a discovered one relaxes as the topic's publishers require. The call does not wait for a publisher: it opens against whatever the graph shows now, possibly nothing.

Parameters
topic:strThe ROS2 topic name.
message_type:str | type[Message]The ROS2 type name (package/Name or package/kind/Name) or an already-resolved message dataclass.
depth:intThe handle's buffer size, and the ROS2 queue depth.
qos:QoSProfile | NoneThe profile to request, or None to discover one: the most permissive request compatible with every publisher now, re-resolved once on the first publisher when there is none yet, and relaxed whenever the middleware reports an incompatibility.
Returns
SubscriptionUndocumented
Raises
RuntimeNotStartedErrorWhen the Runtime is not up.
LoopAffinityErrorWhen awaited on a loop other than the Runtime's.
MissingInterfacePackageErrorWhen the type's interface package is not installed.
@property
domain_id: int =

Return the ROS2 Domain ID this Runtime is confined to.

@property
graph: GraphFacet =

Return the facet answering what is on the ROS2 graph (it reads nothing until watched).

@property
node_name: str =

Return the name of the single rclpy Node this Runtime owns.

@property
parameters: ParameterFacet =

Return the facet for the parameters of ROS2 nodes (/parameter_events only while watched).

@property
started: bool =

Return whether the Context, Node and executor thread are up.

@property
tf: TFFacet =

Return the facet answering where a TF frame sits (/tf is subscribed once a Binding asks).

async def _await_acceptance(self, *, action: str, types: ActionTypes, goal: Message, sink: GoalSink, client: Any, loop: asyncio.AbstractEventLoop) -> Goal:

Send the goal, wait for the server's answer, and build the handle around it.

async def _call_parameter_service(self, node: str, service: str, service_type: str, build: Callable[[type[Message]], Message]) -> Message:

Call one parameter service of a ROS2 node.

Raises
ServiceUnavailableErrorWhen the node's service does not answer in time.
ServiceCallTimeoutErrorWhen the request went and no answer came back.
def _close(self) -> StopOutcome:

Tear the ROS2 objects down (blocking, so called off the loop), collecting faults.

async def _describe_parameter(self, node: str, name: str) -> ParameterDescription:

Ask one ROS2 node about one parameter (one name per call: a batch with an undeclared name answers empty).

def _destroy(self, kind: str, endpoint: Any):

Destroy one rclpy subscription, publisher or client, and wake the executor.

def _destroy_action_client(self, client: Any):

Destroy one rclpy action client and wake the executor so its wait set is rebuilt.

def _feed_transforms(self, message: Message, static: bool):

Put every transform of one message into the buffer, on the loop that received it.

The authority is this Runtime's node name, as a TransformListener would have written it. Nothing is raised: tf2 refuses a non-finite value or an empty frame id, and that is no reason to stop reading the topic.

async def _follow_parameter_events(self) -> AsyncGenerator[ParameterUpdate, None]:

Yield every parameter change on the graph from one /parameter_events subscription.

The facet demultiplexes by node. The subscription closes with the generator.

async def _list_parameters(self, node: str) -> tuple[str, ...]:

Ask one ROS2 node what parameters it declares, recursively.

def _lookup_transform(self, target: str, source: str) -> Transform | None:

Return where one frame sits in another, out of what the buffer already holds.

Non-blocking: lookup_transform at zero time returns the latest cached transform or raises. The _async variant is avoided because awaiting its future on this loop busy-spins until another message feeds the buffer.

Returns
Transform | NoneThe composed transform, or None when the buffer cannot complete the chain (unpublished frame, two trees that do not meet, or a link older than the cache).
def _open(self):

Create and spin the ROS2 objects (blocking, so called off the loop).

async def _read_graph(self) -> GraphSnapshot:

Read every name on the graph once, off the loop; this is what graph polls with.

Raises
RuntimeNotStartedErrorWhen the Runtime is not up (a poll racing teardown).
async def _read_parameter(self, node: str, name: str) -> ParameterReading:

Read one parameter of one ROS2 node (one name per call, see ParameterFacet).

def _report_type_hash_mismatches(self, topic: str, sink: SubscriptionSink):

Compare every publisher's type hash against our own, and warn about each new one.

A warning, not a refusal: a changed hash does not mean the message is undecodable.

def _require_loop(self) -> asyncio.AbstractEventLoop:

Return the Runtime's loop, or refuse because this is not it.

def _require_started(self) -> rclpy.node.Node:

Return the node, or refuse because there is none.

def _ros2_clock(self) -> tuple[int, int]:

Return the Node's clock (not the wall clock, so right under use_sim_time) as seconds and nanoseconds.

def _wake(self):

Wake the executor so its wait set is rebuilt after an endpoint went away.

async def _write_parameters(self, node: str, values: Mapping[str, ParameterValue]) -> Mapping[str, SetOutcome]:

Write a batch of parameters to one ROS2 node, with one outcome per parameter.

Uses set_parameters, not the atomic variant, which discards the whole batch when one name is undeclared.

_buffer: tf2_ros.Buffer | None =

Undocumented

_context: rclpy.context.Context | None =

Undocumented

_domain_id =

Undocumented

_executor: rclpy.executors.SingleThreadedExecutor | None =

Undocumented

_goals: list[Goal] =

Undocumented

_graph =

Undocumented

_loop: asyncio.AbstractEventLoop | None =

Undocumented

_namespace =

Undocumented

_node: rclpy.node.Node | None =

Undocumented

_node_name =

Undocumented

_parameters =

Undocumented

_publishers: list[Publisher] =

Undocumented

_stop_timeout =

Undocumented

_subscriptions: list[Subscription] =

Undocumented

_tf =

Undocumented

_thread: threading.Thread | None =

Undocumented

_transform_cache =

Undocumented