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.AbstractKnotPoint
— TypeAbstractKnotPoint{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 methods | Brief description | |
---|---|---|
state_dim(z) | State vector dimension | |
control_dim(z) | Control vector dimension | |
get_data(z)::V | Get the vector of concatenated states and controls | |
Optional Methods | Default definition | Brief description |
time(z) | z.t | Get the time |
timestep(z) | z.dt | Get the time step |
settime!(z, t) | z.t = t | Set the time |
settimestep!(z, dt) | z.dt = dt | Set 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.getstate
— Functiongetstate(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 SVector
s.
RobotDynamics.getcontrol
— Functiongetcontrol(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 SVector
s. If the knot point is a terminal knot point, it will return an empty view or an SVector
of zeros.
RobotDynamics.state
— Functionstate(z)
Get the state vector. Returns either a view or an SVector
.
RobotDynamics.control
— Functioncontrol(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!
— Functionsetdata!(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.setstate!
— Functionsetstate!(z, x)
Set the state vector for an AbstractKnotPoint
.
RobotDynamics.setcontrol!
— Functionsetcontrol!(z, x)
Set the control vector for an AbstractKnotPoint
.
RobotDynamics.is_terminal
— Functionis_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.vectype
— Functionvectype(x)
Get the vector type used by the object x
. Used to allow either static or dynamic arrays in structs such as AbstractKnotPoint
.
RobotDynamics.datatype
— Functiondatatype(x)
Get the numeric data type used by the object x
. Typically a floating point data type.
Concrete knot point types
RobotDynamics.KnotPoint
— TypeKnotPoint{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 StaticVector
s.
The vector type V
can be queried using vectype(z)
.
RobotDynamics.StaticKnotPoint
— TypeStaticKnotPoint
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