Reference Manual

Turbo PMAC/PMAC2 Software Reference
Turbo PMAC Mathematical Features 491
Examples:
P50=ATAN(P48/P49) ; Computes angle whose tan is P48/P49
C(ATAN(Q70/10)) ; Move C axis to specified angle
ATAN2
Function: Two-argument trigonometric arc-tangent
Syntax: ATAN2({expression})
Domain: All real numbers in both arguments
Domain units: none
Range: -Pi to +Pi radians (-180 to +180 degrees)
Range units: Radians/degrees
ATAN2 implements the expanded (two-argument) inverse tangent, or arc-tangent, function, of the
mathematical expression contained inside the following parentheses, and the value of variable Q0 for the
coordinate system used. (If this function is used inside a PLC program, make sure the desired coordinate
system has been selected with the ADDRESS command.)
This expanded arc-tangent function returns values in the full +/-180-degree range; if only the +/-90-
degree range is desired, the standard ATAN function should be used instead. The ATAN2 function makes
use of the signs of both arguments, as well as the ratio of their magnitudes, to extend the range to a full
360 degrees. The value in the parentheses following ATAN2 is the “sine” argument; the value in Q0 is the
“cosine” argument.
This function returns values in degrees if I15 is set to the default value of 0; it returns values in radians if
I15 is set to 1.
If both arguments for the ATAN2 function are equal to exactly 0.0, an internal division-by-zero error will
result, and an arbitrary value will be returned. No error will be reported, and the program will not stop. It
is the programmer’s responsibility to check for these possible domain errors.
Execution time, 80 MHz CPU: 5.1 µsec interpreted, 3.5 µsec compiled
Examples:
Q30=-0.707 ; Cosine argument
Q31=-0.707 ; Sine argument
Q32=ATAN(Q31/Q30) ; Single-argument arctangent
Q32 ; Query resulting value
45 ; Returns value in +/-90 range
Q0=Q30 ; Prepare cosine for ATAN2
Q33=ATAN2(Q31) ; Two-argument arctangent
Q33 ; Query resulting value
-135 ; Note different result
Q0=M163-M161 ; X target X present position
Q1=M263-M261 ; Y target Y present position
IF (ABS(Q0)>0.001 OR ABS(Q1)>0.001) ; Div by 0 check
Q2=ATAN2(Q1) ; Calculate directed angle
ENDIF