Go Down

Topic: Stepper Changing No. of Steps for position? (Read 131 times) previous topic - next topic

Tbdanny

Jan 12, 2019, 12:02 pm Last Edit: Jan 12, 2019, 12:22 pm by Tbdanny
Hi all,

I've got a NEMA17 stepper motor driving a turntable on my model railroad, and I'm having a bit of trouble calibrating it.  What happens is that I'll set the number of steps required for it to turn to a certain track, in code, and that will work for the first 2-3 times.  But after that, with no changes to the code or hardware, it suddenly starts coming up short.  This has happened multiple times, to the point where I've recalibrated the whole thing about 9 times.  Each time, the motor starts undershooting after a few test goes.  I am using microstepping, set at 16 microsteps per step.  This gives me the accuracy I need (allegedly).

The only thing I can think of for this change in behaviour could be that the stepper motor or the A4988 driver for it is warming up.  Could this be the case, or is there some other thing that could be causing this?

I also use a hall effect sensor for the initial alignment of the tracks, with a magnet embedded in the end of the turntable bridge.  Could this not be as accurate as I need?

Robin2

#1
Jan 12, 2019, 12:23 pm Last Edit: Jan 12, 2019, 12:24 pm by Robin2
You need to post your program.
Also post a link to the datasheet for your stepper motor. Nema17 does not tell anything about its electrical specs.

By how many steps is the motor failing to reach its position?

Are you disabling the stepper driver at any stage? That is a great way to miss steps.

Is there any gearing between your motor and the turntable? Gearing can introduce backlash.

The positioning with microsteps is not as accurate as with full steps as it relies on the motor coils pulling against each other. Have you the opportunity to align your tracks with full-step positions of the motor?

What scale is your train and what level of position error is acceptable (+/- X mm)?

For my N-Gauge track I have a system to extend a pin the stop the table. When the track on the table touches the pin the Arduino knows to stop moving the motor.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Tbdanny

#2
Jan 12, 2019, 12:35 pm Last Edit: Jan 12, 2019, 01:51 pm by Tbdanny
Robin,

I've attached the program, as it's too long to post in a code block here.  As for your other questions:

By how many steps is the motor failing to reach its position?
Usually 4 or 8.

Are you disabling the stepper driver at any stage? That is a great way to miss steps.
No, the stepper driver remains on throughout.  If it is being disabled, it's not from a program point of view.  I have the enable pin soldered to ground.

Is there any gearing between your motor and the turntable? Gearing can introduce backlash.
There's no gearing.  The turntable bridge sits directly on the stepper motor shaft.

The positioning with microsteps is not as accurate as with full steps as it relies on the motor coils pulling against each other. Have you the opportunity to align your tracks with full-step positions of the motor?
I haven't tried that, as I suspect that the tracks won't be able to be aligned properly.

What scale is your train and what level of position error is acceptable (+/- X mm)?
On30, so the track gauge is 16.5mm, same as for HO scale.  With chamfers on the ends of the bridge and turntable tracks, the acceptable error is approximately +/- 1mm.

I was kind of relying on the accuracy of the steps to align the tracks.  Could the hall effect sensor be a possible cause of the issue?  If it's triggering slightly differently each time?

Tbdanny

I've had another thought on this.  My understanding is that the full steps are designated positions in the motor itself, every 1.8 degrees, and that moving to a full step from a microstep will ignore the microstepping.  E.g. if a motor is 1 step and 3 microsteps, then moving to step 2 will go to the next increment of 1.8 degrees, and ignore the microstepping.

If my understanding is correct, then it would be possible to swap between stepping and microstepping by changing the MS1-MS3 pins on the A4988.  I've noticed, while poking around with this, that microstepping seems to be reasonably accurate over short distances.  It's the long-distance microstepping moves that are giving me grief.

As such, I'm considering a hybrid approach; using the full steps to get as close to the track as possible, then enabling microstepping to provide the final alignment.  This would provide the accuracy needed, as well as the precision.  Does this sound plausible?

Robin2

I am sceptical of success with your hybrid approach. The problem is that if you switch from micro-stepping to full stepping when the motor is not at a full step position it will probably move to the nearest full step position and lose count.

When I mentioned aligning the tracks with the full-step positions I meant laying the tracks so that they line up with specific motor positions - not getting the motor to line up with the tracks.

I have not used a hall-effect sensor so I can't comment on the precision for setting the HOME position. However if, following homing, the motor can align the turntable accurately for a number of movements it seems as if the homing is accurate.

How many microsteps are represented by your +/- 1mm (which seems a large error to me).

Have you checked to make sure that the turntable cannot rotate on the motor shaft?

Are you driving the 'table in both directions? Maybe the microstepping gets a bit confused when the direction changes? If so you may be able to include some compensating steps in your code. Or always drive it in the same direction.

A couple of years ago I tried to make an N-gauge train turntable driven by a Nema 17 stepper and, even using full steps and laying the track to match the motor it wasn't providing the repeatable accuracy that I needed. On the other hand I have added stepper motors to a small metal working lathe and they give very good repeatability.

Which reminds me that you have not provided a link to your stepper motor datasheet.

I have not looked at your code yet.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Robin2

#5
Jan 12, 2019, 02:40 pm Last Edit: Jan 12, 2019, 02:44 pm by Robin2
I'm not familiar with the stepper library you are using. Please post a link to its documentation.

With an A4988 driver and a slow moving thing like a turntable there is not much need for a stepper library

I notice you have delay()s all over the shop. Maybe one or other of them is occasionally allowing a couple of steps to be rolled into one.

If this was my project I would test the accuracy of the stepper motor with the shortest possible program. Have a look at this Simple Stepper Code


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Tbdanny

I've already laid the tracks and put the scenery around them, so moving the tracks to line up with the motor steps isn't doable.  It seems that I can't rely on step counting alone to align the tracks, so I'm going to have to come up with some other system.  I'm thinking optical sensors at each track, with a 1mm hole in the base so it's not obvious.  These will be set where they're blocked by the turntable bridge when aligned.

Robin2

#7
Jan 12, 2019, 09:06 pm Last Edit: Jan 12, 2019, 09:08 pm by Robin2
I've just been building a small train turntable for 9mm track which is rotated by a small 28BYJ-48 stepper motor. Because it has a gearbox backlash is inevitable but I thought maybe if I only rotated in one direction it would not be a problem. But it was - probably because the resistance to motion is not constant.

Then I figured I could mount a microswitch that would be triggered by an adjustable pillar on the 'table - adjustable so I could get the position matched up exactly. That drove me nuts. There was no way I could get all the pillars (there are two tracks, so 4 pillars) aligned at the same time. I suspect you will have a similar problem with your optical detector - although if you can get the alignment right it should work fine. For another project I have used QRE1113 reflective optical sensors. They are very small but they have leads that are big enough for hand soldering. They can detect a blob of white paint on a black background. If a reflective system isn't suitable then consider a slotted optical switch in which something breaks the beam. As far as the Arduino is concerned the two types are the same.

For my own project I got an attack of common sense and I soldered small pieces of brass tube on the outside of the rails on the fixed track and I use a servo to extend and withdraw a brass rod through the tube. When the table is nearly in alignment the servo extends the rod and the track on the table touches it and stops. That also makes a circuit so the Arduino knows to stop sending pulses to the motor. When the 'table needs to move the servo withdraws the pin. It works very well - but I probably need an accuracy of +/- 0.25mm or better.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up