API
NamedTrajectory methods
Base.:==
— Method:(==)(traj1::NamedTrajectory, traj2::NamedTrajectory)
Check if trajectories are equal w.r.t. using Base.:(==)
Base.copy
— Methodcopy(::NamedTrajectory)
Returns a copy of the trajectory.
Base.getindex
— Methodgetindex(traj, ts::AbstractVector{Int})::Vector{KnotPoint}
Returns the knot points at times ts
.
Base.getindex
— Methodgetindex(traj, t::Int)::KnotPoint
Returns the knot point at time t
.
Base.getindex
— Methodgetindex(traj, symb::Symbol)
Dispatches indexing of trajectories as either accessing a component or a property via getproperty
.
Base.getproperty
— Methodgetproperty(traj, symb::Symbol)
Returns the component of the trajectory with name symb
or the property of the trajectory with name symb
.
Base.isequal
— Methodisequal(traj1::NamedTrajectory, traj2::NamedTrajectory)
Check if trajectories are equal w.r.t. data using Base.isequal
Base.lastindex
— Methodlastindex(traj::NamedTrajectory)
Returns the final time index of the trajectory.
Base.length
— Methodlength(::NamedTrajectory)
Returns the length of all variables of the trajectory, including global data.
TODO: Should global data be in length?
Base.merge
— Methodmerge(traj1::NamedTrajectory, traj2::NamedTrajectory)
merge(trajs::AbstractVector{<:NamedTrajectory})
Returns a new NamedTrajectory object by merging NamedTrajectory
objects.
Merge names are used to specify which components to merge by index. If no merge names are provided, all components are merged and name collisions are not allowed. If merge names are provided, the names are merged using the data from the index provided in the merge names.
Joined NamedTrajectory
objects must have the same timestep. If a free time trajectory is desired, setting the keyword argument free_time=true
will construct the a component for the timestep. In this case, the timestep symbol must be provided.
Arguments
traj1::NamedTrajectory
: The firstNamedTrajectory
object.traj2::NamedTrajectory
: The secondNamedTrajectory
object.free_time::Bool=false
: Whether to construct a free time problem.timestep_name::Symbol=:Δt
: The timestep symbol to use for free time problems.merge_names::Union{Nothing, NamedTuple{<:Any, <:Tuple{Vararg{Int}}}}=nothing
: The names to merge by index.
Base.setproperty!
— Methodsetproperty!(traj, name::Symbol, val::Any)
Dispatches setting properties of trajectories as either setting a component or a property via setfield!
or update!
.
Base.size
— Methodsize(traj::NamedTrajectory) = (dim = traj.dim, T = traj.T)
Returns the size of the trajectory (dim, T), excluding global data.
TODO: Should global data be in size?
Base.vec
— Methodvec(::NamedTrajectory)
Returns all variables of the trajectory as a vector, Z⃗.
NamedTrajectories.MethodsNamedTrajectory.add_component!
— Methodadd_component!(traj, name::Symbol, data::AbstractVecOrMat; type={:state, :control, :slack})
Add a component to the trajectory.
This function resizes the trajectory, so global components and components must be adjusted.
NamedTrajectories.MethodsNamedTrajectory.add_suffix
— Functionadd_suffix(obj::T, suffix::String)
Add the suffix to the symbols of the object.
NamedTrajectories.MethodsNamedTrajectory.get_component_names
— Methodget_component_names(traj::NamedTrajectory, comps::AbstractVector{<:Int})
Returns the name of the component with the given indices. If only one component is found, the name is returned as a single symbol. Else, the names are returned as a vector of symbols.
The filter requires that the components are a complete subset of the given indices, so that a partial match is excluded from the returned names.
NamedTrajectories.MethodsNamedTrajectory.get_components
— Methodget_components(::NamedTrajectory)
Returns a NamedTuple containing the names and corresponding data matrices of the trajectory.
NamedTrajectories.MethodsNamedTrajectory.get_duration
— Methodget_duration(::NamedTrajectory)
Returns the duration of a trajectory.
NamedTrajectories.MethodsNamedTrajectory.get_suffix
— Functionget_suffix(obj::T, suffix::String; remove::Bool=false)
Get the data with the suffix from the object. Remove the suffix if remove=true
.
NamedTrajectories.MethodsNamedTrajectory.get_times
— Methodget_times(traj)::Vector{Float64}
Returns the times of a trajectory as a vector.
NamedTrajectories.MethodsNamedTrajectory.get_timesteps
— Methodget_timesteps(::NamedTrajectory)
Returns the timesteps of a trajectory as a vector.
NamedTrajectories.MethodsNamedTrajectory.merge_outer
— Methodmerge_outer(objs::AbstractVector{<:Any})
Merge objects. An error is reported if a key collision is detected.
NamedTrajectories.MethodsNamedTrajectory.remove_component
— Methodremove_component(traj, name::Symbol)
Remove a component from the trajectory.
NamedTrajectories.MethodsNamedTrajectory.remove_components
— Methodremove_components(traj, names::Vector{Symbol})
Remove a set of components from the trajectory.
NamedTrajectories.MethodsNamedTrajectory.remove_suffix
— Functionremove_suffix(obj::T, suffix::String)
Remove the suffix from the symbols of the object.
NamedTrajectories.MethodsNamedTrajectory.update!
— Methodupdate!(traj, datavec::AbstractVector{Float64})
Update the trajectory with a new datavec.
NamedTrajectories.MethodsNamedTrajectory.update!
— Methodupdate!(traj, name::Symbol, data::AbstractMatrix{Float64})
Update a component of the trajectory.
NamedTrajectories.MethodsNamedTrajectory.update_bound!
— Functionupdate_bound!(traj, name::Symbol, data::Real)
update_bound!(traj, name::Symbol, data::AbstractVector{<:Real})
update_bound!(traj, name::Symbol, data::Tuple{R, R} where R <: Real)
Update the bound of a component of the trajectory.
Random trajectory methods
Base.rand
— Methodrand(
::Type{NamedTrajectory},
T::Int;
timestep_value::Float64=1.0,
timestep_name::Symbol=:Δt,
free_time::Bool=false,
timestep::Union{Float64,Symbol}=free_time ? timestep_name : timestep_value,
state_dim::Int=3,
control_dim::Int=2
)
Create a random NamedTrajectory
with T
time steps, a state variable x
of dimension state_dim
, and a control variable u
of dimension control_dim
. If free_time
is true
, the time step is a symbol timestep_name
and the time step value is timestep_value
. Otherwise, the time step is a number timestep_value
.
Struct Methods
NamedTrajectories.StructNamedTrajectory.NamedTrajectory
— TypeNamedTrajectory constructor
NamedTrajectories.StructNamedTrajectory.NamedTrajectory
— MethodNamedTrajectory(component_data; kwargs...)
# Arguments
- `component_data::NamedTuple{names, <:Tuple{Vararg{vals}}} where {names, vals <: AbstractMatrix{R}}`: Components data.
- `kwargs...`: The other key word arguments.
NamedTrajectories.StructNamedTrajectory.NamedTrajectory
— MethodNamedTrajectory(component_data; controls=(), timestep=nothing, bounds, initial, final, goal)
# Arguments
- `component_data::NamedTuple{names, <:Tuple{Vararg{vals}}} where {names, vals <: AbstractMatrix{R}}`: Components data.
- `controls`: The control variable in component_data, should be type of `Symbol` among `component_data`.
- `timestep`: Discretizing time step in `component_data`, should be type of `Symbol` among `component_data`.
- `bounds`: Bounds of the trajectory.
- `initial`: Initial values.
- `final`: Final values.
- `goal`: Goal for the states.
NamedTrajectories.StructNamedTrajectory.NamedTrajectory
— MethodNamedTrajectory(data, traj)
# Arguments
- `data`: Trajectory data.
- `traj`: Constructed `NamedTrajectory`.
NamedTrajectories.StructNamedTrajectory.NamedTrajectory
— MethodNamedTrajectory(data, componets; kwargs...)
# Arguments
- `data::AbstractMatrix{R}`: Trajectory data.
- `components::NamedTuple{names, <:Tuple{Vararg{AbstractVector{Int}}}} where names`: components data.
- `kwargs...` : The other key word arguments.
NamedTrajectories.StructNamedTrajectory.NamedTrajectory
— MethodNamedTrajectory(datavec, T, components)
NamedTrajectories.StructNamedTrajectory.NamedTrajectory
— MethodNamedTrajectory(component_data; controls=(), timestep=nothing, bounds, initial, final, goal)
# Arguments
- `datavec::AbstractVector{R} where R <: Real`: Trajectory data.
- `traj`: Constructed `NamedTrajectory`.
NamedTrajectories.StructNamedTrajectory.NamedTrajectory
— MethodNamedTrajectory(component_data; controls=(), timestep=nothing, bounds, initial, final, goal)
# Arguments
- `comps::NamedTuple{names, <:Tuple{Vararg{AbstractMatrix{R}}}} where {names}`: components data.
- `traj`: Constructed NamedTrajectory.
- `goal`: Goal for the states.
Trajectory Utilities
NamedTrajectories.Utils.derivative
— Methodderivative(X::AbstractMatrix, Δt::AbstractVecOrMat)
derivative(X::AbstractMatrix, Δt::Float64)
Compute the derivative of the data matrix X
.
NamedTrajectories.Utils.integral
— Methodintegral(X::AbstractMatrix, Δt::AbstractVector)
integral(X::AbstractMatrix, Δt::Float64)
Compute the integral of the data matrix X
.