By continuing to use this site, you agree to our use of cookies. Find out more
Forum sponsored by:
Forum sponsored by Allendale Jan 24th

Stepper Motor Identification

All Topics | Latest Posts

Search for:  in Thread Title in  
Joseph Noci 126/10/2018 13:07:03
671 forum posts
890 photos

Whilst the gear isn't perfect, the error doesn't accumulate at one end!

That is true in part; the error is added to each subsequent tooth, not just to the end, but the net effect is as Alan describes - Imagine cutting 100 teeth of 1mm pitch onto the periphery of a blank 100mm in circumference. If you rotate the blank precisely 1 circumferential mm all the teeth fit fine, and start and end are in place. But step , to exaggerate, 1.1 mm, and the Final Cut ( Floyd, again..) will destroy the first few teeth.

The first tooth is in place - zero steps, the second is at 1.1mm from that, the third 1.1mm from the second and so on. The hundredth ( 100 teeth worth of stepper steps..) tooth is 100*1.1mm from tooth zero - 110 mm, instead of at 100mm, ie, back at tooth zero . So we just destroyed the first 10 teeth..

Obviously I have exaggerated the step per tooth error grossly to illustrate the point, and that is the effect of Alan's current integer problem - pedantic perhaps, since thinning the last tooth ( remember its opposite flank was cut in the first cut and so fixed in place) by 1.6 percent is probably irrelevant for the intended use. I have not checked the math to see if the 1.6% is correct - seems low at first , but if correct, ignore it perhaps.

The spread of the CONSTANT error is not the (only) problem - the final end point is - all the errors have added to themselves along the way.

The effect is made worse if the blank does more than one rotation - the error simply adds the integer excess onto the last position so it will accumulate all the way, thinning every tooth as it goes, UNLESS Alan's software can reset the pulse generator count accumulator back to zero at the zero tooth position, in which case the errors remain the same for each blank rotation.

Interpolation such as with Bresenham's still spreads the error, but adds or subtracts it from the pulse stream so that it does not accumulate sequentially on itself. At some point the count error with be fractionally ahead, then behind, and occasionally spot on.

Joe

Edited By Joseph Noci 1 on 26/10/2018 13:07:30

SillyOldDuffer26/10/2018 13:17:13
5767 forum posts
1230 photos
Posted by Michael Gilligan on 26/10/2018 12:44:01:
Posted by SillyOldDuffer on 26/10/2018 12:06:35:

Here's a perfect 127 'toothed' 100mm diameter circle:

metric127errorperfect.jpg

.

An excellent post, Dave yes

But one question, if I may be so bold: ... In what sense is that division 'perfect' ?

So far as I am aware, very little to do with circles can be perfectly represented in the digital domain.

MichaelG.

I've got a good lawyer, and he says I obviously meant this definition: 'loosely, To bring nearer to perfection' - as per the Shorter Oxford Dictionary.

Truth is, I've been rumbled again! The circle is far from perfect, it's an approximation.

A better description: the circle is the best that can be drawn in QCAD using ISO 60559:2011 double precision floating point arithmetic, but then it was crunched by me into a 1024x728 pixel JPEG image for storage on the forum. When displayed the Browser and the Forum rescale it again, on my big screen it appears at 495× 371 pixels, you probably see something different.

Sort of makes my point about rounding error though. If you can't detect the effects rounding may not matter.

Dave

John Haine26/10/2018 13:54:59
3082 forum posts
162 photos
Posted by Michael Gilligan on 26/10/2018 12:44:01:
Posted by SillyOldDuffer on 26/10/2018 12:06:35:

Here's a perfect 127 'toothed' 100mm ....

So far as I am aware, very little to do with circles can be perfectly represented in the digital domain.

MichaelG.

Or indeed in the analogue!

SillyOldDuffer26/10/2018 14:07:54
5767 forum posts
1230 photos

