# Given Max Speed, Max Acceleration and Jerk - How do I calculate time?

I'm developing some python code that controls an end effector moving in a two-dimensional plane (XY). It moves through a list of points sequentially and I'd like to estimate the time it will take as precisely as possible.

My constant variables are:

Max_Speed: 30 mm/s
Max_Acceleration: 60 mm/s^2
Max_Jerk: 20 mm/s


For simplicity, we can assume the acceleration curve to be linear. In practice, it's much closer to a sigmoid curve.

For now, let's assume the end-effector will move from the origin to another point.

pt1: 0,0
pt2: 20,20


My current implementation only takes Max speed into account, any improvement would be hugely appreciated. However, given my very limited mathematical background, I'll favour simplicity at the expense of accuracy. A pythonic explanation would also be hugely appreciated.

distance = euclidean_distance(pt1, pt2) = 28.284271
time = distance / Max_Speed =  28.284271 / 30 = 0.9428090333


For the above example, it would be reasonable to assume that the maximum speed was not reached and therefore the calculation is off. The end effector carries a lot of mass, hence the relatively low acceleration value and the assumption that the maximum speed was not reached.

• If the end-effector reaches maximum speed fairly quickly, then your final line is a pretty good approximation. If this is not the case then you will need to supply more information about how the acceleration varies with time. The motion of something through space over time depends on way more than just the maximum speed, maximum acceleration, and maximum jerk. I don't understand why your example shows the maximum speed was not reached. Also keep in mind that this is not a coding site. Your question here should focus on physics concepts. Aug 31, 2018 at 11:14
• Hi Aaron, thanks for your input - you are right that I forgot to mention what the acceleration/deceleration curve is. For simplicity, we can assume it's linear - in reality, it's close to the sigmoid curve. The end effector carries a lot of mass and inertia, hence the relatively low maximum acceleration value. It is for this reason that I assume it hasn't reached its maximum speed. If the acceleration was large relative to the max speed then as you mention the above calculation would be satisfactory. However, in my case the opposite is true. Aug 31, 2018 at 11:21
• Should we assume the slope of the linear acceleration curve is just the maximum jerk? Aug 31, 2018 at 11:28
• Looks like the dimensions for jerk are incorrect. Is that a typo?
– user191954
Aug 31, 2018 at 12:14
• You said "Max_Jerk: 20 mm/s"... It should be $\rm ms^{-3}$. Or $\rm mm s^{-3}$ if you must use millimeters.
– user191954
Aug 31, 2018 at 12:17

Based on information in the comments, we are going to assume that the acceleration increases linearly with time, where the slope of this line is given by the maximum jerk $j_{max}$. Therefore: $$a(t)=j_{max}t$$

Since $a=\dot v$, and $v=\dot x$, we can solve for $v(t)$ and $x(t)$ assuming the end-effector is moving in a straight line with $v(0)=0$ and $x(0)=0$. We will neglect the maximum acceleration and maximum speed for now. If we never reach these thresholds in the calculations, then we do not need to consider these maximum values. If we do reach these maximum values then more work will need to be done.

With the above assumptions: $$v(t)=\int_0^ta(\tau)d\tau=\frac 12j_{max}t^2$$ $$x(t)=\int_0^tv(\tau)d\tau=\frac 16j_{max}t^3$$

Solving for $t$ when we reach the end position $$t=\left (\frac{6x_{end}}{j_{max}}\right )^{1/3}=\left (\frac{6(28.28 \space mm)}{20\space mm/s^3}\right )^{1/3}\approx 2.04 \space s$$

Now let's check our acceleration and speed at this time: $$a(2.04\space s)=40.8\space mm/s^2<a_{max}$$ $$v(2.04\space s)=41.6\space mm/s>v_{max}$$

So you can see that we hit maximum speed after this time interval. Therefore, we need to determine when we hit the maximum speed: $$t_{v_{max}}=\left(\frac{2v_{max}}{j_{max}}\right )^{1/2}\approx 1.73 \space s$$

At this time I am assuming the acceleration goes to $0$? So therefore after about $1.73\space s$ you need to switch to the object moving at constant speed, which it seems like you already know how to do.

• Many thanks, Aaron, I find your answer particularly digestible and am surprised to see by how much it differs to my initial solution. I may be back with some questions after I've implemented it. Aug 31, 2018 at 12:39
• @CharlesFried I previously made an error. I have fixed it, but it changed some things since you accepted this as a correct answer. Please review accordingly, and remove correct answer if needed. Aug 31, 2018 at 12:48

Assuming you need to stop at $P_2$ and that de-acceleration and de-jerk are of the same magnitude as acceleration and jerk than you need to find time to midway between $P_1$ and $P_2$ and multiply by two.

By integrating jerk to obtain acceleration, integrating acceleration to obtain velocity and integrating velocity to obtain distance, you can find that:

• Time from $P_1$ to maximum acceleration is $3 sec$.
• Time from $P_1$ to maximum velocity is $\sqrt3 sec$.

So maximum velocity is the limiting factor.

During these $\sqrt3 sec$, a distance of $17.3 mm$ is traveled. So for distances $P_1 - P_2$ longer than $17.3 X 2$ $mm$ you should subtract $17.3$ $mm$ from half-distance and use maximum velocity for that reduced distance plus $\sqrt3 sec$.

For distances shorter than $17.3 X 2$ $mm$ , you can use directly use the distance formula to obtain time.

All of these can easily be applied in Python with the following prescription:

1. Calculate half the distance (d).

2. If d>17.3, calculate $\frac{d-17.3}{V_{max}}$ + $\sqrt3$.

3. If d<=17.3, calculate $({\frac{6d}{20}})^{\frac{1}{3}}$.

4. Multiply result by 2.

• As a reponse to an earlier comment: I don't think so. $30=\frac{1}{2}20t^2$. Aug 31, 2018 at 12:50
• I'm sure the answer is obvious but how did you arrive to 3sec and sqrt(3)sec? Aug 31, 2018 at 13:22
• I didn't want to write down the explicit integrals, to encourage OP to do some work by his own. But you can use the equations written in the selected answer. For example the one written in my previous comment for the time to maximum velocity. Aug 31, 2018 at 13:29