What's new
What's new

Help me with my milling stepdown macro

CHIPS26

Plastic
Joined
Nov 30, 2020
Need help with the following macro. Essentially I am trying to create a ramping program for milling a rectangular cutout. What I am having trouble with is the stepdowns and the final depth where I want it to stop. I would like the macro to read the current value of Z and then adjust via the inputted stepdown from there, essentially I am trying to limit the length of code. I am unsure if I can read and pass off that value to calculate what the Z position should be for the step down or if I need to create an equation.

What I have so far: Disregard the W values in comment brackets, our machine has a primary W axis instead of Z (ram and spindle), unfortunately Cimco only reads Z in colinear axis.

O0032
(ROUGH BORES)
(THREE RECTANGULAR HOLES)
(7.440 BY 14.420)
(-.020 ON A SIDE)
(CHANGE G54.1 AS NEEDED)
(CENTER OF BORE)
(P24,P26,P29)

(B180.)
(V15.0)
(Z0.0)
(W-6.888)

#24=2.45 ( WIDTH IN X)
#25=5.94 (LENGTH IN Y)
#18=.03 (STEPDOWN DEPTH, R)
#4=2.5 (CUTTER DIAMETER, D)
#26=-3.81 (Z FINAL DEPTH, Z)

(T209,2.5 SECO HFM)
M31
M32
M33
M34
M35
M36
G00 B180.
G00 V15. (Z0.)
T209M6
G00G49G80Z0.0(W-2.0)
G00G54.1P26X0Y0
(Z0.)
G00G43H209Z0.(W0.)M7
S925M3
G01Z-.03(W-.03)F30.0
(MACRO START)
X-[#24+#4/2]
Y-[#25+#4/2] F60.
X[#24+#4/2]
Y[#25+#4/2]Z[#26-#18]
X-[#24+#4/2]
Y-[#25+#4/2]Z[#26-#18]
IF Z=#26 THEN GOTO N0032
N0032 X[#1+#4/2]
Y[#25+#4/2]
X-[#24+#4/2]
Y-[#25+#4/2]
X[#24+#4/2]
N115 Y0
N116 X0F25.0
N117 M05
N118 M09
N119 G00G49G80Z0.0W-2.0
N120 M00

%
 
Hello CHIPS26,

What control do you have?

I'm not sure exactly what you want to do. If only to calculate Z levels associated with successive Depth Of Cuts and ensure no over cut in Z, I can show you a simple method.

Your code as is has errors and is not logical. If your control is a Fanuc, or one that uses the same syntax, then:

1. your GOTO statement is incorrect

2. You can't express the focus of a Conditional Statement in terms of Z=#26; that will raise a Syntax Error

and

3. The logic of the following is flawed.

IF Z=#26 THEN GOTO N0032
N0032 X[#1+#4/2]

Notwithstanding that Z=#26 can't be expressed in that way, Block N0032 will execute irrespective of what the value of Z may be. If its not equal to #26, the program will simply step into the next Block (N0032). If it does equal #26, then the program bill branch to N0032, which also is the next Block; accordingly, there is no difference in the flow of the program.

Regards,

Bill
 
I'm not much for sorting out macros, but this line bothers me in that #1 is undefined as far as I see.

N0032 X[#1+#4/2]

So would this not be the same as just saying X[#4/2]? When a local variable is unassigned is it's value 0 or null?
 
Hello Chips26,
I see that its a pocket and that the Macro is to ramp the cutter down to the specified final Z level.

You're compensating for the Radius of the tool in the Macro. Its rather unusual to add the Tool Radius when machining the inside of a pocket, as the pocket coordinates specified don't relate to the actual size of the pocket. It would be better to register the required coordinates of the pocket in the Macro Variables and then subtract the Tool Radius in the Macro. You could also register the Tool Radius in conventional Offsets and then read the value of the Offset from within the Macro. Its just a bit cleaner registering an Offset to tweak the pocket size, rather than edit the program and run the chance of changing something that you shouldn't have.

In any regard, the following program example will work for you. Its a bare bones example, but you should be able to get the idea. I've used a larger Step Down Value than you specified so that the resulting Tool Path shown in the picture further down is clearer.

Regards,

Bill

Code:
#23 = 0.0 (Z START POINT)
#24 = 2.45 (WIDTH IN X)
#25 = 5.94 (LENGTH IN Y)
#18 = -0.15 (STEPDOWN DEPTH, R)
#4 = 2.5  (CUTTER DIAMETER, D)
#26 = -3.81  (Z FINAL DEPTH, Z)
 (T209,2.5 SECO HFM)

M31
M32
M33
M34
M35
M36
G00 B180.
G00 V15. (Z0.)
T209 M6

G00 G49 G80 Z0.000  
G00 G54.1 P26 X0.000 Y0.000  
G43 H209 Z0.250 M7  
S925 M3  
G01 Z0.050 F100.0  
#23 = #23 + #18
G01 Z#23 F30.
G01 X-[#24 + #4 / 2] F60.
G01 Y-[#25 + #4 / 2]

(MACRO START)
WHILE [#23 GT #26] DO1
G01 X[#24 + #4 / 2]  F60.
#23 = #23 + #18
IF [#23 LT #26] TH #23 = #26 (STOP OVER CUT IN Z)
G01 Y[#25 + #4 / 2] Z#23
G01 X-[#24 + #4 / 2]
#23 = #23 + #18
IF [#23 LT #26] TH #23 = #26 (STOP OVER CUT IN Z)
G01 Y-[#25 + #4 / 2] Z#23
END1

G01 X[#24 + #4 / 2]
G01 Y[#25 + #4 / 2]
G01 X-[#24 + #4 / 2]
G01 Y-[#25 + #4 / 2]
G01 X[#24 + #4 / 2]
G01 Y0.000
G01 X0.000 F25.0
M05
M09
G01 G00 G49 G80 Z0.0 W-2.0
M00

Pocket Ramp Macro1.jpg
 
Last edited:
I'm not much for sorting out macros, but this line bothers me in that #1 is undefined as far as I see.

N0032 X[#1+#4/2]

So would this not be the same as just saying X[#4/2]? When a local variable is unassigned is it's value 0 or null?

Hello Kevin,
When an undefined variable is used with an address, the address itself is ignored; as in the following example:

G01 X150.0 Y#1 (Where #1 is vacant)
has the same meaning as
G01 X150.0 (Not G01 X150.0 Y0.0)

In the following example:

N0032 X[#1+#4/2]

#1 would be treated as having Zero value and the result would be the same as X[#4/2].

Regards,

Bill
 
Last edited:
Hello Chips26,
I see that its a pocket and that the Macro is to ramp the cutter down to the specified final Z level.

You're compensating for the Radius of the tool in the Macro. Its rather unusual to add the Tool Radius when machining the inside of a pocket, as the pocket coordinates specified don't relate to the actual size of the pocket. It would be better to register the required coordinates of the pocket in the Macro Variables and then subtract the Tool Radius in the Macro. You could also register the Tool Radius in conventional Offsets and then read the value of the Offset from within the Macro. Its just a bit cleaner registering an Offset to tweak the pocket size, rather than edit the program and run the chance of changing something that you shouldn't have.

In any regard, the following program example will work for you. Its a bare bones example, but you should be able to get the idea. I've used a larger Step Down Value than you specified so that the resulting Tool Path shown in the picture further down is clearer.

Regards,

Bill

Code:
#23 = 0.0 (Z START POINT)
#24 = 2.45 (WIDTH IN X)
#25 = 5.94 (LENGTH IN Y)
#18 = -0.15 (STEPDOWN DEPTH, R)
#4 = 2.5  (CUTTER DIAMETER, D)
#26 = -3.81  (Z FINAL DEPTH, Z)
 (T209,2.5 SECO HFM)

M31
M32
M33
M34
M35
M36
G00 B180.
G00 V15. (Z0.)
T209 M6

G00 G49 G80 Z0.000  
G00 G54.1 P26 X0.000 Y0.000  
G43 H209 Z0.250 M7  
S925 M3  
G01 Z0.050 F100.0  
#23 = #23 + #18
G01 Z#23 F30.
G01 X-[#24 + #4 / 2] F60.
G01 Y-[#25 + #4 / 2]

(MACRO START)
WHILE [#23 GT #26] DO1
G01 X[#24 + #4 / 2]  F60.
#23 = #23 + #18
IF [#23 LT #26] TH #23 = #26 (STOP OVER CUT IN Z)
G01 Y[#25 + #4 / 2] Z#23
G01 X-[#24 + #4 / 2]
#23 = #23 + #18
IF [#23 LT #26] TH #23 = #26 (STOP OVER CUT IN Z)
G01 Y-[#25 + #4 / 2] Z#23
END1

G01 X[#24 + #4 / 2]
G01 Y[#25 + #4 / 2]
G01 X-[#24 + #4 / 2]
G01 Y-[#25 + #4 / 2]
G01 X[#24 + #4 / 2]
G01 Y0.000
G01 X0.000 F25.0
M05
M09
G01 G00 G49 G80 Z0.0 W-2.0
M00

View attachment 306218

Bill, thanks for sorting this out, I wasn't happy with how I programmed this out starting out (its been a long time since Ive taken a VB class), I ended up scrapping this the same day I posted and rewrote it instead to use a counter with a calculation being figured by the final Z depth of the bore and the stepdowns. Tested it on the machine and it however would only through 1 count of the cycle. I also wasn't able to get the D to work as well. I would like to use different D values as we would finish with a separate smaller tool and would like the macro to keep most of its same structure, as we have multiple square/rectangular bores like this. Control is Fanuc 30i.

%
O0035(ALTERNATE)
(SNUBBERS - ROUGH BORES)
(THREE RECTANGULAR HOLES)
(IN SNUBBERS)
(7.440 BY 14.420)
(-.020 ON A SIDE)
(CHANGE G54.1 AS NEEDED)
(CENTER OF BORE)
(P24,P26,P29)


(A= AMOUNT TO LEAVE ON WALL)
(R= STEPDOWN DEPTH)
(D= CUTTER DIAMETER)
(Z= FINAL DEPTH)

(G65 P0033 A.02 R.03 D2.5 Z-3.81)

(T209,2.5 SECO HFM)
M31
M32
M33
M34
M35
M36
G00 B180.
G00 V15. Z0.
T209M6
G00G49G80Z0.0W-2.0
G00G54.1P26X0Y0
G00G43H209W0.(Z0.)M7
S925M3
G01 W-.03(Z-.03)F30.0
G65 P0036 A.02 R.03 D2.5 Z-3.81
N115 Y0
N116 X0F25.0
N117 M05
N118 M09
N119 G00G49G80Z0.0W-2.0
N120 M00

M30

O0036
(#1= AMOUNT TO LEAVE ON WALL)
(#18= STEPDOWN DEPTH)
(#4= CUTTER DIAMETER)
(#26= FINAL DEPTH)
#100=1

G01 X-[3.72-#1-#4/2] F30.
Y-[7.21-#1-#4/2] F60.
(MACRO START)
WHILE [100LE[[#26-#18]/#18]]DO1
X[3.72-#1-#4/2]
Y[7.21-#1-#4/2]W-[[#100*#18]*2]
X-[3.72-#1-#4/2]
Y-[7.21-#1-#4/2]W-[[#100*[#18*2]]+#18]
END1
N0032 X[3.72-#1-#4/2]
Y[7.21-#1-#4/2]
X-[3.72-#1-#4/2]
Y-[7.21-#1-#4/2]
X[3.72-#1-#4/2]
M99

%
 
If you are using a counter, where are you incrementing that counter? It should be within the loop. Right now, I don't see anything changing within the loop.

In your While statement, shouldn't the 100 be #100?

I've tried, but I can't seem to understand what you intend to do with your While statement. Try writing it out in plain English before putting it into code.

Right now, it looks like:
While 100 is less than or equal to (-3.81-.03)/.03

Well, the number 100 (not the value of the #100 variable) is not less than -128, so it runs through the loop once and exits. Even if it was the #100 variable, that would exit as well since it is not less than a negative number.

I hope this helps. Bill can explain it better than me, I'm sure, but I like looking at macro code so I thought I'd give my thoughts on this.
 
Hello Chips26,
wmpy is correct in that your DO loop won't work when #100 is a positive number and the result of [#26-#18]/#18 will be a negative value.

You're also mistaken that the DO Loop executes once; it won't execute at all and I suspect that you're mistaking the execution of the program commencing at N0032 as the one execution of the Loop you refer to. Whether the 100 in the following Macro statement:

WHILE [100LE[[#26-#18]/#18]]DO1

is supposed to be 100, or #100 (#100 being allocated the initial value of 1), both are greater than [#26-#18]/#18 (-128), therefore, the DO Loop will not execute at all.

However, lets say that the arrangement of values in your algorithm did result in the WHILE statement testing True, in its present form, the DO Loop would never end with the Tool Path executing at a monotonous W coordinate. The reason is that you're not modifying the counter at all.

Although you may get the WHILE DO Loop to work with a Counter, it would be susceptible to error due to all calculations being performed in Binary. Some combinations of values may work, others not. You would have to make allowance for this in your Macro if you proceed with your method.

I'm not sure if you planned it this way, but if you subtract a positive value from a negative number, the result is a negative number of greater magnitude. In your WHILE conditional statement, following is the result of the algorithm used:

#26-#18 = -3.84

If you did increment your counter (#100), the common approach when using a counter, and get the ABS value of [[#26-#18]/#18], the DO Loop would continue to execute until and including a value of 128 for variable #100. This would generally result in an over-cut in W by 0.03. However,in your Macro the following calculation is made:

W-[[#100*[#18*2]]+#18]

When #100 reaches 128, the above calculation would result in a W coordinate of W-7.71. From your last Post, it states that the Z Final Depth is -3.81.

Regards,

Bill
 
Last edited:








 
Back
Top