Robot not being plotted on 3D

7 views (last 30 days)
Mohsina Zafar
Mohsina Zafar on 6 Jan 2019
Commented: Gustavo gomes on 29 May 2023
Hello,
I want to plot a robot but it is not coming to be. A 2-D plane is being generated instead of 3D space. Attached is the code of robot. Please guide in this regard.
syms q1 q2 q4 a1 a2 d3 d4 t
%q1,q2,d3,q4 variable angle
% a1 a2 , d4 length robot
assume(a1,'real');assume(a1>0);
assume(a2,'real');assume(a2>0);
assume(d3,'real');assume(d3>0);
assume(d4,'real');assume(d4>0);
assume(q1,'real');
assume(q2,'real');
assume(q4,'real');
%INPUT MATRIX DEVAVIT HARTENBERG
A_01=[cos(q1) -sin(q1) 0 a1*cos(q1); sin(q1) cos(q1) 0 a1*sin(q1); 0 0 1 0; 0 0 0 1];
A_12=[cos(q2) sin(q2) 0 a2*cos(q2); sin(q2) -cos(q2) 0 a2*sin(q2); 0 0 -1 0; 0 0 0 1];
A_23=[1 0 0 0; 0 1 0 0; 0 0 1 d3; 0 0 0 1];
A_34=[cos(q4) -sin(q4) 0 0; sin(q4) cos(q4) 0 0; 0 0 1 d4; 0 0 0 1];
%MATRIX LAST DENAVIT HARTENBERG
A_04=A_01*A_12*A_23*A_34;
A_02=simplify(A_01*A_12);
A_03=simplify(A_02*A_23);
disp('MATRIX LAST')
A_04=simplify(A_04)
rE=A_04(1:3,4) % FINAL POINT FOR ACTIVITIES
%ROBOTICS SYSTEM TOOLBOX-PEER CORKE
L(1)=Link([0,0,0.5,0,0]);
L(2)=Link([0,0,0.4,pi,0]);
L(3)=Link([0,0,0,0,1]);
L(3).qlim=[0,0.3];
L(4)=Link([0,0.1,0,0,0]);
rob=SerialLink(L);
t=[0:0.005:4];
j=length(t);
for i=1:j
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xE(i)= 0.3+0.2*(1+sin(5*t(i))*cos(t(i)));
yE(i)= 0.3+0.2*(1+sin(5*t(i))*sin(t(i)));
zE(i)=-0.3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=xE(i);
B=yE(i);
D=-0.4^2+xE(i).^2+yE(i).^2+0.5^2;
s1=(D.*B-A.*sqrt(A.^2+B.^2-D.^2))./(A.^2+B.^2);
c1=(D.*A+B.*sqrt(A.^2+B.^2-D.^2))./(A.^2+B.^2);
q1_num(:,i) = atan2(s1,c1);
s2= (yE(i) -0.5.*sin(q1_num(:,i)));
c2= (xE(i) -0.5.*cos(q1_num(:,i)));
q2_num(:,i)= atan2(s2,c2)-q1_num(:,i);
d3_num(:,i) = -zE(i)-0.1;
q4_num(:,1)= q1_num(:,i)+q2_num(:,i);
end
figure
clf
hold on
grid on
axis([-1,1,-1,1,-1,1])
for i=1:length(t)
plot(rob,[q1_num(1,i),q2_num(1,i),d3_num(1,i),q4_num(1,i)])
plot3(xE(i),yE(i),zE(i),'b.')
pause(1/1000) %video
end
The error I get is in this line:
plot(rob,[q1_num(1,i),q2_num(1,i),d3_num(1,i),q4_num(1,i)])
Error:
Index exceeds matrix dimensions.
Error in SerialLink/plot>create_robot (line 469)
d = norm( d(4:6)-d(1:3) ) / 72;
Error in SerialLink/plot (line 252)
handle = create_robot(robot, opt);
P.S: I am using robotics toolbox by Pete Corke.

Answers (1)

Walter Roberson
Walter Roberson on 6 Jan 2019
hold on
grid on
axis([-1,1,-1,1,-1,1])
You had not plotted anything to that axis before that point. It defaulted to 2D. The "hold on" freezes that current view by default, so even though you pass in a 3D view to axis(), if you were to call axis() it would return only a 2D view. This matters because the SerialLink plot routine assumes you are in a 3D view.
The cure is to call view(3) before hold on
  3 Comments
Jubil Mahadevan
Jubil Mahadevan on 19 Jan 2020
God Bless you man!
Gustavo gomes
Gustavo gomes on 29 May 2023
you are my savior! thank you so much!

Sign in to comment.

Categories

Find more on ROS Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!