PDA

View Full Version : in calculating the tool path



Grumpy Mike
26-07-2010, 10:13 PM
I am writing a simple hole generator in Processing because I can run it on the Mac and there is very little CAM on the Mac. So I have this generator that will generate G code snippets. However when it comes to the D shaped hole I ave hit a snag. The yellow is the hole I want to draw and the orange is the tool path. The two orange circles represent the limit of the tool path before going horizontal. The question is how do I calculate the position of these holes, given the diameter of the hole can change as can the tool diameter and the depth of the D shape. My maths isn't up to is could someone help please.

2450

routercnc
26-07-2010, 10:38 PM
Hi Mike,

Just seen your post, but got to go. Sorry it's Wikipedia, but this might be a starter:
http://en.wikipedia.org/wiki/Circular_segment

Also, the corners will have a radius, not be sharp as per the yellow outline. Sure you knew that . . .

Grumpy Mike
26-07-2010, 11:03 PM
Thanks but that doesn't solve the problem. I know all that maths in the link, that's how I drew the figure I posted in the first place. The problem is when it comes to creating the path at the corners. The tool (circle) has to be tangential to both the curve of the hole and the straight line. Yes the sharpness of the corners will depend on the tool size.

Robin Hewitt
26-07-2010, 11:20 PM
Assuming you have the circle radius and the distance from the circle centre to the line centre you can do it with pythagorus.

X = square root (r squared - centre to centre squared).

Your x coordinates for the line ends are then circle centre x + X, and circle centre x - X

Or have I misunderstood?

Grumpy Mike
26-07-2010, 11:40 PM
Thanks but yes you have misunderstood. It is the center of the tools position I am after when it is at the end of the straight bit. It is where the tool path for the straight bit crosses the tool path for the circular bit. Or put it another way it is the difference in the angle between the center and the bit where the straight joins the curve (which I know as that was part of defining the shape) and the angle between the tool center and the center of the hole. These angles are not the same as I first thought.

irving2008
26-07-2010, 11:52 PM
make the centre of the circle 0,0

call the tool radius t, the radius of the actual hole R and the location of the chord is y = -d

the coordinate of the holes are x = +/- (R-t)sin(arccos((d-t)/(R-t))), y = -d+t

How are you programming this, there may be an easier way

Robin Hewitt
27-07-2010, 02:07 AM
Thanks but yes you have misunderstood. It is the center of the tools position I am after when it is at the end of the straight bit.


Well you just subtract the tool radius from the arc radius and add the tool radius to the line y co-ordinates before you do the pythagorus bit.

I've just been writing code to do much the same thing, decided pythagorus was a lot easier than applying the cosine rule even if it meant rotating the chord into the vertical and then back again :whistling:

Just to make it interesting I also spiral down into draft angles and hemispherical sections which is taxing my brain a bit but I'm getting there. Slowly. The G-Code is a bit whacky, I define the arc centre using I and J but the end co-ordinates are not necessarily on the same radius as the start. Dubiously G-code legal. I had to mod my mill driving code a bit before it would accept a spiral :beer:

Grumpy Mike
27-07-2010, 10:20 AM
Thanks irving, I worked out what I needed this morning on the drive in to work and I agree with you. I just got the sin and cos swapped over but that don't matter it just rotates it through 90 degrees.
It's good to have confirmation before I try and code it. I am using the free language called Processing, it runs on all platforms.

Do you think there would be any interest if I posted the final result? I am also working on a program to send a G code file to the miller. I wanted to use Replicator G but I can't get that to work reliably on my Mac, despite several email exchanges with the authors.

routercnc
27-07-2010, 01:40 PM
Hi Mike,

