grasp
All Data Structures Namespaces Functions Modules
iCubPlot.m
1 function [Tr,zs]=iCubPlot(DH,q,color,varargin)
2 Twb=[1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1];
3 
4 if(size(varargin,2)==1)
5  Twb=varargin{1};
6  active_joints=ones(size(q));
7 end
8 if(size(varargin,2)==2)
9  Twb=varargin{1};
10  H0=varargin{2};
11  active_joints=ones(size(q));
12 end
13 if (size(varargin,2)==3)
14  Twb=varargin{1};
15  H0=varargin{2};
16  active_joints=varargin{3};
17 end
18 
19 DHmat=zeros(size(DH,1),size(DH,2));
20 for i=1:size(DH,2)
21  DHmat(i,1)=DH{i}.alpha;
22  DHmat(i,2)=DH{i}.A;
23  DHmat(i,3)=DH{i}.D;
24  DHmat(i,4)=DH{i}.offset;
25 end
26 
27 hold on
28 magnitude=max(max(DHmat(:,2:3))); %this will set the scale for the initial frame and the joints axis display
29 xlabel('x');
30 ylabel('y');
31 zlabel('z');
32 
33 %% plotting the initial frame
34 init_frame=[magnitude/5 magnitude/5 magnitude/5 1 ; 0 0 0 1];
35 %plot3(init_frame(:,1),[0;0],[0;0],'r','LineWidth',3)
36 %plot3([0;0],init_frame(:,2),[0;0],'g','LineWidth',3)
37 %plot3([0;0],[0;0],init_frame(:,3),'b','LineWidth',3)
38 
39 %% plotting the first joint in the z direction (DH rule)
40 
41 init_joint_z=[0 0 0 1 ;0 0 magnitude/5 1];
42 init_joint_y=[0 0 0 1 ;0 magnitude/5 0 1];
43 init_joint_x=[0 0 0 1 ;magnitude/5 0 0 1];
44 
45 %Ts1=FKinematics(DH,base,1);
46 %Ts1=eye(4);
47 for i=0:size(DHmat,1)
48  Tr=Twb*FKinStd(DH,q,i,H0);
49  position=Tr*[0 0 0 1]';
50  x(1,i+1)=position(1);
51  y(1,i+1)=position(2);
52  z(1,i+1)=position(3);
53  if (active_joints(i+1)==1)
54  if (i>0)
55  plot3([x(1,i) x(1,i+1)],[y(1,i) y(1,i+1)],[z(1,i) z(1,i+1)],'k');
56  end
57  resultz=Tr*init_joint_z';
58  jointz=resultz';
59  resulty=Tr*init_joint_y';
60  jointy=resulty';
61  resultx=Tr*init_joint_x';
62  jointx=resultx';
63  %plot3(jointz(:,1),jointz(:,2),jointz(:,3),'b','LineWidth',5)
64  %plot3(jointy(:,1),jointy(:,2),jointy(:,3),'g','LineWidth',5)
65  %plot3(jointx(:,1),jointx(:,2),jointx(:,3),'r','LineWidth',5)
66  quiver3(jointz(1,1),jointz(1,2),jointz(1,3),jointz(2,1)-jointz(1,1),jointz(2,2)-jointz(1,2),jointz(2,3)-jointz(1,3),'b','LineWidth',3);
67  quiver3(jointy(1,1),jointy(1,2),jointy(1,3),jointy(2,1)-jointy(1,1),jointy(2,2)-jointy(1,2),jointy(2,3)-jointy(1,3),'g','LineWidth',3);
68  quiver3(jointx(1,1),jointx(1,2),jointx(1,3),jointx(2,1)-jointx(1,1),jointx(2,2)-jointx(1,2),jointx(2,3)-jointx(1,3),'r','LineWidth',3);
69  plot3(x(1,i+1),y(1,i+1),z(1,i+1),'ok','MarkerFaceColor','k')
70  end
71 end
72 
73 
74 %plot3(x,y,z,color,'LineWidth',2)
75 %plot3(x(base),y(base),z(base),'go','LineWidth',2);
76 
77 %plot3(x(1,size(DH,1)),y(1,size(DH,1)),z(1,size(DH,1)),'ok','MarkerFaceColor','k')
78 
79 z1=[x(end-1) y(end-1) z(end-1)];
80 z2=[x(end) y(end) z(end)];
81 zs=(z2-z1)/norm(z2-z1);
82 
83 hold off
84 
85 
86 end