Why do not run this code ?

1 view (last 30 days)
x y
x y on 29 Mar 2014
Commented: x y on 29 Mar 2014
I found this code for teaching about robot arms simulation,but when I try to run in the .m editor and start,...there are some error, Please help me to run the code .Thank you
figure;
h = plot3(0,0,0);p = get(h,'Parent');xlim(p,'manual');
xlim(p,[0 2]);ylim(p,'manual');ylim(p,[0 2]);zlim(p,'manual');
zlim(p,[0 2]);axis vis3d;grid on;
point1.x =0;point1.y = 0;point1.z = 0;
point2.x = 0;point2.y = 0;point2.z = 1;
point3.x = 0;point3.y = 0;point3.z = 1;
point4.x = 2;point4.y = 0;point4.z = 1;
l= line([point1.x, point2.x],[point1.y,point2.y],[point1.z,point2.z],'Color','r','LineWidth',4);
l1 = line([point2.x, point3.x],[point2.y,point3.y],[point2.z,point3.z],'Color','b','LineWidth',4);
l2 = line([point3.x, point4.x],[point3.y,point4.y],[point3.z,point4.z],'Color','g','LineWidth',4);
pause(0.5);
theta2 = 30;
theta3 =0;
for theta1 =70:-1:0
[point2,point3,point4] = fromDHandTheta(theta1,theta1,theta1); %(each individual theta)
set(l,'ZData',[point1.z,point2.z],'YData',[point1.y,point2.y],'XData',[point1.x,point2.x]);
set(l1,'ZData',[point2.z,point3.z],'YData',[point2.y,point3.y],'XData',[point2.x,point3.x]);
set(l2,'ZData',[point3.z,point4.z],'YData',[point3.y,point4.y],'XData',[point3.x,point4.x]);
hold on;
plot3(point4.x,point4.y,point4.z,'xk');
pause(0.1);
end
end
function [point2,point3,point4] = fromDHandTheta(theta1,theta2,theta3)
% D-H Params:
% N Theta Alpha dN rN
% 1 theta1 alpha1 0 0
% 2 theta2 alpha2 1 0
% 3 theta3 alpha3 1 0
s1 = [0;0;0]; % from dN and rN
s2 = [1;0;0];
s3 = [1;0;0];
alpha1 = 90;
alpha2 = 0;
alpha3 = 0;
pointa = returnUfromTheta(theta1)*returnVfromAlpha(alpha1)*s1 + [0;0;1]; % [0;0;1] is orig position
pointb = returnUfromTheta(theta1)*returnVfromAlpha(alpha1)*returnUfromTheta(theta2)*returnVfromAlpha(alpha2)*s2 + pointa;
pointc = returnUfromTheta(theta1)*returnVfromAlpha(alpha1)*returnUfromTheta(theta2)*returnVfromAlpha(alpha2)*...
returnUfromTheta(theta3)*returnVfromAlpha(alpha3)*s3 + pointb;
point2.x = pointa(1); point2.y = pointa(2); point2.z = pointa(3);
point3.x = pointb(1); point3.y = pointb(2); point3.z = pointb(3);
point4.x = pointc(1); point4.y = pointc(2); point4.z = pointc(3);
end
function U = returnUfromTheta(theta)
U = [ cosd(theta), -sind(theta), 0;...
sind(theta), cosd(theta), 0 ;...
0, 0, 1];
end
function V = returnVfromAlpha(alpha)
V = [ 1, 0 ,0;...
0, cosd(alpha), -sind(alpha);...
0, sind(alpha), cosd(alpha)];
end

Accepted Answer

Walter Roberson
Walter Roberson on 29 Mar 2014
Insert as the very first line,
function armsim
and save the whole thing to armsim.m
You should be able to run it then.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!