Delta Tau GEO BRICK LV Manual Do Utilizador
Turbo PMAC User Manual
326
Writing and Executing Motion Programs
Line Labels
It is possible to put line labels in your motion program to mark particular sections of the program. The
syntax for a line label is N{constant or O{constant}, where {constant} is an integer from 1 to
262,143.
Note that these are line labels, not line numbers (even though they are specified by number). A line does
not require a label; and the labels do not need to be in numerical order. These line labels are used only to
specify the jumps in GOTO, GOSUB, and CALL commands (all discussed below).
GOTO Command
Turbo PMAC provides a GOTO{data} command in its motion program syntax, which causes a jump to
line label N{data} in the same motion program (without return). In general, the use of GOTO
commands is strongly discouraged, because of the tendency to build up programs that are very hard to
decipher.
However, when the {data} in a GOTO command is a variable or expression (e.g. GOTO(P20)), it can
be used to build the equivalent of a structured CASE statement, creating a multiple-pronged branching
point. See an example under the GOTO description in the Program Command Specification.
It is possible to put line labels in your motion program to mark particular sections of the program. The
syntax for a line label is N{constant or O{constant}, where {constant} is an integer from 1 to
262,143.
Note that these are line labels, not line numbers (even though they are specified by number). A line does
not require a label; and the labels do not need to be in numerical order. These line labels are used only to
specify the jumps in GOTO, GOSUB, and CALL commands (all discussed below).
GOTO Command
Turbo PMAC provides a GOTO{data} command in its motion program syntax, which causes a jump to
line label N{data} in the same motion program (without return). In general, the use of GOTO
commands is strongly discouraged, because of the tendency to build up programs that are very hard to
decipher.
However, when the {data} in a GOTO command is a variable or expression (e.g. GOTO(P20)), it can
be used to build the equivalent of a structured CASE statement, creating a multiple-pronged branching
point. See an example under the GOTO description in the Program Command Specification.
Adding Variables and Calculations
Motion programs can be made a lot more flexible with the use of variables and mathematical calculations.
The above example program will command the same moves with the same timing every time it is
executed. If any parameter for the program must be changed, the entire program must be re-entered (or a
different program used). However, if variables are used in place of the constants, only variable values
must be changed to change the action of the program:
The above example program will command the same moves with the same timing every time it is
executed. If any parameter for the program must be changed, the entire program must be re-entered (or a
different program used). However, if variables are used in place of the constants, only variable values
must be changed to change the action of the program:
F(P2)
P1=0
WHILE (P1<P3)
X(P4)
DWELL(P5)
X0
DWELL(P5)
P1=P1+1
ENDWHILE
The variables P2, P3, P4, and P5 could be set by the host with on-line commands (e.g. P2=2000), by a
PLC program as a result of inputs and/or calculations, or even by this or another motion program.
PLC program as a result of inputs and/or calculations, or even by this or another motion program.
General mathematical expressions can be built in a PMAC motion program, using constants, variables,
functions and operators (see the Computational Features section of this manual). The calculations can be
done in separate program statements, assigning the calculated value to a variable, and then using the
variable in another statement. Alternately, use the expression directly in a motion specification statement,
in which case the value of the expression is not retained after the statement is executed.
functions and operators (see the Computational Features section of this manual). The calculations can be
done in separate program statements, assigning the calculated value to a variable, and then using the
variable in another statement. Alternately, use the expression directly in a motion specification statement,
in which case the value of the expression is not retained after the statement is executed.
Subroutines and Subprograms
It is possible to create subroutines and subprograms in PMAC motion programs to create well structured
modular programs with re-usable subroutines. The GOSUBx command in a motion program causes a
jump to line label Nx of the same motion program. Program execution will jump back to the command
immediately following the GOSUB when a RETURN command is encountered. This creates a subroutine.
The CALLx command in a motion program causes a jump to PROG x, with a jump back to the command
immediately following the CALL when a RETURN command is encountered. If x is an integer, the jump
is to the beginning of PROG x; if there is a fractional component to x, the jump is to line label
N(y*100,000), where y is the fractional part of x. This structure permits the creation of special
subprograms, either as a single subroutine, or as a collection of subroutines, that can be called from other
motion programs.
modular programs with re-usable subroutines. The GOSUBx command in a motion program causes a
jump to line label Nx of the same motion program. Program execution will jump back to the command
immediately following the GOSUB when a RETURN command is encountered. This creates a subroutine.
The CALLx command in a motion program causes a jump to PROG x, with a jump back to the command
immediately following the CALL when a RETURN command is encountered. If x is an integer, the jump
is to the beginning of PROG x; if there is a fractional component to x, the jump is to line label
N(y*100,000), where y is the fractional part of x. This structure permits the creation of special
subprograms, either as a single subroutine, or as a collection of subroutines, that can be called from other
motion programs.