1、 机床数控技术课程设计说明书学校:南京航空航天大学专业:机械工程及自动化学号:姓名:设计题目:PL1 DC21指导老师:时间:一课设任务:1.PL1-逐点比较法插补第1象限直线;2.DC21-DDA法插补第21象限顺圆弧。二课设要求:1.含有数据输入界面,如输入直线插补起点、终点,圆弧插补起止点、圆心或半径、插补步长等;2.含有插补过程动态显示功效,如单步插补、连续插补等;3.插补步长可调;4.直线起点、圆弧圆心在坐标系中位置可变(即直线起点、圆弧圆心可不设定在坐标原点)5.提议使用C语言编程,有条件者可使用VB、VC等语言编程。三程序界面及运行截图1.直线连续插补:2. 直线单步插补:3.
2、圆弧连续插补:4.圆弧单步插补:四、程序步骤图1.PL1:逐点比较法插补第1象限直线逐点比较法插补直线过程为每进给一步需完成偏差判别,坐标进给,偏差计算,终点判别四个步骤,具体步骤图1 所表示。开始E=E-1YNY向正Y方向前深入F=F+(x02-x01)向正X方向前深入F=F-(y02-y01)F=0E0N结束E=(abs(x01-x02)+abs(y01-y02)/k (总步数)F=0 (判别函数)初始化,输入起点x01、y01,终点x02、y02,步长k2、DDA法圆弧插补xm=fix(xx-x03)/b);ym=fix(yy+R-y03)/b)Yjvx=0;jvy=0m=2jxm0?j
3、vx=jvx+yj-yyYNym0?jvy=jvy+xx-xjYjvx溢出?0?+X前深入xm=xm-1Yjvy溢出?0?+Y前深入ym=ym-1xm0|ym0?N二一象限顺圆?计算圆心坐标(xx,yy)xj=x03,yj=y03初始化,输入起点坐标(xr03,y03),终点坐标(x04,y04) 半径R步长b和寄存器位数j开始NY+X前深入xn=xn-1-Y前深入yn=yn-1xn=fix(x04-xx)/b);yn=fix(yy+R-y04)/b);Nxn0?jvx=jvx+yj-yyYNyn0?jvy=jvy+xj-xxYjvx溢出?0?Yjvy溢出?0?xn0|yn0?NY结束五程序及
4、变量说明(Matlab)function varargout = cxy_(varargin)gui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, cxy_OpeningFcn, . gui_OutputFcn, cxy_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2f
5、unc(varargin1);end if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end function cxy_OpeningFcn(hObject, eventdata, handles, varargin)global uu=0;global fla;fla=0; handles.output = hObject; guidata(hObject, handles); function varargout = cxy_Ou
6、tputFcn(hObject, eventdata, handles) varargout1 = handles.output; function x1_Callback(hObject, eventdata, handles)global x01;x01=str2double(get(handles.x1,string); function x1_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor
7、) set(hObject,BackgroundColor,white);end function x2_Callback(hObject, eventdata, handles)global x02;x02=str2double(get(handles.x2,string); function x2_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundC
8、olor,white);end function y1_Callback(hObject, eventdata, handles)global y01;y01=str2double(get(handles.y1,string); function y1_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function
9、y2_Callback(hObject, eventdata, handles)global y02;y02=str2double(get(handles.y2,string); function y2_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function x3_Callback(hObject, even
10、tdata, handles)global x03;x03=str2double(get(handles.x3,string); function x3_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function y3_Callback(hObject, eventdata, handles)global y03
11、;y03=str2double(get(handles.y3,string); function y3_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function x4_Callback(hObject, eventdata, handles)global x04;x04=str2double(get(handl
12、es.x4,string); function x4_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function y4_Callback(hObject, eventdata, handles)global y04;y04=str2double(get(handles.y4,string); function y
13、4_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function r_Callback(hObject, eventdata, handles)global R;R=str2double(get(handles.r,string); function r_CreateFcn(hObject, eventdata,
14、handles)if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function clear_Callback(hObject, eventdata, handles)cla; function straightline_Callback(hObject, eventdata, handles)global s;grid on;x01=str2double(get(handles.x1,str
15、ing);x02=str2double(get(handles.x2,string);y01=str2double(get(handles.y1,string);y02=str2double(get(handles.y2,string);x=linspace(x01,x02,1000);y=(y02-y01)/(x02-x01)*(x-x01)+y01;plot(x,y,b);hold on;s=1; function circular_arc_Callback(hObject, eventdata, handles)grid on;x03=str2double(get(handles.x3,
16、string);x04=str2double(get(handles.x4,string);y03=str2double(get(handles.y3,string);y04=str2double(get(handles.y4,string);R=str2double(get(handles.r,string);l=sqrt(y04-y03).2+(x04-x03).2);k=sqrt(R2-(l2)/4);x0=(x03+x04)/2+(y04-y03)*k)/l;y0=(y03+y04)/2-(x04-x03)*k)/l;x=linspace(x03,x04,1000);y=y0+sqrt
17、(R2-(x-x0).2);plot(x,y,b);axis equal;hold on;global ss=0; function lxcb_Callback(hObject, eventdata, handles)global s F X Y;if s=1 x01=str2double(get(handles.x1,string); x02=str2double(get(handles.x2,string); y01=str2double(get(handles.y1,string); y02=str2double(get(handles.y2,string); k=str2double(
18、get(handles.buchang,string); X=x01;Y=y01; F=0; E=(abs(x01-x02)+abs(y01-y02)/k; while E0 if F=0 X=X+k; m=linspace(X-k,X,100); n=Y; F=F-(y02-y01); plot(m,n,r); else Y=Y+k; p=X; q=linspace(Y-k,Y,100); F=F+(x02-x01); plot(p,q,r); end E=E-1; endelse x03=str2double(get(handles.x3,string); x04=str2double(g
19、et(handles.x4,string); y03=str2double(get(handles.y3,string); y04=str2double(get(handles.y4,string); b=str2double(get(handles.buchang,string); j=str2double(get(handles.jcq,string); R=str2double(get(handles.r,string); l=(y04-y03)2+(x04-x03)2)0.5; m=(y04-y03)/l; n=(x03-x04)/l; xx=(x03+x04)/2+(R2-l2/4)
20、0.5*m; yy=(y03+y04)/2+(R2-l2/4)0.5*n;if (x03=xx&xx=yy&y04=yy) errordlg(请输入第二一象限顺圆弧);else xi=x03;yi=y03;xii=x03;yii=y03; jvx=0; jvy=0; xj=fix(xx-x03)/b);yj=fix(yy+R-y03)/b); %计算步数 m=2j; %模 while (xj0|yj0) if xj0 jvx=jvx+yi-yy; end if yj0 jvy=jvy+xx-xi; end flag=0; if(jvxm) xj=xj-1;flag=1; xi=xi+b; jv
21、x=mod(jvx,m); end if(jvym) yj=yj-1;flag=1; yi=yi+b; jvy=mod(jvy,m); end if flag=1 line(xii,xi,yii,yi,color,r); hold on; xii=xi; yii=yi; end endend line(xi,xx,yi,yy+R,color,r); xi=xx;yi=yy+R;xii=xx;yii=yy+R; jvx=0; jvy=0; xj=fix(x04-xx)/b);yj=fix(yy+R-y04)/b); m=2j; axis auto; while (xj0|yj0) if xj0
22、jvx=jvx+yi-yy; end if yj0 jvy=jvy+xi-xx; end flag=0; if(jvxm) xj=xj-1;flag=1; xi=xi+b; jvx=mod(jvx,m); end if(jvym) yj=yj-1;flag=1; yi=yi-b; jvy=mod(jvy,m); end if flag=1 line(xii,xi,yii,yi,color,r); xii=xi; yii=yi; hold on; end end end function dbcb_Callback(hObject, eventdata, handles)global X Y F
23、 u E s;if s=1 x01=str2double(get(handles.x1,string); y01=str2double(get(handles.y1,string); x02=str2double(get(handles.x2,string); y02=str2double(get(handles.y2,string); k=str2double(get(handles.buchang,string); if u=0 X=x01; Y=y01; u=u+1; E=(abs(x01-x02)+abs(y01-y02)/k; F=0; else if E0 if F=0 X=X+k
24、; m=linspace(X-k,X,1000); n=Y; F=F-(y02-y01); plot(m,n,r); hold on; else Y=Y+k; p=X; q=linspace(Y-k,Y); F=F+(x02-x01); plot(p,q,r); hold on; end E=E-1; else u=0; end endelse global fla; x03=str2double(get(handles.x3,string); x04=str2double(get(handles.x4,string); y03=str2double(get(handles.y3,string
25、); y04=str2double(get(handles.y4,string); b=str2double(get(handles.buchang,string); j=str2double(get(handles.jcq,string); R=str2double(get(handles.r,string); l=(y04-y03)2+(x04-x03)2)0.5;m=(y04-y03)/l;n=(x03-x04)/l;xx=(x03+x04)/2+(R2-l2/4)0.5*m;yy=(y03+y04)/2+(R2-l2/4)0.5*n;if (x03=xx&xx=yy&y04=yy) e
26、rrordlg(请输入第二一象限顺圆弧);else %第二象限顺圆插补 xi=x03;yi=y03; jvx=0; jvy=0; xj=fix(xx-x03)/b);yj=fix(yy+R-y03)/b); %第二象限计数器 m=2j; k=1; while (xj0|yj0) if xj0 jvx=jvx+yi-yy; end if yj0 jvy=jvy+xx-xi; end flag=0; if(jvxm) xj=xj-1;flag=1; xi=xi+b; jvx=mod(jvx,m); end if(jvym) yj=yj-1;flag=1; yi=yi+b; jvy=mod(jvy,
27、m); end if flag=1 XC(k)=xi; YC(k)=yi; k=k+1; end end end xi=xx;yi=yy+R;xii=xx;yii=yy+R; %第一象限顺圆插补 jvx=0; jvy=0; xn=fix(x04-xx)/b);yn=fix(yy+R-y04)/b); %第一象限计数器 m=2j; axis auto; while (xn0|yn0) if xn0 jvx=jvx+yi-yy; end if yn0 jvy=jvy+xi-xx; end flag=0; if(jvxm) xn=xn-1;flag=1; xi=xi+b; jvx=mod(jvx,m
28、); end if(jvym) yn=yn-1;flag=1; yi=yi-b; jvy=mod(jvy,m); end if flag=1 XC(k)=xi; YC(k)=yi; k=k+1; end end a=pi-atan(abs(y03-yy)/(x03-xx); b=atan(abs(y04-yy)/(x04-xx); alpha=b:pi/100:a; XQ=xx+R*cos(alpha); YQ=yy+R*sin(alpha); plot(XQ,YQ) hold on; plot(xx,yy,Ro); if fla=0 fla=fla+1; elseif fla=1 line(
29、x03,XC(1),y03,YC(1),color,r); fla=fla+1; elseif fla=k-2 line(XC(fla),XC(fla+1),YC(fla),YC(fla+1),color,r); fla=fla+1; else errordlg(插补结束); fla=0; endend function buchang_Callback(hObject, eventdata, handles) function buchang_CreateFcn(hObject, eventdata, handles)if ispc & isequal(get(hObject,Backgro
30、undColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function jcq_Callback(hObject, eventdata, handles) function jcq_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end六 心得体会此次课设是在考研结束后一周内做完,时间其实应该是很够,不过因为本人不善于编程,所以最终完成得很仓促。经过这次课设,我对matlab操作有了更深认识,对相关函数语句还有逻辑循环套用应用有了更深了解。而且此次课设,让我对逐点比较法直线插补和DDA圆弧插补有了感性和理性全方面认识,对我学习数控机床这门课也有很大帮助。最终,碰到困难不要着急,静下心来总有处理措施