Posted by Joseph Noci 1 on 26/10/2018 13:07:03:

...

The spread of the CONSTANT error is not the (only) problem - the final end point is - all the errors have added to themselves along the way.

The effect is made worse if the blank does more than one rotation - the error simply adds the integer excess onto the last position so it will accumulate all the way, thinning every tooth as it goes

...

Interpolation such as with Bresenham's still spreads the error, but adds or subtracts it from the pulse stream so that it does not accumulate sequentially on itself. At some point the count error with be fractionally ahead, then behind, and occasionally spot on.

Joe

Edited By Joseph Noci 1 on 26/10/2018 13:07:30

Thanks Joe, that makes sense.

While I was aware rounding can cause errors, I'd persuaded myself not to compensate for them on the basis that the effect would always be trivial in practice. Now I'm not so sure, particularly now you've pointed out that blanks may be cut with several rotations. If Alan's example were continued indefinitely, his teeth would be removed entirely, never a happy event!

While there are plenty of times when rounding error wouldn't matter, I think this is worth fixing. Once the algorithm is decided the Arduino doing a bit more arithmetic to compensate is neither here nor there, and far better that the user doesn't have to worry about the possibility of having his gears seriously thinned.

Not quite sure how best to go about it. Bresenham can't be applied directly as I understand it. I shall have to get my thinking cap on.

Problem:

Given a stepper motor, micro-step and gear ratio combination, and the requirement to divide by 'n', what is the best way of compensating for rounding error by finessing the number of microsteps taken to move a blank to the next division such that any error cannot accumulate. Hmmm.

This is why I never finish anything. I'm easily distracted and my 'to do' list is already 3 pages long...

Dave

Joseph Noci 126/10/2018 14:17:49
671 forum posts
890 photos

Hi Dave,

"Given a stepper motor, micro-step and gear ratio combination, and the requirement to divide by 'n', what is the best way of compensating for rounding error by finessing the number of microsteps taken to move a blank to the next division such that any error cannot accumulate. Hmmm."

That is taken care of nicely by Bresenham's line draw algorithm.

It appears you are quite comfortable writing code for these things - I do not know anything about the Arduino dev environment, 'sketches', and the like ( sketches are what I make on scrap paper before I built the part..). However, if you are game, I can give you the C code as we used on the Hobber and on the Lathe ELS for the implementation of Bresenhams. It might not fit your application directly, but may help your grasp?

If so, probably best via email I guess.

Joe

SillyOldDuffer26/10/2018 14:39:07
5767 forum posts
1230 photos
Posted by Joseph Noci 1 on 26/10/2018 14:17:49:

Hi Dave,

"Given a stepper motor, micro-step and gear ratio combination, and the requirement to divide by 'n', what is the best way of compensating for rounding error by finessing the number of microsteps taken to move a blank to the next division such that any error cannot accumulate. Hmmm."

That is taken care of nicely by Bresenham's line draw algorithm.

It appears you are quite comfortable writing code for these things - I do not know anything about the Arduino dev environment, 'sketches', and the like ( sketches are what I make on scrap paper before I built the part..). However, if you are game, I can give you the C code as we used on the Hobber and on the Lathe ELS for the implementation of Bresenhams. It might not fit your application directly, but may help your grasp?

If so, probably best via email I guess.

Joe

Yes please Joe.

I have Ammeraal's 'Programming Principles in Computer Graphics', which has a good description of Bresenham's Line and Circle algorithms, and how he deals with a straight line is easy enough. I don't see how to apply it in this case though. Probably me!

I'll send you a PM with my email address shortly.

Many thanks,

Dave

John Haine26/10/2018 14:59:35
3082 forum posts
162 photos

As I understand it Arduino sketches are essentially C++....

SillyOldDuffer26/10/2018 15:40:23
5767 forum posts
1230 photos
Posted by John Haine on 26/10/2018 14:59:35:

As I understand it Arduino sketches are essentially C++....

