Looking for help for building a Spline's algorithm 10th order

178 Views Asked by At

I'm trying to code the following algorithm in C++ and need help to understand the build of Splines from a mathematical point of view (found on page 129 on this paper). $$ f(t) = \boldsymbol{t} \cdot \boldsymbol{c} ; \quad where \quad \boldsymbol{t} = [1\quad t\quad t^{2}...\quad t^{N-1}]; $$ For this optimal trajectory's problem the spline must be of order 10, with four derivative of position, expressed as following: \begin{align} \frac{d^n f(t_{0})}{dt^{n}} = \frac{d^n(v_{start}.x)}{dt^{n}}; n = 0...4\\ f(T) = (v_{end}.x.p) \quad \quad \quad \quad \quad \quad (eq. 1)& \\ \frac{d^n f(T)}{dt^{n}} = \frac{d^n(v_{end}.x)}{dt^{n}}; n = 1...4 \\ \end{align}

where $T$ is the max time the next point should be reached.

Now looking closely at the equation set you can realize tha I have to find the 9 coefficients of $\boldsymbol{c}$. Since the border conditions are nine (four for the first derivates terms, one for eq. 1 and the last four for the last derivative), I would code my algorithm in the following way:

  • Calculate the $\boldsymbol{t}$ for all four derivatives: \begin{equation} \boldsymbol{t} = [1\quad t\quad t^{2}\quad t^{3}\quad t^{4}\quad t^{5}\quad t^{6}\quad t^{7}\quad t^{8}\quad t^{9}]\\ \boldsymbol{t'} = [0 \quad 1 \quad 2t \quad 3t^{2} \quad 4t^{3} \quad 5t^{4} \quad 6t^{5} \quad 7t^{6} \quad 8t^{7} \quad 9t^{8}]\\ \boldsymbol{t''} = [0 \quad 0 \quad 2 \quad 6t \quad 12t^{2} \quad 20t^{3} \quad 30t^{4} \quad 42t^{5} \quad 56t^{6} \quad 72t^{7}]\\ \boldsymbol{t'''} = [0 \quad 0 \quad 0 \quad 6 \quad 24t \quad 60t^{2} \quad 120t^{3} \quad 210t^{4} \quad 336t^{5} \quad 504t^{6}]\\ \boldsymbol{t''''} = [0 \quad 0 \quad 0 \quad 6 \quad 24 \quad 120t \quad 360t^{2} \quad 840t^{3} \quad 1680t^{4} \quad 3024t^{5}]\\ \end{equation}

  • write the equation system in matrix form to get the nine coefficients $\boldsymbol{c}$, where: $\boldsymbol{c}$ is a $9$x$1$ vector, $t_{0}$ the starting value and $T$ the final value at end of the local path:

\begin{cases} f(t0) = \boldsymbol{t_{t_{0}}} \cdot \boldsymbol{c}\\ f'(t0) = \boldsymbol{t_{t_{0}}'} \cdot \boldsymbol{c}\\ f''(t0) = \boldsymbol{t_{t_{0}}''} \cdot \boldsymbol{c}\\ f'''(t0) = \boldsymbol{t_{t_{0}}'''} \cdot \boldsymbol{c}\\ f''''(t0) = \boldsymbol{t_{t_{0}}''''} \cdot \boldsymbol{c}\\ f(T) = \boldsymbol{t_{T}} \cdot \boldsymbol{c}\\ f(T) = \boldsymbol{t_{T}} \cdot \boldsymbol{c}\\ f'(T) = \boldsymbol{t_{T}'} \cdot \boldsymbol{c}\\ f''(T) = \boldsymbol{t_{T}''} \cdot \boldsymbol{c}\\ f'''(T) = \boldsymbol{t_{T}'''} \cdot \boldsymbol{c}\\ f''''(T) = \boldsymbol{t_{T}''''} \cdot \boldsymbol{c}\\ \end{cases}

  • writing the above system in the following form: $$ \boldsymbol{f} = \boldsymbol{t} \cdot \boldsymbol{c} $$

I get the inverse of the matrix $\boldsymbol{t}$ and as a result the wanted matrix of coefficients $\boldsymbol{c}$

$$ \boldsymbol{c} = \boldsymbol{t}^{-1} \cdot \boldsymbol{f} $$

Done! Then I'll write all that stuff in C++.

Now I have some questions about my code scratch explained above...

  1. Is that the right to get the spline's coefficients? Or I'm doing some mistakes that I'm not aware of?
  2. Most probably you saw the problem in the equation system above but you thought, I did a typing mistake. The 5th and 6th boundary conditions are identical. Looking at the first set of boundary conditions I wrote at the very beginning, I have one condition for: $ f(T) = (v_{end}.x.p) $ and a second condition for the condition: $ f(T) = (v_{end}.x) $ they differ only for the term $.p$ which in the paper is not specified exactly. I'm guessing that $v_{start}, v_{end}$ are velocities, so I suppose it could be a position, but to me should be $x$ the variable for the position. $.p$ seems to me to refer to something else that I don#t know. So I'm asking you if you know or you could help me to find out which parameter should I consider for that condition.

  3. The same paper (I copy the text below for a rapid look) says that the following functional should be calculated for the optimal solution according the following functional: $$ min \int_{t_{0}}^T \| \frac{d^2f(t)}{dt^2} \| s.t. $$

from a mathematical point of view makes sense, but I've no idea how to translate it into a code. The second derivative of the spline is going to be normalized (the spline is a 3D path), and...then? There is a for loop to calculate more splines and check which one has the smallest normalized value? Once the algorithm for the spline has been run once, even running the same algorithm hundreds times doesn't change the min value. So I've no idea how to get the functional through a code.

Many thanks in advance for the help. If something is not clear, I'm going to update the post.

Here an extract from the paper:

enter image description here

1

There are 1 best solutions below

4
On BEST ANSWER

The 5th and 6th boundary conditions are conflicting to each other and there is no way you can solve such equations. If you look at the original paper more carefully, equation (5.7) is only for n=1~4. Therefore, there is no conflicting equations in the original paper.

Also, for minimizing the integral of the squared second derivative, it is for achieving a "smoother" polynomial curve. What you need to do is to use a polynomial curve that has more degrees of freedom than the number of boundary conditions. For example, if you have 10 boundary conditions, you need to use a polynomial curve with degree 10 and above. If you use degree 9, you will end up with the "interpolation" case where the polynomial is obtained by solving equations set from the boundary conditions. If you use degree 10 and above, you have more DoFs that need to be solved for and your problem becomes an optimization problem with linear equality constraints.