The above posts sound alot quicker than my solution which was:
Take the equation for a circle (x^2 + y^2 = r^2)
Take the equation for a straight line (y = mx + c)
these 2 lines are coincident when the x from the circle = x from the line, and y from the circle = y from the line, therefore substitute one equation into the other to create a quadratic equation (x^2 + mx + [c-r^2] = 0. Solve this using the quadratic formula to give x. Substitute back into either of the above to give y. This gives the 2 sets of coordinates of where the circle and line intersect.

This is a bit more generic than the solutions above, so should work for other related shapes, but is more complex!

irving2008
27-07-2010, 03:17 PM
Thanks irving, I worked out what I needed this morning on the drive in to work and I agree with you. I just got the sin and cos swapped over but that don't matter it just rotates it through 90 degrees.
It's good to have confirmation before I try and code it. I am using the free language called Processing, it runs on all platforms.

Do you think there would be any interest if I posted the final result? I am also working on a program to send a G code file to the miller. I wanted to use Replicator G but I can't get that to work reliably on my Mac, despite several email exchanges with the authors.Always interesting to see other people solutions to problems...

Grumpy Mike
27-07-2010, 05:17 PM
Thanks routercnc, that is in essence what the solution posted by irving actually is, only the equations have been bashed about already to give the solution. The only difference being that instead of using:-
The equation for a circle (x^2 + y^2 = r^2)
then you use the parametric equation for a circle of :-
x = r SIN(theta)
y = r COS(theta)

Wobblybootie
27-07-2010, 06:50 PM
Well, my contribution to this thread will be about as much use as tits on a kipper.

Reading it has seriously damaged my belief that I will ever master the maths involved in rudimentary CNC :sad:. I am beginning to think I should have listened to my old teacher instead of getting stuck into some practical human biology!!

Panic stricken in darkest Dorset!!:eek:

routercnc
27-07-2010, 09:22 PM
Hi Mike,

I suspected it was, but posted anyway. I wondered if the approach of simultaneous equations (for arbitrary shapes which can be defined by an equation, such as circle, rectangle, ellipse, lines, parabola etc.) might be useful in the future. Anyway, glad you're sorted. Thanks for posting - it was an interesting puzzle!

I'm impressed you do some of this by hand. When I got started on CNC I went straight to AutoCAD > dxf > toolpath generation > CNC so have never had to do much gcode creation, other then tweaking a few existing codes.

Wobblybootie - panic not! Assuming you can draw stuff in CAD, I suspect you can cut anything you want without getting bogged down in maths. I think there is a contingency of users who not only enjoy making stuff, but also enjoy the ownership and general challenge of CNC in general. I'm trying to resist falling into this latter category, and using it as a means to an end, but I must admit that it is drawing me in dammit. . . .

Grumpy Mike
29-07-2010, 10:28 AM
Thanks, I have now sorted out that bit, although that only generates the drawing on the screen rather then the G-code but I am working through that now.
You might want to see a first trial of my MF70 conversion, with just a pen tapped to the side of the miller.
http://www.vimeo.com/13095771
My ultimate aim is for small PCBs but I am working on automatic levelling correction at the moment as the Y axis tilts by about 0.2mm ever 40mm. I prefer to correct it by making corrections to the Z axis coordinates as I am more comfortable with that.

To Wobblybootie, it's never too late to learn. My wife does home tutoring for kids and I was discussing some mathematical formula with my son (on a visit home). One child overheard and apparently was amassed that this maths stuff was actually really used at work. By the way I spent a year living in Dorset (Weymouth) back in the 70s.
Thanks again for the support.

routercnc
29-07-2010, 01:44 PM
Hi Mike,

If the Y axis is slightly out, and it is difficult to level, then you could always bolt a piece of wood to the table, and run the cutter over it until it was levelled. This would then mean the PCB was flat relative to the cutter.

Also, in my earlier post#9 there was an error in the quadratic equation, although the approach is still valid.

By the way, can we help generate the Gcode for you? It would be a matter of minutes to draw in CAD and create the Gcode automatically. Do you know what post processor you are using on the Mac, and what it might be similar to on the PC? e.g. Mach3 etc. What are the dimensions and tool size?

Grumpy Mike
29-07-2010, 02:48 PM
Do you know what post processor you are using on the Mac, and what it might be similar to on the PC? e.g. Mach3 etc. What are the dimensions and tool size?

Not sure what a post processor is in this respect. I have an arduino based controller that drives the stepping motors and takes in G-code serially. Replacator G can sometimes feed it with G code from a file but it doesn't work very well so I am writing my own.
I have CAD.py and CAM.py but can't get all the dependent packages to install. Like most software of this ilk the writers are more interested in the next fun thing rather than making it install properly.

OK on the levelling system, yes I have seen this technique but it can't compensate for the waviness of the PCB itself. Where as an automatic calibrated system would.

irving2008
29-07-2010, 04:05 PM
OK on the levelling system, yes I have seen this technique but it can't compensate for the waviness of the PCB itself. Where as an automatic calibrated system would.
Not sure what PCB you're using but mine are pretty much flat - except the very cheap SRBP boards. what hold down method do you use?

routercnc
31-07-2010, 11:18 AM
Hi Mike,

Thought I'd explain the post processor bit, then thought I'd go the whole hog and show you one possible way to do it all in software (on a PC, sorry!)

The post processor is the bit which takes the gcode and tells the machine how to move. On a PC this might be Mach3 (Windows), EMC2 (Linux), for example.

But the complete chain, doing it is software, would look something like this (or this is how I would do it anyway):

1. CAD. Any cheap simple CAD program would do, but look for dxf output capability if possible.

2. Toolpath creation. I'm using Vectric Cut2D (117) which is excellent. Other s/ware also available, including CAMBAM which has free 50 trials. This takes the dxf drawing, and you then tell it which outline to cut, inside, outside, or on the line, and the tool diameter, and it will work out all the gcode you need. This can be a simple drawing or a complex drawing, it will work them all out. You can also drill holes, or create pockets, or rebates, all very easy to do. You then select the post processor you will be using, in my case Mach3, and the appropriate Gcode is created in a text file. I've attached one for Mach3 which might by chance work for you too. Do an air cut first! Part is dia 60mm, 3mm thickness, just as a trial.

3. Open up your post processor, Mach3 for me, and it will cut out the part on your machine. Mach3 uses the parallel port, which in my case goes into a DIYCNC system 3 board, and then on to the steppers.

This whole process took me about 10minutes, but I was stopping to take screenshots etc., so it is pretty quick. Life's a bit short to do this by hand - how were you thinking of creating the PCB layout gcode? Would you consider jumping ship over to a PC - it certainly is well supported with quality software and hardware.

Hope this helps . . .