I want to write a Matlab function which takes the DH parameters as input and outputs a 4X4 transformation matrix.
The code I have written is :
function [A] = compute_dh_matrix(r, alpha, d, theta)
A = eye(4);
% ROTATION FOR X
A(1,1) = cos((theta));
A(2,1) = sin((theta));
% ROTATION FOR Y
A(1,2) = -(sin(theta))*(cos(alpha))*(1);
A(2,2) = (cos(theta))*(cos(alpha));
A(3,2) = (sin(alpha));
% ROTATION FOR Z
A(1,3) = (sin(theta))*(sin(alpha));
A(2,3) = -(cos(theta))*(sin(alpha))*(1);
A(3,3) = (cos(alpha));
% TRANSLATION VECTOR
A(1,4) = (alpha)*(cos(theta));
A(2,4) = (alpha)*(sin(theta));
A(3,4) = d;
end
But when I submit the code for evaluation in an online platform it prompts that variable A has incorrect value.
One of the input data used for evaluation of the code is :
r = 5;
alpha = 0;
d = 3;
theta = pi/2;
The matrix representation I have used to write the code is :
$A =$ \begin{bmatrix}cos(\theta)&&-\sin(\theta)\cos(\alpha)&&\sin(\theta)\sin(\alpha)&&\alpha \cos(\theta)\\\sin(\theta)&&\cos(\theta)\cos(\alpha)&&-\cos(\theta)\sin(\alpha)&&\alpha \sin(\theta)\\0&&\sin(\alpha)&&\cos(\alpha)&&d\\0&&0&&0&&1\end{bmatrix}
A is the transformation matrix generated using DH parameters $\theta$, $\alpha$ and d
$\alpha$ is angle about common normal from old z axis to new z axis
$\theta$ is angle about previous z axis, from old x axis to new x axis
d is offset along previous z axis to the common normal
radtodeg
for $\alpha$ in the translation part. $\endgroup$radtodeg
$\endgroup$