Receiving teleop heartbeats

What is a teleop heartbeat?

During a teleop session, a continuous stream of empty protocol messages are sent from the operator to the device at a rate of 50Hz with UDP-like reliability settings.

This stream of messages represents a near-continuous signal that the operator is able to control the device.

When to use teleop heartbeat

For safety or UX reasons, the robot-side application may want to know when the operator or device have lost the ability to receive heartbeats.

Reacting to missing heartbeats is the fastest way to react to a lost network signal or lag spike in teleop on the robot-side application.

Example code

The following example code registers a callback which prints the value of heartbeat.is_disconnect. This value will be True when the session is closed or otherwise completely disconnected, and False otherwise.

Play with the example while opening and closing teleop sessions and through adverse network conditions to understand the heartbeat functionality.

import time

from formant.sdk.agent.v1 import Client as FormantAgentClient


def f(heartbeat):
    print("Received heartbeat callback at", time.time())
    print(heartbeat.is_disconnect)


if __name__ == "__main__":
    fclient = FormantAgentClient(ignore_unavailable=True)
    fclient.register_teleop_heartbeat_callback(f)

    try:
        while True:
            time.sleep(0.1)
    except KeyboardInterrupt:
        exit()