timor.utilities.rtb_trajectory

Attributes

ArrayLike

_scalartypes

Classes

RtbTrajectory

A container class for trajectory data. Reduced version of the original, without plotting functionalities.

Functions

getvector(v[, dim, out, dtype])

Return a vector value

jtraj(q0, qf, t[, qd0, qd1])

Compute a joint-space trajectory

mstraj(viapoints, dt, tacc[, qdmax, tsegment, q0, ...])

Multi-segment multi-axis trajectory

Module Contents

timor.utilities.rtb_trajectory.ArrayLike
class timor.utilities.rtb_trajectory.RtbTrajectory(name, t, s, sd=None, sdd=None, istime=False)

A container class for trajectory data. Reduced version of the original, without plotting functionalities.

Construct a new trajectory instance

Parameters:
  • name (str) – name of the function that created the trajectory

  • t (ndarray(m)) – independent variable, eg. time or step

  • s (ndarray(m) or ndarray(m,n)) – position

  • sd (ndarray(m) or ndarray(m,n)) – velocity

  • sdd (ndarray(m) or ndarray(m,n)) – acceleration

  • istime (float) – t is time, otherwise step number

  • tblend – blend duration (trapezoidal only)

The object has attributes:

  • t the independent variable

  • s the position

  • sd the velocity

  • sdd the acceleration

If t is time, ie. istime is True, then the units of sd and sdd are \(s^{-1}\) and \(s^{-2}\) respectively, otherwise with respect to t.

Note

Data is stored with timesteps as rows and axes as columns.

__len__()

Length of trajectory

Returns:

number of steps in the trajectory

Return type:

int

__repr__()

String representation of the trajectory

__str__()

Print representation of the trajectory

istime = False
name
property naxes

Number of axes in the trajectory

Returns:

number of axes or dimensions

Return type:

int

property q

Position trajectory

Returns:

trajectory with one row per timestep, one column per axis

Return type:

ndarray(n,m)

Note

This is a synonym for .s, for compatibility with other applications.

property qd

Velocity trajectory

Returns:

trajectory velocity with one row per timestep, one column per axis

Return type:

ndarray(n,m)

Note

This is a synonym for .sd, for compatibility with other applications.

property qdd

Acceleration trajectory

Returns:

trajectory acceleration with one row per timestep, one column per axis

Return type:

ndarray(n,m)

Note

This is a synonym for .sdd, for compatibility with other applications.

s
sd = None
sdd = None
t
timor.utilities.rtb_trajectory._scalartypes
timor.utilities.rtb_trajectory.getvector(v, dim=None, out='array', dtype=np.float64)

Return a vector value

Parameters:
  • v – passed vector

  • dim (int or None) – required dimension, or None if any length is ok

  • out (str) – output format, default is ‘array’

  • dtype (numPy type) – datatype for numPy array return (default np.float64)

Returns:

vector value in specified format

Raises:
Return type:

ArrayLike

  • getvector(vec) is vec converted to the output format out where vec is any of:

    • a Python native int or float, a 1-vector

    • Python native list or tuple

    • numPy real 1D array, ie. shape=(N,)

    • numPy real 2D array with a singleton dimension, ie. shape=(1,N) or (N,1)

  • getvector(vec, N) as above but must be an N-element vector.

The returned vector will be in the format specified by out:

format

return type

‘sequence’

Python list, or tuple if a tuple was passed in

‘list’

Python list

‘array’

1D numPy array, shape=(N,) [default]

‘row’

row vector, a 2D numPy array, shape=(1,N)

‘col’

column vector, 2D numPy array, shape=(N,1)

Note

  • For ‘array’, ‘row’ or ‘col’ output the NumPy dtype defaults to the dtype of v if it is a NumPy array, otherwise it is set to the value specified by the dtype keyword which defaults to np.float64.

  • If v is symbolic the dtype is retained as 'O'

Seealso:

isvector()

Return type:

ArrayLike

