CamBam
News:
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 11, 2017, 16:51:38 pm


Login with username, password and session length


Pages: 1 2 3 [4] 5
  Print  
Author Topic: Spiral Toolpath from Profile  (Read 11123 times)
dh42
Administrator
CNC Jedi
*****
Online Online

Posts: 4783



View Profile WWW
« Reply #45 on: October 26, 2016, 23:55:23 pm »

Hello,

@Eddy

It is not perfect but it show an idea to draw a toolpath with radius compensation + ball nose.

That not work on all shape ; I let you discover what are the shapes that fail (overhang)

a little video

http://www.screencast.com/t/rMo4f6IqYYI

and the VBS code

Code:
' New CamBam VBScript
' tool comp attempt for ball nose:)
'


sub main

dim ent as Entity

' tool radius, depht incr

Dim tr as double = 3 ' tool radius
Dim di as double = 0.5' depht incr

Dim accuracy as double = 0.1 'size of the move in x size

Dim ptl as PointList = New PointList 'a point list that will contain the tip_position
Dim path_poly as Polyline = New Polyline 'the resulting toolpath


if (view.SelectedEntities.Length = 1) then

ent = view.SelectedEntities(0)

if typeof ent is Polyline

Dim topcenter as double '= stock surface
Dim max_x as double ' = max x extension of the shape
Dim bottom as double ' = target depth

Dim min As Point3F
Dim max As Point3F

ent.GetExtrema(min,max)

topcenter = max.y
max_x = max.x
bottom = min.y



'-------------------------------------


topcenter = topcenter + tr - di

' repeat for each depth increment
while topcenter >= bottom + tr

ptl.add(detect_edge(tr,topcenter,max_x, Ctype(ent,Polyline),accuracy ))

topcenter = topcenter - di

end while

doc.add(ptl)

path_poly = ptl.ToPolyline()
path_poly.closed = false

doc.add(path_poly)

view.RefreshView()

'--------------------------------------

else
msgbox("not a polyline")

end if
else
msgbox("select only one polyline")


end if


end sub

function detect_edge(radius as double ,start_point as double , x_extent as double , shape as Polyline, stp as double) as Point3F

' move a circle that represent the ball of the mill from center to extend of the shape
' and check if the circle intersect with the shape

Dim c as Circle = New Circle(0, start_point, radius )
Dim tool as polyline = c.ToPolyline()
Dim center as Point3F = New point3F
Dim move as Matrix4x4f = New Matrix4x4f
Dim tip_pos as Point3F = New Point3F

' X move by step
for n as double = 0 to x_extent step stp

'move and apply transformation
tool.ApplyTransformation(move.Translation(stp,0,0), false)

'test for intersect

if tool.Intersects(shape) then

center = tool.GetCentroid()
tip_pos.x = center.x
tip_pos.y = center.y- radius 'correct y for ball radius
tip_pos.z = 0

exit for

end if

next n

' to remove for real use ------------
doc.add(tool)
view.RefreshView()
' -----------------------------------

return tip_pos

end function

I attach my .cb file used for the video

++
David

* toolcomp_test.cb (2.93 KB - downloaded 37 times.)
Logged
dave benson
CNC Jedi
*****
Offline Offline

Posts: 811


View Profile
« Reply #46 on: October 27, 2016, 00:13:56 am »

HI David
Works fine for me "Good Idea".
Dave
Logged
dh42
Administrator
CNC Jedi
*****
Online Online

Posts: 4783



View Profile WWW
« Reply #47 on: October 27, 2016, 00:30:40 am »

almost ... but I just think that if I do the move on the "Z" axis (Y on the screen) instead of the Y axis to detect the shape, I can solve the pb with shapes that have overhang on the "sides" or "waves" or "pikes" on the bottom .. (difficult to explain)

++
David
« Last Edit: October 27, 2016, 00:34:26 am by dh42 » Logged
Garyhlucas
CNC Jedi
*****
Offline Offline

Posts: 1028


View Profile
« Reply #48 on: October 27, 2016, 01:51:07 am »

