# Tactiverge Academy — companion code for "Reading a robot specification"
# Lesson: https://tactiverge.win/academy/robotics-foundations/introduction-to-robotics/reading-a-robot-spec/
# Licence: MIT (see https://tactiverge.win/open-engineering/). Examples appear in lesson order.

# ── Example 1 ────────────────────────────────────────
import math

# Made-up measurements for illustration: the arm was sent to the same
# target (x = 0, y = 0, in mm) five times and its tool position measured.
target = (0.0, 0.0)
visits = [(0.52, 0.31), (0.55, 0.28), (0.49, 0.30), (0.53, 0.33), (0.51, 0.28)]

mean_x = sum(x for x, y in visits) / len(visits)
mean_y = sum(y for x, y in visits) / len(visits)

accuracy = math.dist(target, (mean_x, mean_y))
spread = max(math.dist((mean_x, mean_y), p) for p in visits)

print(f"average position: ({mean_x:.3f}, {mean_y:.3f}) mm")
print(f"accuracy (target to average): {accuracy:.3f} mm")
print(f"repeatability (worst distance from average): {spread:.3f} mm")