timor.utilities.rtb_trajectory.jtraj(q0, qf, t, qd0=None, qd1=None)

Compute a joint-space trajectory

Parameters:
  • q0 (array_like(n)) – initial joint coordinate

  • qf (array_like(n)) – final joint coordinate

  • t (array_like or int) – time vector or number of steps

  • qd0 (array_like(n), optional) – initial velocity, defaults to zero

  • qd1 (array_like(n), optional) – final velocity, defaults to zero

Returns:

trajectory

Return type:

Trajectory instance

  • tg = jtraj(q0, qf, N) is a joint space trajectory where the joint coordinates vary from q0 (M) to qf (M). A quintic (5th order) polynomial is used with default zero boundary conditions for velocity and acceleration. Time is assumed to vary from 0 to 1 in N steps.

  • tg = jtraj(q0, qf, t) as above but t is a uniformly-spaced time vector

The return value is an object that contains position, velocity and acceleration data.

Notes:

  • The time vector, if given, scales the velocity and acceleration outputs assuming that the time vector starts at zero and increases linearly.

Seealso:

ctraj(), qplot(), jtraj()

timor.utilities.rtb_trajectory.mstraj(viapoints, dt, tacc, qdmax=None, tsegment=None, q0=None, qd0=None, qdf=None, verbose=False)

Multi-segment multi-axis trajectory

Parameters:
  • viapoints (ndarray(m,n)) – A set of viapoints, one per row

  • dt (float (seconds)) – time step

  • tacc (float) – acceleration time (seconds)

  • qdmax (array_like(n) or float, optional) – maximum speed, defaults to None

  • tsegment (array_like, optional) – maximum time of each motion segment (seconds), defaults to None

  • q0 (array_like(n), optional) – initial coordinates, defaults to first row of viapoints

  • qd0 (array_like(n), optional) – inital velocity, defaults to zero

  • qdf (array_like(n), optional) – final velocity, defaults to zero

  • verbose (bool, optional) – print debug information, defaults to False

Returns:

trajectory

Return type:

Trajectory instance

Computes a trajectory for N axes moving smoothly through a set of viapoints. The motion comprises M segments:

  • The initial coordinates are the first row of viapoints or q0 if provided.

  • The final coordinates are the last row of viapoints

  • Each segment is linear motion and polynomial blends connect the viapoints.

  • All joints arrive at each via point at the same time, ie. the motion is coordinated across axes

The time of the segments can be specified in two different ways:

  1. In terms of segment time where tsegment is an array of segment times which is the number of via points minus one:

    ``traj = mstraj(viapoints, dt, tacc, tsegment=TS)``
    
  2. Governed by the speed of the slowest axis for the segment. The axis speed is a scalar (all axes have the same speed) or an N-vector of speed per axis:

    traj = mstraj(viapoints, dt, tacc, qdmax=SPEED)
    

The return value is a namedtuple (named mstraj) with elements:

  • t the time coordinate as a numpy ndarray, shape=(K,)

  • q the axis values as a numpy ndarray, shape=(K,N)

  • arrive a list of arrival times for each segment

  • info a list of named tuples, one per segment that describe the slowest axis, segment time, and time stamp

  • via the passed set of via points

The trajectory proper is (traj.t, traj.q). The trajectory is a matrix has one row per time step, and one column per axis.

Notes:

  • Only one of qdmag or tsegment can be specified

  • If tacc is greater than zero then the path smoothly accelerates

between segments using a polynomial blend. This means that the the via point is not actually reached. - The path length K is a function of the number of via points and the time or velocity limits that apply. - Can be used to create joint space trajectories where each axis is a joint coordinate. - Can be used to create Cartesian trajectories where the “axes” correspond to translation and orientation in RPY or Euler angle form. - If qdmax is a scalar then all axes are assumed to have the same maximum speed. - tg has extra attributes arrive, info and via

Seealso:

trapezoidal(), ctraj(), mtraj()