I 3rd order motion profile programming ("sinusoidal")

  • I
  • Thread starter Thread starter Dominik Tugend
  • Start date Start date
  • Tags Tags
    Motion Programming
AI Thread Summary
The discussion focuses on programming a 3rd order motion profile for smooth camera tracking in a hobby project, specifically using a "sinusoidal" jerk control. The user seeks to limit acceleration, velocity, and jerk while managing initial conditions, aiming to minimize position error and time across multiple phases of motion. They express a desire to solve the problem analytically without resorting to non-linear programming, exploring various mathematical approaches and constraints. Suggestions for literature and practical methods to tackle the problem are requested, emphasizing the need for accessible resources. The user is open to alternative formulations, including treating jerk as a left-continuous step function for simplification.
Dominik Tugend
Messages
19
Reaction score
1
What I am actually trying to do:

I actually want to program (better) smooth camera tracking of objects for a hobby project of mine: HLAE / AfxHookSource ( http://www.advancedfx.org )

I made some compromises already to make things not even more complicated, so I am down to trying to use a 3rd order motion profile (so not specifically for angular motion), assuming that the error will be a constant linear factor.

I already posted my question on math.stackexhange.com here:
http://math.stackexchange.com/questions/1750143/3rd-oder-motion-profile-programming-characterized-by-limits-for-jerk-accelerat
But it looks as if won't get any feedback there and a friend recommended me to try this physics forum instead.1. Problem

I am trying to program a 3rd order motion profile. It is driven by controlling the Jerk in a somewhat "sinusoidal" way. The acceleration and velocity are limited. There can be initial acceleration and velocity.

The closest graphical visualization I found is this (main difference is it starts with zero velocity and acceleration): https://en.wikipedia.org/wiki/Jerk_(physics)#/media/File:Schematic_diagram_of_Jerk,_Acceleration,_and_Speed.svg

It has these phases:
  1. acceleration (decelleration) build-up
  2. limit acceleration (decelleration)
  3. acceleration (decelleration) ramp-down
  4. limit speed
  5. deceleration (accelleration) build-up
  6. limit deceleration (accelleration)
  7. deceleration (accelleration) ramp-down
The complete programming problem I derived from these properties is as follows:

1.1. Input:
  • \text{LimitVelocity} \in \mathbb{R}_{\gt 0} - absolute velocity limit
  • \text{LimitAcceleration} \in \mathbb{R}_{\gt 0} - absolute acceleration limit
  • \text{LimitJerk} \in \mathbb{R}_{\gt 0} - absolute jerk limit
  • \text{targetPos} \in \mathbb{R} - target position
  • \text{lastPos} \in \mathbb{R} - last (initial) position
  • \text{lastVel} \in \mathbb{R} - last (initial) velocity, where \left| \text{lastVel} \right| \leq \text{LimitVelocity}
  • \text{lastAccel} \in \mathbb{R} - last (initial) acceleration, where \left| \text{lastAccel} \right| \leq \text{LimitAcceleration}

1.2. Output:
  • \text{phase1T} \in \mathbb{R}_{\geq 0} , \text{phase2T} \in \mathbb{R}_{\geq 0} , \text{phase3T} \in \mathbb{R}_{\geq 0} , \text{phase4T} \in \mathbb{R}_{\geq 0} , \text{phase5T} \in \mathbb{R}_{\geq 0} , \text{phase6T} \in \mathbb{R}_{\geq 0} , \text{phase7T} \in \mathbb{R}_{\geq 0} - Phase times
  • \text{dir} \in \{-1, 1\} - base/intital jerk direction

1.3. Further Equations:

The idea of those equations is that the model is controlled by driving the Jerk in a specific "sinusoidal" (?) way over a to be determined period of time (basically modelling the phases mentioned above).

1.3.1. Jerk

<br /> \text{jerk}(1) = +\text{dir} \cdot \text{LimitJerk} \\<br /> \text{jerk}(2) = 0 \\<br /> \text{jerk}(3) = -\text{dir} \cdot \text{LimitJerk} \\<br /> \text{jerk}(4) = 0 \\<br /> \text{jerk}(5) = -\text{dir} \cdot \text{LimitJerk} \\<br /> \text{jerk}(6) = 0 \\<br /> \text{jerk}(7) = +\text{dir} \cdot \text{LimitJerk} \\<br />

1.3.2. Acceleration

Derived by integrating the jerk.

<br /> \text{accel}(0) = \text{lastAccel} \\<br /> \text{accel}(1) = \text{accel}(0) +\text{jerk}(1) \cdot \text{phase1T} \\<br /> \text{accel}(2) = \text{accel}(1) +\text{jerk}(2) \cdot \text{phase2T} \\<br /> \text{accel}(3) = \text{accel}(2) +\text{jerk}(3) \cdot \text{phase3T} \\<br /> \text{accel}(4) = \text{accel}(3) +\text{jerk}(4) \cdot \text{phase4T} \\<br /> \text{accel}(5) = \text{accel}(4) +\text{jerk}(5) \cdot \text{phase5T} \\<br /> \text{accel}(6) = \text{accel}(5) +\text{jerk}(6) \cdot \text{phase6T} \\<br /> \text{accel}(7) = \text{accel}(6) +\text{jerk}(7) \cdot \text{phase7T} \\<br /> \text{accel}(7) = 0<br />

1.3.3. Acceleration limits

<br /> -\text{LimitAccel} \leq \text{accel}(1) \leq \text{LimitAccel} \\<br /> -\text{LimitAccel} \leq \text{accel}(2) \leq \text{LimitAccel} \\<br /> -\text{LimitAccel} \leq \text{accel}(3) \leq \text{LimitAccel} \\<br /> -\text{LimitAccel} \leq \text{accel}(4) \leq \text{LimitAccel} \\<br /> -\text{LimitAccel} \leq \text{accel}(5) \leq \text{LimitAccel} \\<br /> -\text{LimitAccel} \leq \text{accel}(6) \leq \text{LimitAccel} \\<br /> -\text{LimitAccel} \leq \text{accel}(7) \leq \text{LimitAccel}<br />

1.3.4. Velcoity

Derived by integrating the acceleration.

<br /> \text{vel}(0) = \text{lastVel} \\<br /> \text{vel}(1) = \text{vel}(0) +\text{accel}(0) \cdot \text{phase1T} +\text{jerk}(1)/2 \cdot \text{phase1T}^2 \\<br /> \text{vel}(2) = \text{vel}(1) +\text{accel}(1) \cdot \text{phase2T} +\text{jerk}(2)/2 \cdot \text{phase2T}^2 \\<br /> \text{vel}(3) = \text{vel}(2) +\text{accel}(2) \cdot \text{phase3T} +\text{jerk}(3)/2 \cdot \text{phase3T}^2 \\<br /> \text{vel}(4) = \text{vel}(3) +\text{accel}(3) \cdot \text{phase4T} +\text{jerk}(4)/2 \cdot \text{phase4T}^2 \\<br /> \text{vel}(5) = \text{vel}(4) +\text{accel}(4) \cdot \text{phase5T} +\text{jerk}(5)/2 \cdot \text{phase5T}^2 \\<br /> \text{vel}(6) = \text{vel}(5) +\text{accel}(5) \cdot \text{phase6T} +\text{jerk}(6)/2 \cdot \text{phase6T}^2 \\<br /> \text{vel}(7) = \text{vel}(6) +\text{accel}(6) \cdot \text{phase7T} +\text{jerk}(7)/2 \cdot \text{phase7T}^2 \\<br /> \text{vel}(7) = 0<br />

1.3.5. Velocity limits

<br /> -\text{LimitVelocity } \leq \text{vel}(1) \leq \text{LimitVelocity } \\<br /> -\text{LimitVelocity } \leq \text{vel}(2) \leq \text{LimitVelocity } \\<br /> -\text{LimitVelocity } \leq \text{vel}(3) \leq \text{LimitVelocity } \\<br /> -\text{LimitVelocity } \leq \text{vel}(4) \leq \text{LimitVelocity } \\<br /> -\text{LimitVelocity } \leq \text{vel}(5) \leq \text{LimitVelocity } \\<br /> -\text{LimitVelocity } \leq \text{vel}(6) \leq \text{LimitVelocity } \\<br /> -\text{LimitVelocity } \leq \text{vel}(7) \leq \text{LimitVelocity }<br />

1.3.6. Position

<br /> \text{targetDeltaPos} = \text{targetPos} -\text{lastPos}<br />

Derived by integrating the velocity:
<br /> \text{resultDeltaPos} = 0<br /> +\left( \text{vel}(0) \cdot \text{phase1T} +\text{accel}(0)/2 \cdot \text{phase1T}^2 +\text{jerk}(1)/6 * \text{phase1T}^3 \right)<br /> +\left( \text{vel}(1) \cdot \text{phase2T} +\text{accel}(1)/2 \cdot \text{phase2T}^2 +\text{jerk}(2)/6 * \text{phase2T}^3 \right)<br /> +\left( \text{vel}(2) \cdot \text{phase3T} +\text{accel}(2)/2 \cdot \text{phase3T}^2 +\text{jerk}(3)/6 * \text{phase3T}^3 \right)<br /> +\left( \text{vel}(3) \cdot \text{phase4T} +\text{accel}(3)/2 \cdot \text{phase4T}^2 +\text{jerk}(4)/6 * \text{phase4T}^3 \right)<br /> +\left( \text{vel}(4) \cdot \text{phase5T} +\text{accel}(4)/2 \cdot \text{phase5T}^2 +\text{jerk}(5)/6 * \text{phase5T}^3 \right)<br /> +\left( \text{vel}(5) \cdot \text{phase6T} +\text{accel}(5)/2 \cdot \text{phase6T}^2 +\text{jerk}(6)/6 * \text{phase6T}^3 \right)<br /> +\left( \text{vel}(6) \cdot \text{phase7T} +\text{accel}(6)/2 \cdot \text{phase7T}^2 +\text{jerk}(7)/6 * \text{phase7T}^3 \right)<br />

1.4. Minimize:
  1. Position error: \left| \text{targetDeltaPos} -\text{resultDeltaPos} \right|
  2. Position time: \text{phase1T} +\text{phase2T} +\text{phase3T} +\text{phase4T} +\text{phase5T} +\text{phase6T} +\text{phase7T}

2. Question(s)

Can this be solved without using non-linear programming?

If so, I'd welcome any hints on how to attempt to solve this problem or any literature (if possible freely accessible online) I should read for educating myself about it. I'd prefer practical / easy literature, because as you probably already figured I am not good at mathematics.

(I think non-linear mixed-integer programming can be avoided by trying to solve it for each possible value of \text{dir}, meaning solving two times and taking the "better" one of the feasible solutions (at least one should be feasible).)

I was actually hoping for solving it analytical with different cases or s.th. like that, but I can't even find a way to make it in a linear programming problem (maybe that is not possible).

Please hint me on typos or things I might have forgot, I will try to edit them in (if that is possible).Other notes

If it helps anything, then I can try to write down everything by making the jerk a left-continuous step function and deriving acceleration, velocity and resultDeltaPos from that. However I am not sure if that would make things better, because the functions would still have many cases then.

I hope I posted in the right sub-forum, because this might be more of an artificial model than modelling some real motion.
I selected Intermediate level thread prefix, because I don't know if this is an advanced problem or not.
 
Last edited by a moderator:
Well currently I am examining if it's at least a convex optimization problem.The absoulte objective function can be replaced as it is done with LP-problems, by adding two constraints and a new variable and changing
the first objective function:

<br /> \text{absDiff} \in \mathbb{R}_{\geq 0} \\<br /> \text{targetDeltaPos} -\text{resultDeltaPos} &lt;= \text{absDiff} \\<br /> -\text{targetDeltaPos} +\text{resultDeltaPos} &lt;= \text{absDiff}<br />

New 1.4. Minimize:

1. \text{absDiff}
2. as in first postIf we fix dir on any of the possible two values and if we have any two feasible solutions
<br /> u_1 = \left( \text{phase1T}_1, \text{phase2T}_1, \text{phase3T}_1, \text{phase4T}_1, \text{phase5T}_1, \text{phase6T}_1, \text{phase7T}_1 \right) \\<br /> u_2 = \left( \text{phase1T}_2, \text{phase2T}_2, \text{phase3T}_2, \text{phase4T}_2, \text{phase5T}_2, \text{phase6T}_2, \text{phase7T}_2 \right)<br />

Then we can check if the linear combination u_3 = \lambda_1 \cdot u_1 +\lambda_2 \cdot u_2 where \lambda_1 + \lambda_2 = 1 and \lambda_1 \in \mathbb{R}_{\geq 0} and \lambda_2 \in \mathbb{R}_{\geq 0} is a feasible solution too:Checking the Jerk equations:

Those are not affected.Checking the Acceleration equation constraints:

<br /> \text{accel}(0) = \text{lastAccel} \\<br /> \text{accel}(1) = \text{accel}(0) +\text{jerk}(1) \cdot \left(\lambda_1 \cdot \text{phase1T}_1 + \lambda_2 \cdot \text{phase1T}_2 \right) \\<br /> \text{accel}(2) = \text{accel}(1) +\text{jerk}(2) \cdot \left(\lambda_1 \cdot \text{phase2T}_1 + \lambda_2 \cdot \text{phase2T}_2 \right) \\<br /> \text{accel}(3) = \text{accel}(2) +\text{jerk}(3) \cdot \left(\lambda_1 \cdot \text{phase3T}_1 + \lambda_2 \cdot \text{phase3T}_2 \right) \\<br /> \text{accel}(4) = \text{accel}(3) +\text{jerk}(4) \cdot \left(\lambda_1 \cdot \text{phase4T}_1 + \lambda_2 \cdot \text{phase4T}_2 \right) \\<br /> \text{accel}(5) = \text{accel}(4) +\text{jerk}(5) \cdot \left(\lambda_1 \cdot \text{phase5T}_1 + \lambda_2 \cdot \text{phase5T}_2 \right) \\<br /> \text{accel}(6) = \text{accel}(5) +\text{jerk}(6) \cdot \left(\lambda_1 \cdot \text{phase6T}_1 + \lambda_2 \cdot \text{phase6T}_2 \right) \\<br /> \text{accel}(7) = \text{accel}(6) +\text{jerk}(7) \cdot \left(\lambda_1 \cdot \text{phase7T}_1 + \lambda_2 \cdot \text{phase7T}_2 \right) \\<br /> \text{accel}(7) = 0<br />

Let us check if thes equations still hold valid (meaning don't get infeasible):

It follows:
<br /> \text{lastAccel}<br /> +\text{jerk}(1) \cdot \left(\lambda_1 \cdot \text{phase1T}_1 + \lambda_2 \cdot \text{phase1T}_2 \right)<br /> +\text{jerk}(2) \cdot \left(\lambda_1 \cdot \text{phase2T}_1 + \lambda_2 \cdot \text{phase2T}_2 \right)<br /> +\text{jerk}(3) \cdot \left(\lambda_1 \cdot \text{phase3T}_1 + \lambda_2 \cdot \text{phase3T}_2 \right)<br /> +\text{jerk}(4) \cdot \left(\lambda_1 \cdot \text{phase4T}_1 + \lambda_2 \cdot \text{phase4T}_2 \right)<br /> +\text{jerk}(5) \cdot \left(\lambda_1 \cdot \text{phase5T}_1 + \lambda_2 \cdot \text{phase5T}_2 \right)<br /> +\text{jerk}(6) \cdot \left(\lambda_1 \cdot \text{phase6T}_1 + \lambda_2 \cdot \text{phase6T}_2 \right)<br /> +\text{jerk}(7) \cdot \left(\lambda_1 \cdot \text{phase7T}_1 + \lambda_2 \cdot \text{phase7T}_2 \right)<br /> = 0<br />

Now let's assume \text{dir} = 1 and \text{LimitJerk} = 1

Then it follows that:
<br /> \text{lastAccel}<br /> + \left(\lambda_1 \cdot \text{phase1T}_1 + \lambda_2 \cdot \text{phase1T}_2 \right)<br /> - \left(\lambda_1 \cdot \text{phase3T}_1 + \lambda_2 \cdot \text{phase3T}_2 \right)<br /> - \left(\lambda_1 \cdot \text{phase5T}_1 + \lambda_2 \cdot \text{phase5T}_2 \right)<br /> + \left(\lambda_1 \cdot \text{phase7T}_1 + \lambda_2 \cdot \text{phase7T}_2 \right)<br /> = 0<br />

We know that both solutions u_1, u_2 are 0, so it follows:

<br /> \text{lastAccel}<br /> + \left(\lambda_1 \cdot \text{phase1T}_1 + \lambda_2 \cdot \text{phase1T}_2 \right)<br /> - \left(\lambda_1 \cdot \text{phase3T}_1 + \lambda_2 \cdot \text{phase3T}_2 \right)<br /> - \left(\lambda_1 \cdot \text{phase5T}_1 + \lambda_2 \cdot \text{phase5T}_2 \right)<br /> + \left(\lambda_1 \cdot \text{phase7T}_1 + \lambda_2 \cdot \text{phase7T}_2 \right)<br /> =<br /> \text{lastAccel}<br /> + \left(1 \cdot \text{phase1T}_1 \right)<br /> - \left(1 \cdot \text{phase3T}_1 \right)<br /> - \left(1 \cdot \text{phase5T}_1 \right)<br /> + \left(1 \cdot \text{phase7T}_1 \right)<br />

Which is equivalent to:

<br /> + \lambda_1 \cdot \text{phase1T}_1 + \lambda_2 \cdot \text{phase1T}_2<br /> - \lambda_1 \cdot \text{phase3T}_1 - \lambda_2 \cdot \text{phase3T}_2<br /> - \lambda_1 \cdot \text{phase5T}_1 - \lambda_2 \cdot \text{phase5T}_2<br /> + \lambda_1 \cdot \text{phase7T}_1 + \lambda_2 \cdot \text{phase7T}_2<br /> =<br /> + 1 \cdot \text{phase1T}_1<br /> - 1 \cdot \text{phase3T}_1<br /> - 1 \cdot \text{phase5T}_1<br /> + 1 \cdot \text{phase7T}_1<br />

Which is equivalent to:

<br /> + \lambda_1 \cdot \text{phase1T}_1 + \lambda_2 \cdot \text{phase1T}_2<br /> - \lambda_1 \cdot \text{phase3T}_1 - \lambda_2 \cdot \text{phase3T}_2<br /> - \lambda_1 \cdot \text{phase5T}_1 - \lambda_2 \cdot \text{phase5T}_2<br /> + \lambda_1 \cdot \text{phase7T}_1 + \lambda_2 \cdot \text{phase7T}_2<br /> =<br /> + \left( \lambda_1 + \lambda_2 \right) \cdot \text{phase1T}_1<br /> - \left( \lambda_1 + \lambda_2 \right) 1 \cdot \text{phase3T}_1<br /> - \left( \lambda_1 + \lambda_2 \right) 1 \cdot \text{phase5T}_1<br /> + \left( \lambda_1 + \lambda_2 \right) 1 \cdot \text{phase7T}_1<br />

Which is equivalent to:

<br /> + \lambda_1 \cdot \text{phase1T}_1 + \lambda_2 \cdot \text{phase1T}_2<br /> - \lambda_1 \cdot \text{phase3T}_1 - \lambda_2 \cdot \text{phase3T}_2<br /> - \lambda_1 \cdot \text{phase5T}_1 - \lambda_2 \cdot \text{phase5T}_2<br /> + \lambda_1 \cdot \text{phase7T}_1 + \lambda_2 \cdot \text{phase7T}_2<br /> =<br /> + \left( \lambda_1 + \lambda_2 \right) \cdot \text{phase1T}_1<br /> - \left( \lambda_1 + \lambda_2 \right) \cdot \text{phase3T}_1<br /> - \left( \lambda_1 + \lambda_2 \right) \cdot \text{phase5T}_1<br /> + \left( \lambda_1 + \lambda_2 \right) \cdot \text{phase7T}_1<br />

Which is equivalent to:

<br /> + \lambda_2 \cdot \text{phase1T}_2<br /> - \lambda_2 \cdot \text{phase3T}_2<br /> - \lambda_2 \cdot \text{phase5T}_2<br /> + \lambda_2 \cdot \text{phase7T}_2<br /> =<br /> + \lambda_2 \cdot \text{phase1T}_1<br /> - \lambda_2 \cdot \text{phase3T}_1<br /> - \lambda_2 \cdot \text{phase5T}_1<br /> + \lambda_2 \cdot \text{phase7T}_1<br />

If \lambda_2 = 0 the solution is trivial, otherwise
it follows that

<br /> + \text{phase1T}_2<br /> - \text{phase3T}_2<br /> - \text{phase5T}_2<br /> + \text{phase7T}_2<br /> =<br /> + \text{phase1T}_1<br /> - \text{phase3T}_1<br /> - \text{phase5T}_1<br /> + \text{phase7T}_1<br />

However that would mean that for any feasible solution the sum of these times of phase 1,3,5,7 have to be equal.

In other words if we can show that there are feasible solutions for \text{dir} = 1 and \text{LimitJerk} = 1, that have different values for the sum of the times of phase 1,3,5,7,
then the optimization problem is not even a convex optimization problem.


I will try to continue from here within the next days.
 
There is a stupid mistake by me in the previous post at the end:
Of course I shouldn't have written "sum".
It would need to be the exact equation I have written at the end.

This is always fulfilled, because both sides of the equation would have to be zero by definition of the acceleration equations under the given conditions (\text{dir}=1 and \text{LimitJerk}=1).

In other words, I have not shown anything at all yet about whether this problem is convex or not :-(
 
Dominik Tugend said:
1.4. Minimize:
  1. Position error: \left| \text{targetDeltaPos} -\text{resultDeltaPos} \right|
  2. Position time: \text{phase1T} +\text{phase2T} +\text{phase3T} +\text{phase4T} +\text{phase5T} +\text{phase6T} +\text{phase7T}

How is that a specific objective function? For example, suppose by using a long position time that you can reduce position error and that by allowing a larger position error that you can reduce position time. How do you pick which of those alternatives to use ?

Is this a problem in 1-dimensional position space ? - or 3 ?

From your algorithm, I would assume the variables we are trying to solve for are Jerk's 1,3,5,7 and the variable "dir". Is that correct ?
 
Stephen Tashi said:
How is that a specific objective function? For example, suppose by using a long position time that you can reduce position error and that by allowing a larger position error that you can reduce position time. How do you pick which of those alternatives to use ?

Is this a problem in 1-dimensional position space ? - or 3 ?

From your algorithm, I would assume the variables we are trying to solve for are Jerk's 1,3,5,7 and the variable "dir". Is that correct ?

Thank you very much for your feedback!

By that I meant, that first an optimal solutions that minimize the position error are found (1.) and then from those an optimal solution that minimizes the sum of the phase times is picked (2.) - meaning I want (1.) to be the main objective and (2.) to be the sub-objective. I sadly don't know how to express such a thing properly.

The problem is in one dimensional position space, the position variables are scalars.

No, I am only trying to solve for the variables in Output (phase1T,phase2T,phase3T,phase4T,phase5T,phase6T,phase7T,dir) all variables in Input are given (constants).To be honest I was able to solve a simpler version (only 2nd order motion profile) for my needs, which I presented here:
https://www.physicsforums.com/threads/2nd-oder-motion-profile-trapezoidal-velocity-code.869551/
It's really good enough for me, so I am not that much interested in trying to solve this much more complicated problem anymore to be honest.

Also I think you could either run into patent conflicts or make some money when selling the solution to an elevator company or s.th. like that, because I heard that elevators actually would use such 3rd order motion profiles.Again thank you very much for your feedback :-)
 
Last edited by a moderator:
Suppose ,instead of the usual x,y coordinate system with an I basis vector along the x -axis and a corresponding j basis vector along the y-axis we instead have a different pair of basis vectors ,call them e and f along their respective axes. I have seen that this is an important subject in maths My question is what physical applications does such a model apply to? I am asking here because I have devoted quite a lot of time in the past to understanding convectors and the dual...
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Back
Top