I’m wondering why I get a syntax error some of the time when I use IF statements with multiple ELSE IF conditions unless it has an END IF for each condition, but not every time.
In my first example, I made a function that is comparing which gripper on my end of arm tool & which buffer nest are selected to pick or place a part with. When I use my IF statement with the possible ELSE IF conditions, it has an error unless I have an END IF for every condition.
However in my second example, my proc has the main IF statement with two ELSE IF conditions (as well as another nested statement), but only required a single END IF.
I’m not sure what is different about these examples that makes the first example need so many END IFs.
Example 1:
!**************************************************************************
!* Determine which position the robot is going to for the buffer nests
!* Depends on which buffer nest & which gripper is selected
!**************************************************************************
FUNC num BNPosition(num nBufferNest, num nGripper)
VAR num nBufferNestPosition;
IF (nBufferNest = 0 AND nGripper = 3) THEN
nBufferNestPosition := 0;
ELSE IF ((nBufferNest = 0 AND nGripper = 2) OR (nBufferNest = 1 AND nGripper = 3)) THEN
nBufferNestPosition := 1;
ELSE IF ((nBufferNest = 0 AND nGripper = 1) OR (nBufferNest = 1 AND nGripper = 2) OR (nBufferNest = 2 AND nGripper = 3)) THEN
nBufferNestPosition := 2;
ELSE IF ((nBufferNest = 0 AND nGripper = 0) OR (nBufferNest = 1 AND nGripper = 1) OR (nBufferNest = 2 AND nGripper = 2)) THEN
nBufferNestPosition := 3;
ELSE IF ((nBufferNest = 1 AND nGripper = 0) OR (nBufferNest = 2 AND nGripper = 1)) THEN
nBufferNestPosition := 4;
ELSE IF (nBufferNest = 2 AND nGripper = 0) THEN
nBufferNestPosition := 5;
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
RETURN nBufferNestPosition;
ENDFUNC
Example 2:
!**************************************************************************
!* Move the robot home at the selected speed & zone
!* If the part has been inserted to interference, assembly must be moved clear
!* If the part has been partially inserted, it can be lifted straight out
!* If the part has begun glue/cure, it must be moved clear
!**************************************************************************
PROC Home(speeddata HomeSpeed,zonedata HomeZone) !Slow home
VAR bool bPreInsert;
VAR robtarget pInsert;
jCurr := CJointT();
pCurr := CRobT(\Tool:=tool1 \WObj:=wobj0);
IF (EIP_OUT64 = 0 AND EIP_OUT65 = 0) THEN
!Raise Z
pCurr.trans.z := pHome.trans.z-1;
MoveJ pCurr, HomeSpeed, fine, tool1\WObj:=wobj0;
MoveJ pHome, HomeSpeed, HomeZone, tool1\WObj:=wobj0;
ELSEIF (EIP_OUT64 = 1) THEN
IF (bPreInsert = FALSE) THEN
MoveL Offs(pInsert,0,0,+8),v300,fine,tool1\WObj:=wobj0;
MoveL Offs(pInsert,0,+30,+8),v300,z0,tool1\WObj:=wobj0;
MoveJ Offs(pInsert,0,+100,+50),v300,z10,tool1\WObj:=wobj0;
MoveJ pHome, HomeSpeed, HomeZone, tool1\WObj:=wobj0;
ELSEIF (bPreInsert = TRUE) THEN
MoveL Offs(pInsert,0,0,+40),v100,z10,tool1\WObj:=wobj0;
MoveJ Offs(pHome,0,0,0),v300,fine,tool1\WObj:=wobj0;
bPreInsert := FALSE;
ENDIF
ELSEIF (EIP_OUT65 = 1) THEN
MoveJ Offs(pInsert,0,0,0),v100,z0,tool1\WObj:=wobj0;
MoveJ Offs(pInsert,+10,0,+50),v100,z10,tool1\WObj:=wobj0;
MoveJ Offs(pInsert,0,+100,+50),v100,z10,tool1\WObj:=wobj0;
MoveJ pHome, HomeSpeed, HomeZone, tool1\WObj:=wobj0;
ENDIF
ENDPROC