ros_sugar.robot.transports.udp

UDP transport for robot plugins.

Module Contents

Classes

UdpTransport

UDP transport — sends datagrams to the robot and (optionally) receives a telemetry stream.

API

class ros_sugar.robot.transports.udp.UdpTransport(name: str, *, send_to: Optional[Tuple[str, int]] = None, bind: Optional[Tuple[str, int]] = None, recv_bufsize: int = 4096, **kwargs)

Bases: ros_sugar.robot.transports.Transport

UDP transport — sends datagrams to the robot and (optionally) receives a telemetry stream.

Commands are sent with sendto, which is many-senders-to-one safe, so every component process may hold its own egress socket. Receiving telemetry requires binding a local port; that is done once, on the plugin HOST.

A transport may be send-only (send_to set, bind None), receive-only (bind set, send_to None — e.g. a robot that streams telemetry unprompted), or bidirectional.

Parameters:
  • name (str) – Unique transport name.

  • send_to (Optional[Tuple[str, int]]) – (host, port) the robot listens on for commands, or None for a receive-only transport.

  • bind (Optional[Tuple[str, int]]) – (host, port) to bind locally for inbound telemetry, or None for a send-only transport.

  • recv_bufsize (int) – Max datagram size for recvfrom.

open() None

Open the egress socket and, if bind is set, the ingress socket plus its receive thread.

open_egress() None

Open just the send socket (a no-op for receive-only transports).

close() None

Stop the receive thread and close both sockets.

send(payload: Union[bytes, List[bytes]]) bool

Send payload to send_to.

payload may be a single bytes datagram or a list/tuple of bytes — a burst of datagrams sent in order (some robot protocols, express one logical command as several packets). Returns True only if every datagram was sent.

is_open() bool
subscribe(on_msg: Callable[[Any], None]) ros_sugar.robot.transports.SubscriptionHandle
property kind: str