📄 demobot.m
字号:
'Position',[0.95 0.375 0.03 0.25],'min',-90,'max',90, ...
'Value',0,'Callback',s2,'visible','off','BackgroundColor',[.8 .9 .2]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
s1 = ['T1 = get(gco,''Value'');' ... % defines T1 as slider value
'forkin;' ...
'setplot;']; % calls setplot to figure
slider1=uicontrol(fig,'Style','slider','Units','normalized', ...
'Position',[0.95 0.05 0.03 0.25],'min',-90,'max',90, ...
'Value',0,'Callback',s1,'visible','off','BackgroundColor',[.2 .8 .2]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P1 = ['option(1,4);'];
PushBut1=uicontrol(fig,'Style','pushbutton','Units','normalized', ...
'Position',[0.10 .02 0.17125 0.05],'string','Position-Sliders', ...
'Callback',P1,'visible','on','BackgroundColor',[0.8 0.8 0.8]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P2 = ['option(2,0)'];
PushBut2=uicontrol(fig,'Style','pushbutton','Units','normalized', ...
'Position',[0.30125 .02 0.17125 0.05],'string','Click on Target', ...
'Callback',P2,'visible','on','BackgroundColor',[0.8 0.8 0.8]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P3 = ['option(3,0);'];
PushBut3=uicontrol(fig,'Style','pushbutton','Units','normalized', ...
'Position',[0.5025 .02 0.17125 0.05],'string','Click and Drag', ...
'Callback',P3,'visible','on','BackgroundColor',[0.8 0.8 0.8]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P4 = ['option(4,4)'];
PushBut4=uicontrol(fig,'Style','pushbutton','Units','normalized', ...
'Position',[0.70375 .02 0.17125 0.05],'string', 'Angle-Sliders', ...
'Callback',P4,'visible','on','BackgroundColor',[0.8 0.8 0.8]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P5 = ['close;'];
PushBut5=uicontrol(fig,'Style','pushbutton','Units','normalized', ...
'Position',[0.1 .92 0.17 0.05],'string','EXIT', ...
'Callback',P5,'visible','on','BackgroundColor',[0.8 0.8 0.8]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HELP=0;
P6 = ['if HELP==0;' ...
'set(Help,''visible'',''on'');' ...
'set(Help_mes,''visible'',''on'');' ...
'set(pF1,''visible'',''off'');' ...
'set(pF2,''visible'',''off'');' ...
'set(pF3,''visible'',''off'');' ...
'set(C2,''visible'',''off'');' ...
'set(C3,''visible'',''off'');' ...
'set(Ct,''visible'',''off'');' ...
'set(J2,''visible'',''off'');' ...
'set(J3,''visible'',''off'');' ...
'set(Jt,''visible'',''off'');' ...
'set(dis,''visible'',''off'');' ...
'set(PushBut6,''string'',''HIDE HELP'');' ...
'HELP=1;' ...
'else;' ...
'set(Help,''visible'',''off'');' ...
'set(Help_mes,''visible'',''off'');' ...
'set(pF1,''visible'',''on'');' ...
'set(pF2,''visible'',''on'');' ...
'set(pF3,''visible'',''on'');' ...
'set(C2,''visible'',''on'');' ...
'set(C3,''visible'',''on'');' ...
'set(Ct,''visible'',''on'');' ...
'set(J2,''visible'',''on'');' ...
'set(J3,''visible'',''on'');' ...
'set(Jt,''visible'',''on'');' ...
'set(dis,''visible'',''on'');' ...
'set(PushBut6,''string'',''HELP'');' ...
'HELP=0;' ...
'end;'];
PushBut6=uicontrol(fig,'Style','pushbutton','Units','normalized', ...
'Position',[0.70375 .92 0.17 0.05],'string','HELP', ...
'Callback',P6,'visible','on','BackgroundColor',[0.8 0.8 0.8]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
title('Three Link Planar Robot','FontSize',14)
%xlabel('X-Position(in)')
%ylabel('Y-Position(in)')
axis([-25 25 -3 25]) % axis limits
axis manual % set axis to exact manual value(i.e [-25 25 -10 25])
axis equal % x-scale=y-scale
hold on % does not erase previous graphs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
arc=(0:1:180)*pi/180; % plot desired workspace
arc2=(180:-1:0)*pi/180;
plot([rmax*cos(arc) rmin*cos(arc2) rmax],[rmax*sin(arc) rmin*sin(arc2) 0], ...
'Color',[.8 .4 .2])
legend('Workspace')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
grid off % turns on grid
% manual grid so that axis will be black and grid gray
% minor grid lines
for y=0:1:24
plot([-24.9 25],[y y],'Color',[.97,.97,.97])
end
for x=-24:1:24
plot([x x],[0 25],'Color',[.97,.97,.97])
end
% major grid lines
for y=0:5:20
plot([-24.9 25],[y y],'Color',[0.9 0.9 0.9])
end
for x=-20:5:20
plot([x x],[0 25],'Color',[.9,.9,.9])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plot([rmax*cos(arc) rmin*cos(arc2) rmax],[rmax*sin(arc) rmin*sin(arc2) 0], ...
'Color',[.8 .4 .2])
pos=[15,20];
lg=legend('Workspace',1); % plot workspace or grid
set(lg,'Position',[0.66 0.815 0.203571 0.0492857])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(gca,'GridLineStyle','-') % solid lines
set(gca,'YColor',[0,0,0]) % y axis color
set(gca,'XColor',[0,0,0]) % y axis color
set(gca,'XTick',[-25:5:25]) % numbers on y-axis
set(gca,'YTick',[0:5:25]) % numbers onf x-axis
set(gca,'Color',[1,1,1]) % plot background color
set(gca,'FontSize',8);
set(gcf,'Color',[.95,.95,.95]) % edge background color
set(gca,'Position',[0.10 0.11 0.775 0.815]) % size of data windown
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BF=fill(B(1,:),B(2,:),'r'); % color fill base
set(BF,'FaceColor',[.8 .3 .3]);
pF1=fill(L1(1,:),L1(2,:),'g', 'erasemode','xor'); % color fill link1
set(pF1,'FaceColor',[.2 .8 .2]);
pF2=fill(L2(1,:),L2(2,:),'y', 'erasemode','xor'); % color fill link2
set(pF2,'FaceColor',[.8 .9 .2]);
pF3=fill(L3(1,:),L3(2,:),'b','erasemode','xor'); % color fill link3
set(pF3,'FaceColor',[.2 .2 .8]);
plot(x1,y1,'om'); % circle at joint '1'
C2=plot(x2,y2,'ob', 'erasemode','xor'); % circle at joint '2'
C3=plot(x3,y3,'oy', 'erasemode','xor'); % circle at joint '3'
Ct=plot(xt,yt,'oy', 'erasemode','xor'); % circle at joint 'T'
plot(x1,y1,'+m'); % plus at joint '1'
J2=plot(x2,y2,'+b', 'erasemode','xor'); % plus at joint '2'
J3=plot(x3,y3,'+y', 'erasemode','xor'); % plus at joint '3'
Jt=plot(xt,yt,'+y', 'erasemode','xor'); % plus at joint 'T'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dis(1)=fill([-15.5 -15.5 15.5 15.5 -15.5],[-9 -4 -4 -9 -9],'w'); % plot a white box
dis(2)=plot([-15.5 -15.5 15.5 15.5 -15.5],[-9 -4 -4 -9 -9],'k'); % box's black outline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yrange = axis;
vspace = (yrange(4) - yrange(3))/20;
px=-14;
py=-5.5;
dis(3)=text(px, py, mat2str(S1),'erasemode','xor'); % theta 1
dis(4)=text(px,(py-1.2*vspace), mat2str(S2),'erasemode','xor'); % xt
dis(5)=text(px+11, py, mat2str(S3),'erasemode','xor'); % theta2
dis(6)=text(px+11,(py-1.2*vspace), mat2str(S4),'erasemode','xor'); % yt
dis(7)=text(px+21, py, mat2str(S5),'erasemode','xor'); % theta3
dis(8)=text(px+21,(py-1.05*vspace), mat2str(S6),'erasemode','xor'); % phi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
px=-24;
py=24;
text(px, py,'Matthew Kontz','FontSize',8);
text(px,(py-1*vspace),'Walla Walla College','FontSize',8);
text(px,(py-2*vspace),'February 2001','FontSize',8);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(gco,'BackingStore','off') % for realtime inverse kinematics
set(gco,'Units','data')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Help(1)=fill([-20 20 20 -20 -20 ],[20 20 -10 -10 20],'w'); % plot a white box
Help(2)=plot([-20 20 20 -20 -20 ],[20 20 -10 -10 20],'k'); % box's black outline
set(Help,'visible','off')
Help_mes(1)=text(-19,19,'There are four different ways you can manipulate this');
Help_mes(2)=text(-19,17,'three link planar robot. Here are your choices.');
Help_mes(3)=text(-19,15,'Position sliders: For this option you can change r and \phi ');
Help_mes(4)=text(-19,13,' by moving the sliders. (r and \phi are the polar coordinate');
Help_mes(5)=text(-19,11,' equivalent of x and y in Cartesian coordinates.)');
Help_mes(6)=text(-19,9,'Click on Target: You click on any point inside the work-');
Help_mes(7)=text(-19,7,' space and watch the robot move into that position.');
Help_mes(8)=text(-19,5,'Click and Drag: Simply hold down your mouse button');
Help_mes(9)=text(-19,3,' and drag the end of the robot around the workspace');
Help_mes(10)=text(-19,1,' for real-time graphical inverse kinematics.');
Help_mes(11)=text(-19,-1,'Angle sliders: This allow you to manually change each');
Help_mes(12)=text(-19,-3,' link and watch how the robot moves.');
Help_mes(13)=text(-19,-9,'To make a selection, click on one of the buttons below.');
Help_mes(14)=text(-19,-5,'NOTE: \theta_{1},\theta_{2}, and \theta_{3} are joints space angles. X_{t},Y_{t},');
Help_mes(15)=text(-19,-7,' and \phi_{t} are the position and angle of the tool frame.');
set(Help_mes,'visible','off')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -