# How can I optimise control parameters for a stepper motor?

As an industrial roboticist I spent most of my time working with robots and machines which used brushless DC motors or linear motors, so I have lots of experience tuning PID parameters for those motors.

Now I'm moving to doing hobby robotics using stepper motors (I'm building my first RepRap), I wonder what I need to do differently.

Obviously without encoder feedback I need to be much more conservative in requests to the motor, making sure that I always keep within the envelope of what is possible, but how do I find out whether my tuning is optimal, sub optimal or (worst case) marginally unstable?

Obviously for a given load (in my case the extruder head) I need to generate step pulse trains which cause a demanded acceleration and speed that the motor can cope with, without missing steps.

My first thought is to do some test sequences, for instance:

• Home motor precisely on it's home sensor.
• Move $C$ steps away from home slowly.
• Move $M$ steps away from home with a conservative move profile.
• Move $N$ steps with the test acceleration/speed profile.
• Move $N$ steps back to the start of the test move with a conservative move profile.
• Move $M$ steps back to home with a conservative move profile.
• Move $C$ steps back to the home sensor slowly, verifying that the sensor is triggered at the correct position.
• Repeat for a variety of $N$, $M$, acceleration/speed & load profiles.

This should reliably detect missed steps in the test profile move, but it does seem like an awfully large space to test through however, so I wonder what techniques have been developed to optimise stepper motor control parameters.

• In the RepRap World the Diagnosis is that the print looks awful. That is the detection of missed steps, as far as I know. But I think the current used by the stepper could be used as a feedback if the stepper was able to do the move. But have not heard of somebody really doing that. Dec 11, 2012 at 23:34
• (These topics are getting popular this week. Must be because of that gun article.) The best/easiest way is to do the test prints such as the Torture Test thingiverse.com/thing:33902
– user797
May 9, 2013 at 18:54

The "math" way to do this is to generate a speed/torque curve for your stepper at its given voltage, and determine the maximum force that will be applied to the object in motion (in this case, the largest force is likely to be acceleration).

Note that most hobby 3d printers are so flimsy that the frame bending under acceleration will harm print quality long before you start missing steps. In this case, you could model the deflection of the frame under load.

In my experience, 90% of missed steps are caused by mechanical or software problems such as the axes binding or pulses being missed. Try moving everything by hand to check if it is smooth.

Overly aggressive speeds and accelerations should be visible (and audible) on a 3d printer long before the steppers stall.

Generally a single missed step will also cause the next steps to also be missed (since the motor must now work even harder to catch up) and you get a few seconds of buzzing instead of motion.