Author Topic: Maths help please: Approximating a Flat Iteratively  (Read 13236 times)

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Maths help please: Approximating a Flat Iteratively
« on: June 12, 2019, 04:03:27 PM »
I want to cut spanner flats on round stock in my CNC lathe. I can position the chuck in 1 degree increments and approach the stock with an axially mounted end mill.

I envision positioning the chuck, feeding the end mill a certain X feed, withdrawing it, rotating the chuck to the next angular position and feeding the end mill in a calculated but different X feed then repeating the process.

Now this will make approximations to  flats which are actually a series of scallops with size of scallop depending on end mill diameter and the fine or coarseness of the increments of chuck rotation.

Note: the lathe only can move the cutter in Z (ie towards the chuck) and X (ie towards the axis of rotation) there is no Y movement which would make life so much simpler !

But I can't get my head around the maths of developing a 'general case' that will allow me to write an algorithm with parameters to define the variables. As I see it the parameters are:

a/ Cutter diameter
b/ Angular increment of chuck position
c/ Distance of flat from axis of rotation
d/ Length of flat

My brain hurts, can anyone help?

Andrew Mawson
East Sussex

Offline Sea.dog

  • Full Member
  • ***
  • Posts: 232
  • Country: gb
  • Up Spirits!
Re: Maths help please: Approximating a Flat Iteratively
« Reply #1 on: June 12, 2019, 04:12:47 PM »

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #2 on: June 12, 2019, 04:23:45 PM »
That's a very interesting link Seadog, but the two case they show one has a Y axis and the other has a continuously rotatable C axis allowing milling while, unlike mine that the chuck can be rotated to position and locked for milling at that angular place.
Andrew Mawson
East Sussex

Offline Sea.dog

  • Full Member
  • ***
  • Posts: 232
  • Country: gb
  • Up Spirits!
Re: Maths help please: Approximating a Flat Iteratively
« Reply #3 on: June 12, 2019, 05:41:23 PM »
Knowing nothing about G code I had no idea if there was anything of use there.

Thinking on, I'm wondering about how to generate a cam profile for a specific path, from a radiused follower. My gut intinct is, that for a point, it would travel as an inverse of the diametric portion bounded by the chord (i.e. one of the flats).

That's as far as my brain has let me go, so far. This link is relevant to the problem I believe.

https://www.cs.cmu.edu/~rapidproto/mechanisms/chpt6.html


Offline efrench

  • Full Member
  • ***
  • Posts: 213
Re: Maths help please: Approximating a Flat Iteratively
« Reply #4 on: June 12, 2019, 09:16:27 PM »
I suspect you can use the Pathagorean theorem.  a = distance from the center of the rod to the midpoint of the flat plus the radius of the cutter. b = distance from the midpoint of the the flat to the center of the cutter.  c = distance from the center of the rod to the center of the cutter.  Rotation angle for each cut can be determined from the above. 

For example: If the length of the flat is 10mm, then for the first cut at the edge of the flat, b = 5mm.

I'd post a diagram, but Photobucket says I can only have 250 images and I need to delete 400  :(

p.s. There are quite a few sites for determining cusp height.

p.s.p.s The a,b, and c in my post are not the same as the a,b, and c in the first post   :palm:
« Last Edit: June 13, 2019, 01:26:01 AM by efrench »

Offline chipenter

  • Hero Member
  • *****
  • Posts: 909
  • Country: gb
Re: Maths help please: Approximating a Flat Iteratively
« Reply #5 on: June 13, 2019, 01:34:34 AM »
Spanner flats are hex normally , 360/6 = 60 degrees , af/2 - difference in dia/2 or radius = infeed , length of cut is dependant on the cutter size and hex size .
Jeff

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #6 on: June 13, 2019, 05:56:58 AM »
OK I've had a few more brain cells recover over night - let me simplify the issue:

Using the notation in the attached sketch, I have a bar of stock Radius R, I want to cut a flat of across flats size 2 x S so S = half the AF size

(You have to imagine the whole sketch rotating about the centre of the circle so keeping the cutter travel on the X axis but tilting the required spanner flat)

