Skip to content

sim2bot.Robot.on_telemetry

on_telemetry(callback: Optional[Callable[[RobotState], None]]) -> None

Register or clear a callback for every received robot-state packet.

Parameters:

  • callback (Optional[Callable[[RobotState], None]]) –

    Function receiving one RobotState, or None to unregister the current callback.

Returns:

  • None

    Registration takes effect immediately.

Warning

The callback runs on the SDK reader thread. Keep it short and thread-safe; hand work to your own queue rather than blocking it.

Source code in sim2bot/client.py
def on_telemetry(self, callback: Optional[Callable[[RobotState], None]]) -> None:
    """Register or clear a callback for every received robot-state packet.

    Args:
        callback: Function receiving one
            [`RobotState`][sim2bot.client.RobotState], or ``None`` to unregister
            the current callback.

    Returns:
        Registration takes effect immediately.

    Warning:
        The callback runs on the SDK reader thread. Keep it short and
        thread-safe; hand work to your own queue rather than blocking it.
    """
    self._on_telemetry = callback

Practical examples

Examples use objects discovered from the current scene rather than hard-coded robot metadata.

Print lightweight status

def report(state):
    print(state.robot, state.tcp)

sim.on_telemetry(report)

Hand packets to a worker queue

from queue import SimpleQueue

packets = SimpleQueue()
sim.on_telemetry(packets.put)
state = packets.get(timeout=2.0)

Guidance

Usage tip

Queue the packet and return immediately when processing involves disk, plotting, networking, or heavy numerical work.

Common error

Blocking the callback also blocks the reader thread and can make telemetry appear frozen.


See also