"""Parse the Acuila URDF with yourdfpy and compare it with the designed arm. Design: J1, J2 Y-bend +, L1 25 cm, L2 20 cm, base height 5 cm, gripper 6.8 cm. """ import sys import numpy as np import yourdfpy path = sys.argv[1] robot = yourdfpy.URDF.load(path, load_meshes=False, build_scene_graph=True, load_collision_meshes=False) print("robot:", robot.robot.name) print("links:", [l.name for l in robot.robot.links]) print("actuated joints:", robot.actuated_joint_names) for j in robot.robot.joints: lim = j.limit print(f" {j.name:18s} {j.type:9s} {j.parent}->{j.child} " f"xyz={np.round(j.origin[:3, 3], 6).tolist()} " f"axis={None if j.axis is None else j.axis.tolist()} " f"limit={None if lim is None else (lim.lower, lim.upper)}") # Expected design values (metres, unit vectors) exp = {"joint_1": ([0, 0, 0.05], [0, 1, 0]), "joint_2": ([0, 0, 0.25], [0, 1, 0]), "gripper_mount": ([0, 0, 0.20], None), "tool0_fixed": ([0, 0, 0.068], None)} ok = True for name, (xyz, axis) in exp.items(): j = robot.joint_map[name] d = np.abs(j.origin[:3, 3] - xyz).max() a_ok = axis is None or np.allclose(j.axis, axis) print(f"check {name}: offset err {d:.2e} m, axis ok {a_ok}") ok &= d < 1e-9 and a_ok # Analytic FK of the design (cm): tip = base + Ry(q1)[0,0,L1] + Ry(q1+q2)[0,0,L2+g] def fk_design(q1, q2): a1, a12 = np.radians(q1), np.radians(q1 + q2) x = 25 * np.sin(a1) + 26.8 * np.sin(a12) z = 5 + 25 * np.cos(a1) + 26.8 * np.cos(a12) return np.array([x, 0.0, z]) poses = [(0, 0), (90, 0), (0, 90), (0, 35), (86.3, 7.1), (93.7, -7.1), (30, 45), (-60, 120), (90, 45), (-135, 60)] worst = 0.0 fingers = {"finger_left_joint": 0.0, "finger_right_joint": 0.0} for q1, q2 in poses: cfg = {"joint_1": np.radians(q1), "joint_2": np.radians(q2), **fingers} robot.update_cfg(cfg) T = robot.get_transform("tool0", "base_link") p = T[:3, 3] * 100 e = np.abs(p - fk_design(q1, q2)).max() worst = max(worst, e) print(f"q=({q1:7.1f},{q2:7.1f}) urdf tool0 cm = {np.round(p, 4).tolist()}" f" design = {np.round(fk_design(q1, q2), 4).tolist()} err {e:.1e} cm") print(f"worst FK difference URDF vs design: {worst:.2e} cm") masses = {l.name: l.inertial.mass for l in robot.robot.links if l.inertial} print("masses kg:", masses, "total", round(sum(masses.values()), 6)) print("PASS" if ok and worst < 0.01 else "FAIL")