Trajectories
When dealing with dynamical sytems, we often need to keep track of and represent trajectories of our system. RobotDynamics provides an AbstractTrajectory
that can represent any trajectory, continuous or discrete. The only requirements on an AbstractTrajectory
are that you can query the state and control at some time t
, and that the trajectory has some notion of initial and final time for which it is defined.
RobotDynamics.AbstractTrajectory
— TypeAbstractTrajectory
An abstract representation of a state and control trajectory.
Required methods | Brief description |
---|---|
getstate(Z, t) | Get the state at time t . |
getcontrol(Z, t) | Get the control at time t . |
getinitialtime(Z) | Get the initial time of the trajectory. |
getfinaltime(Z) | Get the final time of the trajectory. |
One convenient way of representing a trajectory is by sampling the states and controls along it. RobotDynamics provides the SampledTrajectory
type which is basically a vector of AbstractKnotPoint
types. This is described by the following API:
RobotDynamics.SampledTrajectory
— TypeSampledTrajectory{Nx,Nu,T,KP} <: AbstractTrajectory
A trajectory represented by a sample of knot points. A vector of AbstractKnotPoint
s of type KP
with state dimension Nx
, control dimension Nu
, and value type T
.
Supports iteration and indexing.
Constructors
SampledTrajectory{Nx,Nu}(n, m; [equal, dt, tf, N])
SampledTrajectory{Nx,Nu}(X, U; [dt, tf, N=length(X)])
SampledTrajectory(n, m; [equal, dt, tf, N])
SampledTrajectory(X, U; [dt, tf, N=length(X)])
where at least 2 of dt
, tf
, or N
must be specified. The length N
is automatically inferred when passing in state and control trajectories X
and U
, which can either be vectors of vectors or a 2D matrix whose 2nd dimension is time.
RobotDynamics.states
— Functionstates(Z)
states(Z, i::Integer)
states(Z, inds)
Get a list of all the state vectors for the trajectory Z
. Passing an integer extracts a vector of the i
th state. Passing a vector of integers provides a list of N
-dimensional vectors, containing the time history for each state index in the vector.
RobotDynamics.controls
— Functioncontrols(Z)
controls(Z, i::Integer)
controls(Z, inds)
Get a list of all the control vectors for the trajectory Z
. Passing an integer extracts a vector of the i
th control. Passing a vector of integers provides a list of N
-dimensional vectors, containing the time history for each control index in the vector.
RobotDynamics.gettimes
— Functiongettimes(Z)
Get a vector of times for the entire trajectory.
RobotDynamics.getdata
— Functiongetdata(Z)
Get a list of the concatenated state and control vectors.
RobotDynamics.setstates!
— Functionsetstates!(Z, X)
Set the states of a trajectory Z
, where X
can be a vector of vectors or a matrix of size (n,N)
.
RobotDynamics.setcontrols!
— Functionsetcontrols!(Z, U)
Set the controls of a trajectory Z
, where U
can be a vector of vectors or a matrix of size (m,N)
or a single vector of size (m,)
, which will be copied to all the time steps.
RobotDynamics.set_dt!
— Functionset_dt!(Z, dt)
Set a constant time step for the entire trajectory.
RobotDynamics.setinitialtime!
— Functionsetinitialtime!(Z, t0)
Set the initial time of the trajectory, shifting all of the times by the required amount.
RobotDynamics.num_vars
— Functionnum_vars(Z)
Total number of states and controls in a trajectory Z
.
RobotDynamics.eachcontrol
— Functioneachcontrol(Z)
Get the range of indices for valid controls.