Skip to content

Get Timestamp

SUMMARY

Get Timestamp returns the timestamp (in seconds) of the most recent state update.

Reads from the manipulator state - controller-reported time of the latest telemetry sample when connected, wall-clock time of the most recent cache write offline.

SUPPORTED ROBOTS

Available on all supported manipulators in offline mode. Live hardware readings are currently supported only on Universal Robots.

UNITS

Returns a timestamp in seconds.

The Skill

python
timestamp = robot.get_timestamp()

The Code

python
"""
Read state timestamp example for the Synapse SDK.

Returns the timestamp of the most recent state update [s since epoch].
With ``--ip``, reads live hardware state. Without ``--ip``, reads from the
internal commanded cache (no connection made) and logs a warning.

Illustrated using Universal Robots (UR10e), supported on all robots.

Usage:
    python get_timestamp.py [--ip <ROBOT_IP>]
"""

import argparse
from loguru import logger

from telekinesis.synapse.robots.manipulators import universal_robots


def main(ip: str | None = None):
    """Log the timestamp of the most recent state update [s]."""

    robot = universal_robots.UniversalRobotsUR10E()

    if ip is not None:
        robot.connect(ip=ip)
    else:
        logger.warning(
            "No --ip provided; reading offline commanded-cache state, "
            "not live hardware readings."
        )

    try:
        logger.success(f"timestamp [s]: {robot.get_timestamp()}")
    finally:
        if ip is not None:
            robot.disconnect()


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Read state timestamp Synapse example")
    parser.add_argument("--ip", type=str, default=None, help="UR robot IP address (optional)")
    args = parser.parse_args()

    main(ip=args.ip)

The Explanation of the Code

python
from telekinesis.synapse.robots.manipulators import universal_robots

robot = universal_robots.UniversalRobotsUR10E()

Create the robot. UR10e is used here for illustration; the same pattern works for every supported brand.

python
if ip is not None:
    robot.connect(ip=ip)

Connect to the robot at the given IP. When no --ip is passed, no connection is made and the getter returns the wall-clock time of the most recent cache write instead of the controller-reported telemetry timestamp.

python
logger.success(f"timestamp [s]: {robot.get_timestamp()}")

Read the timestamp of the most recent state update in seconds. When connected this is the controller-reported time of the latest sample; offline it's the wall-clock time of the last cache write.

python
finally:
    if ip is not None:
        robot.disconnect()

Always release the controller link in a finally block so a failure mid-read still cleans up the connection.

Return Value

TypeDescription
floatTimestamp of the most recent state update, in seconds. Controller-reported time when connected; wall-clock time of the last cache write offline.

Where to Use the Skill

  • State logging - Attach a timestamp to every sampled data point.
  • Duration measurement - Record the timestamp before and after a motion to measure execution time.
  • Data synchronization - Align robot state samples with external sensor streams.

When Not to Use the Skill

  • You need wall-clock time independent of the robot state - use Python's time.time() or datetime.now() instead.