Author Topic: Spiral+spherical toolpath  (Read 40206 times)

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6133
    • View Profile
    • Cambam V1.0 French Doc
Spiral+spherical toolpath
« on: August 06, 2014, 18:11:21 pm »
Hello,

This srcipt as been written by a french user ; I only translate the text to English

It allow to create a hemispherical spiral toolpath of a given diameter (with tool compensation for ballnoze).

Code: [Select]
' For CamBam Plus
' (c) Jean-Luc Laurent 2014
'
' english translation: dh42
'
' Vous pouvez copier et distribuer librement ce programme. Ne retirez pas cet avis.

' You can freely copy and distribute this program. Do not remove this notice.

sub main

rem -----------------Declarations----------------------------

dim inputValue as string
dim rayon_sphere as double
dim rayon_fraise as double
dim rayon_travail as double
dim position_x     as double
dim position_y     as double
dim position_z     as double
    dim profondeur_z as double   
    dim rayon_calcul as double
    dim positions      as integer   ' Nombre dposition sur 1 tour
    dim angle_calcul_diff_rayon as double
    dim angle_calcul_rayon as double
    dim angle_xy as double
    dim angle_depart_z as double
    dim inc as double
dim dline as string = chr(10)+chr(10)


rem --------------- Declarations saisies utilisateur -------------------

dim depart_x as double   ' Position du centre en X
dim depart_y as double   ' Position du centre en Y
dim depart_z as double   ' Départ face en Z
    dim hauteur_centre_sphere as double ' Hauteur du centre de la sphere par rapport au départ face Z
dim increment      as double ' Incrément angulaire
dim sphere         as double ' Diamètre de la sphère
dim outil          as double ' Diamètre de l'outil
    dim sens           as integer   ' Sens d'usinage

rem --------------------Input parameters------------------------

inputValue=inputbox("Enter X center coordinate for the sphere." +dline+"Click Cancel to abort", _
"Location X","0")
if inputValue ="" then exit sub
depart_x=cint(inputValue)    ' convertion en integer

inputValue=inputbox("Enter Y center coordinate for the sphere." +dline+"Click Cancel to abort", _
    "Location Y","0")
if inputValue="" then exit sub
depart_y=cint(inputValue)    ' convertion en integer

inputValue=inputbox("Enter Z center coordinate for the sphere." +dline+"Click Cancel to abort", _
"Location Z", "0")
if inputValue="" then exit sub
hauteur_centre_sphere = cint(inputValue)  ' convertion en integer

inputValue=inputbox("Enter Z coordinate for the top face" +dline+"Click Cancel to abort", _
    "Face location Z","0")
if inputValue="" then exit sub
depart_z=cint(inputValue)    ' convertion en integer

inputValue=inputbox("Enter the spiral deep increment." +dline+"Click Cancel to abort", _
    "Deep increment","10")
if inputValue="" then exit sub
increment=cdbl(inputValue) ' convertion en double
   
  inputValue=InputBox("Enter the diameter of the sphere." +dline+"Click Cancel to abort", _
"Sphere diameter","50")
if inputValue="" then exit sub
sphere=cint(inputValue) ' convertion en integer

inputValue=InputBox("Enter tool diameter (ballnose)." +dline+"Click Cancel to abort", _
    "Tool diameter ","10")
if inputValue = "" then exit sub
outil = cdbl(inputValue)   ' conversion en integer

    inputValue = 3
do while inputValue < 1 or inputValue > 2
        inputValue=InputBox("Enter the machining direction (1= CCW, 2=CW).", _
        "Machining direction ","1")
    loop
sens = cint(inputValue)   ' conversion en integer

inputValue = msgbox("Clear active layer ?", 36,"Clear layer")
If inputValue = "6" then doc.ActiveLayer.Entities.Clear() ' Efface la couche active

rem ----------------- Calculs ------------------------------

dim p as Polyline = new Polyline
    rayon_sphere = sphere / 2
    rayon_fraise = outil / 2
    rayon_travail = rayon_sphere - rayon_fraise
    increment = 360 / (fix(360/increment)+1)
    positions = 360 / increment
    angle_calcul_diff_rayon = increment / positions
   
    angle_calcul_rayon = 0
    angle_xy = 0
    angle_depart_z = 90-(math.acos((hauteur_centre_sphere - depart_z) / rayon_sphere) * 180 / pi)

rem ----------------------Boucle principale de calcul des points -----------------------------

    while angle_depart_z < 90
        angle_depart_z = angle_depart_z + angle_calcul_diff_rayon
        rayon_calcul = rayon_travail * math.cos(angle_depart_z * pi / 180)
        profondeur_z = rayon_travail * math.sin(angle_depart_z * pi / 180)
        position_x   = math.Round(depart_x + (rayon_calcul * math.cos(angle_xy * pi / 180)), 3)
        position_y   = math.Round(depart_y + (rayon_calcul * math.sin(angle_xy * pi / 180)), 3)
        position_z   = math.Round(hauteur_centre_sphere - rayon_fraise - profondeur_z, 3)
        p.Add(position_x,position_y,position_z)
        if sens = 1 then
            angle_xy = angle_xy + increment
        else
            angle_xy = angle_xy - increment
        end if
       
    End While
    doc.Add(p)  ' Print it!
end sub


++
David

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Spiral+spherical toolpath
« Reply #1 on: August 06, 2014, 18:24:40 pm »
Oh, My!  THERE is part of a plug-in, if I ever saw one!

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

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1777
    • View Profile
    • pixelmaker
Re: Spiral+spherical toolpath
« Reply #2 on: August 06, 2014, 18:54:23 pm »
hello
thank you David, This script is more simple to use then the "spiral polygon" script.

