API

NamedTrajectory methods

Base.mergeMethod
merge(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.

Keyword Arguments

  • timestep::Symbol: The timestep symbol to use for free time problems. Default to the last trajectory.
  • merge_names::Union{Nothing, NamedTuple{<:Any, <:Tuple{Vararg{Int}}}}=nothing: The names to merge by index.
source
NamedTrajectories.MethodsNamedTrajectory.get_component_namesMethod
get_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.

source
Base.getpropertyMethod
getproperty(slice::KnotPoint, symb::Symbol)

Returns the component of the knot point with name symb (as a view) or the property of the knot point with name symb.

source
Base.setproperty!Method
setproperty!(slice::KnotPoint, symb::Symbol, val::Any)

Dispatches setting properties of knot points as either setting a component or a property via update! or setfield!, respectively.

source

Random trajectory methods

Base.randMethod
rand(
    ::Type{NamedTrajectory},
    N::Int;
    timestep_value::Float64=1.0,
    timestep_name::Symbol=:Δt,
    timestep::Union{Float64,Symbol}=free_time ? timestep_name : timestep_value,
    state_dim::Int=3,
    control_dim::Int=2
)

Create a random NamedTrajectory with N knot points, a state variable x of dimension state_dim, and a control variable u of dimension control_dim. The time step is a symbol timestep_name and the time step value is timestep_value.

source

Struct Methods

NamedTrajectories.StructNamedTrajectory.NamedTrajectoryType
NamedTrajectory{R <: Real}

Container for trajectory optimization problems, which includes the trajectory data, bounds dimensions, initial and final conditions, goal states, and components.

This struct is designed to hold trajectory data in a named format, allowing for easy access to knot points by Symbol.

NamedTrajectory is designed to make allocation-free access easy to write. The data can be updated after construction, but the fields cannot.

source

Trajectory Utilities

Interpolation Methods

NamedTrajectories.MethodsNamedTrajectory.trajectory_interpolationFunction
trajectory_interpolation(
    traj::NamedTrajectory,
    times::AbstractVector;
    interpolations::NamedTuple=NamedTuple(zip(traj.names, fill(:linear, length(traj.names))))
)

Interpolate a NamedTrajectory at specified time points.

Arguments

  • traj::NamedTrajectory: The trajectory to interpolate.
  • times::AbstractVector: The time points at which to interpolate the trajectory.

Keyword Arguments

  • interpolations::NamedTuple: A named tuple specifying the interpolation method for each component. Supported methods are :constant, :linear, and :spline. Defaults to :linear for all components.

Returns

  • NamedTrajectory: A new trajectory with interpolated values at the specified times.

Notes

  • Components not specified in interpolations will be dropped from the returned trajectory.
  • The timestep component is automatically included with linear interpolation if not specified.
  • Spline interpolation requires derivative components (e.g., du for component u).

Examples

# Linear interpolation at new time points
new_times = [0.0, 0.5, 1.0, 1.5, 2.0]
new_traj = trajectory_interpolation(traj, new_times)

# Mix of interpolation methods
interpolations = (x = :linear, u = :spline, Δt = :linear)
new_traj = trajectory_interpolation(traj, new_times; interpolations=interpolations)
source
trajectory_interpolation(
    traj::NamedTrajectory,
    T::Int;
    kwargs...
)

Interpolate a NamedTrajectory to a new number of time steps.

Arguments

  • traj::NamedTrajectory: The trajectory to interpolate.
  • T::Int: The number of time steps in the interpolated trajectory.

Keyword Arguments

  • kwargs...: Additional keyword arguments passed to the main trajectory_interpolation method.

Returns

  • NamedTrajectory: A new trajectory with T time steps, evenly spaced between the original start and end times.

Examples

# Interpolate to 100 time steps
new_traj = trajectory_interpolation(traj, 100)

# With custom interpolation methods
new_traj = trajectory_interpolation(traj, 100; interpolations=(x=:spline, u=:linear))
source