KnotPoint type
A common way of dealing with trajectories of forced dynamical systems, especially in optimization, is to represent a trajectory with a fixed number of "knot points", typically distributed evenly over time. Each point records the states, controls, time, and time step to the next point. It is often convenient to store all this information together, which is the purpose of the AbstractKnotPoint type. Additionally, it is almost always more efficient to index into a concatenated vector than it is to concatenate two smaller vectors, so the states and controls are stacked together in a single n+m-dimensional vector.
RobotDynamics.jl defines a couple different implementations of the AbstractKnotPoint interface, which can be useful depending on the application.
Types
RobotDynamics.AbstractKnotPoint — TypeAbstractKnotPoint{T,n,m}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:
state(z)::StaticVector{n} # state vector
control(z)::StaticVector{m} # control vector
z.t::Real # time
z.dt::Real # time to next point (time step)By default, it is assumed that if z.dt == 0 the point is the last point in the trajectory.
Alternatively, the methods state and control will be automatically defined if the following fields are present:
z.z: the stacked vector[x;u]z._x: the indices of the states, such thatx = z.z[z._x]z._u: the indices of the controls, such thatx = u.z[z._u]
RobotDynamics.GeneralKnotPoint — TypeGeneralKnotPoint{T,n,m,V} <: AbstractKnotPoint{T,n,m}A mutable instantiation of the AbstractKnotPoint interface where the joint vector z = [x;u] is represented by a type V.
Constructors
GeneralKnotPoint(n::Int, m::Int, z::AbstractVector, dt, [t=0])
GeneralKnotPoint(z::V, _x::SVector{n,Int}, _u::SVector{m,Int}, dt::T, t::T)
KnotPoint(z::V, _x::SVector{n,Int}, _u::SVector{m,Int}, dt::T, t::T)RobotDynamics.KnotPoint — TypeKnotPoint{T,n,m,nm}A GeneralKnotPoint whose stacked vector z = [x;u] is represented by an SVector{nm,T} where nm = n+m.
Setters
Use the following methods to set values in a KnotPoint:
set_state!(z::KnotPoint, x)
set_control!(z::KnotPoint, u)
z.t = t
z.dt = dtConstructors
KnotPoint(x, u, dt, [t=0.0])
KnotPoint(x, m, [t=0.0]) # for terminal knot pointRobotDynamics.StaticKnotPoint — TypeStaticKnotPoint{T,n,m,nm} <: AbstractKnotPoint{T,n,m}An immutable AbstractKnotPoint whose stacked vector is represented by an SVector{nm,T} where nm = n+m. Since isbits(z::StaticKnotPoint) = true, these can be created very efficiently and with zero allocations.
Constructors
StaticKnotPoint(z::SVector{nm}, _x::SVector{n,Int}, _u::SVector{m,Int}, dt::Float64, t::Float64)
StaticKnotPoint(x::SVector{n}, u::SVector{m}, [dt::Real=0.0, t::Real=0.0])
StaticKnotPoint(z0::AbstractKnotPoint, z::AbstractVector)where the last constructor uses another AbstractKnotPoint to create a StaticKnotPoint using the stacked state-control vector z. If length(z) == n, the constructor will automatically append m zeros.
Methods
All AbstractKnotPoint types support the following methods:
RobotDynamics.state — Functionstate(::AbstractKnotPoint)Return the n-dimensional state vector
RobotDynamics.control — Functioncontrol(::AbstractKnotPoint)Return the m-dimensional control vector
RobotDynamics.is_terminal — Functionis_terminal(::AbstractKnotPoint)::BoolDetermine if the knot point is the terminal knot point, which is the case when z.dt == 0.
RobotDynamics.get_z — Functionget_z(::AbstractKnotPoint)Returns the stacked state-control vector z, or just the state vector if is_terminal(z) == true.
RobotDynamics.set_state! — Functionset_state!(z::AbstractKnotPoint, x::AbstractVector)Set the state in z to x.
RobotDynamics.set_control! — Functionset_control!(z::AbstractKnotPoint, u::AbstractVector)Set the controls in z to u.
RobotDynamics.set_z! — Functionset_z!(z::AbstractKnotPoint, z_::AbstractVector)Set both the states and controls in z from the stacked state-control vector z_, unless is_terminal(z), in which case z_ is assumed to be the terminal states.
Mathematical Operations
All AbstractKnotPoint types support addition between two knot points, addition of a knot point and a vector of length n+m, and multiplication with a scalar, all of which will return a StaticKnotPoint.