ros_sugar.robot.transports.udp¶
UDP transport for robot plugins.
Module Contents¶
Classes¶
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.TransportUDP 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_toset,bindNone), receive-only (bindset,send_toNone— 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, orNonefor a receive-only transport.bind (Optional[Tuple[str, int]]) –
(host, port)to bind locally for inbound telemetry, orNonefor a send-only transport.recv_bufsize (int) – Max datagram size for
recvfrom.
- open() None¶
Open the egress socket and, if
bindis 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
payloadtosend_to.payloadmay be a singlebytesdatagram or a list/tuple ofbytes— 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¶