Author Topic: Bottom-up threading of a hole marked by a circle  (Read 20153 times)

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Bottom-up threading of a hole marked by a circle
« on: March 29, 2015, 23:00:07 pm »
I've been needing this for a while, and some of you may find it useful.

It's designed for single-point threading, bottom-up to clear chips better, and to facilitate climb milling, which gives a little smoother thread form.  It has a centering plunge to the desired threading depth followed by a tangent lead-in to the desired threadform depth.

It threads to one pitch above the stock surface, then moves to clearance.

If you have multiple holes, it will connect all of them with one toolpath, moving between them at clearance.

All the parameters are hard-coded right now, except for the hole diameter itself.  In this sort-of 'demo' version, I'm not dealing with the threadform depth, either.

I just want some input as to bugs, suggestions, etc.  Thanks to David's reminding me about the 'reality' of drawing entities, I finished quickly.

Lloyd

(ps... should have waited... it only took about five minutes to add the form depth

=================
Updated version B-threading with bottom-up finish V0.2
'   Bottom-up threading V0.2
'
' For a single-point tool, with clearance moves and
' a tangent lead-in to the thread wall.
'
'      By Lloyd E. Sponenburgh 3/29/2015
'      If you use this, please give credits to me, and leave in the
'      credit to Andy.

' AGAIN, with credits to Andy Payne for Boingy.
' This routine designs a straight spiral of a given threads per inch,
' a given depth, a given stock surface, a given threading-tool diameter,
' and a given desired thread form depth, within a hole of a specified diameter.
'
'
' Given:
' The primitive ID of the hole (circle). Actually, in this case, the hole will
' be gotten from the screen selection.
'
' The stock surface Z, and clearance height Z.
' The threading tool diameter to its tip.
' The desired form depth. (NO protection against exceeding the depth of the
'                     tool's forming tip!!!)
' The desired threads per inch.
'
' The routine is intended to be used with an ENGRAVE MOp.
'
' It will first find the center of the hole, and describe a straight vertical
' line at that center point from clearance to the desired threading depth.
' It will continue that polyline in a curved tangent to the form depth.
' It will describe a straight spiral upwards with a clockwise THREAD, but
'  that means, of course, the toolpath will be spiralling CCW.
' It will continue to one thread pitch above surface, or to clearance, whichever
'  is less above the surface.
' If the end-point of the threading path is lower than clearance, then it will
' continue in a straight vertical line to clearance.  (in fact, it will do so
'   in either case, but the last segment will be zero-length if the tool
'   was already at the clearance height when it stopped the thread)
'
' If there are multiple circles to thread, ONE polyline connecting all of
' them at the clearance height will be made.
'
' A modified BOINGY MakeHelix is used as a subroutine to generate the straight
' spiral path.  Instead of creating a new poly, it will add points to our
' "working" polyline, p.
'
'
dim TP_radius as single         ' toolpath target radius for center of cutter
dim tool_diameter as single      ' diameter to tip of threading tool
dim tool_radius as single      '   we're assuming a single-point tool
dim form_depth as single      ' depth into the wall of the threading point
dim pass_form_depth as single   ' depth increment per pass, less some for finish
dim finish_depth as single      ' finishing pass depth
dim roughing_passes   as integer   ' total number of roughing passes
dim finishing_passes as integer   ' ditto finishing

dim steps as integer         ' total arc segments from bottom to top
'dim i as integer      
dim th as double            ' theta angle per step
dim p as new polyline         ' name of our polyline
dim x,y,z as single            ' cartesian coordinates
dim cp as point3F            ' center-point of selected circle
dim Diameter as Double         ' diameter in CB units of selected circle

dim target_depth,clearance_height,stock_surface as single
dim thread_pitch as single
dim thread_top as single
dim lead_in_diameter            ' radius of the lead-in tangent
dim one_eighty_bulge as single =1  ' +=ccw, -=CW (+-0.4142135237309503 for 90 degrees)
dim steps_per_circuit as single   ' number of divisions of each loop
                        ' arbitrary according to needs
dim e as Circle
dim any_selected as integer=0
dim pass_number as integer      ' loop counter for roughing/finish passes


' this setup makes straight-line segments for the helix.
' Inches is used in this example, but the algorithm is "unit-less".

