ICAM Foundation Webinar Macro Programming Part 2 · 2020. 4. 23. · ICAM Foundation Webinar:...
Transcript of ICAM Foundation Webinar Macro Programming Part 2 · 2020. 4. 23. · ICAM Foundation Webinar:...
ICAM Foundation Webinar Macro Programming Part 2
Presented by:Alexandre Gordon
Daniel Wang
ICAM Foundation Webinar Page 1
ICAM Foundation Webinar: Modules
ICAM Foundation Webinar
1. Macro flow control - Branching Control
2. Macro flow control - Conditional Loops
3. Example #1
4. Example #2
Page 2
MODULE 1 : Macro flow Control – Branching Control
ICAM Foundation Webinar Page 3
1.1. The “IF” statement
1.2. The “CASE” statement
MODULE 1 : The “IF” statement
ICAM Foundation Webinar Page 4
IF / conditional_test_1statements…
ELSEIF / conditional_test_2statements…
…ELSE
statements…ENDOF / IF
IF / conditional_teststatements…
ENDOF / IF
Example:
IF/$T.EQ.1.OR.$T.EQ.10.OR.$T.EQ.20 $$ Tools 1, 10, 20INSERT/'G65 P1012'
ELSEIF/$T.GT.1.AND.$T.LT.10 $$ Tools 2, 3, 4, 5, 6, 7, 8, 9INSERT/'G65 P1016'
ELSEIF/$T.GE.11.AND.$T.LE.60 $$ Tools 11 through 60 except 20INSERT/'G65 P1015'
ELSE
ERROR/8,'Invalid tool number’ $$ Tools 61 and higher not availableENDOF/IF
MODULE 1 : The “CASE” statement
ICAM Foundation Webinar Page 5
Example:CASE/$T
WHEN/1,10,20 $$ Tools 1, 10, 20INSERT/'G65 P1012'
WHEN/2,THRU,9 $$ Tools 2, 3, 4, 5, 6, 7, 8, 9INSERT/'G65 P1016'
WHEN/11,THRU,60 $$ Tools 11 through 60 except 20INSERT/'G65 P1015'
WHEN/OTHERS
ERROR/8,'Invalid tool number' $$ Tools 61 and higher not availableENDOF/CASE
CASE / variableWHEN / const1, const2, const3… (or WHEN / start_value, THRU, end_value)
statements……WHEN / OTHERS
statements…ENDOF / CASE
MODULE 2 : Macro flow Control – Conditional Loops
ICAM Foundation Webinar Page 6
2.1. The “DO” loop
2.2. The “WHILE” loop
2.3. The “REPEAT” loop
2.4. Exiting loops (“EXIT”)
MODULE 2 : The “DO” loop
ICAM Foundation Webinar Page 7
Example:
DO / variable = start, end [ , step ]statements…
ENDOF / DO
the step argument is optional (if omitted, the default is 1) the variable value is iterated between start and end values all statements are executed on each iteration the loop ends when variable reaches the end value
DECLAR/GLOBAL,REAL,TOOLS(100)DO/I=1,100TOOLS(I)=-1
ENDOF/DO
DECLAR/GLOBAL,REAL,TOOLS(100)DO/I=100,1,-1TOOLS(I)=-1
ENDOF/DO
MODULE 2 : The “WHILE” loop
ICAM Foundation Webinar Page 8
Example:
WHILE/ conditionstatements…
ENDOF / WHILE
the condition is tested before each run (including first time) statements are executed as long as the condition is true the loop ends when the condition becomes false
DECLAR/GLOBAL,REAL,TOOLS(100),I=1WHILE/I.LE.100
TOOLS(I)=-1I+=1
ENDOF/WHILE
MODULE 2 : The “REPEAT” loop
ICAM Foundation Webinar Page 9
Example:
REPEATstatements…
UNTIL/ condition
the statements are executed at least one time (no testing of condition the first time)
statements are executed as long as the condition is false the loop ends when the condition becomes true
DECLAR/GLOBAL,REAL,TOOLS(100),I=1REPEAT
TOOLS(I)=-1I+=1
UNTIL/I.EQ.101
DECLAR/GLOBAL,REAL,TOOLS(100),I=1REPEAT
TOOLS(I)=-1I+=1
UNTIL/I.GT.100
MODULE 2 : Exiting loops (“EXIT”)
ICAM Foundation Webinar Page 10
Example:
EXIT/ number_of_levels
number_of_levels is a whole unsigned number (if omitted, the default is 1) each DO, WHILE and REPEAT counts as a level IF and CASE do not count as levels
DECLAR/LOCAL,REAL,I=0WHILE/I.LT.10J=0REPEATJ=J+1IF/J.EQ.12EXIT/2
ENDOF/IFUNTIL/$FALSE
ENDOF/WHILE
Example #1 : String and CL Records Matching
ICAM Foundation Webinar Page 11
1. Writing a header;
2. Ignoring unwanted work offsets;
3. Capturing a custom CL command to split
the motion of the first positioning move
according to the programmed value:
a. XY, then Z
b. XZ, then Y
c. YZ, then X
Example #1 : Solution
ICAM Foundation Webinar Page 12
In Machine Startup:$$ Header
PPRINT/'NC PROGRAM: !(A)',$FBASNAM($TAPEN,'.')
PPRINT/'POST NAME: !(A)',$PPFILE
PPRINT/'POSTED BY: !(A)',$FGETENV('USERNAME')
PPRINT/'DATE: !(A11)',$DATE
PPRINT/'DATE: !(A)',$FDATE('%x')
User Defined Syntax Macro:
CUTCOM/ON,ADJUST,$P1
IF/$P1.NE.$TCF
OUTPUT
ENDOF/IF
PLUNGE/OPTION,$P1CASE/$P1WHEN/1SAFETY/NEXT,XAXIS,YAXIS,NEXT,ZAXIS
WHEN/2SAFETY/NEXT,XAXIS,ZAXIS,NEXT,YAXIS
WHEN/3SAFETY/NEXT,ZAXIS,YAXIS,NEXT,XAXIS
ENDOF/CASE
Example #2 : Incorrect program option and neutral CL data
ICAM Foundation Webinar Page 13
Define a set of user-defined macros to capture tapping cycles programmed using “per minute” feed rates (IPM or MMPM) and convert the programmed feed rates to the equivalent “per revolution” (IPR or MMPR) values.
Define a set of user-defined macros to limit programmed spindle RPM values to the maximum RPM available on the machine (stored in the system variable $MAXRPM). In case the programmed RPM exceeds the maximum, calculate the RPM reduction factor and apply it on all subsequent feedrates in the program (including canned cycles). Each new SPINDL instruction should update the RPM reduction factor (stored in a global variable). Also, when the spindle is turned off, the RPM reduction factor should be reset to 1.
Example #2 : Solution
ICAM Foundation Webinar Page 14
Declaration macro:$$ GLOBAL VARIABLESDECLAR/GLOBAL,REAL,GR_RPM_FACTOR=1
User Defined Syntax Macros:
CYCLE/$P1*,$P2(IPM,MMPM,PERMIN),$P3,$P4*CYCLE/$P1,$P2,$P3*GR_RPM_FACTOR,$P4
CYCLE/TAP,$P1*,$P2(IPM,MMPM,PERMIN),$P3,$P4*IF/$SMODE.EQ.0SPINDL/ON
ENDOF/IFIF/$SR.GT.0$P3=$P3/$SRCASE/$P2WHEN/IPM$P2=IPR
WHEN/MMPM$P2=MMPR
WHEN/PERMIN$P2=PERREV
ENDOF/CASEENDOF/IFCYCLE/TAP,$P1,$P2,$P3,$P4
FEDRAT/$P1(IPM,MMPM,PERMIN),$P2FEDRAT/$P1,$P2*GR_RPM_FACTOR
SPINDL/RPM,$P1,$P2*IF/$P1.GT.$MAXRPMSPINDL/RPM,$MAXRPM,$P2GR_RPM_FACTOR=$MAXRPM/$P1
ELSEOUTPUTGR_RPM_FACTOR=1
ENDOF/IF
SPINDL/OFFOUTPUTGR_RPM_FACTOR=1
Thank you for attending!
ICAM Foundation Webinar Page 15