Eddy,
Really appreciate your efforts on this!  Getting set up to the pipe tapping I spoke about. Just a straight line at a slight angle so I would think your new version would handle that.
Logged

Gary H. Lucas

Have you read my blog?
 http://a-little-business.blogspot.com/
dh42
Administrator
CNC Jedi
*****
Online Online

Posts: 4783



View Profile WWW
« Reply #49 on: October 27, 2016, 03:07:14 am »

Hello,

This code works better, and take care about overhang and pikes.

same method as the previous except that I move the circle vertically to detect the shape.

I also add an approach routine to speed the move (approach with res*100, then with res *1)

Code:
' dh42 10/2016
' tool compensation for ball noze
' first select a polyline then run the plugin
    Sub main()

        Dim ent As Entity

'======== change this values to set the tool radius, stepover (horizontal resolution) and accuracy (detection of the shape)

        Dim tool_radius As Double = 4 ' tool radius
        Dim stepover As Double = 0.5 ' horizontal move = resolution on a 3D mop
        Dim accuracy As Double = 0.02 'size of the move in y size
'================================================================================================

        Dim ptl As PointList = New PointList 'a point list that will contain the tip_position
        Dim path_poly As Polyline = New Polyline 'the resulting toolpath created from the points list

' for tests
Dim t as double 'timer
'--------------------

        If (view.SelectedEntities.Length = 1) Then

            ent = view.SelectedEntities(0)

            If TypeOf ent Is Polyline Then

                Dim stock_surface As Double '= max height (stock surface) and X=0
                Dim max_x As Double ' = max x extension of the shape
                Dim bottom As Double ' = target depth
                Dim x_pos As Double = 0 'x position for the scan

                Dim min As Point3F
                Dim max As Point3F

                ent.GetExtrema(min, max)

                stock_surface = max.y
                max_x = max.x
                bottom = min.y
                x_pos = min.x

t = Timer()

                ' repeat for each horizontal stepover
                While x_pos <= max_x

                    ptl.Add(detect_edge(tool_radius, stock_surface, bottom, _
                                        x_pos, CType(ent, Polyline), accuracy))

                    x_pos = x_pos + stepover
                End While

                doc.add(ptl)

                path_poly = ptl.ToPolyline()
                path_poly.Closed = False

                Doc.Add(path_poly)
                View.RefreshView()

app.log("duration: " & Timer() - t)
            Else
                MsgBox("not a polyline")
            End If
        Else
            msgbox("select only one polyline")
        End If
    End Sub

'--------------------------------------------------------------------------------

    Function detect_edge(radius As Double, top As Double, target_depth As Double, x As Double, shape As Polyline, stp As Double) As Point3F

        ' move a circle that represent the ball of the mill from top to target_depht of the shape
        ' and check if the circle intersect with the shape

        Dim c As Circle = New Circle(x, top + radius, radius)

        Dim tool As polyline = c.ToPolyline()
        Dim center As Point3F = New point3F
        Dim move As Matrix4x4f = New Matrix4x4f
        Dim tip_pos As Point3F = New Point3F

        ' Y move by step with redol * 100 for speed up finding the shape
        For n As Double = top To target_depth Step -(stp * 100)

            'move and apply transformation
            tool.ApplyTransformation(move.Translation(0, -stp * 100, 0), False)

            'test for intersect
            If tool.Intersects(shape) Then
                'move forward a step * 100 and retry with the given resolution
                tool.ApplyTransformation(move.Translation(0, stp * 100, 0), False)

                'and retry with the normal resolution
                For m As Double = n + stp To target_depth Step -stp
                    tool.ApplyTransformation(move.Translation(0, -stp, 0), False)
                    If tool.Intersects(shape) Then

                       center = tool.GetCentroid()
                        tip_pos.x = center.x
                        tip_pos.y = center.y - radius 'correct y for ball radius
                        tip_pos.z = 0

       ' to remove for real use ------------
       doc.add(tool)
       view.RefreshView()
       ' -----------------------------------

         Return tip_pos

                    End If
                Next m
            End If
        Next n
    End Function

++
David

* toolcomp_test2.cb (5.65 KB - downloaded 31 times.)
« Last Edit: October 27, 2016, 03:15:34 am by dh42 » Logged
EddyCurrent
CNC Jedi
*****
Online Online

