Knot Points

RobotDynamics describes forced dynamical systems whose behavior is defined by an $n$-dimensional state vector $x$ and an $m$-dimensional control vector $u$. We often represent trajectories of the systems by sampling a continuous trajectory, where each sample has a state, control, time, and the time step between the current sample and the next. Following terminology from direct trajectory optimization methods such as direct collocation, we refer to each sample as "knot point." This page describes the abstract type AbstractKnotPoint, as well a couple different implementations of the abstraction provided by the package. These types should be sufficient for most use cases: further instantiations of the AbstractKnotPoint type shouldn't be needed in most cases.

The AbstractKnotPoint Type

RobotDynamics.AbstractKnotPointType
AbstractKnotPoint{Nx,Nu,V,T}

Stores the states, controls, time, and time step at a single point along a trajectory of a forced dynamical system with n states and m controls.

Interface

All instances of AbstractKnotPoint should support the following methods:

Required methodsBrief description
state_dim(z)State vector dimension
control_dim(z)Control vector dimension
get_data(z)::VGet the vector of concatenated states and controls
Optional MethodsDefault definitionBrief description
time(z)z.tGet the time
timestep(z)z.dtGet the time step
settime!(z, t)z.t = tSet the time
settimestep!(z, dt)z.dt = dtSet the time step
is_terminal(z)timestep(z) === zero(datatype(z))

Methods

Given the above interface, the following methods are defined for an AbstractKnotPoint:

RobotDynamics.getstateFunction
getstate(z, v)

Extract the state vector from a vector v. Returns a view into the matrix by default, or an SVector if the knot point uses SVectors.

RobotDynamics.getcontrolFunction
getcontrol(z, v)

Extract the state vector from a vector v. Returns a view into the matrix by default, or an SVector if the knot point uses SVectors. If the knot point is a terminal knot point, it will return an empty view or an SVector of zeros.

RobotDynamics.stateFunction
state(z)

Get the state vector. Returns either a view or an SVector.

RobotDynamics.controlFunction
control(z)

Get the control vector. Returns either a view of an SVector. For a terminal knot point it will return an empty view or an SVector of zeros.

RobotDynamics.setdata!Function
setdata!(z, v)

Set the data vector, or the concatenated vector of states and controls.

setdata!(Z, V)

Set the concatenated state and control vector for each knot point in the trajectory Z. V may be either a vector of vectors or a 2D matrix.

RobotDynamics.is_terminalFunction
is_terminal(z)

Determines if the knot point z is a terminal knot point with no controls, only state information. By default a knot point is assumed to be a terminal knot point if the time step is zero. By convention, if the last knot point has control values assigned (for example, when doing first-order hold on the controls), the final time step is set to infinity instead of zero.

RobotDynamics.datatypeFunction
datatype(x)

Get the numeric data type used by the object x. Typically a floating point data type.

Concrete knot point types

RobotDynamics.KnotPointType
KnotPoint{Nx,Nu,V,T}

A mutable AbstractKnotPoint with Nx states, Nu controls, stored using a vector type V with data type T. Since the struct is mutable, the time, timestep, and data can all be changed, which can be very efficient when the data being stored as an SVector.

Constructors

KnotPoint{n,m}(v, t, dt)
KnotPoint{n,m}(x, u, t, dt)
KnotPoint{n,m}(n, m, v, t, dt) 
KnotPoint(n, m, v, t, dt)       # create a KnotPoint{Any,Any}
KnotPoint(x, u, t, dt)

The last method will create a KnotPoint{Any,Any} if x and u are not StaticVectors.

The vector type V can be queried using vectype(z).

RobotDynamics.StaticKnotPointType
StaticKnotPoint

A static version of KnotPoint. Uses all of the same methods and constructors, but also adds the following methods:

StaticKnotPoint(z, v)

which creates a new StaticKnotPoint using the information from the AbstractKnotPoint z, but using data from v. Useful for creating temporary knot points from existing ones without any runtime allocations.

The following methods are similar to their mutable versions, but create a new StaticKnotPoint:

setdata
setstate
setcontrol