9 if/else statements, Introduction – Lenze PM94P01C User Manual
Page 26
PM94P01C
24
Introduction
;*********************** Initialize and Set Variables **********************
UNITS = 1
;Define units for program, 1=revolution of motor shaft
ACCEL = 5
;Set acceleration rate for motion command
DECEL = 5
;Set deceleration rate for motion command
MAXV = 10
;Maximum velocity for motion commands
V1 = 25
;Set Variable V1 equal to 25
V2 = 75
;Set Variable V2 equal to 75
DEFINE
Output_On
1
;Define Name for output On
DEFINE
Output_Off
0
;Define Name for output Off
;*********************** EVENTS *******************************************
EVENT SPRAY_GUNS_ON APOS > V1 ;Event will trigger as position passes 25 in pos dir.
OUT3= Output_On
;Turn on the spray guns (out 3 on)
ENDEVENT
;End event
EVENT SPRAY_GUNS_OFF APOS > V2 ;Event will trigger as position passes 75 in pos dir.
OUT3= Output_Off
;Turn off the spray guns (out 3 off)
ENDEVENT
;End even
;*********************** Main Program *************************************
PROGRAM_START:
;Place holder for main program loop
ENABLE
;Enable output from drive to motor
EVENT
SPRAY_GUNS_ON ON
;Enable the ‘spray guns on’ event
EVENT
SPRAY_GUNS_OFF ON
;Enable the ‘spray guns off’ event
WAIT UNTIL IN_A4==1
;Ensure Arm is retracted before running the program
MOVEP 0
;Move to position 0 to pick part
OUT1 = Output_On
;Turn on output 1 to extend Pick arm
WAIT UNTIL IN_A1==1
;Check input to make sure Arm is extended
OUT2 = Output_On
;Turn on output 2 to Engage gripper
WAIT TIME 1000
;Delay 1 sec to Pick part
OUT1 = Output_Off
;Turn off output 1 to Retract Pick arm
WAIT UNTIL IN_A4==1
;Check input to make sure Arm is retracted
MOVED 100
;Move to Place position
OUT1 = Output_On
;Turn on output 1 to extend Pick arm
WAIT UNTIL IN_A1==1
;Check input to make sure Arm is extended
OUT2 = Output_Off
;Turn off output 2 to Disengage gripper
WAIT TIME 1000
;Delay 1 sec to Place part
OUT1 = Output_Off
;Retract Pick arm
WAIT UNTIL IN_A4==1
;Check input to make sure Arm is retracted
GOTO PROGRAM_START
;Loop back and continuously execute main program loop
END
1.9
IF/ELSE Statements
An IF/ELSE statement allows the user to execute one or more statements conditionally. The programmer can use an
IF or IF/ELSE construct:
Single IF example:
This example increments a counter, Variable “V1”, until the Variable, “V1”, is greater than 10.
Again:
V1=V1+1
IF V1>10
V1=0
ENDIF
GOTO Again
END