Documentation

# bsplinepolytraj

Generate polynomial trajectories using B-splines

## Syntax

``[q,qd,qdd,pp] = bsplinepolytraj(controlPoints,tInterval,tSamples)``

## Description

example

````[q,qd,qdd,pp] = bsplinepolytraj(controlPoints,tInterval,tSamples)` generates a piecewise cubic B-spline trajectory that falls in the control polygon defined by `controlPoints`. The trajectory is uniformly sampled between the start and end times given in `tInterval`. The function returns the positions, velocities, and accelerations at the input time samples, `tSamples`. The function also returns the piecewise polynomial `pp` form of the polynomial trajectory with respect to time.```

## Examples

collapse all

Use the `bsplinepolytraj` function with a given set of 2-D xy control points. The B-spline uses these control points to create a trajectory inside the polygon. Time points for the waypoints are also given.

```cpts = [1 4 4 3 -2 0; 0 1 2 4 3 1]; tpts = [0 5];```

Compute the B-spline trajectory. The function outputs the trajectory positions (`q`), velocity (`qd`), acceleration (`qdd`), time vector (`tvec`), and polynomial coefficients (`pp`) of the polynomial that achieves the waypoints using trapezoidal velocities.

```tvec = 0:0.01:5; [q, qd, qdd, pp] = bsplinepolytraj(cpts,tpts,tvec);```

Plot the results. Show the control points and the resulting trajectory inside them.

```figure plot(cpts(1,:),cpts(2,:),'xb-') hold all plot(q(1,:), q(2,:)) xlabel('X') ylabel('Y') hold off``` Plot the position of each element of the B-spline trajectory. These trajectories are cubic piecewise polynomials parameterized in time.

```figure plot(tvec,q) hold all plot([0:length(cpts)-1],cpts,'x') xlabel('t') ylabel('Position Value') legend('X-positions','Y-positions') hold off``` ## Input Arguments

collapse all

Points for control polygon of B-spline trajectory, specified as an n-by-p matrix, where n is the dimension of the trajectory and p is the number of control points.

Example: `[1 4 4 3 -2 0; 0 1 2 4 3 1]`

Data Types: `single` | `double`

Start and end times for the trajectory, specified as a two-element vector.

Example: `[0 10]`

Data Types: `single` | `double`

Time samples for the trajectory, specified as a vector. The output position, `q`, velocity, `qd`, and accelerations, `qdd`, are sampled at these time intervals.

Example: `0:0.01:10`

Data Types: `single` | `double`

## Output Arguments

collapse all

Positions of the trajectory at the given time samples in `tSamples`, returned as a vector.

Data Types: `single` | `double`

Velocities of the trajectory at the given time samples in `tSamples`, returned as a vector.

Data Types: `single` | `double`

Accelerations of the trajectory at the given time samples in `tSamples`, returned as a vector.

Data Types: `single` | `double`

Piecewise-polynomial, returned as a structure that defines the polynomial for each section of the piecewise trajectory. You can build your own piecewise polynomials using `mkpp`, or evaluate the polynomial at specified times using `ppval`. The structure contains the fields:

• `form`: `'pp'`.

• `breaks`: p-element vector of times when the piecewise trajectory changes forms. p is the number of waypoints.

• `coefs`: n(p–1)-by-`order` matrix for the coefficients for the polynomials. n(p–1) is the dimension of the trajectory times the number of `pieces`. Each set of n rows defines the coefficients for the polynomial that described each variable trajectory.

• `pieces`: p–1. The number of breaks minus 1.

• `order`: Degree of the polynomial + 1. For example, cubic polynomials have an order of 4.

• `dim`: n. The dimension of the control point positions.

 Farin, Gerald E. Curves and Surfaces for Computer Aided Geometric Design: A Practical Guide. San Diego, CA: Academic Press, 1993.

##### Support Get trial now