sub main

  roughing_passes=4         ' four rough
  finishing_passes=2
  thread_pitch=0.050      ' 20tpi for this fixed-pitch example
  tool_diameter=.968      ' for testing -- this is pretty accurate
  form_depth=0.044         ' for 20tpi, pretty exact would be 0.043301
  tool_radius=tool_diameter/2
  steps_per_circuit=180
  stock_surface=0         '  OOPS! bug in starting-depth calculations!
                     ' doesn't account for stock surface!
  clearance_height=0.25
  target_depth=-1.25      ' depth we'll go with this threading
  finish_depth=0.002
  pass_form_depth=(form_depth-finish_depth)/roughing_passes

' find the circle and get its specs
  for each ent as Entity in view.SelectedEntities
    if ent.PrimitiveType()<>"Circle" then
      exit for
   end if
   any_selected=1      ' we had at least one circle!
   
   e=ent
   cp=e.Center()
   x=cp.x
   y=cp.y
   Diameter=e.Diameter      ' get the hole's diameter
   TP_radius=(Diameter/2)-tool_radius   ' zero cutting depth

    for pass_number=1 to roughing_passes+finishing_passes

     if pass_number<=roughing_passes then
      TP_radius+=pass_form_depth   ' increase depth of cut by pass depth
     else
      TP_radius=((Diameter/2)-tool_radius)+form_depth   ' make it EXACT
      end if

     ' see where the thread should stop
     thread_top=stock_surface+thread_pitch
     if thread_top>clearance_height then
        thread_top=clearance_height   ' adjust to clearance if Higher than clearance
     end if

     if pass_number>roughing_passes then
        ' make a bottom_up pass (in climb)
        ' Start at clearance, and work down.
        x=cp.x
      y=cp.y
      z=clearance_height
         p.add(x,y,z)

        ' now plunge to depth
        z=target_depth
        p.add(x,y,z)

        ' now calculate a half-turn circular curve that will go from this
        ' center-point to tangent of the targeted thread form depth
        '
        ' Since we're spiraling up counter-clockwise, the lead-in must curve
        ' CCW from the center.

        lead_in_diameter=TP_radius
        p.add(x,y,z,one_eighty_bulge) ' establish a move from the center to the start
                        ' and the curvature of the line to the next point

        x=x+lead_in_diameter      ' move 'right'to wall of hole
        p.add(x,y,z)         ' set second point of curve
   
        MakeThread()

        ' now add a leadout directly to clearance
        z=clearance_height
        p.add(x,y,z)
     else
       ' make a top-down pass
        ' Start at clearance, and work down.
        lead_in_diameter=TP_radius
        x=x+lead_in_diameter      ' move 'right'to wall of hole
        z=clearance_height         ' but at clearance
         p.add(x,y,z)
      z=thread_pitch            ' then down one 'pitch' above surface
        p.add(x,y,z)         
   
        MakeThread()
        ' Since we're spiraling down clockwise, the lead-out must curve
        ' CW from the center.
        p.add(x,y,z,(-1*one_eighty_bulge)) ' establish a move from the center to the start
                        ' and the curvature of the line to the next point

      ' Move via that curve to the center again
      x=cp.x
      y=cp.y
        p.add(x,y,z)

        ' now add a final leadout directly to clearance
        z=clearance_height
        p.add(x,y,z)
     end if

   next pass_number
  next
  ' finally, add the polyline to the document
  if any_selected>0 then
      doc.add(p)
  end if

end sub



function  MakeThread
   dim start as single   = 0         ' in radians
   dim steps as single            ' number of total steps we'll go
   dim turns as single            ' number of circuits to make
   dim th as single = start
   dim dt as single
   dim dz as single

   turns=((math.abs(target_depth)+thread_top)/thread_pitch)
   steps=turns*steps_per_circuit

   if pass_number>roughing_passes then
     dz = (thread_top-target_depth)/steps
     dt = (2*pi)/steps_per_circuit
   else
     dz = -1*(thread_top-target_depth)/steps
     dt = (-2*pi)/steps_per_circuit
   end if

   '// Play da loop
   for i as short = 0 to steps
      z = z + dz
        th = th + dt      
      x = cp.x+(TP_radius * math.cos(th))
      y = cp.y+(TP_radius * math.sin(th))

      p.Add(x,y,z)
   next i

end function

« Last Edit: March 31, 2015, 20:21:07 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #1 on: March 29, 2015, 23:31:39 pm »
Original post modified with V0.2... threadform depth included now.

