DH Frames and Table

Okay, I'm editing the post and adding some clarifications: I'm considering the slider-crank now as a closed kinematic chain, and for this reason I isolated two different branches. My attempt with the following script is to get a simulation of its motion, but since I've still errors, I think I'm not getting something about the Symbolic Toolbox and about DH convention as well. Edit 2: I'm attaching the picture of a second solution proposal, this time I get complex numbers on MATLAB.. Now I'm sure I miss something about solving closed kinematic chains. DH Tables and parameters alternative

    clear all
close all
%% Input Parameter (Change k in order to vary end-effector trajectory)
% Conversion factor from centimetres to metres
conv = 0.01;
% Incremental step 
h = 0.1;
% Lenght of crank (link L1) in [m]
l = 5*conv;
k = 2;
% Length of links of mechanism

L1 = 9*l;
L3 = 18*l;
L2 = 6*l;

% Length of virtual links for closed loop equations
%L0 = k*L1;

% Actuator - Costant angular velocity
Theta1 = [0:h:2*pi];
Theta1_ = Theta1 + pi;
beta = asin(L1/L2)*sin(Theta1);

%% Denavit Hartenberg - Forward Kinematic
syms  theta1 d3 theta2 theta3 

% For example T30_1s means transformation matrix from Joint 3 to Joint 0
% for the 1 closed loop (p), if second branch is considered (s)
% Transformation matrix Joint 1 to Joint 0 (workspace)
T10 =  DH(L1,0,0,theta1);

% Transformation matrix Joint 2 to Joint 1
T21 = DH(L2,0,0,theta2);

T20 = T10*T21

T32 = DH(0,pi/2,0,theta3);

T30_p = T20*T32; %this is the first branch of my closed kinematic chain

T30_s = DH(L3,-pi/2,d3,pi/2); % this is the second one, it goes from Joint3 (the prismatic one) to Joint0


% Closure equation 
eq2 = T30_p(1:3,end) == T30_s(1:3,end)

[Theta2, Theta3, D3] = solve(eq2,[theta2 theta3 d3]);

  angle2 = double(subs(Theta2(1),theta1,Theta1));
  angle3 = double(subs(Theta3(1),theta1,Theta1));
  displ = double(subs(D3(1),theta1,Theta1));


% Joint vector position
J0 = [0 0 0]';
Joint1 = T10(1:3,end);
Joint2 = T21(1:3,end);
Joint3 = T30_s(1:3,end);

% Compute joint trajectory
for i = 1:length(Theta1)
    J1(:,i) = double(subs(Joint1,{theta1 theta2(1)},{Theta1(i) angle2(i)}));
    J2(:,i) = double(subs(Joint2,{theta1 theta2(1) theta3(1)},{Theta1(i) angle2(i) angle3(i)}));
    J3(:,i) = double(subs(Joint3,{d3(1)},{displ(i)}));

%% Movie
figure('units','normalized','outerposition',[0 0 1 1])
v = VideoWriter('SingleLegFoot.avi');
hold on
grid on
for i = 1:length(Theta1)
    hold on
    grid on
    hold on
    grid on
    axis equal
    xlim([-0.5 1.2]);ylim([-1.6 0.5]);xlabel('X [m]');ylabel('Y [m]')
    title('1 DOF Leg mechanism');
    h12 = plot([J0(1,1),J1(1,i)],[J0(2,1),J1(2,i)],'r','LineWidth',2);
    h13 = plot([J1(1,i),J2(1,i)],[J1(2,i),J2(2,i)],'r','LineWidth',2);
    h14 = plot([J2(1,i),J3(1,i)],[J2(2,i),J3(2,i)],'r','LineWidth',2);

    hold on
    h1 = plot(J0(1,:),J0(2,:),'blackv','MarkerSize',10);
    h2 = plot(J1(1,i),J1(2,i),'o','MarkerSize',7,'MarkerEdgeColor','black','MarkerFaceColor',[0.7529 0.7529 0.7529]);
    h3 = plot(J2(1,i),J2(2,i),'o','MarkerSize',7,'MarkerEdgeColor','black','MarkerFaceColor',[0.7529 0.7529 0.7529]);
    h4 = plot(J3(1,i),J3(2,i),'blackv','MarkerSize',10);
    hold off
    frame = getframe(gcf);
%% Denavit - Hartenberg Transformation Matrix

function dh = DH(link,a_i,d_i,theta_i)
    dh = [cos(theta_i) -sin(theta_i)*cos(a_i)   sin(theta_i)*sin(a_i)     link*cos(theta_i);
          sin(theta_i)  cos(theta_i)*cos(a_i)   -cos(theta_i)*sin(a_i)     link*sin(theta_i);
               0         sin(a_i)                   cos(a_i)                        d_i;
               0             0                          0                           1       ];
  • $\begingroup$ what is your specific question? $\endgroup$
    – jsotola
    Aug 19 at 17:03
  • $\begingroup$ First of all I would like to know if my DH table is correct $\endgroup$
    – dinoZ9
    Aug 19 at 17:21

There's a lot going on here, and it's not specific what your question is as jsotola mentions.

First, you are putting the output of a solve function into Theta2, but then you're using THETA2 as inputs to subsequent subs functions. Matlab is case-sensitive; those are two different terms.

Second, assuming you're using symbolic variables (based on your error) you can't, as the error states, mix symbolic and doubles. This is probably happening in your line eq2 = T_end(1:3,end) == [0;0;0]; which instead needs to be eq2 = T_end(1:3,end) == sym([0;0;0]); to work.

Third, I can't see where any of your stuff is actually defined - your Theta1, THETA3, etc.

Fourth, you're using a DH function but that's not a built-in Matlab function.

Put everything you're trying to do in a script, start that script with the clear or clear all command, and try running as a saved script. Any errors you get will give you line numbers, pointing you to exactly where the problem is. If you still have trouble, please post the entire script so we can follow along with your variable declarations, etc.

  • $\begingroup$ Thank you both! I'll post my entire script, I'm working on it in order to be clear what my problem is next time. $\endgroup$
    – dinoZ9
    Aug 19 at 17:20
  • $\begingroup$ Just edited my post, hope it's better now $\endgroup$
    – dinoZ9
    Aug 19 at 17:37
  • $\begingroup$ @smarzo - When I run your code, I get the error where you're substituting the numeric values for theta1 in the Theta2 expression. The issue is that your Theta2 expression is just z, so the output is a vector of z, and then you're trying to convert that to a numeric value when there is no numeric value for z. $\endgroup$
    – Chuck
    Aug 19 at 19:46
  • $\begingroup$ Yes, I noticed that too. And this makes me think that the equations are wrong! $\endgroup$
    – dinoZ9
    Aug 20 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.