Using the UR5, and extracting DH parameters from a dummy located in the last link (0,0,0 relative to last link), outputs:
Denavit-Hartenberg parameters (classic DH convention):
- between joint '/joint{0}' and joint '/joint{1}': d=0.0661 [m], theta=90.0 [deg], r=0.0000 [m], alpha=-90.0 [deg]
- between joint '/joint{1}' and joint '/joint{2}': d=0.0000 [m], theta=0.0 [deg], r=0.4251 [m], alpha=0.0 [deg]
- between joint '/joint{2}' and joint '/joint{3}': d=0.0000 [m], theta=0.0 [deg], r=0.3922 [m], alpha=0.0 [deg]
- between joint '/joint{3}' and joint '/joint{4}': d=0.0397 [m], theta=-90.0 [deg], r=0.0000 [m], alpha=-90.0 [deg]
- between joint '/joint{4}' and joint '/joint{5}': d=0.0492 [m], theta=90.0 [deg], r=0.0000 [m], alpha=-90.0 [deg]
- between joint '/joint{5}' and object '/TipUR5': d=0.0000 [m], theta=-0.0 [deg], r=0.0000 [m], alpha=0.0 [deg]
Then, I'm using the following code to compute the position of /TipUR5:
Code: Select all
# Classic DH Transformation Matrix
def dh(theta, d, r, alpha):
ct, st = np.cos(theta), np.sin(theta)
ca, sa = np.cos(alpha), np.sin(alpha)
return np.array([
[ct, -st * ca, st * sa, r * ct],
[st, ct * ca, -ct * sa, r * st],
[0, sa, ca, d],
[0, 0, 0, 1]
])
# DH parameters (theta, d, r, alpha)
dh_params = [
(np.deg2rad(90), 0.0661, 0.0, -np.deg2rad(90)),
(0.0, 0.0, 0.4251, np.deg2rad(0)),
(0.0, 0.0, 0.3922, np.deg2rad(0)),
(-np.deg2rad(90), 0.0397, 0.0, -np.deg2rad(90)),
(np.deg2rad(90), 0.0492, 0.0, -np.deg2rad(90)),
(0.0, 0.0, 0.0, np.deg2rad(0))
]
# Compute the full transformation matrix
FK = np.eye(4)
for param in dh_params:
theta, d, r, alpha = param
tj = dh(theta, d, r, alpha)
FK = np.dot(FK, tj)
position = FK[:3, 3]
FK result by DH: [-0.04 0.866 0.066]
Sim (relative to joint): [-0.172 -0. 0.978]
Sim (relative to World): [-0.172 -0. 0.987]
My result is far from the true position, what am I missing?