Example: Local Scope
#Local
JS
#POWER
(2,2)
MG
_JS
JS
#POWER
(2,16)
MG
_JS
JS
#POWER
(2,-8)
MG
_JS
'
#POWER
;NO(base ^a,exponent^b) Returns base^exponent power.
±
integer only
^c=1
;'unpassed variable space (^c-^h) can be used as local scope variables
IF
^b=0
;'special case, exponent = 0
EN
,,1
ENDIF
IF
^b<0
;'special case, exponent < 0, invert result
^d=1
^b=
@ABS
[^b]
ELSE
^d=0
ENDIF
#PWRHLPR
^c=^c*^a
^b=^b-1
JP
#PWRHLPR,^
b>0
IF
^d=1
;'if inversion required
^c=(1/^c)
ENDIF
EN
,,^c
Executed program from program1.dmc
4.0000
65536.0000
0.0039
Example: Recursion
'although the stack depth is only 16, Galil DMC code does support recursion
JS
#AxsInfo
(0)
MG
{Z2.0}
"Recursed through "
,
_JS
,
" stacks"
EN
'
#AxsInfo
;NO(axis ^a) List info for axes
~h=^a
^b=(^a+$41)*$1000000
;'convert to Galil String
MG
^b{S1},
" Axis: "
{N}
MG
{F8.0
}"Position: "
,
_TP
~h,
" Error:"
,
_TE
~h,
" Torque:"
,
_TT
~h{F1.4}
IF
^a=7
;'recursion exit condition
EN
,,1
ENDIF
JS
#AxsInfo
(^a + 1)
;'stack up recursion
EN
,,
_JS
+1
;' as recursion closes, add up stack depths
Executed program from program1.dmc
A Axis: Position: 00029319 Error: 00001312 Torque: 9.9982
B Axis: Position: -00001612 Error: 00000936 Torque: 1.7253
C Axis: Position: 00001696 Error:-00001076 Torque:-1.9834
D Axis: Position: -00002020 Error: 00001156 Torque: 2.1309
E Axis: Position: 00000700 Error:-00001300 Torque:-2.3963
F Axis: Position: 00000156 Error:-00000792 Torque:-1.4599
G Axis: Position: -00002212 Error: 00001732 Torque: 3.1926
H Axis: Position: 00002665 Error:-00001721 Torque:-3.1723
Recursed through 8 stacks
Chapter 7 Application Programming ▫ 119
DMC-42x0 User Manual
Summary of Contents for DMC-42 0 Series
Page 195: ...ICM 2900 PCB Layout Appendices 191 DMC 42x0 User Manual...
Page 205: ...CB 50 100 Drawings Appendices 201 DMC 42x0 User Manual...
Page 206: ...Appendices 202 DMC 42x0 User Manual...
Page 207: ...Appendices 203 DMC 42x0 User Manual...
Page 208: ...Appendices 204 DMC 42x0 User Manual...
Page 209: ...Appendices 205 DMC 42x0 User Manual...
Page 210: ...Appendices 206 DMC 42x0 User Manual...
Page 211: ...Appendices 207 DMC 42x0 User Manual...
Page 214: ...CB 50 80 Drawing Appendices 210 DMC 42x0 User Manual...