Posts: 3254



View Profile
« Reply #50 on: October 27, 2016, 08:06:15 am »

David,

I was reluctant to post version 2 yesterday because I knew it was not fully formed, however I'm now pleased I did because you would not have posted your ideas which to my mind are just brilliant !

Thank you very much, all I have to do now is see if they fit into the existing code and overall algorithm.
« Last Edit: October 27, 2016, 15:15:09 pm by EddyCurrent » Logged
Bob La Londe
CNC Jedi
*****
Offline Offline

Posts: 3023


^ 8.5 pounds on my own hand poured bait.


View Profile WWW
« Reply #51 on: October 27, 2016, 15:53:30 pm »

I will look at it, but I think I can make the first version work for tapered thread milling.  Inside or outside.  Just have to account for all those pesky details.  

~~~~~  OH!  ~~~~~

I just realized the problem.  The increment is along the line.  Neither vertical nor horizontal isn't it?  

In order to use it for thread milling you need to do a little trig to get the proper increment.  

Bob,

It was never designed for and I'm sure it won't yield results for tapered thread milling.
If there is currently no other plugin for tapered thread milling then that might be something for the future.

I tend to shy away from thread milling now that I've done a bit of it.  Most I do on the lathe or on the drill press with a tapping head.  Both are better IMO for the job when they will work.  I even hand tap often enough, although I tend to use machine taps for hand tapping.  Pipe threads (tapered threading) are a unique situation where they can be done on the lathe but not easily, not at all with the average tapping head, and can be quite hard by hand (inside).  I was not particularly looking for a tapered threading application, although one would be handy if it incorporated a built in table of standard thread forms.  

In this context I was only commenting on it because Gary seemed like he was using this plug-in for tapered thread cutting.  Then I realized the mathematical issue requiring some trig to get it exactly right.  Actually now that I think about it, just some basic geometry.  
« Last Edit: October 27, 2016, 15:55:49 pm by Bob La Londe » Logged

Getting started on CNC?  In or passing through my area?
If I have the time I'll be glad to show you a little in my shop. 

Some Stuff I Make with CamBam
http://www.CNCMOLDS.com
Garyhlucas
CNC Jedi
*****
Offline Offline

Posts: 1028


View Profile
« Reply #52 on: October 27, 2016, 18:38:35 pm »

Bob,
We have a tapping head and it works great up to 1/2". However I got a 5/8" thread mill because I have a thin thru hole 5/8-11 tap that we have to do by hand and it pulls up the edge badly. Then I have a two parts that need a total of 20 3/4" pipe taps done to a deep depth, and I need two of each. Not a fun job done manually!
In addition these parts repeat for every job, so now I am looking at hundreds of holes tapped.
Logged

Gary H. Lucas

Have you read my blog?
 http://a-little-business.blogspot.com/
dh42
Administrator
CNC Jedi
*****
Online Online

Posts: 4783



View Profile WWW
« Reply #53 on: October 27, 2016, 20:28:36 pm »

Hello

Quote
Thank you very much, all I have to do now is see if they fit into the existing code and overall algorithm.

I think it is possible to speed up calculation time by using an arc instead a circle for the "tool" shape (a circle as 3 arcs, so I assume CB test for the 3 arcs when testing "intersects"), but in this case the GetCentroid can't be used (it give not the center of the arc but the center of it's bounding box) and I think we must use the extrema min for y to get the tip position of the tool (certainly it also remove some useless calculations)

I think I'll add some other features (other tool shapes + extend limits) then make a plugin with this code, maybe it can be useful sometimes.

++
David
Logged
Garyhlucas
CNC Jedi
*****
Offline Offline

Posts: 1028


View Profile
« Reply #54 on: October 27, 2016, 22:49:32 pm »

Hey you programmer guys. If I load your CB file will the VB script you are testing get loaded and work?
Logged

Gary H. Lucas

Have you read my blog?
 http://a-little-business.blogspot.com/
lloydsp
CNC Jedi
*****
Offline Offline

Posts: 7209



