Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: lakeguy2 on April 19, 2010, 10:44:56 AM

Title: mach's rounding of measurements?
Post by: lakeguy2 on April 19, 2010, 10:44:56 AM
How does mach handle the rounding of decimal points I am looking at using a .375 pitch 26 tooth drive gear(belt) with a 20:1 reducer, with a 200 step stepper. anyways, any formula using a .375 pitch belt vs. a .200 pitch will result in a long carried out decimal number. does mach round up, I assume all is from home. so .375 x 26 = 9.75 divided by 4000 = .0024375 per step in full step. I am not using or going to use micro-step. so to go one inch i need to move 410.34058  am i correct it will move 410 steps with an accuracy of .0024375
Title: Re: mach's rounding of measurements?
Post by: ger21 on April 19, 2010, 04:57:46 PM
Mach doesn't round any numbers off internally. If it did, you'd lose position over time. It'll move to the nearest step, 410 in your example.

Are you sure you're math is correct? I don't quite understand  what you're doing, but a 20:1 reduction should get you better than .002 per step.
Title: Re: mach's rounding of measurements?
Post by: lakeguy2 on April 19, 2010, 11:49:31 PM
.375 inch times 26 tooth gear(sync) equals 9.75 inches per revolution divided by 200 steps per revolution equals .004875 divided by twenty  equals .0024375 per step of stepper motor. so my calculations i believe are correct? ( a .2 pitch gear [ a 5 tpi lead screw] will round, end up with even numbers) divided by 200 .001 per step......... i didnt think it was rocket science but maybe it is?


Title: Re: mach's rounding of measurements?
Post by: lakeguy2 on April 20, 2010, 12:19:58 AM
sorry .04875 div by 20, none the less, no rounding? if i was walking towards a doorway and took 2 foot steps i would need to program myself somehow because i can only walk in two foot steps, and the door is closed, so i need to stop out of the door knobs reach or walk through the door? maybe that is all those posts ( i am losing steps) . am I correct im saying the only way this program will work is to use a drive that only runs in thousandths, what if you have a metric screw? or visa versa, a metric screw wont match a us. so the program just wont work and will crash if everything doesnt matc > exactly? :o
Title: Re: mach's rounding of measurements?
Post by: Hood on April 20, 2010, 03:13:02 AM
Mach will keep track of decimals to 16 positions if I recall but what it cant do is move a distance less than one step. What I am meaning by that is if you command a move to 1.5 x the distance of a step then Mach will just move just one, as commanding two would go past that point you commanded and it is impossible to command a move of half of a step. If you command a further move of 1.5 x your steps(in the same direction) it will move two steps as it kept track of the last move asked for and can now complete the full distance.
Hood
Title: Re: mach's rounding of measurements?
Post by: lakeguy2 on April 22, 2010, 01:52:36 AM
Am I understanding corrrectly? as in my first post all measurements are from home ( obviously).

410.34058 pulses per inch, say i need to go 1" and .003 thousandths? what if my encoder is in english, and I am using mm, how does mach handle the difference?

from your previous - post hood, mach will never go over a step.... always under?

i am not sure anyone undertsnds the question? i am not trying to move in 1/2 steps but the fact is 10 divided by 3 is what? how does mach deal with it?

the machine cannot possibly line up on 9.5 because 10 divided by 3's 3,6,9 only not 7  not 4, not 5,  I am thinking prime number thing.

I am not asking mach to go to an irregular position, but the fact the gearing is irregular, mach has to choose where it will or will not go.

perhaps rounding was not correct...... linear interpolation of axis movement?
Title: Re: mach's rounding of measurements?
Post by: Hood on April 22, 2010, 04:21:56 AM
You can set the steps per unit in motor tuning to 8 decimal places so I dont think you need to worry about the difference between imperial and metric.

Hood
Title: Re: mach's rounding of measurements?
Post by: Hood on April 22, 2010, 04:54:07 AM
To put it another way, with your figures above your steps per unit would be 4000/9.75= 410.256410256410256410256410245 etc
now divide  1 inch by that number and you get 0.0024375000000018281250000013710939 per step
Now instead if you enter to 8 decimal places  it would be 410.25641026 so 1 divided by that is 0.002437499999978618750001866210937 per step
Difference between the two would be 0.00000000000002315624999981474990625163293457
So for example if you moved a distance of 100 inches the rounded to 8 decimals would theoretically be out by 0.000000000950000000000714296153846646 inches
I dont think you need to worry about that, there is probably 1000 x more error in a tooth of your gear.

Hope my calcs are right ;D

Hood
Title: Re: mach's rounding of measurements?
Post by: zephyr9900 on April 22, 2010, 12:00:47 PM
Looks spot on to me, Hood.  ;D

Randy
Title: Re: mach's rounding of measurements?
Post by: RICH on April 23, 2010, 09:23:46 AM
Randy,
Your showing your age by posting a picture of a back scratcher.......!   :D
Ok, in all fairness, at least you don't need batteries to make it work....!  ;)
 :)  :)
RICH
Title: Re: mach's rounding of measurements?
Post by: lakeguy2 on April 23, 2010, 10:31:59 PM
Your math is correct, and your reasoning is also correct,that it doesn't realy matter.
however the answer is not 100% clear

from what i understand.......... mach will go to the nearest step without going over 410.1= 410, 410.2= 410, 410.3=410, 410.4= 410
410.5=410, 410.6=410, 410.7=410, 410.8=410, 410.9=410, 410.912432=410.

so my understanding is correct mach rounds down to the nearest whole decimal???????? without going over?

my machine has an accuracy of .0024375....

i understand that it is not a cumulative problem as all measurements are from home!!!!!!!!!!!!!!!!!!!!!!!

the question is DOES MACH ROUND UP OR DOWN!

I am sorry if i am hashing this over like crazy, but........ I am more interested in the answer, than if it really matters...

Hood, I did the math you posted... it is good.... and probly cant even measure it....... and doesn't matter,  the fact it carries out to 16 digits there is only one choice .0023475 plus or minus when it hits the magical 410.500000000000000000
Title: Re: mach's rounding of measurements?
Post by: Hood on April 24, 2010, 12:18:15 AM
so my understanding is correct mach rounds down to the nearest whole decimal???????? without going over?

my machine has an accuracy of .0024375....


Not to the nearest decimal, to the nearest step, you say you machine has a resolution of 0.002437 so if you command a move of 0.003 Mach will move to 0.002437. If you command a move back to zero then Mach will move back to zero.
This is not a problem with Mach but rather a problem with your resolution. If you need better accuracy then you need a  better resolution, simple fact is Mach can only move in increments of a whole step.

Hood
Title: Re: mach's rounding of measurements?
Post by: ger21 on April 24, 2010, 07:16:27 AM
Quote
from what i understand.......... mach will go to the nearest step without going over 410.1= 410, 410.2= 410, 410.3=410, 410.4= 410
410.5=410, 410.6=410, 410.7=410, 410.8=410, 410.9=410, 410.912432=410.

so my understanding is correct mach rounds down to the nearest whole decimal?HuhHuh? without going over?

Basically, Yes, without going over. But see below.

Quote
my machine has an accuracy of .0024375....

i understand that it is not a cumulative problem as all measurements are from home!!!!!!!!!!!!!!!!!!!!!!!

the question is DOES MACH ROUND UP OR DOWN!

Mach doesn't think in terms of fractional steps, only integer steps. So there is no rounding. You want to move 1". Mach3 knows that 411 steps will go over, so it moves 410 steps. There's no such thing as 410.2 steps.

What you're calling "rounding down" is not really rounding. So perhaps this whole thread is just an issue with terminology. :)
Title: Re: mach's rounding of measurements?
Post by: RICH on April 24, 2010, 10:56:10 AM
Quote
So perhaps this whole thread is just an issue with terminology.
Think you got it right Gerry.

410 steps per unit is just the # of steps as they relate to the mechanical movement over a unit of distance.
Resolution is just the inverse (1/410 ) or the mechanical movement for a single step. The calculated resolution is just a
an "ideal" Reference NUMBER.

