11 subroutines and loops, 1 subroutines, Introduction – Lenze PM94P01C User Manual
Page 32

PM94P01C
30
Introduction
;**************************** Main Program ********************************
PROGRAM_START:
;Place holder for main program loop
ENABLE
;Enable output from drive to motor
WAIT UNTIL IN_A4==1
;Make sure Arm is retracted before starting the program
MOVEP 0
;Move to position 0 to pick part
OUT1 = 1
;Turn on output 1 to extend Pick arm
WAIT UNTIL IN_A1==1
;Check input to make sure Arm is extended
OUT2 = 1
;Turn on output 2 to Engage gripper
WAIT TIME 1000
;Delay 1 sec to Pick part
OUT1 = 0
;Turn off output 1 to Retract Pick arm
WAIT UNTIL IN_A4==1
;Check input to make sure Arm is retracted
MOVED 100,C
;Move to Place position and continue code execution
WAIT UNTIL APOS >25
;Wait until pos is greater than 25
OUT3 = 1
;Turn on output 3 to spray part
WAIT UNTIL APOS >=75
;Wait until pos is greater than or equal to 75
OUT3 = 0
;Turn off output 3 to shut off spray guns
WAIT UNTIL APOS >=95
;Wait until move is almost done before extending arm
OUT1 = 1
;Turn on output 1 to extend Pick arm
WAIT UNTIL IN_A1==1
;Check input to make sure Arm is extended
OUT2 =0
;Turn off output 2 to Disengage gripper
WAIT TIME 1000
;Delay 1 sec to Place part
OUT1 = 0
;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
When the “C” argument is added to the standard MOVED and MOVEP statements, program execution is not interrupted by
the execution of the motion command. NOTE: With an MDV move the execution of the program is never suspended.
The generated motion profiles are stored directly to the Motion Queue and are then executed in sequence. If the
MOVED and MOVEP statements don’t have the “C” modifier, then the motion profiles generated by these statements
go to the motion stack and the program is suspended until each profile has been executed.
1.11 Subroutines and Loops
1.11.1 Subroutines
Often it is necessary to repeat a series of program statements in several places in a program. Subroutines can be useful
in such situations. The syntax of a subroutine is simple. Subroutines must be placed after the main program, i.e. after
the END statement, and must start with the subname: label (where subname is the name of subroutine), and must end
with a statement RETURN.
Note that there can be more than one RETURN statement in a subroutine. Subroutines are called using the GOSUB
statement.