View Profile
« Reply #55 on: October 27, 2016, 22:59:50 pm »

Gary,
Scripts must first be placed in the scripts folder, then loaded 'by hand' with the scripts menu -- if they're actual CB scripts.

If they're plugins, they must be installed in the plugins folder, then become 'active' as soon as CB is restarted.

Lloyd
Logged

"Pyro for Fun and Profit for More Than Fifty Years"
dh42
Administrator
CNC Jedi
*****
Online Online

Posts: 4783



View Profile WWW
« Reply #56 on: October 27, 2016, 23:16:36 pm »

Hey you programmer guys. If I load your CB file will the VB script you are testing get loaded and work?

It is a little "rough" to be used but I'll attach a version with a way to enter tool diameter and other things and I'll post it as a .vbs file.

++
David
Logged
dh42
Administrator
CNC Jedi
*****
Online Online

Posts: 4783



View Profile WWW
« Reply #57 on: October 27, 2016, 23:50:18 pm »

Hello

Unzip the file in attachment

in CB, go to menu Tools/browse system folder, you'll find a "scripts" folder
copy the unzipped file in the script folder.

to run the script, go to menu scripts/open then choose the toolcomp_usable.vbs file

in the drawing, select a polyline and only one

run the script with the menu Tool/compil(F5) of the script windows.

reply to the questions.

note the value for accuracy must be smaller than: tool_diameter/100.

so if you use a 1mm tool, accuracy must be < 0.01 (ex: 0.005 work) ; if not, you'll get strange results

only ball mills are supported a this moment.

If you found this script useful, I can quickly turn it to a plugin.

for inches users ; the values in boldface in the script can be changed to obtain more convenient default values for inches. (then save the script)

      tool_radius = val(inputbox("Tool Diameter: ","", 4))/2
      if tool_radius <= 0 then exit sub

      stepover = val(inputbox("Horizontal resolution: ","", 0.5))
      if stepover <= 0 then exit sub

      accuracy = val(inputbox("shape detection accuracy: ","", 0.02))
      if accuracy <= 0 then exit sub


++
David

* toolcomp_usable.zip (1.59 KB - downloaded 37 times.)
« Last Edit: October 27, 2016, 23:59:30 pm by dh42 » Logged
EddyCurrent
CNC Jedi
*****
Online Online

Posts: 3254



View Profile
« Reply #58 on: November 14, 2016, 11:20:18 am »

Thanks to David for the compensated toolpath algorithm, I could see that my mind had stupidly been focused on the tool centre point rather than the tool periphery  Roll Eyes Tongue

Anyway it gave me the opportunity to completely rewrite the plugin.
The biggest drawback at present is creating toolpaths to hog out the waste, this is proving problematic, so if anyone has ideas on that please let me know.

I left it like that for now because I know Gary has been waiting for this.

In this version;

1. roughing and finishing COMPENSATED toolpaths (Ball Nose only)  Cheesy
   roughing is optional.
2. values from the form are stored in Windows Registry
3. Z alignment options added
4. At first use it auto detects metric or inches and uses sensible default values.

Pictures show;

origianl profile in RED
compensated toolpath in PURPLE
tool tip in WHITE
helix toolpath in GREEN
roughing clearance in CYAN

You have to keep in mind that the tool is coming down vertically from the top which means any profile drawn cannot double back on itself.

Version 3 dll attached below.

* Profile2Helix_v3.zip (10.23 KB - downloaded 30 times.)

* finishing.jpg (373.73 KB, 1500x1479 - viewed 64 times.)

* roughing.jpg (314.57 KB, 1500x1368 - viewed 61 times.)
« Last Edit: November 14, 2016, 11:32:47 am by EddyCurrent » Logged
dh42
Administrator
CNC Jedi
*****
Online Online

Posts: 4783



View Profile WWW
« Reply #59 on: November 21, 2016, 01:27:14 am »

Hello Eddy,

I'm updating the website and language and it seems that on the last version the translation is not working.

++
David
Logged
Pages: 1 2 3 [4] 5
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.141 seconds with 19 queries.

Copyright © 2008 HexRay Ltd. | Sitemap