It would also be quite easy to make this thing take multiple passes for heavy threads... with a user-specified stepover and/or a finishing depth value.  It would be expensive in terms of milling time, but could be done all in one toolpath.

Lloyd
« Last Edit: March 29, 2015, 23:33:21 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline klystron

  • Ewok
  • *
  • Posts: 36
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #2 on: March 30, 2015, 10:42:06 am »
merci Lloyd, for the script cone en spirale .
Yves

Offline kvom

  • CNC Jedi
  • *****
  • Posts: 1580
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #3 on: March 30, 2015, 10:44:24 am »
The thread mill plugin already does this, so wondering why you wanted/needed this script.

I've found that most of my milled threads need a spring pass, so I've been coding the threadmill MOPs twice on each hole/shaft.

As for the script itself, it's unclear whether the hole diameter means the major or minor diameter.  If you specify the major diameter as a parameter than you could use either a circle or a point to find the center of the spiral.

You could also accommodate multi-point cutters rather easily.  Just reduce the number of turns in the spiral by the number of extra teeth in the cutter.
« Last Edit: March 30, 2015, 10:54:44 am by kvom »

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #4 on: March 30, 2015, 12:35:11 pm »
Heh!  I wondered if anyone would ask that, Kvom!

Have you tried to modify the behavior of the threading plugin?

Have you tried to add a specific plunge path that guarantees the tool is centered in the hole before it plunges?

<G>

If I had the source for the threadmill plugin, I'd have never bothered.   My needs extended beyond just those two things above:  I have a plate in which some 100+ holes must be threaded.  The ability to 'connect' those individual actions into one big threading "fest" was one reason for this.  It is, after all, a very simple script -- not like a re-do of the whole threading plugin.

The hole diameter is just that... the diameter of the hole in which you'll be threading.  The threadform depth figure states how far into the wall the threads will be cut.  It's not for 'standard' threads, but for any arbitrary hole and threadform sizes.

Yes... I'll later consider the multi-point tools.  Just now, I must thread that plate.

I figured the script would be useful to folks just as an example of how to create an "extended" polyline with various features, plunges, lead-ins, etc.... not so much just for threading, which the thread mill plugin does adequately.

Thanks, all.
LLoyd
« Last Edit: March 30, 2015, 15:09:11 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #5 on: March 30, 2015, 15:14:47 pm »
Just another note on this:

I had mentioned this a long time ago in a thread far, far away...

IF one wishes to use 'bottom-up' threading to obtain a climb finish, then with most single-point thread forming tools, you MUST use progressively-deeper passes, with each pass LESS deep than the trailing relief on the cutter tip.

Otherwise, the trailing edge of the bit will come in contact with the un-cut work before the tip cuts deeply enough to relieve it, and it will 'spring' the tool, or break the insert.

This is because of how the tangents between the tool rotation and the work walls relate;  it's not real clear unless you draw it out.   The larger the effective diameter of the threading tool as compared to the minor diameter of the threaded hole, the worse this relationship becomes.

For instance, my threading tool has only .009" relief, so in climb, that's as deeply as I can cut in one pass in climb in a hole about 125% larger than the tool's effective diameter.

If there's any question, it must be done 'top-down' with conventional milling -- most especially if you cut full-depth threads in one pass.

I will make the script work either way, for safety.

Lloyd
« Last Edit: March 30, 2015, 15:18:33 pm by lloydsp »
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #6 on: March 30, 2015, 17:59:43 pm »
I've added 'step-overs' for roughing/finishing, although right now they're limited by some hard-coding.

The roughing passes are done top-down in conventional, to avoid that back-relief problem, and the (supposedly fine) finishing pass is done bottom-up in climb.

I'll hang onto it a short while, during which I'll cut some real metal with it.

LLoyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline kvom

  • CNC Jedi
  • *****
  • Posts: 1580
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #7 on: March 31, 2015, 03:00:25 am »
Regardless of the type of thread, major and minor diameters are common terms.  I think it would be preferable to use these terms rather than hole diameter and form depth if you want to  make it easier to use for us the masses.

With multi-pass capability it will be more efficient than the threadmill plugin, which needs a separate MOP for each pass.

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #8 on: March 31, 2015, 10:40:25 am »
Well... yeah... I'm relatively familiar with the common terms used in threading!  ;D

