- •第一章OpenCnc发展环境安装及使用说明
- •第二章OpenCnc Structure Motion language 一、Block Format
- •三、Expressions Operators
- •五、Functions Listing
- •六、Variables
- •程序批注 (Comment)
- •七、Macro Program Call Methods:
- •Return Methods:
- •System Variables
- •Modal information
- •Argument specification
- •Operation control/status
- •Single Block Control Word(#1502)
- •Feed Control Word(#1504)
- •Current position
- •Runtime state variable
- •Workpiece coordinate system compensation values (workpiece zero point offset values)
- •Reference point position
- •八、扩充插值G码(Extended Interpolation g Code)宏程序说明:
- •九、macro 撰写需注意事项:
- •十、macro范例:
五、Functions Listing
Function |
Description |
ABS |
Calculates the absolute value of a number Ex: #1 := ABS(-2.3); // #1 will be 2.3 |
ACOS |
Calculates the arc cosine of a number Ex: #1 := ACOS(#10); |
ASIN |
Calculates the arc sine of a number Ex: #1 := ASIN(#10); |
ATAN |
Calculates the arc tangent of a number Ex: #1 := ATAN(#10); |
COS |
Calculates the cosine of a number Ex: #1 := COS(#10); |
MAX |
Determines the maximum of two inputs Ex1: #1 := MAX(10,20); // #1 will be 20 Ex2: #1 := MAX(#2,#3); |
MIN |
Determines the minimum of two inputs Ex1: #1 := MIN(10.0,20.0); // #1 will be 10.0 Ex2: #1 := MIN(#10,#11); |
SIN |
Calculate the sine of a number. Ex: #1 := SIN(#10); |
SQRT |
Calculates the square root of a number. Ex1: #2 := SQRT(3); // #2 will be 1.732.. Ex2: #2 := SQRT(#10); |
TAN |
Calculates the tangent of a number. Ex: #1 := TAN(#10); |
SIGN |
Return sign of a number, –1 for negative number, 1 for positive number, 0 for zero number. Ex: IF( SIGN(#10) > 0 ) THEN …. END_IF; |
CEIL |
Return the smallest integer that is greater than or equal to a number. Ex1: #2 := CEIL(2.3); // #2 will be 3 Ex2: #2 := CEIL(#10); |
FLOOR |
Return the largest integer that is less than or equal to a number Ex1: #2 := FLOOR(2.3); // #2 will be 2 Ex2: #2 := FLOOR(#10); |
ROUND |
Return the value of the argument rounded to the nearest long value Ex1: #2 := ROUND(2.3); // #2 will be 2 Ex2: #2 := ROUND(#10); |
STD |
Standardize arguments, read a number, in argument one, by least increment method, in argument two, when necessary for decimal point programming Ex: #9 := STD(#9,#1600); // normalize by distance axis |
PUSH |
Push value into Macro stack. Ex: PUSH(#1); // push #1 variable into stack PUSH(#3); // push #3 variable into stack |
POP |
Pop value from Macro stack. Ex: #1 := POP(); // popup a value to #1
|
STKTOP |
Peek the stack value by index form top one. Ex: STKTOP(0) the most top element value STKTOP(1) the element value below top one STKTOP(2) the element value below top two …etc |
ALARM |
Issue Macro alarm Ex: ALARM(300); // issue macro alarm id 300 ALARM(#1); // #1 must be integer |
SLEEP |
Temporarily give up this cycle execution Ex: SLEEP(); |
WAIT |
Wait until all previous motion/logic commands are finished. Ex: WAIT(); |
RANDOM |
Generates a pseudorandom number. Ex: #1 := RANDOM(); |
AXID |
Lookup axis identifier, the axis identifier is the machine axis number. When the specified axis’s name not exist, then return value will be vacant. Ex: Assume 6th axis’s name is Y2, 2nd axis’s name is Y, then AXID(Y) will return 2 AXID(Y2) will return 6 |
STDAX |
Standardize arguments, read a number, in argument one, by least increment method, in argument two is axis address Ex: #24 := STDAX(#24,X); // normalize by X dimension #3 := STDAX(#3,A); // normalize by A dimension |
OPEN(“文件名称”) |
开启所指定的文件名称。此函数如果成功响应值为1,失败时响应值为0。档案开启后PRINT函数才有效。
文件名称为“COM”时表示打开RS232传输端口,其设定由系统参数3905等参数设定之。 例: OPEN(“PROBE.NC”); //打开PROBE.NC档准备输出 例 OPEN(“COM”); //打开传输埠 PRINT("\p"); //输出’%’字符 FOR #1 = 1 TO 5000 DO #30 = #1 * 10.; PRINT( "G01 X#30" ); //输出 G01 X10.000… END_FOR; PRINT(“\p”); //输出‘%’字符 CLOSE(); //关闭传输埠 |
CLOSE() |
关闭前面由OPEN函数所开启的档案。程序结束后档案亦会自动关闭。档案关闭后PRINT函数就无效。 例: CLOSE(); //关闭档案 |
PRINT(“输出字符串”) |
此函数用来输出字符串,输出字符串中的变量名称会被取代成该变量的值,此函数如果成功响应值为1,失败时响应值为0。 例: @53 = 20; #3 = 23.1; PRINT(“G01 X#3 Y@53 Z20.0”); 输出结果为 G01 X23.100 Y20 Z20.0; 字符‘\’为逃脱字符,特殊字符定义如下: ‘\\’ 表示’\’ 字符 ‘\@’ 表示’@’字符 ‘\#’ 表示’#’字符 ‘\p’ 表示’%’字符 因此欲输出 G01 X(@20/@30) Y#20/2.0; 其语法格式为 PRINT(“G01 X(\@20/\@30) Y\#20/2.0”); |
GETARG(address) |
读取呼叫者传递的自变量 例: O0001主程序 G101 X30. Y40. Z1=40. Z2=50.; . G0101扩充宏程序 #1 = GETARG(X); // 将X自变量内容30.存到#1 #2 = GETARG(Z1); // 将Z1自变量内容40.存到#2 #3 = GETARG(W); // 因W不存在#3值为VACANT |
GETTRAPARG(address) |
For G66/G66.1 modal macro call handler to get trap block’s information 例: O0001主程序 G66 P100 X100. Y100. G01 X20. . O0100子程序 #1 = GETARG(X); // 将X自变量内容100.存到#1 #2 = GETTRAPARG(X); // 将Trap单节X自变量内容20.存到#2 |
DBOPEN(“文件名称”) |
加载指定的XML资料表,文件名称路径相对于XML数据库的根目录。 例: DBOPEN(“FLAT\\TAB01”); // 加载FLAT\\TAB01 资料文件 例: #1 = 51; DBOPEN(“FLAT\\AB#1[3]ZZ” ); //加载 FLAT\\AB051ZZ 资料文件,[3]表示三为有效数字。 |
DBLOAD( CycleNo ) |
从目前加载的XML资料表中,加载指定的资料 例: // 加载FLAT\\TAB01 资料文件 DBOPEN(“FLAT\\TAB01”); // 加载第0笔资料 DBLOAD( 0 ); … // 加载第1笔资料 DBLOAD( 1 ); … |
COMMENT(“批注字符串”) |
此函数用来输出批注字符串,输出字符串中的变量名称会被取代成该变量的值,此函数如果成功响应值为1,失败时响应值为0。 例: @53 = 20; #3 = 23.1; COMMENT(“// G01 X#3 Y@53 Z20.0”); 输出结果为 // G01 X23.100 Y20 Z20.0; 字符‘\’为逃脱字符,特殊字符定义如下: ‘\\’ 表示’\’ 字符 ‘\@’ 表示’@’字符 ‘\#’ 表示’#’字符 ‘\p’ 表示’%’字符 因此欲输出 // THIS IS TURNING CYCLE 其语法格式为 COMMENT(“// THIS IS TURNING CYCLE”); |
DRAWHOLE() |
Draw a hole using current tool radius, line color, fill color at current position. This function only take effect under graphics simulation |
DRAWMARK(shape,size,color) |
Draw a mark with specified shape, size, color at current position. The marker will fix in size not regards to zoom scaling. Size: In Pixel Shape:0:Circle,1:Square;2:Diamond. This function only take effect under graphics simulation |
SETDRAW(LineColor) or SETDRAW(LineColor,FillColor,ToolRadius) |
To assign draw style LineColor: use for draw contouring line ToolRadius: use for draw hole radius size FillColor: use for fill hole interior. This function only take effect under graphics simulation |
PARAM( no ) |
To read specified system parameter number #1 = PARAM(3204) // to access PLC scan time interval |
SYSVAR( AxisGroupID, No ) |
To read system variable of specified coordinate system. AxisGroupID axis group identifier, 1 for first axis group, 2 for 2nd axis group, etc… No The system variable number. e.g. #1 = SYSVAR( 1, 1000 ); // to read interpolation mode of first axis group. |
SCANTEXT( No ) |
To scan text string from global variable. Notes: Because string is local, so only can stores in local variable, and can not save to global variable. That is, following will get wrong result.
e.g. // scan string text from @300 #1 = SCANTEXT(300);
// following will get wrong result @100 = #1; // @100 will loss string information DBOPEN(“ABC_@100”); // this will got wrong result
// following will get correct result #100 = #1; // #100 contain valid string from @300~ DBOPEN(“ABC_#300”); // correct result |