Yes, that's right. For simplicity most Arduino tutorials stick to 'C' syntax which is a sub-set of C++ and plenty powerful enough most of the time. Under the bonnet the compiler is full blown C++ and modern, so you can write things like:

char s[] = "Hello World";
for (auto ch: s)
    Serial.print( ch );

Mainly because memory is limited C++ is distinctly cramped on a small microcontroller. For example, you shouldn't use heavy duty C++ features like the Standard Template Library. I find being able to write C++ classes jolly useful though.

Dave

John Haine26/10/2018 15:45:50
3082 forum posts
162 photos

So hopefully Joe's C code should be usable then?

duncan webster26/10/2018 16:41:35
avatar
2588 forum posts
33 photos

This is all getting a bit heavy for my od brain. Surely all we need to do is to work out how many steps from zero to each tooth, make sure the integer arithmetic rounds to the nearest rather than always down, then subtract the steps to the previous tooth. Something like

unsigned long lastSteps = 0, nextSteps = 0;

unsigned int teeth, increment;

for (teeth = 1; teeth <=127; teeth++)

{

wait to be told to move to next tooth;

nextSteps = (teeth*4800*40+63)/127); //the +63 makes it round to nearest

increment = nextSteps - lastSteps;

lastSteps = nextSteps;

whatever function moves the motor by increment steps;

}

I've tried the logic on a spreadsheet and it works, the nextStep position is never more than 0.5 a motor step out, an error of <0.5/1512 = 1 part in 3024

SillyOldDuffer26/10/2018 17:07:40
5767 forum posts
1230 photos
Posted by duncan webster on 26/10/2018 16:41:35:

This is all getting a bit heavy for my od brain. Surely all we need to do is to work out how many steps from zero to each tooth, make sure the integer arithmetic rounds to the nearest rather than always down, then subtract the steps to the previous tooth.

...

I've tried the logic on a spreadsheet and it works, the nextStep position is never more than 0.5 a motor step out, an error of <0.5/1512 = 1 part in 3024

My old brain isn't up to much either either and I admit Duncan's suggestion looks much better than my first attempt! Not only is my effort far more complicated, it also plonks corrections in the same positions each time round the blank. Not ideal, because certain teeth get particularly thinned in order to make the others better.

To answer John's point about re-using Joe's code, more likely I shall have to adapt rather than cut and paste it directly, but just seeing how he did it will save a lot of time. As it's not arrived yet I shall have a play with Duncan's suggestion first.

Dave

Neil Wyatt26/10/2018 17:14:18
avatar
Moderator
17889 forum posts
706 photos
77 articles
Posted by SillyOldDuffer on 26/10/2018 14:39:07:

I have Ammeraal's 'Programming Principles in Computer Graphics', which has a good description of Bresenham's Line and Circle algorithms, and how he deals with a straight line is easy enough. I don't see how to apply it in this case though. Probably me!

If you plot number of teeth as X and number of steps as Y, then draw a line from the origin to the point that represents a full rotation.

If you go along X in steps of of one tooth bressenham will give you the best Y value to use distributing the error evenly.

Neil

Neil Wyatt26/10/2018 17:19:32
avatar
Moderator
17889 forum posts
706 photos
77 articles
Posted by duncan webster on 26/10/2018 16:41:35:

This is all getting a bit heavy for my od brain. Surely all we need to do is to work out how many steps from zero to each tooth, make sure the integer arithmetic rounds to the nearest rather than always down, then subtract the steps to the previous tooth. Something like

Bressenham does this without having to keep track of how far you have come.

Basically you round to the nearest integer position keep track of the cumulative error, when this becomes more than half a step, you take an extra step, adjusting the error by -1 so it is now just less than half a step the opposite way.

The advantage is you don't need to now your start or end points, but just the slope of your intended path.

Neil

