Assume two uniform cylindrical links robot has 3 DOF as shown in the figure. Where link one has 1 dof that is rotation on its main axis. The second link has 2 DOF yaw and pitch movements. I can calculate forward kinematic, Jacobian, kinetic and potential energy of it using below code. However, I am not sure how can I verify that the computed kinetic and potential energy equations are correct? Moreover, the computed equations seem not right, for example if we check PE for q2 joint (which is m2g((r2_0(1,1))) becomes zero with this code. However, we know it should be equal to somewhat like m2*g(L2/2)*sinq2.
It would be great if someone can help me in this. Thank you in advance.
DH parameters of 3 DOF robot
% DH parameters
% theta, d, a, alpha
dh_params = [q1, 0, 0, 0;
q2, L1, 0, pi/2;
q3+pi/2, 0, 0, pi/2;
0, 0, L2, 0];
homogeneous transformation matrices
% Define homogeneous transformation matrices
T = sym(zeros(4,4,4)); %T = sym(zeros(4,4,2));
for i=1:4
T(:,:,i) = [cos(dh_params(i,1)), -sin(dh_params(i,1))*cos(dh_params(i,4)), sin(dh_params(i,1))*sin(dh_params(i,4)), dh_params(i,3)*cos(dh_params(i,1));
sin(dh_params(i,1)), cos(dh_params(i,1))*cos(dh_params(i,4)), -cos(dh_params(i,1))*sin(dh_params(i,4)), dh_params(i,3)*sin(dh_params(i,1));
0, sin(dh_params(i,4)), cos(dh_params(i,4)), dh_params(i,2);
0, 0, 0, 1];
end
% Calculate forward kinematics
T01 = simplify(T(:,:,1));
T12 = simplify(T(:,:,2));
T02 = simplify(T01*T(:,:,2));
T23 = simplify(T(:,:,3));
T03 = simplify(T02*T(:,:,3));
T34 = simplify(T(:,:,4));
T04 = simplify(T03*T(:,:,4));
Then
px = T04(1,4);
py = T04(2,4);
pz = T04(3,4);
%ri_i represents the position of the mass center of link i relative to its own coordinate frame
r1_1 = [0; 0; L1/2];
r2_2 = [0; L2/2; 0]; %r2_2 = [0; -L2/2; 0]; may be also
r3_3 = [L2/2; 0; 0];
%ri_0 is the distance of ith link mass center to base coordinates frame
r1_0 = simplify(T01 * [r1_1; 1]);
r2_0 = simplify(T02 * [r2_2; 1]);
r3_0 = simplify(T03 * [r3_3; 1]);
Calculate Jacobian matrix
J = simplify([diff(px, q1), diff(px, q2), diff(px, q3), diff(px, q4); diff(py, q1), diff(py, q2), diff(py, q3), diff(py, q4); diff(pz, q1), diff(pz, q2), diff(pz, q3), diff(pz, q4)]);
Output:
J =
[ L2*sin(q1 + q2)*sin(q3), L2*sin(q1 + q2)*sin(q3), -L2*cos(q1 + q2)*cos(q3), 0]
[-L2*cos(q1 + q2)*sin(q3), -L2*cos(q1 + q2)*sin(q3), -L2*sin(q1 + q2)*cos(q3), 0]
[0, 0, -L2*sin(q3), 0]
Calculate Kinetic energy
% Calculate kinetic energy
KE = simplify(0.5*(m1*(diff(px, q1)^2 + diff(py, q1)^2) + m2*(diff(px, q1)^2 + diff(py, q1)^2 + diff(px, q2)^2 + diff(py, q2)^2) ...
+ m2*(diff(px, q1)^2 + diff(py, q1)^2 + diff(px, q2)^2 + diff(py, q2)^2) + diff(px, q3)^2 + diff(py, q3)^2)...
+ I1*dq1^2 + I2*(dq1 + dq2)^2 + I3*(dq1 + dq2 +dq3)^2);
Calculate potential energy
% Calculate potential energy
PE = simplify(m1*g*(r1_0(1,1)) + m2*g*((r2_0(1,1))+m2*g*((r3_0(1,1)))));
PE output:
PE =-(L2*g^2*m2^2*cos(q1 + q2)*sin(q3))/2