Convert coordinate data into radians
This FP instruction returns the angle j of the Cartesian coordinates (x,y) within the range of -p to +p.
Input
Cartesian y coordinate
Cartesian x coordinate
Output
Result in radians
Each position P of the two-dimensional coordinates can be defined by Cartesian coordinates P(x,y) or by polar coordinates P(r,j) (r = radius, j = angle).
Define FP_ATAN2 as follows:
ATAN2_YX(y,x) |
x |
y |
---|---|---|
x > 0 |
||
x < 0 |
y ³ 0 |
|
y < 0 |
||
x = 0 |
y > 0 |
|
y < 0 |
||
Operation error |
y = 0 |
if a non-real number is specified for s1_y (y coordinate) or s2_x (x coordinate)
if 0.0 is specified for s1_y (y coordinate) and 0.0 for s2_x (x coordinate)
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
bStart: BOOL:=FALSE;
(*activates the instruction*)
rPhi1Rad: REAL:=0.0;
rPhi1Degree: REAL:=0.0;
END_VAR
VAR CONSTANT
DEGR_OF_RAD: REAL:=57.295779513082320876798154814105;
END_VAR
VAR
END_VAR
When the variable bStart is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,FP_ATAN2!,,10,1,16,6,,?DEN?Ds1_y?Ds2_x?AENO?Cd);
B(B_VARIN,,10.0,8,3,10,5,);
B(B_VARIN,,-10.0,8,4,10,6,);
B(B_VAROUT,,rPhi1Rad,16,3,18,5,);
B(B_CONTACT,,bStart,3,2,5,4,);
L(1,3,3,3);
L(5,3,10,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,@MUL-2!,,11,1,16,4,,?D?D?C);
B(B_VARIN,,rPhi1Rad,9,1,11,3,);
B(B_VARIN,,DEGR_OF_RAD,9,2,11,4,);
B(B_VAROUT,,rPhi1Degree,16,1,18,3,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
rPhi1Rad:=ATAN2_YX(y := 10.0, x := -10.0); (* Result: 2.3561947 *)
rPhi1Degree := rPhi1Rad * DEGR_OF_RAD; (* Result: 135.00002 *)