SillyOldDuffer26/10/2018 17:24:54
5767 forum posts
1230 photos
Posted by Neil Wyatt on 26/10/2018 17:14:18:
Posted by SillyOldDuffer on 26/10/2018 14:39:07:

I have Ammeraal's 'Programming Principles in Computer Graphics', which has a good description of Bresenham's Line and Circle algorithms, and how he deals with a straight line is easy enough. I don't see how to apply it in this case though. Probably me!

If you plot number of teeth as X and number of steps as Y, then draw a line from the origin to the point that represents a full rotation.

If you go along X in steps of of one tooth bressenham will give you the best Y value to use distributing the error evenly.

Neil

Ah, daylight! Even better, I'll try that first.

Thanks,

Dave

Michael Gilligan26/10/2018 18:25:20
avatar
15707 forum posts
687 photos

Posted by SillyOldDuffer on 26/10/2018 13:17:13:

[ ... ]

Sort of makes my point about rounding error though. If you can't detect the effects rounding may not matter.

Dave

.

Thanks, Dave ... I can live with that ^^^ and I particularly like your inclusion of the word 'may' yes

I will now happily leave you clever chaps to your coding.

MichaelG.

SillyOldDuffer26/10/2018 21:32:18
5767 forum posts
1230 photos

My entry for the Most Boring Post contest:

756 1512 1512 1512 1512 1511 1512 1512 1512 1512 1512 1511
1512 1512 1512 1512 1511 1512 1512 1512 1512 1511
1512 1512 1512 1512 1511 1512 1512 1512 1512 1512 1511
1512 1512 1512 1512 1511 1512 1512 1512 1512 1511
1512 1512 1512 1512 1512 1511 1512 1512 1512 1512 1511
1512 1512 1512 1512 1511 1512 1512 1512 1512 1512 1511
1512 1512 1512 1512 1511 1512 1512 1512 1512 1511
1512 1512 1512 1512 1511 1512 1512 1512 1512 1512 1511
1512 1512 1512 1512 1511 1512 1512 1512 1512 1511
1512 1512 1512 1512 1512 1511 1512 1512 1512 1512 1511
1512 1512 1512 1512 1511 1512 1512 1512 1512 1511
1512 1512 1512 1512 1512 1511 1512 1512 1512 1512

Starting 756 is a bug. Otherwise this is Bresenham stepping a 127 tooth gear. I'll try Duncan's method next, I think the advantage may be it's more obvious how it works, even if it's slower.

Dave

Edited By SillyOldDuffer on 26/10/2018 21:32:45

Alan Charleston28/10/2018 07:06:07
85 forum posts
20 photos

Hi,

Thanks for all the comments. I don't think lost steps are a problem. I've reduced the speed to about 60rpm to reduce the acceleration when starting each step and the registration pin on the head engaged the built in indexing plate at 0 degrees before and after 40 steps of 9 degrees each.

If I was confident of programming the Arduino I think I'd follow Duncan's approach and calculate the number of cumulative pulses for each tooth as the gear is cut, subtract the total for the previous tooth and round it to the nearest integer.

Alas I'm not. I have tried for years to get my head around programming the Arduino but I've got a teflon brain that nothing computer oriented will stick to. I'm in the frustrating position of understanding enough to see what can be done but not being able to do it.

That's one of the reasons I'm keen to stick with the simple solution I outlined in my last post. I take the point that it's probably not wise to do all the residual pulse correction on consecutive teeth but rather spread them out over the whole tooth. I can do that by using the two outputs from the Stepduino as I outlined earlier. I need some way of easily swapping between the two outputs as the gear is cut. My first thought was to have a plug from each of the outputs and switch the motor plug between the two at regular intervals throughout the cutting operation. It would be better however to have a rotary switch between the controller and a single plug. The operation of the switch would need to carry out the operation shown in the photo.

switch.jpg

It would need to switch the 4 wires of the motor between the 4 outlets from controller one and the 4 outlets of controller two. I don't know what the name of such a switch is which makes it hard to find out where to get one. Can anyone tell me?

