If logic not working correctly

I have the below code in a PROC and am passing a few variables to it move a target based on an angle that is passed from the PLC, one being the Angle_Data. there are values numbers passed like 0.35 -141 -36.8
0.35 is supposed to hit the Vertical but it is falling through Negative.
-141 is supposed to hit Positive but is falling through Vertical
-36.8 is supposed to hit Negative but is falling through Positive

I see nothing to make this happen and i have coded it a few ways but still not working. it did work one day and the next day stopped working with not changes.

code below
   PROC Reset_Web_Place_Adj()
        
VAR bool isVertical;
VAR bool isPositive;
VAR bool isNegative;

! Define angle zones
isVertical := (Angle_Data >= -15.9999 AND Angle_Data <= 15.9999) OR
              (Angle_Data >= 166.0000 AND Angle_Data <= 180.0000) OR
              (Angle_Data >= -180.0000 AND Angle_Data <= -166.0000);

isPositive := (Angle_Data >= 16.0000 AND Angle_Data <= 90.9999) OR
              (Angle_Data >= -165.9999 AND Angle_Data <= -91.0000);

isNegative := (Angle_Data >= -90.9999 AND Angle_Data <= -16.0000) OR
              (Angle_Data >= 91.0000 AND Angle_Data <= 165.9999);

! Apply vertical adjustment
IF isVertical THEN
    Web_X_Adj := Web_X_Vert_Shift;
    Web_Y_Adj := Web_Y_Vert_Shift;
    Web_Z_Adj := Web_Z_Vert_Shift;
    Web_Rx_Adj := Web_Rx_Vert_Rot;
    Web_Ry_Adj := Web_Ry_Vert_Rot;
    Web_Rz_Adj := Web_Rz_Vert_Rot;
ENDIF

! EndRod Only
IF Di_IsEndRod = 1 THEN
    Web_X_Adj := Web_X_EndRod_Shift;
    Web_Y_Adj := Web_Y_EndRod_Shift;
    Web_Z_Adj := Web_Z_EndRod_Shift;
    Web_Rx_Adj := Web_Rx_EndRod_Rot;
    Web_Ry_Adj := Web_Ry_EndRod_Rot;
    Web_Rz_Adj := Web_Rz_EndRod_Rot;
ELSE
    ! Positive Only
    IF isPositive THEN
        Web_X_Adj := Web_X_Pos_Shift;
        Web_Y_Adj := Web_Y_Pos_Shift;
        Web_Z_Adj := Web_Z_Pos_Shift;
        Web_Rx_Adj := Web_Rx_Pos_Rot;
        Web_Ry_Adj := Web_Ry_Pos_Rot;
        Web_Rz_Adj := Web_Rz_Pos_Rot;
    ENDIF

    ! Negative Only
    IF isNegative THEN
        Web_X_Adj := Web_X_Neg_Shift;
        Web_Y_Adj := Web_Y_Neg_Shift;
        Web_Z_Adj := Web_Z_Neg_Shift;
        Web_Rx_Adj := Web_Rx_Neg_Rot;
        Web_Ry_Adj := Web_Ry_Neg_Rot;
        Web_Rz_Adj := Web_Rz_Neg_Rot;
    ENDIF
ENDIF

    ENDPROC
Tagged:

Comments

  • I cannot see where you have assigned the data from the PLC to those variables.  How is it mapped, Analog?  If not, then how?
    Finally, single step through the logic while examining the values and which thing evaluate TRUE or FALSE.
    Lee Justice
  • DenisFR
    DenisFR ✭✭✭
    Hello,
    I think you have to use ELSEIF for Di_IsEndRod.


    ☑️2024 - RobotStudio® User Group

  • Is it intended that you have overlapping zones?

    For example if Angle_Data was 1.0 (or 0.35 as in your example) then it would be both

    Vertical
    isVertical := (Angle_Data >= -15.9999 AND Angle_Data <= 15.9999) OR

    And it wold also be

    Negative
    isNegative := (Angle_Data >= -90.9999 AND Angle_Data <= -16.0000) OR
                  (Angle_Data >= 91.0000 AND Angle_Data <= 165.9999);