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

Offline RussellT

  • Sr. Member
  • ****
  • Posts: 447
  • 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: 7126
  • 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: 167
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: 7126
  • 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: 7126
  • 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: 7126
  • 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: 7126
  • 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: 7126
  • 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: 7126
  • 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: 7126
  • 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: 7126
  • 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: 7126
  • 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: 7126
  • 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: 7126
  • 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.