Page 1 of 1

Lathe Turret/ATC macro code question

Posted: Sat Feb 22, 2020 10:10 pm
by frijoli
Can someone help me understand this line in the bold code below? I didn't write the code, but I believe "8" should actually be #100
;------------------------------------------------------------------------------
; Filename: cnctch.mac
; Description: Axis driven tool change macro for Lathe
; Notes: Turns/rev must be configured 1 = 1 turret position change
; Turret is on 4th axis, positions are in machine position.
; Requires: Machine home must be set prior to use.
;
;#100 = Number turret positions
;#101 = Calculated position to move to when requested position < current position.
;#4120 = requested tool
;#20601-#20604 = Counts per unit for axes1-4
;#5021-#5024 is the current machine position for axes 1(#5021) through 4(#5024)
;------------------------------------------------------------------------------

;follow with a block that skips if graphing or searching
IF #50001 ;Prevent lookahead from parsing past here
IF #4201 || #4202 THEN GOTO 1000 ;Skip macro if graphing or searching

;If not searching or graphing, check to make sure the turret is not already
;at the requested position. If it is, skip the macro
IF [ABS[#4120-#5024] < .002] THEN GOTO 1000

; Notes: Turns/rev must be configured 1 = 1 turret position change
; Turret is on 4th axis, positions are in machine position.
; Requires: Machine home must be set prior to use.
;
;#101 = ;Calculated position to move to when requested position < current position
;#20601-#20604 = Counts per unit for axes1-4
;#5021-#5024 is the current machine position for axes 1(#5021) through 4(#5024)
;#4120 = requested turret position from g code

IF #5024 > #4120 THEN #101 = [8 + #4120] ELSE #101 = #4120

G53 A[#101] ;originally was +.5
;G4 P1 ; added pause 1 second
;G53 A[#101 - .005] ;removed -.5

M26 /A L[#4120*#20604]

N1000 ;Macro finished

Re: Lathe Turret/ATC macro code question

Posted: Sun Feb 23, 2020 2:58 am
by cncsnw
Perhaps, but only if #100 then gets assigned to have that value somewhere, either at the top of the cnctch macro, or before the macro is called. Since #100 is a general-purpose user variable, it will start every new job with a value of zero.

I would instead use variable #9161, which retrieves the current value of Machine Parameter 161, which is customarily used to store the number of available tool positions.

Re: Lathe Turret/ATC macro code question

Posted: Sun Feb 23, 2020 10:27 am
by frijoli
cncsnw wrote: Sun Feb 23, 2020 2:58 am Perhaps, but only if #100 then gets assigned to have that value somewhere, either at the top of the cnctch macro, or before the macro is called. Since #100 is a general-purpose user variable, it will start every new job with a value of zero.

I would instead use variable #9161, which retrieves the current value of Machine Parameter 161, which is customarily used to store the number of available tool positions.
Good point, Thanks.
This was a macro written by Centroid for an axis driven turret changer. Fortunately I have 8 positions which is why it was indexing correctly.