There is a practical side of interpreting the resolution. Mechanical, software, and electrical ( system ) come into play as all is not perfect and influences
the accuracy. Accuracy defined as to how closely the "system" is to the ideal. The only way to improve resolution is to increase the steps required for the movement. Each of the above three has an effect on the actual accuracy of movement as it relates to the reference number and are related. Thus one would use the calculated resolution and then measure the actual. The user can make improvements but must keep in mind the practical influences of the above and the individual limitations associated with them.

RICH




Title: Re: mach's rounding of measurements?
Post by: zephyr9900 on April 24, 2010, 12:10:07 PM
Quote from: ger21 on April 24, 2010, 06:16:27 AM
Mach3 knows that 411 steps will go over, so it moves 410 steps. There's no such thing as 410.2 steps.

But if a move called for 352.7 steps, wouldn't Mach move 353 steps, Gerry?  Maybe I'm "mixing metaphors" here, but in displaying a vector line on a computer screen (which has discrete pixels) the rendering engine will always pick the X-Y pixel that is closest to the mathematical line no matter if it is to the right or left of the theoretical line.  Wouldn't Mach's motion engine do the same?  Mach obviously won't know whether a given motion is, for example, an inside or outside contour and thus which direction will be metal-safe, so I'd think that the only reasonable thing to do is rounding rather than truncating...

Randy
Title: Re: mach's rounding of measurements?
Post by: ger21 on April 24, 2010, 12:31:15 PM
Quote
But if a move called for 352.7 steps, wouldn't Mach move 353 steps, Gerry?

No.
As I said, there are no fractional steps, so a move won't call for 352.7 steps. A move will call for a given distance. Mach3 will send as many steps are needed to reach that distance, without exceeding it, to the nearest full step.
Title: Re: mach's rounding of measurements?
Post by: lakeguy2 on April 24, 2010, 01:03:52 PM
thankyou for explanation guys ;D

Stevo.....
Title: Re: mach's rounding of measurements?
Post by: zephyr9900 on April 24, 2010, 10:24:40 PM
As I said, there are no fractional steps, so a move won't call for 352.7 steps.
Gerry, I worded my question badly.  I meant "if the distance called for scaled to 352.7 steps".  I realize that steps are a quantum measurement. :)

A move will call for a given distance. Mach3 will send as many steps are needed to reach that distance, without exceeding it, to the nearest full step.
OK, I won't dispute that since you say it is fact and fact is fact.  But I wonder why.  In my professional life I have worked with stepper-driven systems for almost 30 years now (many with relatively coarse timing belt drive) and the controlling firmware's criterion has always been "what step is the closest to the destination?" and not "what step is <= the destination?".  It is just a surprise to me that Mach adopts the latter criterion... [insert shrug emoticon here]

Randy
Title: Re: mach's rounding of measurements?
Post by: ger21 on April 24, 2010, 10:31:17 PM
I didn't say it was a fact.

And looking back, I was probably wrong when I said without going over. ;)
As Hood said, it goes to the nearest step. But I'm not really sure now. I know I've read the explanation from Art before, but no longer have a clear memory of it.

Title: Re: mach's rounding of measurements?
Post by: zephyr9900 on April 24, 2010, 10:56:14 PM
I didn't say it was a fact.
Well, you did use bold and that made me take it as a fact... ;D  I would be interested to learn about the inner workings of Mach's motion engine if the information is available.  Do you have any pointers of how/where I would look?

Randy
Title: Re: mach's rounding of measurements?
Post by: HimyKabibble on April 24, 2010, 11:44:17 PM
As I said, there are no fractional steps, so a move won't call for 352.7 steps.
Gerry, I worded my question badly.  I meant "if the distance called for scaled to 352.7 steps".  I realize that steps are a quantum measurement. :)

A move will call for a given distance. Mach3 will send as many steps are needed to reach that distance, without exceeding it, to the nearest full step.
OK, I won't dispute that since you say it is fact and fact is fact.  But I wonder why.  In my professional life I have worked with stepper-driven systems for almost 30 years now (many with relatively coarse timing belt drive) and the controlling firmware's criterion has always been "what step is the closest to the destination?" and not "what step is <= the destination?".  It is just a surprise to me that Mach adopts the latter criterion... [insert shrug emoticon here]

