杭州ug培訓班
轉移和循環(huán)
在程序中使用GOTO和IF可以改變程序執(zhí)行順序
1.
例如
G0 X0 Y0;
G01 X100 Y100 F100;
X500;
GOTO 01;
Y500;
N01 X550;
Y550;
G0 Z200;
2. IF語句
1).IF[條件表達式]GOTO n
如果指定的表達式滿足,則轉移到標有順序號n 的程序段,如果不滿足指定的條件表達式,則順序執(zhí)行下一個程序段。
例如
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.循環(huán)(WHILE語句)
在WHILE后制定一個條件表達式,當指定條件滿足時,則執(zhí)行從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(銑圓形)
基本數(shù)學知識
圓的方程式;
標準方程X2 Y2=R2
參數(shù)方程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(銑橢圓)
基本數(shù)學知識
橢圓方程
標準方程 X2/A2 Y2/B2=1
參數(shù)方程 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培訓
了解更多杭州培訓網(wǎng)>>>>杭州培訓網(wǎng)