Regards,

Alan

John Haine28/10/2018 09:42:29
3082 forum posts
162 photos

Alan, I'm afraid that won't work, for two reasons. First, stepper drivers do not like having their outputs disconnected when energised and may just retire from the fray. Second, when you disconnect the stepper it will jump to the nearest whole step from whatever microstep state it was in so you will lose the accuracy you are trying to achieve.

I suggest that you should look at the software that was written for the Arduino divider controller described in MEW. I'm sure someone here can point you to it. If that works anything like my Ward indexer, you just configure it with the number of (micro)steps per full rev of the divider head spindle, than tell it on the mmi how many divisions you want and it does all the rest for you. Or you could just go to **LINK** and buy one of his controllers as I did. You would need to buy a stepper driver but as I pointed out those are very cheap and easy to get.

SillyOldDuffer28/10/2018 12:26:04
5767 forum posts
1230 photos
Posted by John Haine on 28/10/2018 09:42:29:

Alan, I'm afraid that won't work, for two reasons. First, stepper drivers do not like having their outputs disconnected when energised and may just retire from the fray. Second, when you disconnect the stepper it will jump to the nearest whole step from whatever microstep state it was in so you will lose the accuracy you are trying to achieve.

I suggest that you should look at the software that was written for the Arduino divider controller described in MEW. I'm sure someone here can point you to it. If that works anything like my Ward indexer, you just configure it with the number of (micro)steps per full rev of the divider head spindle, than tell it on the mmi how many divisions you want and it does all the rest for you. Or you could just go to **LINK** and buy one of his controllers as I did. You would need to buy a stepper driver but as I pointed out those are very cheap and easy to get.

Agreed. Also, as I know to my cost, there's a third reason! My stepper-controller connects the motor via a 5-pin DIN connector. If the motor is plugged after the unit is powered on the resulting electrical misbehaviour is enough to corrupt the Arduino's memory, and the Arduino has to be reloaded from scratch.

The MEW Article is based on Gary Liming's original and it was widely discussed on the forum. I think I'm correct in saying that Gary's code doesn't correct for rounding error, no doubt because usually it doesn't matter. (See my earlier post showing how the error is distributed.)

An alternative is my stepper which uses a keypad rather than nested menus. As a result of your question I will modify it to minimise rounding error later this week. Unfortunately the hardware build instructions aren't newbie friendly because they're out of date.

Neither my effort or Gary's would transfer easily to the StepDuino hardware because they both use input buttons.

If I were you, I'd write some simple code to drive the StepDuino and try it. There's a good chance rounding error won't matter in practice.

Dave

Neil Wyatt28/10/2018 13:01:51
avatar
Moderator
17889 forum posts
706 photos
77 articles

My advice is to decide what level of precision you need to machine to and multiply the number of steps to give about ten times that resolution.

You can then use integer division by the number of teeth required and divide the number of step moves outputted by 10.

N.

All Topics | Latest Posts

Please login to post a reply.

Magazine Locator

Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!

Find Model Engineer & Model Engineers' Workshop

Latest Forum Posts
Support Our Partners
Allendale Electronics
emcomachinetools
Warco
ChesterUK
cowells
Eccentric July 5 2018
Eccentric Engineering
Subscription Offer

Latest "For Sale" Ads
Latest "Wanted" Ads
Get In Touch!

Do you want to contact the Model Engineer and Model Engineers' Workshop team?

You can contact us by phone, mail or email about the magazines including becoming a contributor, submitting reader's letters or making queries about articles. You can also get in touch about this website, advertising or other general issues.

Click THIS LINK for full contact details.

For subscription issues please see THIS LINK.

Digital Back Issues

Social Media online

'Like' us on Facebook
Follow us on Facebook

Follow us on Twitter
 Twitter Logo

Pin us on Pinterest