(Part A) Machinerys Handbook 31st Edition Pages 1-1484

Machinery's Handbook, 31st Edition

1384 CNC SUBROUTINES AND MACROS Miscellaneous Functions: There are two common miscellaneous functions, SQRT and ABS. Several others exist but are not available on all control models. (1) SQRT: The SQRT function calculates the square root of a number supplied between brackets: SQRT[25.0] Returns 5.0 (2) ABS: The ABS function (absolute function) always returns a positive value of a given number: ABS[ − 1.3] Returns 1.3 ABS[1.3] Returns 1.3 Using the ABS function is very useful in many applications, for example, to guarantee a positive or a negative value: #26 = 1.3 Positive input G01 Z −[ ABS[#26]] The motion will be equivalent to Z − 1.3 #26 = − 1.3 Negative input G01 Z −[ ABS[#26]] The motion will be equivalent to Z − 1.3 Logical Functions: Logical functions consist of Boolean operators and bitwise or binary functions: Boolean functions (operators) compare two values and return a true or false condition: EQ Equal to GT Greater than GE Greater than or equal to NE Not equal to LT Less than LE Less than or equal to Bitwise functions provide a means of combining comparisons. AND And OR Or XOR Exclusive Or The AND, OR, and XOR functions compare two defined conditions simultaneously. The compared conditions are evaluated, and return either a TRUE value or a FALSE value. In English language, it is easy to understand the difference between the AND and the OR functions, because they follow the basic logic of everyday language. Function XOR is not used with the same frequency in machining macros. Examples of usage: Example 1, (OR) #33 = [#1 EQ #2] OR [#3 EQ #4] Variable #33 returns true (return value is 1) if #1 equals #2 OR #3 equals #4—otherwise it returns zero (false). Example 2, (AND) : #33 = [#1 EQ 1] AND [#2 EQ 2] Variable #33 returns 1 (true) if #1 equals 1 AND #2 equals 2—otherwise it returns 0 (false). Example 3, (XOR) #33 = [#1 EQ 1] XOR [#2 EQ 2] Variable #33 returns 0 (false) if both expressions are true or both expressions are false. If only one expression is true and the other is expression false, #33 returns 1 (true). XOR function is also known as the “exclusive or” function. Branching and Looping.— Both branches and loops (iterations) are based on the re- turn value of an evaluated condition. There are three macro functions available: “IF”, “GOTOn”, and WHILE (also IF-THEN on some controls). IF function: The “IF” function evaluates a given condition and branches to a specified block number providing the condition is true. If the condition is false, the macro processing continues in the next block. This function is commonly used when choosing between two alternatives. Effectively, the IF function bypasses one or more blocks if a certain condition is true. The programming format is: IF [< this condition is true >] GOTOn

Copyright 2020, Industrial Press, Inc.

ebooks.industrialpress.com

Made with FlippingBook - Share PDF online