Randy


Why on earth do you care?  In the real world, it makes absolultely no difference whatsoever whether it rounds up, rounds down, truncates or anything else.  In any real machine, the inaccuracies of the machine itself vastly exceed any positioning error due to rounding.  The stepper motors are nowhere near that accurate, especially when micro-stepping, and especially when the machine is actually moving under any load whatsoever.  The flex in the machine, inaccuracies in the screws, runout in the pulleys/gear/whatever, and backlash (which is NEVER zero) will completely swamp any error due to rounding up or down by a single fractional step.  Worrying about this is truly picking the fly poop out of the pepper...

Regards,
Ray L.
Title: Re: mach's rounding of measurements?
Post by: zephyr9900 on April 25, 2010, 12:17:12 AM
Why on earth do you care?
The answer is contained in my question, Ray.  ;)

Randy
Title: Re: mach's rounding of measurements?
Post by: stirling on April 27, 2010, 04:01:45 AM
with the OP steps per, compare commanded moves to DRO readings.

g0 x1.0 -> 0.9994
g0 x2.0 -> 1.9987
g0 x3.0 -> 3.0006

conclusion: Mach moves as near as it can to the commanded position - under or over. Simples. :)

Cheers

Ian
Title: Re: mach's rounding of measurements?
Post by: zephyr9900 on April 27, 2010, 08:49:20 PM
Mach moves as near as it can to the commanded position - under or over.
Ah, but there is so much more to it, Ian...  It is actually outside the realm of the original question, but multi-axis moves is where it gets interesting.  On linear moves, do you scale each axis independently, or deal with the dominant axis and have tests for the dependant axes on when to take a step?  And how do you deal with circular moves?  On the last system I was involved with, acceleration was handled with a lookup table.  Modern stepper motors all have a "knee" in their torque/velocity curves, and with an acceleration lookup table you can take advantage of the increased torque at lower speeds without overtaxing the motors above the knee.  It is those aspects in which I'm interested (I'm a mechanical engineer but very interested in all aspects of motion control so I know intelligently how to maximize system performance).  My familiarity with DIY CNC led to the adoption of the Allegro 3977 driver chip for several products at my last employer in preference to less integrated solutions...

Randy
Title: Re: mach's rounding of measurements?
Post by: ger21 on April 27, 2010, 09:11:35 PM
Quote
On linear moves, do you scale each axis independently, or deal with the dominant axis and have tests for the dependant axes on when to take a step?  And how do you deal with circular moves

Each axis has a final destination position, so wouldn't Mach3 have each axis get as close to this position as possible, for each axis?
Title: Re: mach's rounding of measurements?
Post by: zephyr9900 on April 27, 2010, 09:36:27 PM
Each axis has a final destination position, so wouldn't Mach3 have each axis get as close to this position as possible, for each axis?
Possibly, Gerry.  I'm kind of a technology magpie.  I try to learn as much as possible on many different subjects.  I have read about displaying vector lines on a monitor (quantizing a theoretical vector line in two dimensions--not very different than running stepper motors).  The algorithm I read about stepped along the major axis of the line, and looked at the root-mean-squared distance of the two adjacent pixels on the minor axis to determine which to light up.  That is one reason I wonder if Mach is blindly stepping each axis, or calculating at each quantum of the major axis whether or not to step the minor axes...

Randy
Title: Re: mach's rounding of measurements?
Post by: stirling on April 28, 2010, 04:39:52 AM
Ah, but there is so much more to it, Ian...
LOL - hang on a cotton pickin' minute! I offered my answer to the question that was asked. I'm well aware there are all sorts of complexities with interpolated motion but that wasn't the question here.

It is actually outside the realm of the original question, but...
Too right...

...multi-axis moves is where it gets interesting.  On linear moves, do you scale each axis independently, or deal with the dominant axis and have tests for the dependant axes on when to take a step?
The latter

And how do you deal with circular moves?
The same way, but with the added complexity that the dominant axis changes (depending on the length of the arc) as the path progresses.

