6.2.3 Arithmetic and Logic Operation


Variables can be used to perform the operations in the following table. The right-hand side of a mathematical sign can be a combination of constants and/or variables and operators. The variables #j and #k can also be replaced by constants. The variable to the left of the equal sign can be replaced by an equation.


Function

Format

Explain

definition

#i=#j


Addition, subtraction, multiplication and division/four operations

(+, -, ×, ÷)

#i=#j+#k;

#i=#j–#k;

#i=#j*#k;

#i=#j/#k;


Trigonometric functions

#i=SIN[#j];

#i=ASIN[#j];

#i=COS[#j];

#i=ACOS[#j];

#i=TAN[#j];

#i=ATAN[#j]/[#k];

The unit of angle is degree, and 90 degrees and 30 points will be expressed as 90.5 degrees.

square root

Absolute value

rounding

Unconditionally

#i=SQRT[#j];

#i=ABS[#j];

#i=ROUND[#j];

#i=FIX[#j];


logic operation

(OR, XOR, AND)

#i=#j OR #k;

#i=#j XOR #k;

#i=#j AND #k;

Logical operations will be performed in units of binary digits.


Explain:

  • Angle units

The trigonometric functions (SIN, COS, ASIN, ACOS, TAN, ATAN) use angles in degrees, for example: 90 degrees and 30 minutes in 90.5 degrees.


  • Arc Sine Trigonometric Function:ARCSIN #i = ASIN[#j];


  • The answer ranged from –90° to 90°.


  • When the variable #j exceeds the range of -1~1, a warning is issued.


  • In addition to the variable #j, constants can also be used.


  • Arc cosine trigonometric function:ARCCOS #i = ACOS[#j];


  • The answer ranged from 180° to 0°.


  • When the variable #j exceeds the range of -1~1, a warning is issued.


  • In addition to the variable #j, constants can also be used.


  • Arctangent trigonometric function:ARCTAN #i = ATAN[#j]/[#k];


  • Given both sides of the length, and separated by a slash(/).


  • The answer ranged from -180° to 180°. For example: Given #1 = ATAN[–1]/[–1];When #1 為 -135.0.0。


  • In addition to the variable #j, constants can also be used.


  • Round/Fetch integers


  • When mathematical or logical expressions such as IF or WHILE conditional expressions contain rounded functions, the system rounds the calculations to the first decimal place.

For example, in program line #1=ROUND[#2]; if #2 evaluates to 1.2345,the result of #1 will be rounded off to 1.0.


  • When rounding a function in an NC program, the value will be rounded off in the least significant unit of the address.

For example: Suppose you want to write a drilling program and let it use the values ​​of the variables #1 and #2 to process it and then return to the original position. If the system feed unit is 1/1000 mm, the value of variable #1 is 1.2346, and the value of variable #2 is 2.3456, then:


G00 G91 X–#1  ;move 1.235 mm

G01 X–#2 F300 ;move 2.346 mm

G00 X[#1+#2]  ;Since 1.2345+2.3456=3.5801,the moving distance will be 3.580 and the tool will not return to the original position


This difference comes from the fact that the added action is performed before or after rounding. To return the tool to its original position, the instruction needs to be written as G00X–[ROUND[#1]+ROUND[#2]]



  • unconditionally

In the controller system, if the absolute value of the integer generated by the result of a certain number is smaller than the absolute value of the original number, the operation is considered to be rounded down to an integer without conditions. EX:


set #1=1.2 and #2=–1.2,

when execute #3=FIX[#1],1.0 will be set to variable #3,

when execute #3=FIX[#2],-1.0 will be set to variable #3.