But what I wish is a script that draws a spiral from a outline to the center, that we can use for spiral milled pockets. I found this in C++, I can not translate it into another programming language.
Perhaps one of you understand how todo this.

ralf

Offline Garyhlucas

  • CNC Jedi
  • *****
  • Posts: 1369
    • View Profile
Re: Spiral+spherical toolpath
« Reply #3 on: August 06, 2014, 21:33:18 pm »
Been waiting for this one! I have an application for it right now.
Gary H. Lucas

Have you read my blog?
 http://a-little-business.blogspot.com/

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 2984
    • View Profile
Re: Spiral+spherical toolpath
« Reply #4 on: August 06, 2014, 23:42:01 pm »
But what I wish is a script that draws a spiral from a outline to the center, that we can use for spiral milled pockets.
+++++++++++++++++++

+1 ;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: Spiral+spherical toolpath
« Reply #5 on: August 07, 2014, 00:42:37 am »
Ralf,

Do you mean hemispherical pockets, or just _any_ pockets?

If just any, I am not clear on what is the advantage of outside-in vs inside/outside offsets.

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

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1345
    • View Profile
Re: Spiral+spherical toolpath
« Reply #6 on: August 07, 2014, 02:19:38 am »
Ralf
That code may have been a programmers "thought bubble" as it won't compile <char side = 0;>
should read
<int side = 0;>
and the rest of the code uses integer math, and there's no spiral math in the code at all.
Dave

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 8331
    • View Profile
Re: Spiral+spherical toolpath
« Reply #7 on: August 07, 2014, 11:09:33 am »
After having a spent a bit of time with that script, David, I must say it's pretty much worthless.

It uses a fairly crude iterative routine that for a simple 3" sphere of a very coarse .050" depth increment generates over 12 MILLION line segments, and forces an out-of-memory exception in CB.

It will need to be rewritten to use splines and/or arcs, and to make much more conservative use of memory through the appropriate selection of variables' precision.

It also ONLY generates the outer surface path, leaving the user to figure out what to do with the volume inside.  I can easily re-write it to take care of that volume, but with the current misuse of memory, that's not an option.

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

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6133
    • View Profile
    • Cambam V1.0 French Doc
Re: Spiral+spherical toolpath
« Reply #8 on: August 07, 2014, 12:35:08 pm »
Hello,

I have not spend much time to play with ; the thing that I view in the code is that it seems to use integer value even if "double" are used as variable ("cast" from double to int).

I think that Jluc has written this script very quickly to answer to a wish of a guy on the forum that need to machine spherical prints with spiral cut (I don't know why)

Quote
But what I wish is a script that draws a spiral from a outline to the center, that we can use for spiral milled pockets. I found this in C++, I can not translate it into another programming language.

For any shape, or only for circular pockets ?

++
David


Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1345
    • View Profile
Re: Spiral+spherical toolpath
« Reply #9 on: August 07, 2014, 12:41:54 pm »
HI David
I played around with script, Created a hemisphere and used an engrave mop then produced the g-code
and simulated it in (openscad and mach3) and it seems to work fine. If I get time tomorrow I'll
run a  quick test piece in mdf to see if cuts OK and report back.
Here is the file if anyone's interested.
Dave

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6133
    • View Profile
    • Cambam V1.0 French Doc
Re: Spiral+spherical toolpath
« Reply #10 on: August 07, 2014, 12:43:28 pm »
re

a thing that can cause memory problem is that the same step (increment) is used both for depth increment and for angular increment ; I think that this two value must be separated.

++
David

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1777
    • View Profile
    • pixelmaker
Re: Spiral+spherical toolpath
« Reply #11 on: August 07, 2014, 13:25:35 pm »
Quote
For any shape, or only for circular pockets ?
A circular pocket I can do with the flat spiral in cambam. But I can´t find a (simple) way to do other pocket with a circular toolpath.
A circular toolpath is not a fast way to finish a pocket but it looks very good for works in metal.
Attached is a file with such a toolpath, I use a engraving mop to mill it. The edges I finish with a separate profile.
Here is the simulation
Perhaps this is a challenge for all you programmers.
The toolpath starts at the center point and if it hits the contour it is parallel to the contour.

@ David: what I don´t understand with this script. If I choose X,Y,Z=0, topface=0.
The toolpath starts 1 tooldiameter lower then Z 0. It starts never at Z 0

ralf

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6133
    • View Profile
    • Cambam V1.0 French Doc
Re: Spiral+spherical toolpath
« Reply #12 on: August 07, 2014, 13:57:43 pm »
Hello Ralf,

Quote
Perhaps this is a challenge for all you programmers.

For me, yes ! ... not because coding but because math .. :'( my knowledge of geometry is very light.

++
David

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1345
    • View Profile
Re: Spiral+spherical toolpath
« Reply #13 on: August 08, 2014, 01:13:36 am »
Hi all
Ok a couple of observations, This script will be ok for shallow dish like objects (which is what I'm interested
in) Perhaps a couple of diameters of the tool deep, And was faster than the 3d method.
However any deeper required a second mop (scaled and stacked on top with a larger diameter tool) to remove the bulk material.
Ralf I like that finish too, and my first thought on seeing the file was to use a
pocketing mop -->Region/Fill/style -->hatch, In this case  a spiral hatch. If I get some time,  I'll troll
through the documentation to see if this function can be adapted  by simply passing it
a new fill style template.
Dave.

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 6133
    • View Profile
    • Cambam V1.0 French Doc
Re: Spiral+spherical toolpath
« Reply #14 on: December 22, 2014, 17:04:24 pm »