NamedTrajectories.jl is a package for working with trajectories of named variables. It is designed to be used with the Piccolo.jl ecosystem.
NamedTrajectories.jl is registered! Install in the REPL by entering pkg mode with ]
and then running
pkg> add NamedTrajectories
or to install the latest master branch run
pkg> add NamedTrajectories#main
- Abstract away messy indexing and vectorization details required for interfacing with numerical solvers.
- Easily handle multiple trajectories with different names, e.g. various states and controls.
- Simple plotting of trajectories.
- Provide a variety of helpful methods for common tasks.
Users can define NamedTrajectory
types which have lots of useful functionality. For example, you can access the data by name or index. In the case of an index, a KnotPoint
is returned which contains the data for that timestep.
using NamedTrajectories
# define number of timesteps and timestep
T = 10
dt = 0.1
# build named tuple of components and data matrices
components = (
x = rand(3, T),
u = rand(2, T),
)
# build trajectory
traj = NamedTrajectory(components; timestep=dt, controls=:u)
# access data by name
traj.x # returns 3x10 matrix of x data
traj.u # returns 2x10 matrix of u data
z1 = traj[1] # returns KnotPoint with x and u data
z1.x # returns 3 element vector of x data at timestep 1
z1.u # returns 2 element vector of u data at timestep 1
traj.data # returns data as 5x10 matrix
traj.names # returns names as tuple (:x, :u)
NamedTrajectories.jl is designed to aid in the messy indexing involved in solving trajectory optimization problems of the form
where
In more detail, this problem might look something like
where
It is common practice in trajectory optimization to bundle all of the state and control variables together into a single knot point
The trajectory optimization problem can then be succinctly written as
The NamedTrajectories
package provides a NamedTrajectory
type which abstracts away the messy indexing and vectorization details required for interfacing with numerical solvers. It also provides a variety of helpful methods for common tasks. For example, you can access the data by name or index. In the case of an index, a KnotPoint
is returned which contains the data for that timestep.
This package uses a Documenter config that is shared with many of our other repositories. To build the docs, you will need to run the docs setup script to clone and pull down the utility.
# first time only
./docs/get_docs_utils.sh # or ./get_docs_utils.sh if cwd is in ./docs/
To build the docs pages:
julia --project=docs docs/make.jl
or editing the docs live:
julia --project=docs
> using LiveServer, Piccolo, Revise
> servedocs(literate_dir="docs/literate", skip_dirs=["docs/src/generated", "docs/src/assets/"], skip_files=["docs/src/index.md"])
Note:
servedocs
needs to watch a subset of the files in thedocs/
folder. If it watches files that are generated on a docs build/re-build,servedocs
will continuously try to re-serve the pages.To prevent this, ensure all generated files are included in the skip dirs or skip files args for
servedocs
.
For example, if we forget index.md like so:
julia --project=docs
> using LiveServer, Piccolo, Revise
> servedocs(literate_dir="docs/literate", skip_dirs=["docs/src/generated", "docs/src/assets/"])
it will not build and serve.
"It seems that perfection is attained not when there is nothing more to add, but when there is nothing more to take away." - Antoine de Saint-Exupéry