Successful User Macro Repository

Moderator: cnckeith

Post Reply
martyscncgarage
Posts: 9932
Joined: Tue Mar 28, 2017 12:01 pm
Acorn CNC Controller: Yes
Allin1DC CNC Controller: Yes
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: Yes
CPU10 or CPU7: Yes
Location: Mesa, AZ

Successful User Macro Repository

Post by martyscncgarage »

Share your macros in this thread with others. Describe what the end goal was and any other details about the Macro. Video clip of the macro running and you narrating the video would be a bonus!
Also share what version of CNC12 Software you are running.
It is my hopes that it becomes a repository of ideas that will help or inspire others to do the same, or perhaps use your macro as a spring board to modify to suit their needs.

Any questions about a given Macro, ask the user that created it. Centroid is not support for this thread.

Marty
Reminder, for support please follow this post: viewtopic.php?f=20&t=383
We can't "SEE" what you see...
Mesa, AZ


briuz
Posts: 127
Joined: Wed Jul 10, 2019 9:24 am
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Macro to set WCS position to 0 on lathe

Post by briuz »

On a milling machine, you can use G92 to set the absolute position in the current WCS to whatever value you'd like. (On my mill I've used it to zero an axis.) On the lathe, G92 is for the thread cutting cycle and I found no such G code or Macro to do this in the lathe manual.

With my tool setter stylus prototype I needed to set the master tool position to zero so that all of the other tools could be set off of the stylus position. Since I didn't find a G92 type function on the lathe I created a macro to do this my re-setting the WCS variables. Here is a video of it working (the first tool is the master tool) and below is the macro...




;------------------------------------------------------------------------------
; Filename: mfunc58.mac - To run from VCP AUX 11 key, set CNC12 p198 = 5811
; M58 macro
; Description: User Customizable Macro -- Set Master tool relative to stylus.
; Notes:
; Requires: Machine home must be set prior to use.
; Please see TB300 for tips on writing custom macros.
;------------------------------------------------------------------------------

IF #50010 ;Prevent lookahead from parsing past here
IF #4201 || #4202 THEN GOTO 1000 ;Skip macro if graphing or searching


N100 ;Insert your code between N100 and N1000

;Assume stylus is 0.500 in diameter.

; Variable descriptions.
;
; #2501 WCS g54 x axis zero position. Set to machine position for x axis (#5021) to set zero.
; #2601 WCS g54 z axis zero position. Set to machine position for z axis (#5022) to set zero.
; #5021 machine position for x axis.
; #5022 machine position for z axis.


g54 ; Force first WCS for setting master tool.

m115 /z p3 f5 ; Probe z axis at 5 inches per minute.
#2601 = #5022 ; Temporarily Set (zero) g54 WCS z axis (#2601) to machine position for z axis (#5022)
g00 z 0.015
m115 /z p3 f0.1 ; Probe Z axis at 0.1 inch per minute. Slow movement is to reduce deflection.
#2601 = #5022 ; Finally set (zero) g54 WCS (#2601) to machine position for z axis (#5022)

g00 z 0.100
#2501 = #5021 ; Temporarily Set (zero) g54 WCS x axis (#2501) to machine position for x axis (#5021)
; This zero is to have a known starting position.
g00 x 1.100 ; Move clear of stylus.
g00 z -0.250 ; Move Tool behind stylus.
m115 /x p3 f5 ; Probe x axis at 5 inches per minute.
#2501 = #5021 ; Temporarily Set (zero) g54 WCS x axis (#2501) to machine position for x axis (#5021)
g00 x 0.015
m115 /x p3 f0.1 ; Probe x axis at 0.1 inches per minute. Slow movement is to reduce deflection.
#2501 = #5021 ; Set (zero) g54 WCS x axis (#2501) to machine position for x axis (#5021)

g00 x 0.1 ; Pull back from stylus.
g00 z 0.5 ; Move 0.500 clear of stylus.

g00 x -0.500 ; Move to center of stylus.

#2501 = #5021 ; Set (zero) g54 WCS x axis (#2501) to machine position for x axis (#5021) at center of stylus.



N1000 ;End of Macro


cncsnw
Posts: 4096
Joined: Wed Mar 24, 2010 5:48 pm

Re: Successful User Macro Repository

Post by cncsnw »

On a lathe, "G50 X_ Z_" does what G92 does on a mill.

But assigning to the #25xx and #26xx variables works equally well.


briuz
Posts: 127
Joined: Wed Jul 10, 2019 9:24 am
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Re: Successful User Macro Repository

Post by briuz »

cncsnw wrote: Sun May 17, 2020 2:08 pm On a lathe, "G50 X_ Z_" does what G92 does on a mill.

But assigning to the #25xx and #26xx variables works equally well.
Thanks for pointing that out. I saw G50 but wasn't clear about what it did based upon the description.


briuz
Posts: 127
Joined: Wed Jul 10, 2019 9:24 am
Acorn CNC Controller: Yes
Allin1DC CNC Controller: No
Oak CNC controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC12: Yes
CNC11: No
CPU10 or CPU7: No

Portable 5c CNC Collet Lathe Turret Tool Changer Macro

Post by briuz »

Here is the macro file for the turret.



;Tool Change Macro
;

