#### thesidetalker

##### Stainless

- Joined
- Jan 11, 2015

- Location
- Bay Area, CA

It's a work in-progress, but I think it should be good to go for now. I've only cut air with it, and some of the code is copy 'n pasted from the peck-tapping one, so I'm not sure it's 100% yet. Posting it here since this is probably a bit long of a post for that other thread..

Most of this I already had, but in my MPost template, so all of the variables were different. Just figured today I would put it in a macro on the machines and condense this cycle in my post to one line. (I'm out of space lol) I'm sure there's stuff we could change or improve because, well I've never actually used it to broach with, and I haven't really spent any time thinking about what if's, or if I need to change stuff. That's where you guys come in.

So far it's setup for absolute coordinates, with exception of distance to move.

I'm just trying it for now as program #2060, but will probably save it as a 9000 later and use a user-defined G code to call it.

Eg:

T1 M6

G0 G90 G54 G43 H1 Z2.0

G65 P2060 X0 Y0 Z-3.0 A270. D.13 Q.0022 R1.0 F500.

XY: starting position for tool center - can be left out, and it will use current position

Z: depth..

D: (positive value) distance to move

Q: increment to move each pass

R: Return plane

F: Feed rate - currently setup so 1000 or greater will use rapid instead.

A: absolute angular direction to move, 0 being X+, and positive values being CCW like you'd think.

I use an angular offset to align the tool to X+ direction at "A0." The first way I did this is just hard coded into the program (#32= 524. in my case) but I decided it would probably be more useful if you can specify this, so it works for more than one tool.

When I was testing this, M19P524. would align (pretty close) to "A0" with my broach tool.

I changed it so I can put an angle (in this case 0.524) in "Actual Diameter" for the tool. (not D offset). This value is normally just used to calculate SFM and chipload (I think?), so I'm thinking it should probably be fine... Macro multiplies this by 1000, so in my case this tool would use .524*1000= 524.

Program would use M19 P524. to align the tool to X+ direction at "A0".

A90. would be 524-90= M19P434. to align to Y+

So... currently the macro works as follows:

Rapid to XY

Rapid to R-plane

Orient tool (spindle) to [angle offset, minus] A-angle.

Move to XY for first pass

Feed or rapid to Z level

Back off 2X step-over for retract

Rapid to R-plane for next pass, and repeat

At end, rapid to initial Z.

Code below:

Code:

```
%
O02060(BROACHING MACRO 10-22-15-R2)
G103 P1
(ALL COORDINATES ABSOLUTE)
(UNLESS OTHERWISE SPECIFIED)
(X #24: X POSITION)
(Y #25: Y POSITION)
(Z #26: Z DEPTH)
(A #1 : ANGULAR DIRECTION TO MOVE)
(D #7 : POSITIVE, TOTAL DISTANCE TO MOVE)
(Q #17: STEP-OVER)
(R #18: R-PLANE)
(F #9 : FEED RATE)
(CHECK INPUTS)
IF [ #24 EQ #0 ] THEN #24= #5001 (X MODAL)
IF [ #25 EQ #0 ] THEN #25= #5002 (Y MODAL)
IF [ #26 EQ #0 ] GOTO100
IF [ #17 EQ #0 ] GOTO101
IF [ #18 EQ #0 ] GOTO102
IF [ #9 EQ #0 ] GOTO103
IF [ #26 GE #18 ] GOTO200
IF [ #18 GT #5003 ] GOTO300
IF [ #17 LE 0 ] GOTO400
IF [ #9 LE 0 ] GOTO500
(REMEMBER CURRENT Z POSITION)
#33= #5003
(MOVE TO POSITION)
G00 G90 X#24 Y#25
(RAPID TO R PLANE)
Z#18
(SET TOOL ANGULAR OFFSET)
(THIS IS SPINDLE ORIENT ANGLE + 360)
(OLD WAY: #32= 524.)
(NEW WAY: USE "ACTUAL DIA" X 1000)
#32= #[3200 + #3026] * 1000.
(SET 31 - ANGLE TO MOVE)
#31= #32 - #1
(SET 1ST PASS TO REMAINDER)
(SO LAST IS EXACT)
#30= #17 * [ [ #7 / #17 ] - FIX[ #7 / #17 ] ]
(ORIENT SPINDLE)
M19 P[#31]
G4P0.5
(FEED OR RAPID?)
IF [ #9 LE 999. ] THEN #29= 1 (FEED)
IF [ #9 GT 999. ] THEN #29= 0 (RAPID)
(LOOP START)
WHILE [ #30 LE #7 ] DO1
(POSITIONING)
G0 G90 X [ #24 + #30 * COS[ #1 ] ] Y [ #25 + #30 * SIN[ # 1 ] ] G9
F [ #9 ]
(MAKE CUT)
G [ #29 ] Z [ #26 ]
(BACK OFF CLEARANCE 2X STEP-OVER)
G1 G91 X [ -2 * #17 * COS[ #1 ] ] Y [ -2 * #17 * SIN[ #1 ] ] F100.
(RAPID TO R-PLANE)
G0 G90 Z [ #18 ]
(ADD TO DIST FOR NEXT PASS)
#30= #30 + #17
END1
(RAPID BACK TO INITIAL PLANE)
G0 G90 Z [ #33 ]
(EXIT)
G103
M99
N100
#3000= 1 (G204 ERROR: NO Z DEPTH)
N101
#3000= 1 (G204 ERROR: MISSING Q INPUT)
N102
#3000= 1 (G204 ERROR: MISSING R INPUT)
N103
#3000= 1 (G204 ERROR: MISSING F INPUT)
N200
#3000= 1 (G204 ERROR: Z DEPTH GT R PLANE)
N300
#3000= 1 (G204 ERROR: R ABOVE RAPID PLANE)
N400
#3000= 1 (G204 ERROR: INVALID Q INPUT)
N500
#3000= 1 (G204 ERROR: INVALID FEED RATE)
%
```