杭州ug培训班
转移和循环
在程序中使用GOTO和IF可以改变程序执行顺序
1.
例如
G0 X0 Y0;
G01 X100 Y100 F100;
X500;
GOTO 01;
Y500;
N01 X550;
Y550;
G0 Z200;
2. IF语句
1).IF[条件表达式]GOTO n
如果指定的表达式满足,则转移到标有顺序号n 的程序段,如果不满足指定的条件表达式,则顺序执行下一个程序段。
例如
IF[#1 GT 100] GOTO 01;
G0 X0 Y0;
N01 X200;
运算符 |
含义 |
EQ |
等于 = |
NE |
不等于 ≠ |
GT |
大于 > |
GE |
大于或等于 ≥ |
LT |
小于 < |
LE |
小于或等于 ≤ |
典型例子
#1=0;
#2=1;
N01 IF[#2 GT 100] GOTO 02;
#1= #1 #2;
#2= #2 #1;
GOTO 01;
N02 M30;
3.循环(WHILE语句)
在WHILE后制定一个条件表达式,当指定条件满足时,则执行从DO到END之间的程序,否则,转到END后的程序段
例如
#2=10;
#3=20;
WHILE[#2 LT #3]
#2=#2-1;
END01;
实例运用
O2012(螺旋铣孔)
#1=50;
#2=40;
#3=30;
#4=0;
#17=1;
#5=[#1-#3]/2;
S1000 M3;
G54 G90 G00 X0 Y0 Z30;
G00 X#5
Z[-#4 1];
G01 Z-#4 F200;
WHILE[#4 LT #2]
#4= #4 #17;
G03 I-#5 Z-#4 F1000;
END 01;
G03 I-#5;
G01 X[#5-1];
G0 Z100;
M30;
O2013(群孔)
#1=40;
#2=30;
#3=12;
#4=10;
#5=6;
S1000 M3;
G54 G90 G00 X0 Y0 Z30
G16;
#6=1;
WHILE[#6 LE #3]
#7=1;
WHILE[#7 LE #5]
#8= #1/2 [#7-1]*#4
#9= [#6-1]*#2;
G98 G81 X#8 Y#9 Z-60 R3 F100;
#7=#7 1;
END 02;
#6=#6 1;
END 01;
G80 Z30;
G15;
M30;
O2013(可变式深孔钻)
#1=3;
#2=20;
#3=0.5;
#4=35;
#5=5.;
M3 S1000;
G54 X0 Y0;
G0 Z#5;
WHILE[#4 GT 0] DO 01;
G01 Z-#2 F1000;
G0 Z#5;
Z[-#2 #1];
#7=#2*#3;
#2=#2 #7;
#4=#4-#2;
END 01;
G0 Z100;
M30;
O2014(铣平面)
#1=1000;
#2=1000;
#3=10;
#4=-#2/2;
#14=0.8*#3;
#5=[#1 #3]/2 2.;
S1000 M3;
G54 G90 G00 X0 Y0 Z30;
X#5 Y#4;
Z0;
WHILE[#4 LT #2/2] DO01;
G01 X-#5 F1000;
#4= #4 #14;
Y#4;
X#5;
#4= #4 #14;
Y#4;
END 01;
G0 Z30;
M30;
另一种编程方式
#1=1000;
#2=1000;
#3=10;
#4=-#2/2;
#14=0.8*#3;
#5=[#1 #3]/2 2.;
S1000 M3;
G54 G90 G00 X0 Y0 Z30;
X#5 Y#4;
Z0;
N01 G01 X-#5 F1000;
#4= #4 #14;
Y#4;
X#5;
#4= #4 #14;
Y#4;
IF [#4 LT #2/2] GOTO 01;
G0 Z30;
M30,
O2015(铣三角形)
#1=1000;
#2=0.;
#3=1.
#4=1.5;
G43 Z53 H01;
WHILE [#1 GT 0] DO 01;
G01 Z#1 F1000;
X#2;
Z[#1-#4];
X[-#2-#3];
#2=[#2 #3];
#1=#1-2*#4;
END 01;
G0 Z300;
M30;
O2016(铣圆形)
基本数学知识
圆的方程式;
标准方程X2 Y2=R2
参数方程X=R*COSA
在宏程序中SQRT是平方根的意思,例如#12= #2,那么#1=SQRT#2
所以则有X=SQRT[R2-Y2]
#1=50;
#4=1;
#6=2500;
G43 Z60. H01;
WHILE[#1 GT -50] DO 01;
G01 Z#1 F2000;
#7=SQRT[#6-#1*#1];
X#7;
#5= #1-#4;
Z#5;
#8=SQRT[#6-#5*#5];
X-#8;
#1=#1-2*#4;
END 01;
Z200;
M30;
O2017(铣椭圆)
基本数学知识
椭圆方程
标准方程 X2/A2 Y2/B2=1
参数方程 X=A*COSα
其中A为长半轴B为短半轴
#1=50;
#2=30;
#3=0.;
G90 G1 X#1 Y0.;
G43 Z0. H01;
G01 Z-10.;
WHILE[#3 GT 360] DO 01;
#13= #1*COS#3;
#14= #1*SIN#3;
G01 X#13 Y#14 F1000;
#3= #3 1.;
END 01;
G0 Z100.;
M30;
O2017(铣球)
M3 S1000;
G0 G54 G90 X0 Y0 ;
#1=10;
#4=90;
G43 Z50 H21;
Z[#1 1];
WHILE[#4 GT -90] DO 01;
#5= #1*SIN#4;
#6= #1*COS#4;
G0 X#6 Y0;
GO Z#5 F1000;
G03 I-#6;
#4= #4-2;
END 01;
G0 Z200.;
M30;
O2019(两个圆柱垂直相接)
#1=35.;
#10=1444;
#11=3364
#2=SQRT[#10-#1*#1];
#3=SQRT[#11-#2*#2];
G54 G90 G80 X-#3 Y#2;
G43 Z40 H12;
G01 Z#1 F1000;
WHILE[#1 GT 0] DO01;
G01 Z#1;
#2=SQRT[#10-#1*#1];
#3=SQRT[#11-#1*#1];
G02 X-#3 Y-#2 R-58
#1= #1-2;
G01 Z#1 F1000;
#2=SQRT[#10-#1*#1];
#3=SQRT[#11-#2*#2];
G03 X-#3 Y#2 R-58 F1000;
#1= #1-1;
END 01;
G0 Z100;
M30;
咨询电话【詹老师】:17706505315
了解更多杭州ug培训>>>>杭州ug培训
了解更多杭州培训网>>>>杭州培训网