《机床数控技术课程设计说明书.pdf》由会员分享,可在线阅读,更多相关《机床数控技术课程设计说明书.pdf(58页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精心打造 未来1 机床数控技术课程设计说明书 指导老师:姓名:班级:学号:2014/01/10 精心打造 未来2 精心打造 未来3 目录 一 课设任务.1 二 课设要求.1(一)DDA 第四象限直线插补.1(二)逐点比较法第 21 象限顺圆弧插补.2(一)DDA 第四象限直线插补.5 精心打造 未来4 初始化参数x1 y1 x2 y2 L N绘制直线初始化寄存器选择加载方式Mx0或 My0转化到第一象限转化到第二象限转化到第三象限转化到第四象限 Xe Xe+Xe Ye Ye+Ye Xe Xe+Xe Ye Ye+Ye Xe Xe+Xe Ye Ye+Ye Xe Xe+Xe Ye Ye+YeX 积分
2、累加器溢出+XY 积分累加器溢出Mx=Mx-1+YMy=My-1X 积分累加器溢出-XY 积分累加器溢出Mx=Mx-1+YMy=My-1X 积分累加器溢出-XY 积分累加器溢出Mx=Mx-1-YMy=My-1X 积分累加器溢出+XY 积分累加器溢出Mx=Mx-1-YMy=My-1插补完成NYNNNNNNNYYYYYYYNYYYYY.5(二)逐点比较法第 12 象限逆圆弧插补.6 精心打造 未来5 初始化参数x1 y1 r x2 y2 L绘制圆弧计算插补步数MM0插补完成判断转化后圆弧的象限第一象限第二象限第三象限第四象限圆内-YM=M-1+X圆内+YM=M-1-X圆内-XM=M-1-Y圆内+Y
3、M=M-1+XNYNNNNNNNYYYY.6 六 源程序.6 function varargout=f2(varargin).6%F2 MATLAB code for f2.fig.6%F2,by itself,creates a new F2 or raises the existing.6%singleton*.6%.6%H=F2 returns the handle to a new F2 or the handle to.6%the existing singleton*.6%.6%F2(CALLBACK,hObject,eventData,handles,.)calls the lo
4、cal.6%function named CALLBACK in F2.M with the given input arguments.6%.6%F2(Property,Value,.)creates a new F2 or raises the.6%existing singleton*.Starting from the left,property value pairs are.6%applied to the GUI before f2_OpeningFcn gets called.An.6%unrecognized property name or invalid value ma
5、kes property application.7%stop.All inputs are passed to f2_OpeningFcn via varargin.7%.7%*See GUI Options on GUIDEs Tools menu.Choose GUI allows only one.7 精心打造 未来6%instance to run(singleton).7%.7%See also:GUIDE,GUIDATA,GUIHANDLES.7%Edit the above text to modify the response to help f2.7%Last Modifi
6、ed by GUIDE v2.5 09-Jan-2014 10:52:17.7%Begin initialization code-DO NOT EDIT.7 gui_Singleton=1;.7 gui_State=struct(gui_Name,mfilename,.7 gui_Singleton,gui_Singleton,.7 gui_OpeningFcn,f2_OpeningFcn,.7 gui_OutputFcn,f2_OutputFcn,.7 gui_LayoutFcn,.7 gui_Callback,);.7 if nargin&ischar(varargin1).7 gui_
7、State.gui_Callback=str2func(varargin1);.7 end.7 if nargout.7 varargout1:nargout=gui_mainfcn(gui_State,varargin:);.7 else.7 gui_mainfcn(gui_State,varargin:);.7 end.7%End initialization code-DO NOT EDIT.7%-Executes just before f2 is made visible.7 function f2_OpeningFcn(hObject,eventdata,handles,varar
8、gin).7%This function has no output args,see OutputFcn.7%hObject handle to figure.7%eventdata reserved-to be defined in a future version of MATLAB.7%handles structure with handles and user data(see GUIDATA).7%varargin command line arguments to f2(see VARARGIN).7%Choose default command line output for
9、 f2.7 handles.output=hObject;.7%Update handles structure.7 guidata(hObject,handles);.8%UIWAIT makes f2 wait for user response(see UIRESUME).8%uiwait(handles.figure1);.8%-Outputs from this function are returned to the command line.8 function varargout=f2_OutputFcn(hObject,eventdata,handles).8%varargo
10、ut cell array for returning output args(see VARARGOUT);.8%hObject handle to figure.8%eventdata reserved-to be defined in a future version of MATLAB.8%handles structure with handles and user data(see GUIDATA).8%Get default command line output from handles structure.8 varargout1=handles.output;.8%-Exe
11、cutes on button press in pushbutton1.8 精心打造 未来7 function pushbutton1_Callback(hObject,eventdata,handles)%绘制直线.8 global x1 y1 x2 y2 L N x y Mx My Jvx Jrx1 Jrx2 Jrx3 Jvy Jry1 Jry2 Jry3 X Y;.8 x1=str2double(get(handles.edit1,string);.8 y1=str2double(get(handles.edit2,string);.8 x2=str2double(get(handle
12、s.edit3,string);.8 y2=str2double(get(handles.edit4,string);.8 L=str2double(get(handles.edit7,string);.8 N=str2double(get(handles.edit6,string);.8 if x1=0|x2=0.8 set(handles.text11,string,直线不在第四象限!);%判断直线是否在第四象限.8 else.8 if x1=x2.8 y=y1:(y2-y1)/100:y2;.8 x=y.*0+x1;.8 plot(x,y,k);.8 hold on;.8 else.8
13、x=x1:(x2-x1)/100:x2;.8 plot(x,y,k);.8 hold on;.8 end.8 xmin=min(x);.8 xmax=max(x);.8 ymin=min(y);.8 ymax=max(y);.8 axis equal;.9 axis(xmin-L xmax+L ymin-L ymax+L);%定义坐标轴的边界.9 set(handles.text11,string,绘图完成);.9 Mx=ceil(abs(x2-x1)/L);%计算插补步数.9 My=ceil(abs(y2-y1)/L);.9 Jvx=abs(x2-x1);%给寄存器赋值.9 Jrx2=2N-
14、1;.9 Jrx3=2(N-1);.9 Jvy=abs(y2-y1);.9 Jry1=0;.9 Jry2=2N-1;.9 Jry3=2(N-1);.9 X=x1;.9 Y=y1;.9 end.9%hObject handle to pushbutton1(see GCBO).9%eventdata reserved-to be defined in a future version of MATLAB.9%handles structure with handles and user data(see GUIDATA).9 function edit1_Callback(hObject,eve
15、ntdata,handles).9 精心打造 未来8%hObject handle to edit1(see GCBO).9%eventdata reserved-to be defined in a future version of MATLAB.9%handles structure with handles and user data(see GUIDATA).9%Hints:get(hObject,String)returns contents of edit1 as text.9%str2double(get(hObject,String)returns contents of e
16、dit1 as a double.9%-Executes during object creation,after setting all properties.9 function edit1_CreateFcn(hObject,eventdata,handles).9%hObject handle to edit1(see GCBO).9%eventdata reserved-to be defined in a future version of MATLAB.9%handles empty-handles not created until after all CreateFcns c
17、alled.9%Hint:edit controls usually have a white background on Windows.9%See ISPC and COMPUTER.9 if ispc&isequal(get(hObject,BackgroundColor),get(0,defaultUicontrolBackgroundColor).9 set(hObject,BackgroundColor,white);.9 end.9 function edit2_Callback(hObject,eventdata,handles).10%hObject handle to ed
18、it2(see GCBO).10%eventdata reserved-to be defined in a future version of MATLAB.10%handles structure with handles and user data(see GUIDATA).10%Hints:get(hObject,String)returns contents of edit2 as text.10%str2double(get(hObject,String)returns contents of edit2 as a double.10%-Executes during object
19、 creation,after setting all properties.10 function edit2_CreateFcn(hObject,eventdata,handles).10%hObject handle to edit2(see GCBO).10%eventdata reserved-to be defined in a future version of MATLAB.10%handles empty-handles not created until after all CreateFcns called.10%Hint:edit controls usually ha
20、ve a white background on Windows.10%See ISPC and COMPUTER.10 if ispc&isequal(get(hObject,BackgroundColor),get(0,defaultUicontrolBackgroundColor).10 set(hObject,BackgroundColor,white);.10 end.10 function edit3_Callback(hObject,eventdata,handles).10%hObject handle to edit3(see GCBO).10%eventdata reser
21、ved-to be defined in a future version of MATLAB.10%handles structure with handles and user data(see GUIDATA).10%Hints:get(hObject,String)returns contents of edit3 as text.10%str2double(get(hObject,String)returns contents of edit3 as a double.10%-Executes during object creation,after setting all prop
22、erties.10 function edit3_CreateFcn(hObject,eventdata,handles).10%hObject handle to edit3(see GCBO).10%eventdata reserved-to be defined in a future version of MATLAB.10%handles empty-handles not created until after all CreateFcns called.10 精心打造 未来9%Hint:edit controls usually have a white background o
23、n Windows.10%See ISPC and COMPUTER.10 if ispc&isequal(get(hObject,BackgroundColor),get(0,defaultUicontrolBackgroundColor).10 set(hObject,BackgroundColor,white);.10 end.10 function edit4_Callback(hObject,eventdata,handles).11%hObject handle to edit4(see GCBO).11%eventdata reserved-to be defined in a
24、future version of MATLAB.11%handles structure with handles and user data(see GUIDATA).11%Hints:get(hObject,String)returns contents of edit4 as text.11%str2double(get(hObject,String)returns contents of edit4 as a double.11%-Executes during object creation,after setting all properties.11 function edit
25、4_CreateFcn(hObject,eventdata,handles).11%hObject handle to edit4(see GCBO).11%eventdata reserved-to be defined in a future version of MATLAB.11%handles empty-handles not created until after all CreateFcns called.11%Hint:edit controls usually have a white background on Windows.11%See ISPC and COMPUT
26、ER.11 if ispc&isequal(get(hObject,BackgroundColor),get(0,defaultUicontrolBackgroundColor).11 set(hObject,BackgroundColor,white);.11 end.11 function edit5_Callback(hObject,eventdata,handles).11%hObject handle to edit5(see GCBO).11%eventdata reserved-to be defined in a future version of MATLAB.11%hand
27、les structure with handles and user data(see GUIDATA).11%Hints:get(hObject,String)returns contents of edit5 as text.11%str2double(get(hObject,String)returns contents of edit5 as a double.11%-Executes during object creation,after setting all properties.11 function edit5_CreateFcn(hObject,eventdata,ha
28、ndles).11%hObject handle to edit5(see GCBO).11%eventdata reserved-to be defined in a future version of MATLAB.11%handles empty-handles not created until after all CreateFcns called.11%Hint:edit controls usually have a white background on Windows.11%See ISPC and COMPUTER.11 if ispc&isequal(get(hObjec
29、t,BackgroundColor),get(0,defaultUicontrolBackgroundColor).11 set(hObject,BackgroundColor,white);.12 end.12 function edit6_Callback(hObject,eventdata,handles).12%hObject handle to edit6(see GCBO).12%eventdata reserved-to be defined in a future version of MATLAB.12%handles structure with handles and u
30、ser data(see GUIDATA).12 精心打造 未来10%Hints:get(hObject,String)returns contents of edit6 as text.12%str2double(get(hObject,String)returns contents of edit6 as a double.12%-Executes during object creation,after setting all properties.12 function edit6_CreateFcn(hObject,eventdata,handles).12%hObject hand
31、le to edit6(see GCBO).12%eventdata reserved-to be defined in a future version of MATLAB.12%handles empty-handles not created until after all CreateFcns called.12%Hint:edit controls usually have a white background on Windows.12%See ISPC and COMPUTER.12 if ispc&isequal(get(hObject,BackgroundColor),get
32、(0,defaultUicontrolBackgroundColor).12 set(hObject,BackgroundColor,white);.12 end.12 function edit7_Callback(hObject,eventdata,handles).12%hObject handle to edit7(see GCBO).12%eventdata reserved-to be defined in a future version of MATLAB.12%handles structure with handles and user data(see GUIDATA).
33、12%Hints:get(hObject,String)returns contents of edit7 as text.12%str2double(get(hObject,String)returns contents of edit7 as a double.12%-Executes during object creation,after setting all properties.12 function edit7_CreateFcn(hObject,eventdata,handles).12%hObject handle to edit7(see GCBO).12%eventda
34、ta reserved-to be defined in a future version of MATLAB.12%handles empty-handles not created until after all CreateFcns called.12%Hint:edit controls usually have a white background on Windows.12%See ISPC and COMPUTER.13 if ispc&isequal(get(hObject,BackgroundColor),get(0,defaultUicontrolBackgroundCol
35、or).13 set(hObject,BackgroundColor,white);.13 end.13%-Executes on button press in pushbutton2.13 function pushbutton2_Callback(hObject,eventdata,handles)%直线单步插补.13%hObject handle to pushbutton2(see GCBO).13%eventdata reserved-to be defined in a future version of MATLAB.13%handles structure with hand
36、les and user data(see GUIDATA).13 global x1 y1 x2 y2 L N x y Mx My Jvx Jrx1 Jrx2 Jrx3 Jvy Jry1 Jry2 Jry3 X Y;.13 if(get(handles.radiobutton1,Value)=0).13&(get(handles.radiobutton2,Value)=0).13&(get(handles.radiobutton3,Value)=0).13 set(handles.text11,string,请选择插补方式);.13 else.13 if(Mx=0)&(My=0).13 se
37、t(handles.text11,string,插补结束);.13 else.13 精心打造 未来11 Jrx1=Jvx+Jrx1;.13 Jry1=Jvy+Jry1;.13 Jrx2=Jvx+Jrx2;.13 Jry2=Jvy+Jry2;.13 Jrx3=Jvx+Jrx3;.13 Jry3=Jvy+Jry3;.13 if get(handles.radiobutton1,Value)=1%普通 DDA.13 if(x1=x2)&(y1=2N).13 Jrx1=Jrx1-2N;.13 X=X+L;.13 x=linspace(X-L,X,100);.13 Mx=Mx-1;.13 else.13
38、 x=zeros(1,100)+X;.13 end.13 if(Jry1=2N).13 Jry1=Jry1-2N;.13 y=linspace(Y-L,Y,100);.13 My=My-1;.13 else.13 y=zeros(1,100)+Y;.13 end.13 plot(x,y,r);.13 hold on;.14 elseif(x1x2)&(y1=2N).14 Jrx1=Jrx1-2N;.14 X=X-L;.14 x=linspace(X+L,X,100);.14 Mx=Mx-1;.14 else.14 x=zeros(1,100)+X;.14 end.14 if(Jry1=2N).
39、14 Jry1=Jry1-2N;.14 Y=Y+L;.14 y=linspace(Y-L,Y,100);.14 My=My-1;.14 else.14 y=zeros(1,100)+Y;.14 end.14 plot(x,y,r);.14 hold on;.14 精心打造 未来12 elseif(x1x2)&(y1y2)%转化后直线在第三象限.14 if(Jrx1=2N).14 Jrx1=Jrx1-2N;.14 X=X-L;.14 x=linspace(X+L,X,100);.14 Mx=Mx-1;.14 else.14 x=zeros(1,100)+X;.14 end.14 if(Jry1=
40、2N).14 Jry1=Jry1-2N;.14 Y=Y-L;.14 y=linspace(Y+L,Y,100);.14 My=My-1;.14 y=zeros(1,100)+Y;.14 end.14 plot(x,y,r);.14 hold on;.14 else%转化后直线在第四象限.14 if(Jrx1=2N).14 Jrx1=Jrx1-2N;.14 X=X+L;.14 x=linspace(X-L,X,100);.14 Mx=Mx-1;.14 else.15 x=zeros(1,100)+X;.15 end.15 if(Jry1=2N).15 Jry1=Jry1-2N;.15 Y=Y-L
41、;.15 y=linspace(Y+L,Y,100);.15 My=My-1;.15 else.15 y=zeros(1,100)+Y;.15 end.15 plot(x,y,r);.15 hold on;.15 end.15 elseif get(handles.radiobutton2,Value)=1%全加载.15 if(x1=x2)&(y1=2N).15 Jrx2=Jrx2-2N;.15 X=X+L;.15 x=linspace(X-L,X,100);.15 精心打造 未来13 Mx=Mx-1;.15 else.15 x=zeros(1,100)+X;.15 end.15 if(Jry
42、2=2N).15 Jry2=Jry2-2N;.15 Y=Y+L;.15 y=linspace(Y-L,Y,100);.15 My=My-1;.15 else.15 y=zeros(1,100)+Y;.15 end.15 plot(x,y,r);.15 hold on;.15 elseif(x1x2)&(y1=2N).15 Jrx2=Jrx2-2N;.15 X=X-L;.15 x=linspace(X+L,X,100);.15 Mx=Mx-1;.15 else.15 x=zeros(1,100)+X;.15 end.15 if(Jry2=2N).15 Jry2=Jry2-2N;.16 Y=Y+L
43、;.16 y=linspace(Y-L,Y,100);.16 My=My-1;.16 else.16 y=zeros(1,100)+Y;.16 end.16 plot(x,y,r);.16 hold on;.16 elseif(x1x2)&(y1y2).16 if(Jrx2=2N).16 Jrx2=Jrx2-2N;.16 X=X-L;.16 x=linspace(X+L,X,100);.16 Mx=Mx-1;.16 else.16 x=zeros(1,100)+X;.16 end.16 if(Jry2=2N).16 Jry2=Jry2-2N;.16 精心打造 未来14 Y=Y-L;.16 y=
44、linspace(Y+L,Y,100);.16 My=My-1;.16 else.16 y=zeros(1,100)+Y;.16 end.16 plot(x,y,r);.16 hold on;.16 else.16 if(Jrx2=2N).16 Jrx2=Jrx2-2N;.16 X=X+L;.16 x=linspace(X-L,X,100);.16 Mx=Mx-1;.16 else.16 x=zeros(1,100)+X;.16 end.16 if(Jry2=2N).16 Jry2=Jry2-2N;.16 Y=Y-L;.16 y=linspace(Y+L,Y,100);.16 My=My-1;
45、.16 else.16 y=zeros(1,100)+Y;.16 end.17 plot(x,y,r);.17 hold on;.17 end.17 else%半加载.17 if(x1=x2)&(y1=2N).17 Jrx3=Jrx3-2N;.17 X=X+L;.17 x=linspace(X-L,X,100);.17 Mx=Mx-1;.17 else.17 x=zeros(1,100)+X;.17 end.17 if(Jry3=2N).17 Jry3=Jry3-2N;.17 Y=Y+L;.17 y=linspace(Y-L,Y,100);.17 My=My-1;.17 else.17 精心打
46、造 未来15 y=zeros(1,100)+Y;.17 end.17 plot(x,y,r);.17 hold on;.17 elseif(x1x2)&(y1=2N).17 Jrx3=Jrx3-2N;.17 X=X-L;.17 x=linspace(X+L,X,100);.17 Mx=Mx-1;.17 else.17 x=zeros(1,100)+X;.17 end.17 if(Jry3=2N).17 Jry3=Jry3-2N;.17 Y=Y+L;.17 y=linspace(Y-L,Y,100);.17 My=My-1;.17 else.17 y=zeros(1,100)+Y;.17 end
47、.17 plot(x,y,r);.17 hold on;.17 elseif(x1x2)&(y1y2).17 if(Jrx3=2N).18 Jrx3=Jrx3-2N;.18 X=X-L;.18 x=linspace(X+L,X,100);.18 Mx=Mx-1;.18 else.18 x=zeros(1,100)+X;.18 end.18 if(Jry3=2N).18 Jry3=Jry3-2N;.18 Y=Y-L;.18 y=linspace(Y+L,Y,100);.18 My=My-1;.18 else.18 y=zeros(1,100)+Y;.18 end.18 plot(x,y,r);.
48、18 hold on;.18 else.18 if(Jrx3=2N).18 精心打造 未来16 Jrx3=Jrx3-2N;.18 X=X+L;.18 x=linspace(X-L,X,100);.18 Mx=Mx-1;.18 else.18 x=zeros(1,100)+X;.18 end.18 if(Jry3=2N).18 Jry3=Jry3-2N;.18 Y=Y-L;.18 y=linspace(Y+L,Y,100);.18 My=My-1;.18 else.18 y=zeros(1,100)+Y;.18 end.18 plot(x,y,r);.18 hold on;.18 end.18
49、end.18 end.18 end.18%-Executes on button press in pushbutton3.18 function pushbutton3_Callback(hObject,eventdata,handles)%直线连续插补.19%hObject handle to pushbutton3(see GCBO).19%eventdata reserved-to be defined in a future version of MATLAB.19%handles structure with handles and user data(see GUIDATA).1
50、9 global x1 y1 x2 y2 L N x y Mx My Jvx Jrx1 Jrx2 Jrx3 Jvy Jry1 Jry2 Jry3 X Y;.19 if(get(handles.radiobutton1,Value)=0).19&(get(handles.radiobutton2,Value)=0).19&(get(handles.radiobutton3,Value)=0).19 set(handles.text11,string,请选择插补方式);.19 else.19 while(Mx0)|(My0).19 Jrx1=Jvx+Jrx1;.19 Jry1=Jvy+Jry1;.