s-curve math?

I'm working on a similar S-curve with ControlLogix - is there a shortcoming by rolling my own general logistic function, providing raw output with a single CPT instruction? Mathematically this works, but I haven't the hardware on hand yet to measure the scan time impact.

This can be called on RTC pulses at selected intervals to tune output resolution and scan times, I suppose.


Simple answer - yes you can with limitations

better answer is don't
you can have a virtual axis in control logix processor and use that to provide the S-curve for you - no maths and you have access to using CAM tables also
 
The math isn't a bother. In fact, I think it's the best tool in the box. I can model and tune the machine/process and it's portability is gold; do other systems provide the same implementation of virtual axes, for example?

I grant that you can't easily or reasonably do higher orders of math on a PLC, but I'm also never comfortable using blackboxes without at least understanding how they work and what their side-effects are. Logistics are a subset of exponential functions, so it's just algebra. :)
 
OK, now you have a 3rd order ramp. Is the ramp for position, velocity or acceleration?
If you are really interested you should look into cubic splines. Learning how to generate the formulas for moving from a starting position and velocity to a destination position and velocity.

As for higher order math. I think 5th order is doable. The problem with 3rd order ramps is that they require 3 different sets of equations to ramp up or ramp down whereas 5th order ramps can ramp up or down with just one polynomial which is really much simpler in the end.
 
Derivation Mystery

What is needed is a s-curve index into the SCP instead of the timer like this:
Code:
frac = time/ramp_time;
f=(3-2*frac)*frac*frac;
f goes from 0 to 1. Now use f to index into the SCP instruction.
Simple.

Fifth order polynomials cost extra.

Peter, I saw someone else ask about the derivation of this expression but I didn't see a response. I've searched through a number of books but couldn't determine how this is derived. Perhaps I should have paid more attention to my numerical methods class (and kept the textbook).:unsure: I'm hoping you'll be willing to share. 🤞🏻
 
Last edited:

Assume move will be neither acceleration- nor velocity-limited, so jerk will (1) have constant magnitude, and (2) flip sign half way through.

  • Normalized position (0-1) is cubic polynomial, because third derivative (jerk) is constant
    • f(frac) = k0 + k1 frac + k2 frac**2 + k3 frac**3
  • Normalized velocity is f'(frac) = df(frac)/dfrac
    • f'(frac) = k1 + 2 k2 frac + 3 k3 frac**2
  • Position is 0 at frac=0 (time=0), solve for k0:
    • 0 = k0 + k1 0 + k2 0**2 + k3 0**3
    • 0 = k0 + 0 + 0 + 0
    • 0 = k0
  • Velocity (df(frac)/dfrac) is 0 at frac=0, solve for k1:
    • 0 = k1 + k2 2 0 + 3 k3 0**2
    • 0 = k1 + 0 + 0
    • 0 = k1
  • Position is 1 at frac=1 (time=RAMP_TIME):
    • 1 = k0 + k1 1 + k2 1**2 + k3 1**3
    • 1 = 0 + 0 1 + k2 1 + k3 1
    • 1 = k2 + k3
  • Velocity is 0 at frac=1:
    • 0 = k1 + k2 2 1 + k3 3 1**2
    • 0 = 0 + k2 2 + k3 3
    • 0 = 2 k2 + 3 k3
  • Solve for k3:
    • 1 = 1 k2 + 1 k3
    • 0 = 2 k2 + 3 k3
    • 2 = 2 k2 + 2 k3 <== [1 = 1 k2 + 1 k3] * 2
    • -2 = (2-2) k2 + (3-2) k3 <== subtract last eqn from its previous eqn
    • -2 = 0 k2 + 1 k3
    • -2 = k3
  • Solve for k2:
    • 1 = k2 + k3
    • 1 = k2 + -2
    • 3 = k2
  • Substitute k0-k3 into original equation:
    • f(frac) = 0 + 0 frac - 2 frac**2 + 3 frac**3
    • f(frac) = 3 frac**3 - 2 frac**2
    • f(frac) = (3 - 2 frac) frac**2




It gets a lot more complicated if the initial or final velocity is not zero, but you asked about the formula @Peter Nachtwey provided.


.
 
Last edited:
Your solution ramps up and then down.