By rotating the stock in finite increments between +A degrees and -A degrees the axially mounted cutter will approach along the X axis for a travel of  X mm which will vary from a maximum of X = R to a minimum of S (no allowance for cutter diameter but that's easy)

So between the limits of +A degrees and -A degrees I need to evaluate X for any given angle (B in the sketch) to which the bar has been rotated

Now I think that  the 'half chord length'  C is given by:

C= Square Root{R*R - S*S)

But going from there to solving X for any angle of B within those limits is eluding me at the moment  :scratch:
Andrew Mawson
East Sussex

Offline djc

  • Jr. Member
  • **
  • Posts: 85
Re: Maths help please: Approximating a Flat Iteratively
« Reply #7 on: June 13, 2019, 06:45:31 AM »
As I see it the parameters are:
a/ Cutter diameter
b/ Angular increment of chuck position
c/ Distance of flat from axis of rotation
d/ Length of flat

At the beginning, simplify the problem and forget cutter diameter (or assume it is zero). Work out the x-coordinate of the polygon side as it rotates from vertical to having its vertex aligned with x-axis.

Then add in correction for cutter diameter.

Your last two (c & d) are not independent parameters; one is derived from the other.

(1) Call number of polygon sides n. Hence interior angle subtended by the chord (polygon side) is 360/n and interior half angle is 180/n (e.g. 90 and 45 degrees for a square). Call radius of circumscribed circle of polygon r. As we will see later, this does not necessarily have to be your stock diameter.

(2) With stock rotational axis at (0,0), when one side of polygon is vertical, edge of polygon has x-coord = r cos(180/n). Call this m. When vertex of polygon lies along x-axis, 'side' of polygon has x-coord = r.

So that gives you two (three, due to symmetry) points along the side of the polygon. The challenge is to work out the intermediate points.

(3) Rotate your polygon side clockwise about (0,0) some angle a (limits/bounds of a are + or - 180/n as above). Draw the perpendicular bisector of your rotated polygon side, which should pass through (0,0). The distance from the midpoint of your polygon side to your rotational axis is m as above. The (horizontal) distance x from the rotational centre to the intersection of the polygon side with the x-axis is x = m/cos a.

This is the general formula for the intersection of the polygon side with the x-axis. Check it works by putting in a = 0 [x = m = r cos (180/n)] and a = 180/n [x = r].

(4) Now you have to add in an additional dx to cater for cutter diameter. Draw a circle centred on the x-axis of radius c (cutter radius). Draw a tangent to that circle on the left hand side of the circle, such that the angle between the tangent and the x-axis is acute above the axis. Call this angle 90 - a. Now draw a line from the centre of the circle to the point of tangency (of length c). The angle of this line with the x-axis is a.

The extra offset required due to the cutter is dx = c / cos a.

So for any angle a, the x-coord of the cutter (of radius c) is x + dx.

(5) This works up to the point where the vertex of the polygon is tangent to the cutter. This will always be at an angle a less than 180/n. If your stock diameter is bigger than the circumscribed circle of your polygon, you now have to roll the cutter around the vertex of the polygon in order to complete its shape. The maths here becomes more involved, so we will leave it there just for now and assume our stock diameter equals the circumscribed circle of the polygon.

(6) I think you can show that the vertex of the polygon is tangent to the cutter when tan a = (r sin (180/n))/ (m + C). This means that if your stock is exactly the diameter of the circumscribed circle of the polygon, you can stop at this point (i.e. you do not have to keep incrementing a until it reaches 180/n) as any further angular increment of the rotational axis will only cut air.

The bigger the cutter diameter, the less the scallops will be.

Could I ask you a favour in return? Please work out a formula relating cutter diameter, cut spacing and scallop height.

Other homework: consider what happens for n < 3. Consider what happens when n is not an integer.

Doing maths like this is how I imagine long division was in Roman times. I can send diagrams if you pm me your email address.


Offline efrench

  • Full Member
  • ***
  • Posts: 213
Re: Maths help please: Approximating a Flat Iteratively
« Reply #8 on: June 13, 2019, 02:43:55 PM »
Here's the diagram.  For any position of the cutter, the distance from the center is simply a squared + b squared. Note: The relationship between a, b, and c doesn't change when the diagram is rotated so the center of the cutter is on the centerline.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #9 on: June 13, 2019, 03:28:32 PM »
Thanks for the suggestions chaps but there are too many differing letter systems now in this thread. Sticking to the letters on my last diagram in post #6 I need to evaluate the length X for varying angles B as the stock is rotated between it's limits.

X will have a minimum where X = S and a maximum where X =R as the stock rotates. Don't worry about cutter diameter etc that is the easy bit.

I'll repeat the sketch below
Andrew Mawson
East Sussex

Offline efrench

  • Full Member
  • ***
  • Posts: 213
Re: Maths help please: Approximating a Flat Iteratively
« Reply #10 on: June 13, 2019, 04:03:50 PM »
Your 'X' is my 'c'.   A right triangle is always formed from a line perpendicular to the center of the flat, the end of the flat, and the axis of the lathe. As the cutter is moved tangent to the flat, the distance 'b' changes, but 'a' doesn't.  'b' varies by the stepover amount.  'c' squared is simply 'a' squared plus 'b' squared.  Use sine/cos to determine the spindle angle.

Offline RussellT

  • Hero Member
  • *****
  • Posts: 520
  • Country: gb
Re: Maths help please: Approximating a Flat Iteratively
« Reply #11 on: June 13, 2019, 04:19:30 PM »
My mathematician son says

"The last post in the thread (from early this morning) I don't fully follow, I think because it's assuming more understanding of the setup than I have, but the penultimate post seems fairly clear or at least the question in the diagram does and simple trig on the two right angled triangles with common edge L and angles A and B leads me to believe

X = R (cos A/cos B)

Does that help?"

I did discuss the setup briefly with him because I'm not convinced by your suggestion that allowance for cutter diameter is easy, it's complicated by the fact that the cutter doesn't just cut on the centre line and so you need to align a tangent of the cutter with the spanner flats.

Russell
Common sense is unfortunately not as common as its name suggests.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #12 on: June 13, 2019, 04:50:00 PM »
Russell please thank your son, I think he's cracked it  :thumbup:

I need to model the cutter / tangent issue and get my head round that bit, but to my simplistic way of thinking an infinitely small cutter just slides along the flat with no issue so a 10 mm cutter just slides along 5 mm further in so X needs 5 mm adding  :scratch:
Andrew Mawson
East Sussex

Offline djc

  • Jr. Member
  • **
  • Posts: 85
Re: Maths help please: Approximating a Flat Iteratively
« Reply #13 on: June 14, 2019, 04:07:57 AM »
I need to model the cutter /
tangent issue and get my head round that bit, but to my simplistic way of thinking an infinitely small cutter just slides along the flat with no issue so a 10 mm cutter just slides along 5 mm further in so X needs 5 mm adding

Your diagram, whether enhanced or no, does not capture what is going on because your polygon edge is always vertical. This will not be so. It means the terms you want us to use are not helpful. This is also why you are incorrect in your constant cutter offset.

Your part geometry is rotating around your coordinate system (which is fixed). Your cutter is not rotating relative to your coordinate system.

I am sure you have CAD. Draw a pentagon with its right side vertical inscribed in a circle. Draw the perpendicular bisector of this vertical line, starting at the line and going to the centre (so there are six lines so far on the drawing). Draw your cutter touching the edge of the pentagon. Draw a standard set of axes over this in a different colour. Lock the axis layer. Rotate the six lines on the pentagon layer some arbitrary angle (if your software will do rotate and copy at the same time, so much the better). Move the cutter circle horizontally only until it touches the edge of the pentagon again. The point of tangency will now be above the horizontal centreline of the cutter.

PDF attached. Diagram numbers relate to previous post.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #14 on: June 14, 2019, 05:58:42 AM »
I do take your point, but I suspect that at a practical level (and particularly where the cutter diameter is small in comparison the the stock diameter) the error between tangential contact and diametrical contact will be acceptable.

This is a work in progress and entirely experimental, and I suspect that I would do best to get the simple case working then apply any sophisticated corrections later as things evolve dependant on the results that I get. And those corrections will probably be based on your calculations for which I thank you  :thumbup:

In built into the Siemens 820T controller (1990 remember) is an arcane mathematical series of '@' commands that theoretically should allow for all the trig required, but is a nightmare to get going and understand, and I suspect that they will take a considerable proportion of the controls CPU time so best to keep it minimalistic initially !

Andrew Mawson
East Sussex

Offline RussellT

  • Hero Member
  • *****
  • Posts: 520
  • Country: gb
Re: Maths help please: Approximating a Flat Iteratively
« Reply #15 on: June 14, 2019, 07:04:31 AM »
Hi Andrew

I will pass on your thanks.

djc's diagram shows exactly what I was referring to with cutters, where the cutter is shown in his diagram it isn't cutting on the centre line.  I understand your point about tool diameter, as you mention earlier an infinitely small cutter would solve the problem.  The trouble with infinitely small cutters is that they're difficult to find and quite fragile. :lol:  Of course an infinitely large cutter would also solve the problem but you may struggle to fit it in the lathe. :D

As a more serious question from my position of knowing very little about the capabilities of CNC lathes could this be done with a conventional lathe tool?  I have in mind moving the tool in and out 6 times for each rotation of the work.

Russell
Common sense is unfortunately not as common as its name suggests.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #16 on: June 14, 2019, 07:05:55 AM »
I've tried graphically to estimate the real life error using a piece of 25 mm stock and a 10 mm end mill. Cutting a hexagon, so six sided, the worst case occurs when the wanted flat is inclined at  75 degrees.

The discrepancy between tangential cutting and diametrical cutting works out at 0.1711 mm and obviously will reduce with larger stock and or smaller end mills.

So in a real life situation where I am putting two opposite spanner flats for an 18 mm spanner on a CAT40 pull stud for my vertical mill that represents a 0.95% error - so I don't think that the spanner will mind much!

That said, once I get his working I will try and perfect it as per DJC's musings, as it would be nice to get it spot on despite the fact that using finite angular movements rather than continuous cutting will always result is scalloping errors

Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #17 on: June 14, 2019, 07:09:18 AM »
Here's my attempt at the problem. This uses the tangent relationship between cutter and machined face and should be exact.

In the attached Figure 1, S is the centre of the spindle and C is the centre of the cutter. The blue line shows the face being machined, with the centre of the face rotated anticlockwise by an angle alpha from the line between S and C.

The distance from the centre of the workpiece to the face (half the "across flats" distance) is d. The radius of the cutter is r.

The distance between S and C, x, is given by the equation:

x = (d + r) / cos(alpha)

Note that alpha is zero when cutting the centre of the face. To machine a face, step the spindle angle (alpha) from -30 degrees to +30 degrees or so and bring the cutter in to a distance x calculated from the above equation at each step.

If you're making fewer than six faces, you'll need to vary alpha over a slightly larger range, since the face will be a bit longer.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #18 on: June 14, 2019, 07:15:33 AM »


As a more serious question from my position of knowing very little about the capabilities of CNC lathes could this be done with a conventional lathe tool?  I have in mind moving the tool in and out 6 times for each rotation of the work.

Russell


Russell, the Traub WAS capable of that and they had a special software package available (at enormous cost!) for the Mitsubishi control to do exactly that. I suppose it depends how quickly the X axis slide can reciprocate and maintain an accurate position, or alternatively how slowly you can rotate the work and get a decent cut. More room for future experimentation, so no chance to get bored with the lathe just yet  :lol:
Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #19 on: June 14, 2019, 08:52:41 AM »
Now to calculate the positions of the scallops and how deep they will be.

Fig 2 shows the same geometry as in the earlier post, but this time we are interested in the distance u between the centre of the machined face and the tangential point of contact with the cutter. This is the point where the cut is the deepest and corresponds to the bottom of the scallop.

A bit more simple trigonometry gives:

u = (d + r) tan(alpha)

It's a bit tricky to visualise the effect of the cuts in Fig 2, since the workpiece face is rotating. Fig 3 shows the situation from the point of view of the workpiece. Here a number of cuts have been made at different spindle angles alpha. I've used a small cutter and a large step in angle to show the cusps (pointy bits) between the cuts more clearly.

Due to the tan(alpha) term, the cutter positions become further apart as alpha increases, and the cusp height increases accordingly. However, as you can see from Fig 3 (which is roughly to scale), this effect is small for values of alpha likely to be used in practice.

Finally, how high will the cusps be?
 
Fig 4 is an enlarged version of part of Fig 3, showing two cutter passes spaced by w.

A bit more geometry gives the cusp height h above the bottom of the scallop as:

h = r - sqrt(r2 - (w/2)2)

It would be straightforward to put these equations into a program or spreadsheet to calculate values for conditions of interest.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #20 on: June 14, 2019, 09:03:57 AM »
Archie, you are a handy chap to have about, welcome to the forum  :clap:
Andrew Mawson
East Sussex

Offline efrench

  • Full Member
  • ***
  • Posts: 213
Re: Maths help please: Approximating a Flat Iteratively
« Reply #21 on: June 14, 2019, 04:05:49 PM »
You all are working too hard  :D Review my posted diagram.  By using one leg of the right triangle as a line perpendicular to the midpoint of the flat, there is only one right triangle to solve for. The cutter is always tangent to the flat.

Offline Sea.dog

  • Full Member
  • ***
  • Posts: 232
  • Country: gb
  • Up Spirits!
Re: Maths help please: Approximating a Flat Iteratively
« Reply #22 on: June 14, 2019, 04:20:45 PM »
Doesn't your diagram assume the cutter is moving across the flat? It's only movement is, in fact, is along the diameter of the workpiece.

Offline chipenter

  • Hero Member
  • *****
  • Posts: 909
  • Country: gb
Re: Maths help please: Approximating a Flat Iteratively
« Reply #23 on: June 14, 2019, 04:21:44 PM »
Use a 90 degree tool holder and the scallop is on the Z axis .
Jeff

Offline efrench

  • Full Member
  • ***
  • Posts: 213
Re: Maths help please: Approximating a Flat Iteratively
« Reply #24 on: June 14, 2019, 04:38:56 PM »
Doesn't your diagram assume the cutter is moving across the flat? It's only movement is, in fact, is along the diameter of the workpiece.

No, the cutter only moves towards or away from the spindle axis.  The diagram shows the relative positions of the cutter, the flat, and the spindle axis. Rotate the diagram if you want to see the cutter at its actual position at any point along the flat.

Offline RussellT

  • Hero Member
  • *****
  • Posts: 520
  • Country: gb
Re: Maths help please: Approximating a Flat Iteratively
« Reply #25 on: June 15, 2019, 04:13:17 AM »
You all are working too hard  :D Review my posted diagram.  By using one leg of the right triangle as a line perpendicular to the midpoint of the flat, there is only one right triangle to solve for. The cutter is always tangent to the flat.

I think your maths is right but incomplete.  In your diagram B varies with the angle to which the workpiece is rotated.  You need to use
 A * tan(angle) = B and then apply Pythagorus.

Russell
Common sense is unfortunately not as common as its name suggests.

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #26 on: June 15, 2019, 05:58:44 AM »
I wondered how large the scallop cusp heights would turn out to be, so I plugged some numbers into my equations. The answer is - surprisingly small!

Using figures from Andrew's post above - 25mm diameter stock with 18mm spanner flats, a 10mm diameter cutter and 1 degree angle steps - the cusp heights go from 0.0015mm near the centre to 0.0029mm near the edge of the face. I don't think many spanners would complain about that.

Larger cutters reduce these heights further, and it should even be possible to use larger angle steps and still get good results.

I've attached a simple spreadsheet for anyone who wants to play with the figures. This a zip file containing a .xls document. If you have any trouble with it, please let me know.

So it looks like the technique is viable, in theory at least. Now we need to see how it works in practice, so, Andrew, over to you   :wave:

The generating equation x = (d+r) / cos(alpha) is nice and simple, and I notice that your Siemens controller has a cosine function, which I'm sure it would love to use. Dividing a constant by a cosine shouldn't put much strain on the CPU, especially since it only has to be done once for each spindle angle.

I would find it fascinating to see a machine produce a flat surface from circular movements. It's one of those "impossible" things, like the drill that makes square holes.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #27 on: June 15, 2019, 10:27:38 AM »
So it looks like the technique is viable, in theory at least. Now we need to see how it works in practice, so, Andrew, over to you   :wave:

It was my intention to do just that today but I got diverted - nice weather so I started paint stripping the trolley for the vacuum former and was about to start spraying when a load of straw bales arrived and needed stacking. When they were done and the spraying almost finished some friends arrived so now time to feed the pigs and I'm knackered and need a shower and wait for a decent hour to knock back a few Old Speckled Hens. So hopefully tomorrow , but I have already started keying in the embryo of a program with loops doing the angular stepping :clap:
Andrew Mawson
East Sussex

Offline efrench

  • Full Member
  • ***
  • Posts: 213
Re: Maths help please: Approximating a Flat Iteratively
« Reply #28 on: June 15, 2019, 12:58:10 PM »
You all are working too hard  :D Review my posted diagram.  By using one leg of the right triangle as a line perpendicular to the midpoint of the flat, there is only one right triangle to solve for. The cutter is always tangent to the flat.

I think your maths is right but incomplete.  In your diagram B varies with the angle to which the workpiece is rotated.  You need to use
 A * tan(angle) = B and then apply Pythagorus.

Russell

Or B varies by the step over amount and determines the rotation angle.  Which method you choose depends on  whether you want a consistent cusp height or a consistent rotation angle.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #29 on: June 16, 2019, 11:54:06 AM »
So I spent much of the day chasing a silly bug in my embryo program (it wouldn't loop and denied knowing the loop back destination - solved, too many zeros on a line number  :bang:)

But I don't think the maths is right. I set up some variables:

R10 = starting angle
R11 = angle span
R12 = angle step
R13 = stock diameter
R14 = End Mill diameter

Then having selected the correct tool the @714 command ensures tool changing is completed before I set it spinning I move to a safe distance from the  stock

Then I rotate the stock to the starting angle and calculate the term  X = (D+R)/ Cos (Angle) and move the cutter to that point at feed rate then move in rapid back to my safe height.

Then I calculate the next angle by adding the step, and if the angle span hasn't been exceeded, loop back and do it all over again.

For testing purposes I I have kept the cutter well clear of the stock and temporarily added a 500 millisecond delay when the cutter is at full depth so I stood a chance of reading its position on the screen. This has given me the following X values which obviously are not correct:

A=00, X=30.000
A=05, X=30.114
A=10, X=30.462
A=15, X=31.058
A=20, X=31.925
A=25, X=33.101
A=30, X=34.641
A=35, X=36.623
A=40, X=39.162
A=45, X=42.426
A=50, X=46.671
A=55, X=52.303
A=60, X=60.000

So no metal cut yet, but then no cutters broken either  :thumbup:

I suppose that it's possible that the cosine function work in radians rather than degrees, but I can find absolutely no reference to radians in the book of words, and all other values are expressed in degrees. :scratch:

If anyone can please critique the code - I attach a copy and also the relevant crib sheet - I'd be most grateful




Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #30 on: June 16, 2019, 12:30:26 PM »
I checked your A and X values against my spreadsheet, and they are spot on, so your cosine calculation is working fine. However, the angle A is relative to the centre of the flat, so you need to vary it from -30 to + 30. Try changing your first line to R10 = -30 (assuming your controller can handle negative numbers). You'll also need to change the second line to R11 = 30.

Also, D is half the AF distance. You'll need another variable for AF (which will be less than the stock diameter), and you'll need to divide that by 2 to get D.

The stock diameter only determines the angle you start and finish at (R10 and R11).

It's looking good though. Excellent work  :clap:

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #31 on: June 16, 2019, 12:43:28 PM »
Archie that's sort of good news, but the M19 Sxx command will only take positive numbers from zero to 359.9 degrees or it errors.

I suppose some sort of offset is needed to shift the angle into the -30 to +30 before calculating the cosine  :scratch:
Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #32 on: June 16, 2019, 12:58:55 PM »
Ok, I wondered if that was the case.

Does the cosine function accept negative numbers? If so, give it (R10-30). You might need to calculate this in another variable.

Looking at your video, the cutter seems to cut away from the workpiece, not towards it.

The calculations assume X is zero when the cutter axis is in line with the spindle axis, and that positive X is towards the back of the machine.

Which way is the X positive X direction, and where is your X zero? You might need an X offset to correct for this.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #33 on: June 16, 2019, 01:06:20 PM »
I've no idea if the trig functions will take negative angles - that one for experiment.

X=0 is the centre of the spindle (if no tool offset applied) but travel away from the spindle, (ie larger diameters) is +ve so another correction to apply !

Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #34 on: June 16, 2019, 01:26:22 PM »
I've had another look at the video, and I now reckon the X zero position and direction are OK, What was confusing me is that the "stand clear" position is inside the travel range. This should be OK once the cosine sign issue is sorted out.

If the cosine function doesn't accept negative numbers, it would be possible to take the absolute value, since cos(x) = cos(-x). Hopefully that won't be needed though.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #35 on: June 16, 2019, 02:56:25 PM »
It looks like negative angles ARE acceptable to the Cosine function.

I've modified the program to give the -30 offset and taken my luck in my hands and cut metal  :bugeye:

We have a flat, but displaced in X by about 9 mm so tweaking required

Youtube video uploading as I type

Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #36 on: June 16, 2019, 03:57:06 PM »
Andrew, that's brilliant  :clap:  :clap:  :clap:

I don't know why the flat is offset. Your program looks OK to me. I wonder if your X zero is offset for some reason. Is there a work offset or tool compensation in effect? Perhaps you could move to X0 (with a suitably large value of Z, of course) and see if the centre of the cutter lines up with the centre of the spindle. Another check would be to move to X = (25+10)/2 to see if the cutter just touches the edge of the stock.

I assume the cutter diameter really is 10mm. Looks pretty close though, compared with the 25mm stock.

Other than that, I can only think of something weird happening in the program...


Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #37 on: June 16, 2019, 04:48:42 PM »
Archie,

T9 (the endmill) has a suitable Z offset but it's X offset is zero. Yes it lines up with the spindle centre when sent to X=0, and is a true 10 mm diameter.

I'll do a few more experiments tomorrow and see what's happening.
Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #38 on: June 16, 2019, 05:04:13 PM »
Watching the video again, I notice that when the cutter moves to R1, the "stand clear" position, and the spindle rotates (lines N0115 and N0120), a small cut is made. R1 = R13 + 10 = 25 + 10 = 35, which should keep the cutter well clear of the work.

With a 25mm diameter stock and a 10mm diameter cutter, the point of contact will be at X = (25+10)/2, exactly half that figure. Strange coincidence?

Is it possible that X is in "diameter mode", so when you ask it for 10mm it assumes you want 10mm diameter and only moves 5mm?

I know some lathe DROs can be switched between reading radius and diameter...

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #39 on: June 16, 2019, 05:10:39 PM »
Theoretically it's always working in diameter mode but as I say I'll experiment in the morning.
Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #40 on: June 17, 2019, 02:30:45 AM »
Quote
Theoretically it's always working in diameter mode

OK, I hadn't realised that. The answer is just to double the X values, of course. Alternatively, you could use the values for cutter diameter and AF distance (R14 and R15) instead of their half values (R5 and R16). This will have the same effect and save a couple of variables and a couple of lines of program.

The angle span of +/- 30 degrees is OK for hexagons, but a bit small for flats, and will leave material at the end of each flat. You can use the spreadsheet I posted earlier to calculate exact values, but a value of +/- 40 degrees (span, R11=80) should be a good default and will work in most situations.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #41 on: June 17, 2019, 05:24:14 AM »
OK a few more tests this morning:

Cutter compensation is not working as I'd expected for this end mill. As Archie observed when it was at a supposedly safe distance of 35 mm  with zero X tool compensation I'd expected its centre to be at 35 mm, so with 25 mm stock a clearance of 5mm. In fact it was taking a light cut. Now actually the stock is 1" or 25.4 mm and it's taking that 0.4 mm off.  So 25.0 plus 5 (half cutter diam) mean that the centre of the cutter is actually at 30 mm but no where in the compensation table is it told that the diameter is 10 mm so what the heck is going on.

Just to check my sanity I selected Tool #1 whose compensation values have been set in the old fashioned way of turning a diameter and measuring it so I know it's right. Telling it to go to 25.4 mm in X sure enough it's bang on the periphery of the stock.

So back to the Tool #9 compensation values : I decided to treat it like a lathe tool, set the stock and cutter both spinning and took a light cut and used the inbuilt compensation facility to transfer the measured diameter to the tool compensation table. As I would have expected the value now was very close to 1/2 of 120 mm at 4.910 mm defining the cutting periphery of the tool not it's centre. So why the heck when the compensation value was zero was it not putting the axis of the tool on position? Something very odd.

However now the positioning system is placing the cutting edge and not the tool centre tool diameter is I assume no longer relevant :scratch:

So, but Archie please confirm, I can drop the R term entirely and as we are working to diameters use the whole AF size rather than half of it  :scratch:
Andrew Mawson
East Sussex

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #42 on: June 17, 2019, 07:04:40 AM »
OK That didn't work   :bugeye:


I've lost the nice flat (all be it displaced) and got an unwanted curve  :ddb:


Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #43 on: June 17, 2019, 07:56:57 AM »
Andrew, you still need the R term to make the calculations work.

I suspect tool compensation is a red herring. The tool originally just touched the surface of the stock (taking off 0.4mm) when X was set to 35mm. This is what you'd expect if X is in diameter mode, since 35/2 = 25/2 (stock radius) + 10/2 (cutter radius)

I've attached what I think your program should look like. I put your .jpg file though an OCR program and corrected all the conversion errors I could see, but there may still be some lurking (eg letter O vs zero), so beware.

Have a try and see what it does.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #44 on: June 17, 2019, 09:26:58 AM »
Many thanks for that Archie. I had to re-type it as there were various embedded characters that the controller objected to but I attach a .JPG and a text file of what I used.

All I changed was the R1 stand clear location which isn't used in the calculations, and the Z position to actually cut metal.

Initially I ran it with the tool offset still with an X value of 4.91 but there was no cutting, so I set it back to zero and ran it again and I'm afraid we are still getting a curve as per the picture.

There may be some confusion regarding the diameter mode. If X is commanded to go to (say) X=35 the currently selected tool is moved so that it's tip (taking into account length compensation) will cut a diameter of 35 mm so yes it's really gone to 35/2 = 17.5 mm but the display will say 35.

With an end mill that is axially mounted it's axis when the tool carrier is moved to X=0 should be co-axial with the spindle axis of rotation, (there may be a very small error but we are talking .01 mm or so) So with zero X compensation the centre line of the end mill is programmed,  but for this nominal 10 mm cutter, with 4.910 X compensation brings the cutting periphery nearest the spindle centre to be the programmed point.

(I hope that wasn't too confusing  :scratch:)
Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #45 on: June 17, 2019, 10:24:02 AM »
This is getting very strange  :bang:

One of the odd things is that the curve in your latest photo doesn't seem to be symmetrical - it's deeper on the left. Since you are stepping from 0 to 80, with a cosine offset of 40, it should be the same on both sides of the centre angle, whatever the actual shape of the curve. Is the cutter at centre height?

I don't know if your controller has any debugging facilities, but it would be nice to check what some of the variables are actually doing.

In your earlier post, you provided a table of X vs A values. Would it be possible to do the same for values of R10 (spindle angle) and R4 (the final X value)?

This will probably turn out to be something quite simple, but it may take some tracking down.  :scratch:

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #46 on: June 17, 2019, 10:48:30 AM »
Silly idea coming up...

I've just been staring at the code to see if I can see anything that would make the cosine term asymmetrical. When you made the first flat (albeit in the wrong place), you subtracted a constant value of 30 from the angle R10. The corresponding line now uses a variable:

N0135 R17= R10-R11/2 (offset angle value)

Is it possible that the controller is interpreting this as

R17 = (R10-R11)/2

ie doing the operations in strict order instead of using the normal arithmetic conventions? Surely not. But it would give a lopsided cosine function which might account for the asymmetric curve.

Perhaps it would be worth replacing R11/2 with 40, just to rule that out.

Clutching at straws, I know.  :scratch:

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #47 on: June 17, 2019, 11:03:57 AM »
Not a silly idea at all, and I will try it out - at the moment my head is spinning staring at your original .png image of the issue. What is clear to me looking at the drawing, the centre of the end mill MUST be programmed not the cutting edge or the maths won't work.

Give me an hour or so and I'll be back  :clap:

But meanwhile look at this excel spread sheet that is giving odd results  :scratch:

It is an XLS file but renamed to be able to be uploaded
Andrew Mawson
East Sussex

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #48 on: June 17, 2019, 11:30:47 AM »
OK there was a copy / paste error in the spreadsheet where excel had adjusted references  :bang:

Corrected version attached again its an XLS file renamed as txt
Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #49 on: June 17, 2019, 11:45:47 AM »
Yes, you're right. :thumbup: The calculations are all based on the centre of the cutter, so tool corrections must be turned off. If you need to make a correction for actual cutter diameter, you need to change the value of R14 in the code.

The spreadsheet values look fine to me.

BTW, I don't know if you've come across the method of making absolute references by putting $ signs in front of the row and/or column labels (eg $C$2 and $C$3), but it can save a lot of time. If you enter

=(($C$2/2)+($C$3/2))/C6

in the top cell (D6), you can copy and paste it into the rest of the cells in that column. The C6 references will be modified appropriately, but the C2 and C3 references will stay the same.

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #50 on: June 17, 2019, 12:07:23 PM »
 :clap: :clap:  Whoopee   :clap: :clap:

We have a flat :thumbup: :thumbup:

Thanks Archie, and of course everyone else who contributed - what a result, but what a journey - I was running out of 1" bar  :lol:

Yes the order of calculation MUST be strictly left to right and ignoring good old BODMAS

As for the intricacies of Excel I'm glad to say all my professional report writing and playing with spread sheets was over 15 years ago :)

Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #51 on: June 17, 2019, 02:25:28 PM »
Well done, Andrew. That's an excellent result  :clap:

It's not surprising that the controller doesn't handle expressions fully. It's quite a tricky business https://en.wikipedia.org/wiki/Shunting-yard_algorithm and needs a lot of resources for a machine of that vintage. Hopefully the instructions warn you about this though.

According to the spreadsheet I posted earlier, the cusp height for the conditions you used should be between 0.038mm near the centre and 0.081mm near the edge. I don't know how that compares with the reality...

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #52 on: June 17, 2019, 03:17:32 PM »
Archie I'm really chuffed  :thumbup:

I did try setting the starting angle to 180 to do the 'other flat' of the spanner flats, but it faulted out saying a destination was beyond the soft limits. Not had time to trace what's happening  but presumably the cos function isn't happy in that / those quadrants.

The finish to be honest is rather rough - the poor old end mill has been being used without coolant so that I could see what is happening, so it's not as sharp as it was!

However I did put a vernier guessing stick on the one flat and work out what the AF would have come out to and it's 18.02 mm so not to bad without any tweaking.

Many thanks for your help with this little conundrum .
Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #53 on: June 17, 2019, 03:48:47 PM »
It's probably not the cosine function itself that's unhappy, but rather that the cosine of 180 degrees is -1. Your X distance will therefore work out negative, which will probably make the tool try to emerge from the front of the cabinet  :bugeye: Good for soft limits, eh?

You'll probably need to subtract an additional 180 degrees from the value you give to the cosine function.

It's good to know the dimensions are coming out as expected  :D

Offline PekkaNF

  • Hero Member
  • *****
  • Posts: 2523
  • Country: fi
Re: Maths help please: Approximating a Flat Iteratively
« Reply #54 on: June 18, 2019, 01:37:25 AM »
Happy that you guys got it sorted very elegant.


These PLC controllers don't quite work as expected and sometimes even reading the programmer guide does to reveal all. I hope I never need to get too deep on them again. I remember few ocassion when same Siemes S5 machine code produced different results with different model CPU:s. I.E. the instruction was supported, but result was different. Once on night sift at the site the function call would return garbage (worked on the office with different CPU), tracking the error was not too easy and in the end we had to write subsitute function in ASM, because it was time critical. Brown pants moment. Felt really awkward. We did not want to rewrite the code (no-one wants fork), but sometimes you really have to get dirty to get system up and running. I think we ended up supporting internally two codes, because customer did not want to upgrade CPU (cost of spares and all).

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #55 on: June 18, 2019, 07:24:54 AM »
As you suspected Archie, it was the fact that the X travel was going negative that was upsetting things. I ended up forming the modulus of the evaluated travel distance by multiplying by -1 if it was less than zero, as the controller doesn't appear to have a modulus function.

I had to do a few more tweaks regarding loop values now that the angle are bigger, but now it works for start=0 and start =180 degrees. I suspect that it will fault if asked to cut a flat where the angle goes through 359.99 but that's for the future - as predicted the flat AF is 18.02 so that's good :thumbup:

This is just one feature of a series to make a part (CNC CAT40 special Beaver Pull Stud) to try and avoid second ops off the lathe
Andrew Mawson
East Sussex

Offline Archie Opteryx

  • Jr. Member
  • **
  • Posts: 16
Re: Maths help please: Approximating a Flat Iteratively
« Reply #56 on: June 18, 2019, 03:28:15 PM »
Andrew, those flats look very good, It's great to see the final result  :clap:
The spanner seems to be a good fit on them too. They could almost have been made for it  :lol:

I'm curious to know how you intend to program the rest of the part. Are you going to write all the g code for it by hand, or are you going to use a CAD program to generate the other features?

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #57 on: June 18, 2019, 03:52:20 PM »
Archie, I've had an Autocad sketch of the stud that I drew up years ago as these studs are now unobtainable. It will be a two operation process. Firstly I will thread a bit of suitable steel with an M16 stud with those flats on the chuck side, which will be parted off with sufficient length to make the rest of the part.

This will then be screwed into an M16 female 'receiver' in the chuck, and the stud shape turned to completion, the stud unscrewed (using those flats!) and the next blank inserted.

The thread I have modelled in FeatureCAM and the stud end I have yet to model. I have written a post processor for FeatureCAM that generates passable code for the Siemens control. I will probably hand stitch the bits of code together.


Andrew Mawson
East Sussex

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: Maths help please: Approximating a Flat Iteratively
« Reply #58 on: June 18, 2019, 06:13:49 PM »
So.. I googled "CNC CAT40 special Beaver Pull Stud", found lots of pictures of similar looking things, and I still have no idea what it's supposed to do  :scratch:

Looks nice though!
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #59 on: June 19, 2019, 02:37:00 AM »
The 'pull stud' is what pulls the 40 taper tool shank tightly into the female socket in the milling machine spindle. It is gripped by a special finger collet. The arrangement performs the same function as the draw bar on a Bridgeport manual mill. Your interact of course has no draw bar as its presumably a QC30 nose?

Using the pull stud allows for automatic tool changing. There are many shapes in use and Beaver of course HAD to design their own  :ddb:
Andrew Mawson
East Sussex

Offline AdeV

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2434
  • Country: gb
Re: Maths help please: Approximating a Flat Iteratively
« Reply #60 on: June 19, 2019, 03:37:25 AM »
 :doh: Obvious when you know! Yes, you're right, my Interact has the QC30 spindle which uses a ring to push the tool into the taper from below. No automatic tool changes for me!
Cheers!
Ade.
--
Location: Wallasey, Merseyside. A long way from anywhere.
Occasionally: Zhengzhou, China. An even longer way from anywhere...

Offline awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Maths help please: Approximating a Flat Iteratively
« Reply #61 on: June 22, 2019, 09:36:55 AM »
Having got this program cutting a pair of flats @0 and 180 degrees, I though that before I 'put it away' I'd try and cut a full hexagon, so flats at 0, 60, 120, 180, 240 and 300 degrees.

Well it didn't  :bang:

Only 0 & 180 worked - the rest calculated increasingly large opposite sign cutter movements ie outwards. It dawned on me that the cos function needed to be limited to angles between plus and minus half of the span term, (so +-40 degrees usually) where as the rotation of the work piece needs the actual angle being used. So I split it up into two formats with a variable for the cosine function and a separate variable for the angular positioning.

This worked fine until I came to the case of a flat at 300 degrees, 300 plus the angle (usually 80 degrees) is larger than the M19 spindle positioning function will accept, being limited to 0-359.9 degrees - so another tweak was added to correct this, and lo and behold it is now a general function that will cut a flat at any angle I dictate in the R10 variable on the first line.

So have a picture of a hexagon  :ddb:
Andrew Mawson
East Sussex