Controlling Lathe turret as axis with stepper and no encoder

All things related to the Centroid Acorn CNC Controller

Moderator: cnckeith

Post Reply
jay_m
Posts: 11
Joined: Mon Mar 30, 2020 1:37 pm
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

Controlling Lathe turret as axis with stepper and no encoder

Post by jay_m »

Hi guys.
So I have an 8-tool turret on an old Rhino ST8 lathe that I am trying to drive as an A axis on the lathe. I have modified it to be spun by a stepper motor and there is a pneumatic cylinder that locks the turret in position when the desired position is achieved. I have a home switch that aligns with Tool 1 on the turret.

I am having a hard time writing the tool change macro for this, even though in theory it seems so simple. There are some a lot of variables that I keep digging for and at the end I have gotten nowhere.

The sequence has to be like this:
1. A certain tool is requested (for example, T0404)
2. Output 2 on the board turns on (M62) to disengage the pneumatic cylider
3. Stepper motor is enabled (M63 to trigger a relay to supply the correct signal to the enable pin of the stepper)
4. A axis spins to A180 (tool # 4 position at 180deg from Tool 1, which is at A0)
5. Motor is disabled (M83)
6. Pneumatic cylinder is engaged to apply brake (M82)
and that's it.

Now in these simple 6 steps there seem to be so many variables/parameters that I just get lost in. Any guidance would be much much appreciated. I have read what seems to be all the sample macros out there but I am still quite lost.

Thanks in advance for all the help.
cncsnw
Posts: 3764
Joined: Wed Mar 24, 2010 5:48 pm

Re: Controlling Lathe turret as axis with stepper and no encoder

Post by cncsnw »

You have most of it figured out already.

I recommend setting up the A axis turns ratio ("motor revs/inch") so that one unit of travel is one tool position, rather than one degree. That way you can simply set and command A positions by tool number.

You should flag the A axis as a rotary axis using Parameter 93 or Parameter 94 (depending on whether it is your 3rd or your 4th axis). I would set that parameter = 33, so that the axis is rotary, but is displayed the same as a linear axis.

The tool-change macro on a lathe is cnctch.mac, in the c:\cnct directory.

Yours would look something like this:

Code: Select all

; cnctch.mac - Automatic Tool Change
; This is one of the rare cases where it really is important to skip over processing the macro codes
; when using Search or Resume.  We will skip them in Graph as well, though that does not really matter.
IF [#4201 || #4202] THEN GOTO 900
  M62    ; Unlock the turret
  M63    ; Allow the stepper motor to move
  G53 A#4120  ; move the A axis to the requested tool number, using Machine Coordinates
  M83    ; Cut off power to the stepper motor
  M82    ; Lock the turret back down
N900
By setting one unit = one tool, you do not have to do any degrees-per-tool calculations.

By designating the A axis to be a rotary axis, you will not get unwanted inch/millimeter conversions in your turret positions, even if you run a job that contains G20 or G21.

By using G53 to command the A axis in Machine Coordinates, you get consistent turret positions regardless of which WCS is active.

You will, of course, need to set Machine Home on the A axis at the T8 position, so that T1 is found by going one unit positive from home, and so on for the rest.

This will probably work, and perhaps work best, with Parameter 6 = 0.

If you set Parameter 6 = 1, then you will have the use of the F7/ATC key on the setup menu and in the offset library, but the "Tool Number" display in the status window will no longer be correct, unless/until you add some further logic to communicate with the PLC program. This is because when P6=1, the tool number displayed in the status window is one that is reported to CNC12 by the PLC program.

This example does not do shortest-path indexing. If you ask it to go from T1 to T7, it will go forward six positions, instead of backing up two. That could be resolved by adding some modulo arithmetic based on variables #502x and #4120.

It is also possible to add code to the tool-change macro, and to your homing macro (cnct.hom) to remember the last turret position (perhaps by storing it in a static CNC variable such as #150); and then to set home on the A axis so that the current position is maintained (by using the "L" parameter with M26).

All those things are left as exercises for the reader....
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: Controlling Lathe turret as axis with stepper and no encoder

Post by briuz »

Here is the code I use to turn the turret on my Portable Collet Production Lathe that is under development. The "Raise Paw" and "Lower Pawl" sections would be replaced by the relays to lock or unlock the collet. (This code will change as the next version of my turret uses a locking pin.)

This turret has 16 positions and they are not located at equidistant spacing across the turret face. So all of the locations are hard-coded.

Code: Select all


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:  Odd numbered tools are standard 3/8" tooling and even 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 = 18;				;  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

jay_m
Posts: 11
Joined: Mon Mar 30, 2020 1:37 pm
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: Controlling Lathe turret as axis with stepper and no encoder

Post by jay_m »

Thanks for the helps, guys.

I am a bit unclear on the concept of setting the gear ratio to be one tool increment. Let's say, hypothetically speaking, my motor requires 400 steps to to make one revolution of its OWN axis and is connected to the turret via a 4:1 gear ratio.The turret has 8 tools, spaced 45degrees apart.
So when I request a tool change for, let's say tool # 4, I would call out T0404. What variable exactly gets called where and how would the whole ratio adjustment work? At first glance it seems simple but when I start thinking about the code I am definitely missing some pieces in my little brain. :)
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: Controlling Lathe turret as axis with stepper and no encoder

Post by briuz »

#4120 is the tool number

With 400 steps per revolution and a 4:1 gear ratio, that would be 1,600 steps per revolution.

Without any lock/unlock commands the idea is as follows:

1. Get the tool number from #4120
2. Calculate the position (angle) of the tool in degrees like: Angle = Tool * 45
3. G00 A[Angle]

I've just learned that after you set the tool, and with the ATC PLC, you need to execute the following:

G10 P1976 R[#4120] ;Set parameter 976 to tool number

I added some notes to the code as follows:

; CNC12 Parameters:
; Parameter = Setting
; 6 = 1
; 160 = 1 (ATC to non-random)
; 161 = 16 (Maximum number of tool positions)
; 820 = 1 (Sets machine type to lathe)
; 830 = 6 (Axis Driven Turret)
Post Reply