Make M-file attached to a guide
Show older comments
I work with MATLAB 2007A and I want to put this M-file attached to a guide? helpme please this is a job for my final year of study
function draw_lines
% Click the left mouse button to define a point
% Drag the mouse to draw a line to the next point and
% left click again
% Right click the mouse to stop drawing
ComId = Com_construct;
OmniDriveId= OmniDrive_construct;
OdometryId = Odometry_construct;
BumperId = Bumper_construct;
fh = figure('units','pixels',...
'position',[100 100 800 500],...
'menubar','none',...
'name','figure',...
'numbertitle','off',...
'resize','on',...
'WindowButtonDownFcn',@wbdcb);
dist= uicontrol(fh,'Style','edit',...
'String','',...
'backgroundcolor','r',...
'Position',[200 450 130 20]);
posX0= uicontrol(fh,'Style','edit',...
'String','',...
'backgroundcolor','r',...
'Position',[20 450 130 20]);
posY0= uicontrol(fh,'Style','edit',...
'String','',...
'backgroundcolor','r',...
'Position',[20 420 130 20]);
posX1= uicontrol(fh,'Style','edit',...
'String','',...
'backgroundcolor','b',...
'Position',[20 390 130 20]);
posY1= uicontrol(fh,'Style','edit',...
'String','',...
'backgroundcolor','b',...
'Position',[20 360 130 20]);
buttonconnecter = uicontrol(fh,'style','push',...
'units','pix',...
'position',[10 100 180 40],...
'fontsize',14,...
'string','connecter',...
'callback',@connect);
buttonmarcher = uicontrol(fh,'style','push',...
'units','pix',...
'position',[10 50 180 40],...
'fontsize',14,...
'string','marcher',...
'callback',@marche);
buttonarreter = uicontrol(fh,'style','push',...
'units','pix',...
'position',[10 10 180 40],...
'fontsize',14,...
'string','arret',...
'callback',@arret);
buttonclear = uicontrol(fh,'style','push',...
'units','pix',...
'position',[10 150 180 40],...
'fontsize',14,...
'string','clear',...
'callback',@clear);
ah = axes('Parent',fh,'Position',[.25 .05 .7 .7],...
'DrawMode','fast');
axis ([1 1000 1 1000])
function wbdcb(src,evnt)
if strcmp(get(src,'SelectionType'),'normal')
[x,y,str] = disp_point(ah);
hl = line('XData',x,'YData',y,'Marker','.');
text(x,y,str,'VerticalAlignment','bottom');drawnow
set(src,'WindowButtonMotionFcn',@wbmcb)
elseif strcmp(get(src,'SelectionType'),'alt')
set(src,'WindowButtonMotionFcn','')
[x,y,str] = disp_point(ah);
text(x,y,str,'VerticalAlignment','bottom');drawnow
end
function wbmcb(src,evnt)
[xn,yn,str] = disp_point(ah);
xdat = [x,xn];
ydat = [y,yn];
set(hl,'XData',xdat,'YData',ydat);
set(posX0,'string',num2str(xdat(1:1),'%0.3g'));
set(posY0,'string',num2str(ydat(1:1),'%0.3g'));
end
end
function [x,y,str] = disp_point(ah)
cp = get(ah,'CurrentPoint');
x = cp(1,1);y = cp(1,2);
str = ['(',num2str(x,'%0.3g'),', ',num2str(y,'%0.3g'),')'];
set(posX1,'string',num2str(x,'%0.3g'));
set(posY1,'string',num2str(y,'%0.3g'));
end
function connect (h,evnt)
Com_setAddress(ComId, '127.0.0.1:8080'); % 172.26.1.1 127.0.0.1:8080
Com_connect(ComId);
Odometry_set(OdometryId, 0, 0, 0);
end
function marche(h,evnt)
x0=str2double(get(posX0,'string'));
y0=str2double(get(posY0,'string'));
OmniDrive_setComId(OmniDriveId, ComId);
Odometry_setComId( OdometryId, ComId );
Bumper_setComId(BumperId, ComId);
tStart = tic;
Odometry_set(OdometryId, x0, y0, 0);
a=str2double(get(posX1,'string'));
b=str2double(get(posY1,'string'));
while (Bumper_value(BumperId) ~= 1)
tElapsed = toc(tStart);
% % % If 60 seconds are elapsed then exit while loop
if(tElapsed >= 60 )
break;
end;
%Odometry_set(OdometryId, x0, y0, 0);
[x, y, phi]= Odometry_get(OdometryId);
%xlswrite('testdata.xls', x, 1, 'A1')
Dy= b - y0;
Dx= a - x0;
D= sqrt(Dx.^2+Dy.^2);
set(dist,'string',num2str(D,'%0.3g'));
if ((Dx==0) && (Dy<0))
while (phi<=270)
[x, y, phi]= Odometry_get(OdometryId);
OmniDrive_setVelocity(OmniDriveId, 0, 0 ,-50);
end;
elseif ((Dx==0) && (Dy>0))
while (phi<=90)
[x, y, phi]= Odometry_get(OdometryId);
OmniDrive_setVelocity(OmniDriveId, 0, 0 ,50);
end;
else
angle= atan(Dy/Dx);
phi1= rad2deg(angle);
if (phi1<0)
while (phi>phi1)
[x, y, phi]= Odometry_get(OdometryId);
OmniDrive_setVelocity(OmniDriveId, 0, 0 ,-50);
end;
elseif (phi1>1)
while (phi<=phi1)
[x, y, phi]= Odometry_get(OdometryId);
OmniDrive_setVelocity(OmniDriveId, 0, 0 ,50);
end;
else
OmniDrive_setVelocity(OmniDriveId, 0, 0 ,0);
end;
end;
[x, y, phi]= Odometry_get(OdometryId);
Dyy= b - y;
Dxx= a - x;
%while (D>0)
if ((Dxx<=0)&& (Dyy<=0))
OmniDrive_setVelocity(OmniDriveId, 0, 0 ,0);
break;
else
OmniDrive_setVelocity(OmniDriveId, 800, 0 ,0);
[x, y, phi]= Odometry_get(OdometryId);
line(x,y,'Marker','.');
% xlswrite('testdata.xls', x, 1, 'A1')
end;
%end;
end;
end
function clear(src,evt)
cla(ah,'reset')
%lbs = '';
set(ah,'DrawMode','fast');
axis ([1 1000 1 1000])
end
function arret(h,evnt)
Com_disconnect(ComId);
close(fh);
end
end
Accepted Answer
More Answers (0)
Categories
Find more on App Building 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!