**Trajectory generation**

**Introduction**

A trajectory is basically the set of positions commands that are sent to the system. The importance of trajectory generation lies making a trajectory that can feasibly be followed in by a machine. For example, the trajectory must not require the system to apply force beyond its capacities.

The general approach to generating trajectories is to obtain the one dimensional tangential position commands and then map this to higher dimensions.

**Basic principles**

The most basic trajectory is based on the trapezoidal velocity profile where the velocity increases linearly, cruises and then decreases linearly. Although more complex methods are used in practice, this introduces the basic concept of generating a feasible trajectory. The linear increase of velocity implies a constant acceleration. As long as the acceleration is below what can be produced by the machine, it is deemed feasible. A plot is shown below of the tangential characteristics of displacement, velocity and acceleration using the trapezoidal velocity profile.

**Equations**

For the trapezoidal profile, the equations for the position commands are shown below.

$$ l_{1}(t) = \frac{At^2}{2} $$

$$ l_{2}(t) = l_{1}(T_1)+f_c\cdot(t-T_{1}) $$

$$ l_{3}(t) = l_{2}(T_1+T_2)+f_c\cdot(t-T_{1}+T_{2}) -\frac{A\cdot(t-T_{1}+T_{2})^2}{2}$$

An example plot of the displacement, velocity and acceleration is shown below. We can see the quadratic behaviour of the displacement in the accelerating and decelerating regions, and the linear behaviour in the cruising region.

Depending on the length of the curve travelled, as well as the maximum acceleration of the machine, the times \(T_1,T_2,T_3\) will change. It is also possible that the path increment will be too short, thus, cruising speed will not be reached. This will not be discussed in this description.

The general equations for the time periods \(T_1,T_2,T_3\) are given below.

Now suppose that we have a general path \(P\) with length \(L\). The objective them becomes to trace \(P\) with the trapezoidal velocity profile discussed earlier.

In fact this is done quite easily using an arc length parametrization of the path \(P\). Suppose that the path \(P\) is a three dimensional path in space parametrized by variable \(\alpha\).

$$ P = (x(\alpha),y(\alpha),z(\alpha)) $$

The arc length of the curve is then given by the equation below

$$ s = \int{|P'(\alpha)|d\alpha} = f(\alpha) $$

Then the arc length parameterization of \(P\) is obtained by substituting \(\alpha\) for \(\alpha=f^{-1}(s)\). Let \(P(s)\) denote the arc length parameterization of \(P\). At this point all we need to do is let \(s=l(t)\) and the tangential velocity is preserved. This occurs because by an arc length parameterization forces unit velocity. However, what is important to understand is that in non-linear path motion, there is an added normal acceleration to the kinematics. Thus, trajectory generation must also be done in order to guarantee that the added acceleration does not exceed that which can be provided by the machine.

**Line example**

Suppose the problem is to trace a line with trapezoidal velocity profile. The equation for a general line in the plane along a specified direction is shown below.

$$ P(\alpha) = (x_0,y_0)+u \cdot \alpha $$

Where (\u\) is a directional vector

In this case, the arc length parameterization can be found easily by differentiating \(P\) with respect to \(\alpha\). This gives the below expression for the arc length \(s\).

$$ s = \int{|u|d\alpha} = \sqrt{u_{1}^2+u_{2}^2} \cdot \alpha $$

Therefore, a substitution can be made to find the arc length parameterization for a line.

$$ P(\alpha) = (x_0,y_0) + \frac{u}{|u|}\cdot \alpha $$

Note that the arc length parameterization of a line will be obtained as long as a unit directional vector is used to define the line. The last step is then to substitute \(\alpha\) for \(s\).

$$ P(s) = (x_0,y_0) + \frac{u}{|u|}\cdot s $$

**Arc example**

Suppose we wished to trace a section of an arc with a circular tool. The first thing to do is obtain an equation for the path, for a circle it is shown below.

$$ P(\alpha) = (R_{0}cos(\alpha),R_{0}sin(\alpha)) $$

$$ \alpha_{0}<\alpha\leq\alpha_{f} $$

First differentiate the components in respect to (\alpha\).

$$ P'(\alpha) = R_{0}(-sin(\alpha),cos(\alpha)) $$

Therefore after integrating, we find the simple equation for arc length \(s\) as a function \(\alpha\).

$$ s = R_{0}\alpha $$

Then substitution in the original equation yields the arc length parameterization

$$ P(s) = \left( R_{0}cos\left( \frac{s}{R_{0}} \right) , R_{0}sin\left( \frac{s}{R_{0}} \right) \right)$$

This makes sense as the angle \(\alpha\) by the definition of a radian should be proportional to the arc length. At this point all that needs to be done is to substitute the piece-wise displacement curve into the equation for \(s\).

$$ P(s) = \left( R_{0}cos\left( \frac{l(t)}{R_{0}} \right) , R_{0}sin\left( \frac{l(t)}{R_{0}} \right) \right)$$