Stepper Motor acceleration profiles for short runs - Electrical Engineering Stack Exchange most recent 30 from electronics.stackexchange.com 2019-06-20T04:00:10Z https://electronics.stackexchange.com/feeds/question/395430 http://www.creativecommons.org/licenses/by-sa/3.0/rdf https://electronics.stackexchange.com/q/395430 6 Stepper Motor acceleration profiles for short runs darrob https://electronics.stackexchange.com/users/196596 2018-09-11T08:28:06Z 2018-09-20T13:17:31Z <p>I've done a fair bit of reading on stepper motors and acceleration. I had to wade through a lot of different strategies with a lot of calculations, including one which called for several candles, and "A maiden of virtue pure" Which while interesting, seemed impractical (Not enough space on the Arduino) Basically they all boil down to this: "Accelerate using some type of ramp, run at speed, then decelerate to stop"</p> <p>All good. Accelerating will get the load moving, and smooth deceleration will get the load to stop at the (hopefully) correct position.</p> <p>My issue is this. All of the reading I've done so far seem to have the assumption that the distance to travel will be enough to accommodate all three phases of travel. ie Accel, Coast at speed , Decel. I've not found much discussion on how to handle very short distance situations.</p> <p>For example, moving only two steps will not, can not possibly have enough distance to go through all three phases. step - step - done. While that particular example seems to be simple enough to solve, what are the best ways of determining if deceleration is required, and if so, when?</p> <p>At what point do I determine that some sort of deceleration profile will be needed to get the stepper to stop at the required position without overshooting.</p> <hr> <p>So after a whole bunch more looking, and reading and getting confused I decided on the simplest solution.</p> <p>I stayed with a trapezoidal/triangle profile. Essentially I determined the distance a constant acceleration ramp would use to get to speed. If the acceleration distance was greater than half of the total distance to travel, I accelerate for only half the total travel distance and not worry about getting to max speed. Because I decided to use a symmetrical approach, the decel part took care of itself.</p> <p>The equations I utilised are essentially the ones posted by Chuck, although the addition of different acceleration and deceleration rates he uses gives me food for thought.</p> <p>Many, many thanks to all who contributed.</p> https://electronics.stackexchange.com/questions/395430/-/395454#395454 1 Answer by WhatRoughBeast for Stepper Motor acceleration profiles for short runs WhatRoughBeast https://electronics.stackexchange.com/users/40487 2018-09-11T12:25:53Z 2018-09-11T12:25:53Z <p>Well, for short runs, it should be obvious that you can skip the coast phase.</p> <p>As for the others, it's pretty simple. Maintain constant acceleration until you are halfway to the target, then decelerate until you reach the target.</p> <p>However, there's a catch (there always is, isn't there?). If you have misjudged the distance to the target, and it is closer than you think, then accelerating to your (erroneous) half-way point will mean that you will not be able to stop when you reach the real target point. </p> https://electronics.stackexchange.com/questions/395430/-/395455#395455 1 Answer by Transistor for Stepper Motor acceleration profiles for short runs Transistor https://electronics.stackexchange.com/users/73158 2018-09-11T12:28:01Z 2018-09-11T12:28:01Z <p>If you want to roll your own it will be something like this.</p> <ul> <li>If accel == decel then the number of steps for the accel phase is equal to the total number of steps required / 2.</li> <li>Accelerate until you reach the target number of steps or until you reach Vmax.</li> <li>Note the step count, c.</li> <li>Run at Vmax until you reach target - c.</li> <li>Start deceleration.</li> <li>Stop at target.</li> </ul> <p>If you have accel != decel then you have some additional work to do to work out the ratios.</p> https://electronics.stackexchange.com/questions/395430/-/395508#395508 1 Answer by Mark Booth for Stepper Motor acceleration profiles for short runs Mark Booth https://electronics.stackexchange.com/users/3774 2018-09-11T17:02:35Z 2018-09-14T13:42:43Z <p>When planning a <a href="https://robotics.stackexchange.com/a/7512/37">trapezoidal move profile</a>, if you are not travelling far enough, it devolves into a triangular move. I.e. "accelerate, max velocity, decelerate", becomes "accelerate, decelerate".</p> <p>I typically calculate cruise distance based on subtracting acceleration &amp; deceleration distances (based on max. acceleration and max. velocity) from the total distance. If this cruise distance is negative, I recalculate acceleration &amp; deceleration distances &amp; velocities based on half the total distance (or the ratio of max acceleration &amp; max deceleration if they are different).</p> <p>Trapezoidal move profiles are often used because they are simple, and easy to calculate move speed and distance for each waypoint. The problem is, they are not very flexible, as they assume an instantaneous change in acceleration, which as we know is only an approximation to the behaviour of real systems.</p> <p>Many move controllers have the option of using S-curve motion profiles. You start off by ramping up acceleration at the start of the acceleration phase, and ramping it down at the end, doing the same agasn at the start and end of the deceleration phase.</p> <p>While it might seem logical that the fastest move you can do would involve accelerating at the highest rate possible, then decelerating at the highest rate possible, that may not always be the case. Reducing jolt (jerk) on a move by starting with a lower initial acceleration can enable you to maintain a higher peak acceleration for longer, resulting in a higher overall acceleration, all at the expense of more complex trajectory planning calculations.</p> <p>This is especially a problem with stepper motors without encoders. Stepper motors suffer from the problem that if you demand they do something they can only just manage, their behaviour is unpredictable. Push your stepper motor just a little too hard and it will miss steps. If you don't have an encoder to detect these missed steps and correct for them (in your servo loop) then you will have to down-rate your max. acceleration parameter to the point that it can cope with all potential situations.</p> <p>In general, you want to try to avoid discontinuities in control, so control algorithms should, much like the motors they control, transition smoothly between different modes of operation.</p> https://electronics.stackexchange.com/questions/395430/-/395629#395629 1 Answer by Marko Buršič for Stepper Motor acceleration profiles for short runs Marko Buršič https://electronics.stackexchange.com/users/82111 2018-09-12T11:23:46Z 2018-09-12T11:39:29Z <p>I gave you links of simple traj. planner from linuxnc.org. It has to be noted that is not in use since it has been superseeded by new and better (more complex) one.</p> <p><a href="http://wiki.linuxcnc.org/cgi-bin/wiki.pl?Simple_Tp_Notes" rel="nofollow noreferrer">wiki.linuxcnc.org/cgi-bin/wiki.pl?Simple_Tp_Notes</a></p> <p><a href="https://github.com/LinuxCNC/linuxcnc/blob/master/src/emc/motion/simple_tp.c" rel="nofollow noreferrer">Source code</a></p> <p>So, how it works:</p> <p>At the beginning you set <strong>pos_cmd</strong> = <strong>curr_pos</strong> (actual position), the planner does nothing. Then you set a new <strong>pos_cmd</strong> (setpoint position) and <strong>vel_req</strong> (setpoint velocity) with constraints: <strong>max_acc</strong> , <strong>max_vel</strong>.</p> <p>The algorithm computes for each step (recursion) the distance to stop regarding the actual velocity, actual position, max_acc. </p> <p>If the position to stop is equal or bigger than actual distance to stop, then it begins to coast.</p> <p>Else if the current velocity is smaller than vel_req it ramps up with max_acc ramp.</p> <p>Else if the current velocity is equal or grater than vel_req, then it moves with constant velocity.</p> <p>It has to be said that this is pure open loop control, no feedback. The planner generates trapezoidal profile and outputs setpoints for position and velocity and the drive has to follow it. As said it may not stop at exact position, see notes.</p> <p>P.S: IMO the article you have proposed is more specific fo use for stepper motors, in fact it calculates pulses. The linuxcnc is more generalized approach, but you can have a wider look for your problem. There is no flaw using a planner either for small or large movements, all calculations are limited by phyisical constraints that are input as parameters.</p> https://electronics.stackexchange.com/questions/395430/-/396648#396648 2 Answer by Chuck for Stepper Motor acceleration profiles for short runs Chuck https://electronics.stackexchange.com/users/76598 2018-09-18T14:14:20Z 2018-09-18T14:14:20Z <p>You always need a deceleration ramp, or you'll incur a jerk and/or overshoot the target. My company uses acceleration and deceleration <em>times</em>, as in the time it takes to get from 0% to 100%. This is equivalent to an acceleration of</p> <p>$$a = \frac{\Delta v}{\Delta t} \\$$</p> <p>where</p> <p>$$\Delta v = v_{\mbox{max}} \\ \Delta t = \mbox{time to accelerate from 0 to }v_{\mbox{max}} \\$$</p> <p>Whatever convention you use to define your acceleration and deceleration rates, you should convert to "proper" acceleration rates, length/time^2.</p> <p>Inline Mathjax (LaTeX) isn't enabled on this site, which is kind of a pain, but I'll use acceleration as a sub-positive and deceleration as a sub-negative, as in:</p> <p>$$\mbox{Acceleration} = a_+ \\ \mbox{Deceleration} = a_- \\$$</p> <p>You can use acceleration and top speed to get the time to top speed as:</p> <p>$$\Delta t = \frac{v_{\mbox{max}}}{a} \\$$</p> <p>Double integrate acceleration to get displacement:</p> <p>$$dS = S_0 + v_0\Delta t + (0.5)a\Delta t^2 \\$$</p> <p>Assuming your starting position is zero and your starting speed is zero, that reduces to:</p> <p>$$dS = (0.5)a\Delta t^2 \\$$</p> <p>So you have two distances that you can travel, which aren't necessarily the same - the distance you traverse on acceleration, and then the distance you traverse on deceleration. If the accel/decel rates are the same then the distances are the same, but this seems to be the confounding point for you if they're not. </p> <p>No worries! You have a time to accelerate to top speed:</p> <p>$$\Delta t_+ = \frac{v_{\mbox{max}}}{a_+} \\$$</p> <p>And you have a time to decelerate <em>from</em> top speed:</p> <p>$$\Delta t_- = \frac{v_{\mbox{max}}}{a_-} \\$$</p> <p>So you have a distance you traverse on acceleration and a distance you traverse on deceleration:</p> <p>$$dS_+ = (0.5)a_+\Delta t_+^2 \\ dS_- = (0.5)a_-\Delta t_-^2 \\ dS_{\mbox{total}} = dS_+ + dS_- \\$$</p> <p>This is your <em>test condition</em>. If your <code>targetDistance</code> is greater than dS (which is the combination of dS+ and dS-) then you will need some coast time at top speed. The coast time is:</p> <p>$$\mbox{distanceRemaining} = \mbox{targetDistance} - dS \\ \Delta t_{\mbox{coast}} = \frac{v_{\mbox{max}}{\mbox{distanceRemaining}} \\$$</p> <p>If your <code>targetDistance</code> is LESS than dS, then you need to crop your acceleration and deceleration ramps. This means solving for the new top speed. Working out the dS equation from earlier:</p> <p>$$dS_{\mbox{total}} = dS_+ + dS_- \\ dS_{\mbox{total}} = (0.5)a_+\Delta t_+^2 + (0.5)a_-\Delta t_-^2 \\ dS_{\mbox{total}} = (0.5)a_+\left(\frac{v_{\mbox{max}}}{a_+}\right)^2 + (0.5)a_-\left(\frac{v_{\mbox{max}}}{a_-}\right)^2 \\$$</p> <p>Pull out the vMax term:</p> <p>$$dS_{\mbox{total}} = \left((0.5)a_+\left(\frac{1}{a_+}\right)^2 + (0.5)a_-\left(\frac{1}{a_-}\right)^2\right)\left(v_{\mbox{max}}\right)^2 \\$$</p> <p>Acceleration terms cancel:</p> <p>$$dS_{\mbox{total}} = \left((0.5)\left(\frac{1}{a_+}\right) + (0.5)\left(\frac{1}{a_-}\right)\right)\left(v_{\mbox{max}}\right)^2 \\$$</p> <p>Pull out the 0.5, too:</p> <p>$$dS_{\mbox{total}} = (0.5)\left(\left(\frac{1}{a_+}\right) + \left(\frac{1}{a_-}\right)\right)\left(v_{\mbox{max}}\right)^2 \\$$</p> <p>Then clean it up and start solving for vMax:</p> <p>$$dS_{\mbox{total}} = (0.5)\left(\frac{1}{a_+} + \frac{1}{a_-}\right)\left(v_{\mbox{max}}\right)^2 \\ 2\left(dS_{\mbox{total}}\right) = \left(\frac{1}{a_+} + \frac{1}{a_-}\right)\left(v_{\mbox{max}}\right)^2 \\ 2\left(dS_{\mbox{total}}\right)\frac{1}{\left(\frac{1}{a_+} + \frac{1}{a_-}\right)} = \left(v_{\mbox{max}}\right)^2 \\$$</p> <p>The acceleration terms can be cleaned up by cleverly multiply by one in the form of a+/a+ or a-/a-:</p> <p>$$2\left(dS_{\mbox{total}}\right)\frac{1}{\left(\frac{a_-}{a_-a_+} + \frac{a_+}{a_-a_+}\right)} = \left(v_{\mbox{max}}\right)^2 \\$$</p> <p>Now those fractions add:</p> <p>$$2\left(dS_{\mbox{total}}\right)\frac{1}{\left(\frac{a_- + a_+}{a_-a_+}\right)} = \left(v_{\mbox{max}}\right)^2 \\$$</p> <p>So now they can be inverted:</p> <p>$$2\left(dS_{\mbox{total}}\right)\left(\frac{a_-a_+}{a_- + a_+}\right) = \left(v_{\mbox{max}}\right)^2 \\$$</p> <p>Which finally leaves:</p> <p>$$v_{\mbox{max}} = \sqrt{2\left(dS_{\mbox{total}}\right)\left(\frac{a_-a_+}{a_- + a_+}\right)}\\$$</p> <p>Once you have this, you go back and re-calculate the acceleration and deceleration times (t+ and t-) and that gives you your new speed profile. </p> <p>Final note/P.S. - Note that if a- is equal to a+ (drop the subscripts and just use 'a') that you get:</p> <p>$$v_{\mbox{max}} = \sqrt{2\left(dS_{\mbox{total}}\right)\left(\frac{aa}{a + a}\right)}\\ v_{\mbox{max}} = \sqrt{2\left(dS_{\mbox{total}}\right)\left(\frac{a^2}{2a}\right)}\\ v_{\mbox{max}} = \sqrt{2\left(dS_{\mbox{total}}\right)\left(\frac{a}{2}\right)}\\ v_{\mbox{max}} = \sqrt{\left(dS_{\mbox{total}}\right)a}\\$$</p> <p>I know from great experience that sometimes the hardest part of reading papers is that the authors all seem to believe the math is trivial for a particular step, so they skip sometimes crucial (to us) points in the derivation, or bad authors omit the derivation entirely. For that reason, I've tried to be explicit about every step I've taken, but if I've left something off or you're still confused just let me know. </p>