Shop OBEX P1 Docs P2 Docs Learn Events
S-curve motion generator — Parallax Forums

S-curve motion generator

mwrobertsmwroberts Posts: 78
edited 2025-08-21 03:04 in Propeller 2

Here is a s-curve step/dir motion generator I was working on a while back.
It could use some work, but it shows how to generate a trapezoidal with s-curve velocity profile for a given distance and feed rate.

Comments

  • MicksterMickster Posts: 2,879

    Mine works beautifully and is generated in real-time. The full motion profile is only part of the problem; one needs to account for short moves that don't reach slew and also on-the-fly velocity/acceleration changes.

    Craig

  • @Mickster said:
    The full motion profile is only part of the problem; one needs to account for short moves that don't reach slew and also on-the-fly velocity/acceleration changes.

    Yes, it doesn't handle short moves where block time is shorter than the acceleration time constant. To handle them correctly, the decel ramp starts before the accel ramp finishes, giving constant velocity while overlapped.
    I should fix that, but software preprocessing of the move could lower the move feedrate so the blocktime is a bit longer than the acceleration time constant. That may not work properly if there are many short moves in a row. The feed rate override can be accomplished by making the PASM interpolation loop counter longer... the one set to 200 counts with the clock speed set at 200Mhz to get 1uSec interpolation period.
    This program outputs step/dir pulses in realtime.

  • @Mickster , can you share details on "short moves that don't reach slew and also on-the-fly velocity/acceleration changes"?

  • MicksterMickster Posts: 2,879

    @mwroberts said:
    @Mickster , can you share details on "short moves that don't reach slew and also on-the-fly velocity/acceleration changes"?

    We have a target velocity (sp) that is not achievable if distance-to-accelerate (da) + distance-to-decelerate (dd) > distance-to-move (move)

    I just make it fit:

    if (da+dd)>move then
      sp = sqr((2 * move * ac * dc) / (ac + dc))
      ta = sp / ac        'new time-to-accelerate
      td = sp / dc        'new time-to-decelerate
      da = (ta * sp)/2        'new distance-to-accelerate
      dd = (td * sp)/2        'new distance-to-decelerate
    end if
    
    

    The on-the-fly stuff, I haven't messed with (yet) because I have no use for it. When I get around to a more general-purpose motion controller, I'll need it.

Sign In or Register to comment.