IF #50010 ;Prevent lookahead from parsing past here
IF #4201 || #4202 THEN GOTO 9999 ;Skip macro if graphing or searching

;IF #9006 != 0 THEN GOTO 200
;M225 #100 "Please Change to Tool Number %.0f\nThen Press Cycle Start to continue" #4120



; Variable Reference Table
;
;
; #100 -- Temporary Math
; #101 -- Temporary Math
; #105 -- Debugging Tool Number
;
; #157 -- Turret Offset To Raise/Lower Paw
;
;
;
; #4120 -- Tool Number
; #5044 -- Turret Axis Position In Degrees
;
; #29000 -- Value Passed To Sub Program
; #29001 -- Return Value From Sub Program

M40 ; ; Set custom tuning variables for lathe.
;#157 = 25 ; DEBUGGING SET OFFSET TO RAISE/LOWER PAW


N200

G98 ; Set feedrate to inches/minute


O9100 ; IsNumberEven()

;M225 #100 "IsNumberEven"

; Note: Even numbered tools are standard 3/8" tooling and odd numbered tools are round such as drills, taps, reamers, and round tool steel.
; #29000 -- Number To Check
; #29001 = 0 If Even and 1 If Odd

#100 = [#29000 % 2] ; Get remainder of number (#29000) and place in #100

#29001 = 0
IF [#100 > 0.0] #29001 = 1

M99

;M225 #100 "test"



O9200 ; CalculateEvenToolPosition()

;M225 #100 "CalculateEvenToolPosition"

; Even tool positions are for square lathe tool bits and carbide tool holders.
; Gets the tool number from #29000
; Returns new turret position (in degrees) in #29001

#100 = [#29000 - 1] ; Tool calculations are zero-based. i.e. Tool 1 is 0, Tool 2 is 1, etc.
;#101 = [#100 * 22.5] ; Each odd tool is 45 degrees apart.
;#29001 = [#101 - 18] ; Subtract from the odd tool to find the even tool. (Is it 27 degrees or 18 degrees?)

#101 = 27; ; Difference, in degrees, from odd tool position. (27 or 18)

; Hard-code turret positions to prevent floating point errors building up in math.
IF [#100 == 1] #29001 = [0 + #101]
IF [#100 == 3] #29001 = [45 + #101]
IF [#100 == 5] #29001 = [90 + #101]
IF [#100 == 7] #29001 = [135 + #101]
IF [#100 == 9] #29001 = [180 + #101]
IF [#100 == 11] #29001 = [225 + #101]
IF [#100 == 13] #29001 = [270 + #101]
IF [#100 == 15] #29001 = [315 + #101]



M99



O9300 ; CalculateOddToolPosition()

;M225 #100 "CalculateOddToolPosition"

; Odd tool positions are for round tooling such as drills, taps, reamers, and round tool steel.
; Note: Tool #1 is round and will be at zero degrees.
; Gets the tool number from #29000
; Returns new turret position (in degrees) in #29001

#100 = [#29000 - 1] ; Tool calculations are zero-based. i.e. Tool 1 is 0, Tool 2 is 1, etc.
;#29001 = [#100 * 22.5] ; Each odd tool is 45 degrees apart.


; Hard-code turret positions to prevent floating point errors building up in math.
IF [#100 == 0] #29001 = 0
IF [#100 == 2] #29001 = 45
IF [#100 == 4] #29001 = 90
IF [#100 == 6] #29001 = 135
IF [#100 == 8] #29001 = 180
IF [#100 == 10] #29001 = 225
IF [#100 == 12] #29001 = 270
IF [#100 == 14] #29001 = 315

M99



O9400 ; RaisePaw()

;M225 #100 "RaisePaw"

#100 = [#5044 - #157] ; Calculate the new turret position to raise the paw.

;M225 #100 "Number %f" #100

M65 ; Activate the solenoid.
;G01 A[#100] F360 ; Slowly rotate the turret to the raised paw position.
G00 A[#100] ; Rotate the turret to the raised paw position.

M99



O9500 ; LowerPaw()

;M225 #100 "LowerPaw"

;#100 = #5044 ; Store the current turret position.
;#101 = [#5044 - #157] ; Calculate the raised paw position.
;G00 A#101 ; Rotate the turret to the raised paw position.
#100 = [#5044 + #157] ; * Calculate lowered paw position.
M85 ; Release the solenoid.
G01 A[#100] F360 ; Rotate the turret back to the tool position.
M99


; main()

; To change the tool, raise the paw, see if the new tool is odd or even, calculate the new position, move to the new position, then lower the paw.

M98 P9400 ; RaisePaw()

#29000 = #4120 ; Set #29000 to the tool number

M98 P9100 ; IsNumberEven()

IF [#29001 == 0] M98 P9200 ; If the tool number is even, CalculateEvenToolPosition()
IF [#29001 == 1] M98 P9300 ; If the tool number is odd, CalculateOddToolPosition()

#100 = [#29001 - #157] ; * Calculate raised paw position.
;G00 A#29001 ; Rotate turret to new tool position
G00 A#100 ; * Rotate turret to raised paw position of new position

M98 P9500 ; LowerPaw()





N9999
Attachments
cnctch.mac
(4.5 KiB) Downloaded 289 times


Post Reply