But the user need never _know_ what the minor diameter will be; and he never specifies it, in this script.

One simply selects a circle representing the 'minor diameter', without ever knowing its diameter.  Then the script will cut the desired threadform depth from that diameter, without the user's ever knowing (or needing to know) the major diameter.

It doesn't presently, but it could very simply 1) state what the minor and major diameters will be after finishing, and 2) give hints on what a 100% thread depth should be, given the desired pitch.

It's working pretty well.  I threaded eight 1.255" i.d. holes last night using roughing/finishing, and they turned out OK.

I'll doll up the hard-coding a bit, and post it later today.

(all the terminology is free to be changed... ;) )

Lloyd

"Pyro for Fun and Profit for More Than Fifty Years"

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 2985
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #9 on: March 31, 2015, 12:11:50 pm »
I threaded eight 1.255" i.d. holes last night using roughing/finishing, and they turned out OK.
**************************
I presume the 1.255" is the minor dia, so what thread you were threading? This number is strange to me.. With out my machinist hand book I'm lost and don't have it with me by the computer.. :D
My 2¢

Win 10 64 bit, CB [1.0} rc 1 64 bit, Mach3, ESS, G540

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #10 on: March 31, 2015, 12:22:17 pm »
Bubba, you just made my key point for me in the issue of not naming the parts according to convention.

It was not ANY particular 'standard thread'.

I have some cavities in a pressing mold which need to be lined with bronze inserts.  They are not sized according to any conventions, but instead upon percentages of the diameter of the finished pressings, and wall thicknesses to take the forces involved.

The holes just happened to end up 1.255" i.d.

And regardless of their diameters, I have chosen a 20tpi thread to secure the liners in the cavities.
The liners will be turned and lathe-threaded to match the cavities.

So... I have this array of circles on the CB drawing representing all the cavities.  I just select them and run the script.  It does all the rest, including connecting all the toolpaths together to make ALL the holes in one MOp.

Am I beginning to make it clear why I diverged from 'standard terms' ?

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #11 on: March 31, 2015, 12:29:00 pm »
I have a bunch more work to do on this thing before it will be 'friendly'.

One thing is:  Right now, it's based on the "boingy" thing from Andy (because it's simple and intuitive), and calculates 2-degree steps around the helix, with straight lines between points.  This results in HUGE g-code files and some noticeable 'granularity' in the toolpath if coarser steps are selected.

It will mean a re-write, but I intend to make those lines as 1/3-revolution arcs of descending Z instead, like a circle is now defined in CB.  That will make the g-code vastly smaller, and eliminate any 'jaggies' in the toolpaths.  Doing it that way also allows the math to be exact at each 'return' to the starting xy of the cut, so that any errors due to math precision are not cumulative through the whole threading path.

LLoyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 2985
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #12 on: March 31, 2015, 16:55:09 pm »
Am I beginning to make it clear why I diverged from 'standard terms' ?
*************************
Kind of.. ;D

It's just me.. But, I just could not bring myself to any random number(hole dia) and 'go for it'..
I guess all of those years maintaining standards is ingrained in me. I'm permanently damaged.. ;) :D ;D

Bottom line Lloyd.
As long as the end result is what you are after then it really does not matter what me or anyone else think! ;D
My 2¢

Win 10 64 bit, CB [1.0} rc 1 64 bit, Mach3, ESS, G540

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #13 on: March 31, 2015, 17:22:13 pm »
Well,
Bubba, to further yours and Kvom's arguments, it would be helpful to have an ability to establish a major diameter.   The minor diameter would, of needs, be established by the major diameter and the thread pitch.

I will consider how to do that.  If one wishes to make 'standard' threaded holes, then it's a necessity.

I just started out with the question -- "If I had to thread a hole... ANY hole, how would I go about it?"  This is what evolved.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 4468
    • View Profile
Re: Bottom-up threading of a hole marked by a circle
« Reply #14 on: March 31, 2015, 18:28:45 pm »
While I don't cut threads on the machine I've tapped many holes by hand. All I do is look in a table for the 'tapping hole' diameter, drill the hole and tap it.
With regard to Lloyd's script I would do the same thing, get the tapping hole size, drill it, set my tpi and depth of cut to match the major diameter, otherwise the 'bolt' is going to be slack or tight.
For non standard sizes I would just make sure my hole and 'bolt' had compatible dimensions.
Made in England