#520=#5061(REMEMBER START POSITION)
WHILE[#5061GT#513]DO1
IF[[#5041-#513]LT#521]THEN#521=#5041-#513+.002(PREVENT OVERRUN)
G1U-#521F#511(PECK AT FEEDRATE)
IF[#5041LT#520-.1]#535=201(TURN ON TLM)
IF[#5041LT#513+.1]#535=200(TURN OFF TLM)
M#535(TURN ON/OFF TLM)
G4P#522(DWELL)
END1
M200 (TURN OFF TLM)
Hello avongil,
#520=#5061 can't be used in that manner unless the X Axis Slide was moved to position with the following command:
G31 X_ _
Without an External Skip Signal, System Variable #5061 will take on the value of the value specified in the Command Block at the end of travel. As G31 acts in the same way as G01, moving to an initial position in other than Rapid Mode may not be desirable.
An accurate result for recording the X Start Position can be achieved with the following:
G00 X_ _
G31 (or G53) (STOP BUFFERING)
#520=#5041
With a Peck of 0.04" and the following Conditional Statement:
IF[#5041LT#520-.1]#535=201(TURN ON TLM)
with a difference of 0.1 (#520 - .1), neither of the following Conditional Statements:
IF[#5041LT#520-.1]#535=201(TURN ON TLM)
IF[#5041LT#513+.1]#535=200(TURN OFF TLM)
will Test True and therefore, #535 will remain Vacant, or, because its a Nonvolatile Variable, the value it was set to previously (the classic reason for not using #500 Series Variable when not necessary) for the first two cycles of the LOOP. Accordingly, when M#535 is executed for the first time, either the wrong "M" code will be executed, or an error may be raised. You would need to Initialize #535, probably to 200, before commencing the DO LOOP.
Following is the pseudo code generated by your Macro in its present form, but with #5061 replaced with #5041 and the appropriate Stop Buffering code in place:
Code:
G1 U-0.0400 F0.0020
G31
M00
G4 P100
G1 U-0.0400 F0.0020
G31
M00
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M201
G4 P100
G1 U-0.0400 F0.0020
G31
M200
G4 P100
G1 U-0.0400 F0.0020
G31
M200
G4 P100
G1 U-0.0270 F0.0020
G31
M200
G4 P100
M200
There is no Stop to Buffering before the #5041 in the Conditional Statement; accordingly, #5041 in the Conditional Statements won't reflect the position at the end of the Peck Move, if that is what you are aiming for. This may, or may not work in your favor, as the TLM may turn on earlier than you expected, or later than desired when into the next Peck Move. However, TML won't be turned off until the Peck Move after the one you're expecting it to. If you were to program G31, or G53 before the Conditional Statements, an accurate Current Position for the End of the Peck Move will be returned.
In your previous example using the 2nd DO LOOP, I'm not sure if "IF[#5041LT#500]DO2", as in your following example, is legal or not.
IF[#5041LT#500]DO2
M201 (IF IN CUT TURN ON TLM)
END2
I've never seen a DO LOOP as the subject of a Conditional Statement, but I've not seen any reference to it not being allowed.
WHILE is also a Conditional operative. Accordingly, logic would dictate that an IF Conditional statement may be legal.
The following DO LOOP without a WHILE is quite legal
DO2
-----
-----
-----
END2
and will result in an Endless Loop.
If your example above using the IF Statement to Start the DO LOOP is legal syntax, it would also result in an Endless Loop, with no means of escape. Accordingly, when seeking help with an issue, you need to explain what the problem is. For example, you may have been getting a Macro Statement Syntax Error, indicating that the Macro Statement is not legal, or you may have had the program hang inside the DO2 LOOP and not know why.
There is nothing wrong with an "M" code being represented by a Variable. However, following is my interpretation of your Macro, configured is a way that the actual "M" code can be specified and with code to Stop Buffering to give you an accurate End of Peck, Current Position.
#1= 0.505 (X START - MATERIAL DIAMETER)
#2= -0.04(PECK AMMOUNT)
#3=-.06(PART OFF X FINAL POS)
#4= #1 [COPY OF MATERIAL DIAMETER]
#9= 0.002
WHILE [#1 GT #3]DO1
#1=#1+#2
IF[#1 LT #3]TH #1=#3 (PREVENT OVERCUT)
G01 X#1 F#9 (PECK AT FEEDRATE)
G31 (STOP BUFFERING)
IF[[#5041 LE #4] AND [#5041 GT [#3+0.1]]] GOTO10
M200 (TURN OFF TLM)
GOTO20
N10
M201 (TURN ON TLM)
N20
G04P#522 (DWELL)
END1
Following is the pseudo code generated by the Macro above, showing TLM On/Off being executed each cycle of the LOOP respectively.
Code:
G01 X0.4650 F0.002
G31
M201
G04 P100
G01 X0.4250 F0.002
G31
M201
G04 P100
G01 X0.3850 F0.002
G31
M201
G04 P100
G01 X0.3450 F0.002
G31
M201
G04 P100
G01 X0.3050 F0.002
G31
M201
G04 P100
G01 X0.2650 F0.002
G31
M201
G04 P100
G01 X0.2250 F0.002
G31
M201
G04 P100
G01 X0.1850 F0.002
G31
M201
G04 P100
G01 X0.1450 F0.002
G31
M201
G04 P100
G01 X0.1050 F0.002
G31
M201
G04 P100
G01 X0.0650 F0.002
G31
M201
G04 P100
G01 X0.0250 F0.002
G31
M200
G04 P100
G01 X-0.0150 F0.002
G31
M200
G04 P100
G01 X-0.0550 F0.002
G31
M200
G04 P100
G01 X-0.0600 F0.002
G31
M200
G04 P100
If having the TLM On Command continually executed each cycle of the LOOP and similarly the TLM Off Command when the program advances that far, is an issue (it shouldn't be), then the following code shown in Red can be added to avoid this and give the pseudo code shown below.
#1 = 0.505 (X START - MATERIAL DIAMETER)
#2 = -0.04 (PECK AMMOUNT)
#3 = -0.06 (PART OFF X FINAL POS)
#4 = #1 (COPY OF MATERIAL DIAMETER)
#5 = 0 (INITIALISE TLM STATUS)
#9 = 0.002 (FEED RATE)
#522 = 100 (DWELL PERIOD)
WHILE [#1 GT #3] DO1
#1 = #1 + #2
IF [#1 LT #3] TH #1 = #3 (PRE#ENT O#ERCUT)
G01 X#1 F#9 (PECK AT FEEDRATE)
G31 (STOP BUFFERING)
IF [[#5041 LT #4] And [#5041 GT [#3 + 0.1]]] GOTO10
IF [#5 EQ 0] GOTO20
M200 (TURN OFF TLM)
#5 = 0
GOTO20
N10
IF [#5 EQ 1] GOTO20
M201 (TURN ON TLM)
#5 = 1
N20
G04 P#522 (DWELL)
END1
Following is the pseudo code generated by the Macro above, showing TLM On/Off only being executed once each .
Code:
G01 X0.4650 F0.002
G31
M201
G04 P100
G01 X0.4250 F0.002
G31
G04 P100
G01 X0.3850 F0.002
G31
G04 P100
G01 X0.3450 F0.002
G31
G04 P100
G01 X0.3050 F0.002
G31
G04 P100
G01 X0.2650 F0.002
G31
G04 P100
G01 X0.2250 F0.002
G31
G04 P100
G01 X0.1850 F0.002
G31
G04 P100
G01 X0.1450 F0.002
G31
G04 P100
G01 X0.1050 F0.002
G31
G04 P100
G01 X0.0650 F0.002
G31
G04 P100
G01 X0.0250 F0.002
G31
M200
G04 P100
G01 X-0.0150 F0.002
G31
G04 P100
G01 X-0.0550 F0.002
G31
G04 P100
G01 X-0.0600 F0.002
G31
G04 P100
Regards,
Bill