is f(frac) a position or velocity?
It looks like you assumed it is a position so your solution ramps up and down since the velocity is 0 at both ends.
Usually people want to start with a velocity of 0 and ramp up to a velocity of 1 as a function of f(frac).
 
is f(frac) a position or velocity?


I dunno, you tell me: you supplied the formula back in post #4!



It looks like you assumed it is a position so your solution ramps up and down since the velocity is 0 at both ends.
Usually people want to start with a velocity of 0 and ramp up to a velocity of 1 as a function of f(frac).


Ah, my mistake; the OP was asking for a way to control the speed reference.


Well, if f is fractional velocity, then velocity is 0 and 1, and accel is 0 and 0, at a frac of 0 and 1, respectively. Jerk is single sawtooth, and jounce (dJerk/dt) is a positive and negative pulse.

@brimal was asking for the derivation, and the math is the same. So although I got the labels wrong, they are not really important for answering that question.

...
 
I dunno, you tell me: you supplied the formula back in post #4!
Most people use that for ramping velocity set points.

Your solution results in a parabolic like velocity profile, not a ramp to a constant speed or down to a constant speed.

Ah, my mistake; the OP was asking for a way to control the speed reference.
Yes, it works for ramping just about anything but yes,

Well, if f is fractional velocity, then velocity is 0 and 1,
Yes

and accel is 0 and 0,
yes, if you are ramping velocities.

at a frac of 0 and 1, respectively. Jerk is single sawtooth, and jounce (dJerk/dt) is a positive and negative pulse.
No, if
Code:
vel(f) = a+b*f+c*f^2+d*f^3
acc(f) = b+2*c*f+3*d^2
jerk(f) = 2*c+6*d*t
The jerk is definitely a line. When ramping up it is a line with a negative slope because c=3 and d=-2.When ramping up the jerk is a line with a positive slope because c=-3 and d=2


@brimal was asking for the derivation, and the math is the same. So although I got the labels wrong, they are not really important for answering that question.
...
Yes,I have a couple of ways of figuring these out but I use Mathcad. This simple problem can be done in my head. If we assume the parameter is a fraction from 0 to 1 then the formula is in he form

Code:
velocity(f)=a+b*f+c*f^2+d*f^3
acceleration(f)=b+2*c*f+3*d*f^2
since the velocity and acceleration are 0 when f is 0 and ramping up we know that a and b are 0. When f = 1 then velocity(1)=1 and acceleration(1)=0 so c+d=1 and 2*c+3*d=0

substitute c=1-d in the acceleration formula
2*(1-d)+3*d=0
2+d=0 so d=-2 and c=3
when ramping down
a = 1 b=0 c=-3 and d=2

However, all of this does not change the real problem. Over what distance or time do you change the fraction from 0 to 1 if you must consider the distance traveled?
 
Last edited:
Two other things to check when using a ramping scheme algorithm
1. What is the peak acceleration? We judge this as the ratio of the peak to average acceleration. If the peak acceleration is too high the torque/acceleration/force limits could be exceeded.

I ran into this when trying to have IPM define ramp time.
Code:
TimeRamp.PRE := abs(SP - PVinit)/IPM*60000;

I was going to try and calculate an offset multiplier so the peak velocity doesn't exceed, but I have yet to do so. There never being a constant velocity with this is kind of unpleasant as well. It makes it hard to explain to management that the quoted ramp time is only made for a single instance.

Also to extend the scurve into units of consequence.
[CODE}
Targ := PVinit + (SP - PVinit) * f;
Code:
 

Similar Topics

Hello everyone, this is my first question in this forum and I'm still learning about these matters. I apologize if I make any mistakes. I am...
Replies
28
Views
4,372
Hi The pump smart PS220 VFD has the ability to estimate pump flow based of pump characteristics and measured motor data. The calculations...
Replies
12
Views
3,747
Hello all, I need to write a code for S-curve motion profiles (7 segments) to control speed of motor via PLC. however, I cannot find the...
Replies
78
Views
17,862
Does anyone know of an Add-On Inst. or PAX Block that can be used to develop a characteristic curve? I have a Variable Speed Pump with a Current...
Replies
13
Views
2,651
Hello Forum, I am developing a Pump Control System and one of the most important modes of operation, is to keep the Pump operating inside it's...
Replies
36
Views
15,021
Back
Top Bottom