4 views (last 30 days)

a1 = 0; alpha1 = 0; d1 = 0;

a2 = 475; alpha2 = pi/2; d2 = 150;

a3 = 600; alpha3 = 0; d3 = 0;

%DH parameter

t1_min = -pi/2; t1_max = pi/2;

t2_min = -pi/3; t2_max = pi/3;

t3_min = -pi/3; t3_max = pi/3;

% joint limits

% Monte Carlo method

% sampling size

N = 20000;

t1 = t1_min + (t1_max-t1_min)*rand(N,1);

t2 = t2_min + (t2_max-t2_min)*rand(N,1);

t3 = t3_min + (t3_max-t3_min)*rand(N,1);

function [ T ] = TranMat( a,b,c,d )

T = [ cos(d) -sin(d)*cos(b)

sin(d)*sin(b) a*cos(d); sin(d)

cos(d)*cos(b) -cos(d)*sin(b) a*sin(d);

0 sin(b) cos(b) c;

0 0 0 1

];

for i = 1:N

A1 = TransMat(a1,alpha1,d1,t1(i));

A2 = TransMat(a2,alpha2,d2,t2(i));

A3 = TransMat(a3,alpha3,d3,t3(i));

T = A1*A2*A3;

X=T(1,4);

Y=T(2,4);

Z=T(3,4);

plot3(X,Y,Z,'.')

hold on;

end

end

Geoff Hayes
on 22 Jun 2020

Geoff Hayes
on 22 Jun 2020

You could defer the plots until after the loop. Perhaps

N = 20000;

t1 = t1_min + (t1_max-t1_min)*rand(N,1);

t2 = t2_min + (t2_max-t2_min)*rand(N,1);

t3 = t3_min + (t3_max-t3_min)*rand(N,1);

X = zeros(N,1); % <--- presize X,Y,Z

Y = zeros(N,1);

Z = zeros(N,1);

for i = 1:N

A1 = TransMat(a1,alpha1,d1,t1(i));

A2 = TransMat(a2,alpha2,d2,t2(i));

A3 = TransMat(a3,alpha3,d3,t3(i));

T = A1*A2*A3;

X(i)=T(1,4);

Y(i)=T(2,4);

Z(i)=T(3,4);

end

figure(1)

view(3);

title('Isometric view');

xlabel('x (m)');

ylabel('y (m)');

zlabel('z (m) ');

plot3(X,Y,Z,'.'); % <---- plot for figure 1

figure(2)

view(2); % top view

title(' Top view');

xlabel('x (m)');

ylabel('y (m)');

plot3(X,Y,Z,'.') % <---- plot for figure 2

figure(3)

view([1 0 0]); % y-z plane

title('Side view, Y-Z');

ylabel('y (m)');

zlabel('z (m)');

plot3(X,Y,Z,'.') % <---- plot for figure 3

I haven't tested the above but it might work...

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.