On the last system I was involved with, acceleration was handled with a lookup table.  Modern stepper motors all have a "knee" in their torque/velocity curves, and with an acceleration lookup table you can take advantage of the increased torque at lower speeds without overtaxing the motors above the knee.  It is those aspects in which I'm interested (I'm a mechanical engineer but very interested in all aspects of motion control so I know intelligently how to maximize system performance).  My familiarity with DIY CNC led to the adoption of the Allegro 3977 driver chip for several products at my last employer in preference to less integrated solutions...

Great - but this has nothing to do with the question that was asked - I'm all for a discussion on the nitty gritty of motion controller design for the fun and interest but if that's what we're going to do let's have a new thread - then at least we can all be clear on what the question is before we attempt to answer it. :)

Cheers

Ian
Title: Re: mach's rounding of measurements?
Post by: zephyr9900 on April 28, 2010, 11:53:00 AM
Ian, too right.   :)

My thinking about the multi-axis moves came from the thought that in general, CNC moves are not Etch-A-Sketch-like X-Y-X-Y-X-Y and that

G1X5.
G1Y1.

G1X5.Y1.

G2X5.Y1.R15.

will all go to the same point, but the Y move will be generated differently in each case.

And then I admit really diverging (though that did come from discussions with our firmware guy about short moves taking place entirely in accel-decel rather than hitting full speed as long moves do, but that of course will only affect the steps' timing and not thier number...)

But I will heed your good judgement and shut up now.  ;D

Randy
Title: Re: mach's rounding of measurements?
Post by: stirling on April 28, 2010, 01:32:50 PM
Hi Randy

You obviously want to get deep into this (and good for you) so why not take a look at Dr. Jack Bresenham's work. He was really the father, guru and all round smart egg when it came to this stuff (amongst other things he developed the first algorythms for the rasterized display of vector graphics for IBM). Take a look at his algorythms for interpolation of lines, circular arcs, elipses and gawd knows what else. Then if you really want to blow your mind - take a look at Driving Stepper Motors with Quadratic Equations (all about acceleration) which is based on more of his work. Have fun  ;D

Cheers

Ian
Title: Re: mach's rounding of measurements?
Post by: BR549 on April 29, 2010, 10:03:43 AM
> Its remembered and done when it can do it..
>
> Think of it this way. A position counter of distance, where the
final output is a stepvalue, if the number of steps increases, a step
goes out, if it decreases, a reverse step is poutout..
>
> double movement = .000001;
> double totaldistance = totaldistance + movement
> totalsteps = (int) (totaldistance / stepsPermm);
>
> With this method, no step can ever be lost due to rounding..
>
> Thanks,
> Art
> www.artofcnc.ca
>
******************************************************************>
> Hi ART, I know we have had this converstion before but I am not
clear
> of the results( old age). WHat happens if Mach cannot make the
> commanded move with 1 step. Say the commanded move is .0001" and
the
> machine resolution is .001" per step. How is the differential
handled?
>
********************************************************************
>
> --- In mach1mach2cnc@yahoogroups.com, Art Fenerty <fenerty@>
wrote:
> >
> > Hi:
> >
> > No, mach wont skip anything. IT uses max number of decimals
> internally, but the DRO';s are set to display only 4. ( They can
be
> told to display 16).
> >
> > The DRO's though, are separate code. They dictate if the right
> number of pulses went out. If, at the end of a program, the axis
is
> wrong, but the DRO is right, then the machine lost pulses that
were
> sent. There can be no questions about it. In this case, where the
Z
> lost position ( it is usually the Z that does this on long 3d
> programs ) the Z aacel shoudl be turned down. Also, you migth
want to
> set a dir prechange of 5 or so in the motor tuning to make sure
its
> not a direction signal issue.
> > As a last report, try sherline mode in the ports & pins, this
> will limit you to 1/2 of the max velocity for any kernal speed,
but
> stretches the pulses out to a minimum of 40us. IF it doesnt lose
> then, the wiring shodul be checked for good coneection, or the
> optocouplers checked to see if they are too slow.
> >
> >
> > Thanks,
> > Art
> > www.artofcnc.ca