Galil Motion Control DMC-21 5 Series User Manual page 100

Table of Contents

Advertisement

Example: Local Scope
#main;
JS
#power(2,2);
MG
_JS;
JS
#power(2,16);
MG
_JS;
JS
#power(2,-8);
MG
_JS;
EN;
#power;
^c=1;
IF
(^b=0);
EN,,1;
ENDIF;
IF
(^b<0);
^d=1;
^b=@ABS[^b];
ELSE;
^d=0;
ENDIF;
#pwrhlpr;
^c=^c*^a;
^b=^b-1;
JP
#pwrhlpr,(^b>0);
IF
(^d=1);
^c=(1/^c);
ENDIF;
EN,,^c;
Example: Recursion
JS
#axsInfo(0);
MG
{Z2.0}"Recursed through
",_JS,"
stacks";
EN;
#axsInfo;
~h=^a;
^b=(^a+$41)*$1000000;
MG^b{S1},
" Axis:
MG{Z8.0}"Position:
",_TP~h," Error:",_TE~h,"
Torque:",_TT~h{F1.4}
IF
(^a=(_BV-1));
EN,,1;
ENDIF;
JS
#axsInfo(^a+1);
EN,,_JS+1;
Chapter 7 Application Programming ▫ 95
'label for main program
'call power subroutine to calculate 2^2
'message returned value
'call power subroutine to calculate 2^2
'message returned value
'call power subroutine to calculate 2^2
'message returned value
'(base ^a,exponent^b) returns base^exponent power
'if exponent is 0
'return 1
'if exponent is negative
'create a variable for later
'find absolute value of exponent
'if exponent is positive
'label for loop for calculations
'multiply through
'decrement index
'loop while index is above 0
'if exponent is negative
'invert value
'return value
'jump to axsInfo subroutine with recursion
'message number of stacks
'assign variable axis designator
'convert variable axis to ASCII
"{N}
'message axis, suppress carriage return
'message info
'if last axis info has printed
'end routine
'jump back into axsInfo, increment axis
'end routine
DMC-21x5 User Manual 1.0a1

Advertisement

Table of Contents
loading

Table of Contents