API
4.5.1
For C++ developers
|
The values of the variables in an optimal control problem. More...
Public Member Functions | |
MocoTrajectory ()=default | |
MocoTrajectory (std::vector< std::string > state_names, std::vector< std::string > control_names, std::vector< std::string > multiplier_names, std::vector< std::string > parameter_names) | |
Create a trajectory with no data. More... | |
MocoTrajectory (std::vector< std::string > state_names, std::vector< std::string > control_names, std::vector< std::string > multiplier_names, std::vector< std::string > derivative_names, std::vector< std::string > parameter_names) | |
Create a trajectory (including columns for derivatives) with no data. More... | |
MocoTrajectory (std::vector< std::string > state_names, std::vector< std::string > control_names, std::vector< std::string > input_control_names, std::vector< std::string > multiplier_names, std::vector< std::string > derivative_names, std::vector< std::string > parameter_names) | |
MocoTrajectory (const SimTK::Vector &time, std::vector< std::string > state_names, std::vector< std::string > control_names, std::vector< std::string > multiplier_names, std::vector< std::string > parameter_names, const SimTK::Matrix &statesTrajectory, const SimTK::Matrix &controlsTrajectory, const SimTK::Matrix &multipliersTrajectory, const SimTK::RowVector ¶meters) | |
MocoTrajectory (const SimTK::Vector &time, std::vector< std::string > state_names, std::vector< std::string > control_names, std::vector< std::string > multiplier_names, std::vector< std::string > derivative_names, std::vector< std::string > parameter_names, const SimTK::Matrix &statesTrajectory, const SimTK::Matrix &controlsTrajectory, const SimTK::Matrix &multipliersTrajectory, const SimTK::Matrix &derivativesTrajectory, const SimTK::RowVector ¶meters) | |
This constructor is for use with the implicit dynamics mode, and allows specifying a derivativesTrajectory. More... | |
MocoTrajectory (const SimTK::Vector &time, std::vector< std::string > state_names, std::vector< std::string > control_names, std::vector< std::string > input_control_names, std::vector< std::string > multiplier_names, std::vector< std::string > derivative_names, std::vector< std::string > parameter_names, const SimTK::Matrix &statesTrajectory, const SimTK::Matrix &controlsTrajectory, const SimTK::Matrix &inputControlsTrajectory, const SimTK::Matrix &multipliersTrajectory, const SimTK::Matrix &derivativesTrajectory, const SimTK::RowVector ¶meters) | |
MocoTrajectory (const SimTK::Vector &time, const std::map< std::string, NamesAndData< SimTK::Matrix >> &continuousVars, const NamesAndData< SimTK::RowVector > ¶meters={}) | |
MocoTrajectory (const std::string &filepath) | |
Read a MocoTrajectory from an STO file (see STOFileAdapter). More... | |
virtual | ~MocoTrajectory ()=default |
virtual MocoTrajectory * | clone () const |
Returns a dynamically-allocated copy of this trajectory. More... | |
bool | empty () const |
bool | hasCoordinateStates () const |
Change the length of the trajectory | |
void | setNumTimes (int numTimes) |
Resize the time vector and the time dimension of the states, controls, multipliers, and derivatives trajectories, and set all times, states, controls, multipliers, and derivatives to NaN. More... | |
double | resampleWithNumTimes (int numTimes) |
Uniformly resample (interpolate) the trajectory so that it retains the same initial and final times but now has the provided number of time points. More... | |
double | resampleWithInterval (double desiredTimeInterval) |
Uniformly resample (interpolate) the trajectory to try to achieve the provided time interval between mesh points, while preserving the initial and final times. More... | |
double | resampleWithFrequency (double desiredNumTimePointsPerSecond) |
Uniformly resample (interpolate) the trajectory to try to achieve the provided frequency of time points per second of the trajectory, while preserving the initial and final times. More... | |
void | resample (SimTK::Vector newTime) |
Resample (interpolate) the data in this trajectory at the provided times. More... | |
Set the data | |
void | setTime (const SimTK::Vector &time) |
Set the time vector. More... | |
void | setState (const std::string &name, const SimTK::Vector &trajectory) |
Set the value of a single state variable across time. More... | |
void | setControl (const std::string &name, const SimTK::Vector &trajectory) |
Set the value of a single control variable across time. More... | |
void | setInputControl (const std::string &name, const SimTK::Vector &trajectory) |
Set the value of a single Input control variable across time. More... | |
void | setMultiplier (const std::string &name, const SimTK::Vector &trajectory) |
Set the value of a single Lagrange multiplier variable across time. More... | |
void | setDerivative (const std::string &name, const SimTK::Vector &trajectory) |
Set the value of a single state derivative variable across time. More... | |
void | setParameter (const std::string &name, const SimTK::Real &value) |
Set the value of a single parameter variable. More... | |
void | setTime (std::initializer_list< double > time) |
Set the time vector. More... | |
void | setState (const std::string &name, std::initializer_list< double > trajectory) |
Set the value of a single state variable across time. More... | |
void | setControl (const std::string &name, std::initializer_list< double > trajectory) |
Set the value of a single control variable across time. More... | |
void | setInputControl (const std::string &name, std::initializer_list< double > trajectory) |
Set the value of a single Input control variable across time. More... | |
void | setMultiplier (const std::string &name, std::initializer_list< double > trajectory) |
Set the value of a single Lagrange multiplier variable across time. More... | |
void | setDerivative (const std::string &name, std::initializer_list< double > trajectory) |
Set the value of a single state derivative variable across time. More... | |
void | setStatesTrajectory (const TimeSeriesTable &states, bool allowMissingColumns=false, bool allowExtraColumns=false) |
Set the states trajectory. More... | |
void | insertStatesTrajectory (const TimeSeriesTable &subsetOfStates, bool overwrite=false) |
Add additional state columns. More... | |
void | insertControlsTrajectory (const TimeSeriesTable &subsetOfControls, bool overwrite=false) |
Add additional control columns. More... | |
void | generateSpeedsFromValues () |
Compute coordinate speeds based on coordinate position values and append to the trajectory. More... | |
void | generateAccelerationsFromValues () |
Compute coordinate accelerations based on coordinate position values and append to the trajectory. More... | |
void | generateAccelerationsFromSpeeds () |
Compute coordinate accelerations based on coordinate speeds and append to the trajectory. More... | |
void | generateControlsFromModelControllers (Model model, bool overwrite=false) |
Compute model controls based on any Controllers in the model and append to the trajectory. More... | |
void | trimToIndices (int newStartIndex, int newFinalIndex) |
Trim the trajectory to include the rows starting at newStartIndex and and ending at newFinalIndex. More... | |
Accessors | |
int | getNumTimes () const |
const SimTK::Vector & | getTime () const |
double | getInitialTime () const |
The first time in the time vector. More... | |
double | getFinalTime () const |
The last time in the time vector. More... | |
int | getNumStates () const |
int | getNumControls () const |
int | getNumInputControls () const |
int | getNumMultipliers () const |
int | getNumDerivatives () const |
int | getNumValues () const |
int | getNumSpeeds () const |
int | getNumMultibodyStates () const |
int | getNumAuxiliaryStates () const |
int | getNumAccelerations () const |
int | getNumDerivativesWithoutAccelerations () const |
int | getNumParameters () const |
const std::vector< std::string > & | getStateNames () const |
const std::vector< std::string > & | getControlNames () const |
const std::vector< std::string > & | getInputControlNames () const |
const std::vector< std::string > & | getMultiplierNames () const |
const std::vector< std::string > & | getDerivativeNames () const |
std::vector< std::string > | getValueNames () const |
std::vector< std::string > | getSpeedNames () const |
std::vector< std::string > | getMultibodyStateNames () const |
std::vector< std::string > | getAuxiliaryStateNames () const |
std::vector< std::string > | getAccelerationNames () const |
std::vector< std::string > | getDerivativeNamesWithoutAccelerations () const |
const std::vector< std::string > & | getParameterNames () const |
SimTK::VectorView_< double > | getState (const std::string &name) const |
SimTK::VectorView_< double > | getControl (const std::string &name) const |
SimTK::VectorView_< double > | getInputControl (const std::string &name) const |
SimTK::VectorView_< double > | getMultiplier (const std::string &name) const |
SimTK::VectorView_< double > | getDerivative (const std::string &name) const |
const SimTK::Real & | getParameter (const std::string &name) const |
const SimTK::Matrix & | getStatesTrajectory () const |
const SimTK::Matrix & | getControlsTrajectory () const |
const SimTK::Matrix & | getInputControlsTrajectory () const |
const SimTK::Matrix & | getMultipliersTrajectory () const |
const SimTK::Matrix & | getDerivativesTrajectory () const |
SimTK::Matrix | getValuesTrajectory () const |
SimTK::Matrix | getSpeedsTrajectory () const |
SimTK::Matrix | getMultibodyStatesTrajectory () const |
SimTK::Matrix | getAuxiliaryStatesTrajectory () const |
SimTK::Matrix | getAccelerationsTrajectory () const |
SimTK::Matrix | getDerivativesWithoutAccelerationsTrajectory () const |
const SimTK::RowVector & | getParameters () const |
Comparisons | |
bool | isCompatible (const MocoProblemRep &, bool requireAccelerations=false, bool throwOnError=false) const |
Do the state, control, multiplier, derivative, and parameter names in this trajectory match those in the problem? This may not catch all possible incompatibilities. More... | |
bool | isNumericallyEqual (const MocoTrajectory &other, double tol=SimTK::NTraits< SimTK::Real >::getDefaultTolerance()) const |
Check if this trajectory is numerically equal to another trajectory. More... | |
double | compareContinuousVariablesRMS (const MocoTrajectory &other, std::map< std::string, std::vector< std::string >> columnsToUse={}) const |
Compute the root-mean-square error between the continuous variables of this trajectory and another. More... | |
double | compareContinuousVariablesRMSPattern (const MocoTrajectory &other, std::string columnType, std::string pattern) const |
This is an alternative interface for compareContinuousVariablesRMS() that uses regular expression patterns to select columns. More... | |
double | compareParametersRMS (const MocoTrajectory &other, std::vector< std::string > parameterNames={}) const |
Compute the root-mean-square error between the parameters in this trajectory and another. More... | |
Convert to other formats | |
void | write (const std::string &filepath) const |
Save the trajectory to a STO file. Use the ."sto" file extension. More... | |
TimeSeriesTable | exportToStatesTable () const |
This table can be saved as a Storage file that can be used in the OpenSim GUI to visualize a motion, or as input to OpenSim's conventional tools (e.g., AnalyzeTool). More... | |
TimeSeriesTable | exportToControlsTable () const |
Export the controls trajectory to a TimeSeriesTable. More... | |
TimeSeriesTable | exportToInputControlsTable () const |
Export the Input controls trajectory to a TimeSeriesTable. More... | |
TimeSeriesTable | exportToMultipliersTable () const |
Export the multipliers trajectory to a TimeSeriesTable. More... | |
TimeSeriesTable | exportToDerivativesTable () const |
Export the derivatives trajectory to a TimeSeriesTable. More... | |
TimeSeriesTable | exportToValuesTable () const |
Export the coordinate values from the states trajectory to a TimeSeriesTable. More... | |
TimeSeriesTable | exportToSpeedsTable () const |
Export the coordinate speeds from the states trajectory to a TimeSeriesTable. More... | |
TimeSeriesTable | exportToAccelerationsTable () const |
Export the coordinate accelerations from the derivatives trajectory to a TimeSeriesTable. More... | |
TimeSeriesTable | exportToDerivativesWithoutAccelerationsTable () const |
Export the derivatives trajectory without coordinate accelerations to a TimeSeriesTable. More... | |
StatesTrajectory | exportToStatesTrajectory (const MocoProblem &) const |
Controls are not carried over to the StatesTrajectory. More... | |
StatesTrajectory | exportToStatesTrajectory (const Model &) const |
This is similar to the above function but requires only a model, not a MocoProblem. More... | |
Modify the data | |
void | randomizeReplace (const SimTK::Random &randGen=SimTK::Random::Uniform(-0.1, 0.1)) |
Randomize all data except time using the provided random number generator. More... | |
void | randomizeAdd (const SimTK::Random &randGen=SimTK::Random::Uniform(-0.1, 0.1)) |
Randomize all data except time using the provided random number generator. More... | |
Public Types | |
template<typename T > | |
using | NamesAndData = std::pair< std::vector< std::string >, T > |
This constructor allows you to control which data you provide for the trajectory. More... | |
Static Public Member Functions | |
Convert from other formats | |
static MocoTrajectory | createFromStatesControlsTables (const MocoProblemRep &, const TimeSeriesTable &statesTrajectory, const TimeSeriesTable &controlsTrajectory) |
(Experimental) Create a trajectory from a states trajectory and controls trajectory (i.e, from Manager::getStatesTable() and Model::getControlsTable()). More... | |
Protected Member Functions | |
void | setSealed (bool sealed) |
bool | isSealed () const |
void | ensureUnsealed () const |
The values of the variables in an optimal control problem.
This can be used for specifying an initial guess, or holding the solution returned by a solver.
A MocoTrajectory can be written to and read from an STO (".sto") file. The file format is comprised of a file header followed by a row of column names and the stored data. The file header contains the number of states, controls, Input controls, Lagrange multipliers (for kinematic constraints), derivatives (non-zero if the dynamics mode is implicit), slacks (for special solver implementations), and parameters (order does not matter). Order does matter for the column names and corresponding data columns. The columns must follow this order: time, states, controls, Input controls, multipliers, derivatives, slacks, parameters.
Sample file:
num_controls=<number-of-control-variables> num_derivatives=<number-of-derivative-variables> num_input_controls=<number-of-input-control-variables> num_multipliers=<number-of-multiplier-variables> num_parameters=<number-of-parameter-variables> num_slacks=<number-of-slack-variables> num_states=<number-of-state-variables> time,<state-0-name>,...,<control-0-name>,...,<input-control-0-name>,..., \ <multiplier-0-name>,...,<derivative-0-name>,...,<slack-0-name>,..., \ <parameter-0-name>,... <#>,<#>,...,<#>,...,<#>,...,<#>,...,<#-or-NaN>,...,<#> ,... <#>,<#>,...,<#>,...,<#>,...,<#>,...,<#-or-NaN>,...,<NaN>,... : , : ,..., : ,..., : ,..., : ,..., : ,..., : ,... <#>,<#>,...,<#>,...,<#>,...,<#>,...,<#-or-NaN>,...,<NaN>,...
Column labels starting with "lambda" are Lagrange multipliers, and columns starting with "gamma" are slack variables (probably velocity corrections at certain collocation points).
using OpenSim::MocoTrajectory::NamesAndData = std::pair<std::vector<std::string>, T> |
This constructor allows you to control which data you provide for the trajectory.
The possible keys for continuousVars are "states", "controls", "multipliers", and "derivatives". The names and data are grouped together, and you can leave out any of the keys.
|
default |
OpenSim::MocoTrajectory::MocoTrajectory | ( | std::vector< std::string > | state_names, |
std::vector< std::string > | control_names, | ||
std::vector< std::string > | multiplier_names, | ||
std::vector< std::string > | parameter_names | ||
) |
Create a trajectory with no data.
To add data, use setNumTimes(), setTime(), and the other setters.
OpenSim::MocoTrajectory::MocoTrajectory | ( | std::vector< std::string > | state_names, |
std::vector< std::string > | control_names, | ||
std::vector< std::string > | multiplier_names, | ||
std::vector< std::string > | derivative_names, | ||
std::vector< std::string > | parameter_names | ||
) |
Create a trajectory (including columns for derivatives) with no data.
To add data, use setNumTimes(), setTime(), and the other setters.
OpenSim::MocoTrajectory::MocoTrajectory | ( | std::vector< std::string > | state_names, |
std::vector< std::string > | control_names, | ||
std::vector< std::string > | input_control_names, | ||
std::vector< std::string > | multiplier_names, | ||
std::vector< std::string > | derivative_names, | ||
std::vector< std::string > | parameter_names | ||
) |
OpenSim::MocoTrajectory::MocoTrajectory | ( | const SimTK::Vector & | time, |
std::vector< std::string > | state_names, | ||
std::vector< std::string > | control_names, | ||
std::vector< std::string > | multiplier_names, | ||
std::vector< std::string > | parameter_names, | ||
const SimTK::Matrix & | statesTrajectory, | ||
const SimTK::Matrix & | controlsTrajectory, | ||
const SimTK::Matrix & | multipliersTrajectory, | ||
const SimTK::RowVector & | parameters | ||
) |
OpenSim::MocoTrajectory::MocoTrajectory | ( | const SimTK::Vector & | time, |
std::vector< std::string > | state_names, | ||
std::vector< std::string > | control_names, | ||
std::vector< std::string > | multiplier_names, | ||
std::vector< std::string > | derivative_names, | ||
std::vector< std::string > | parameter_names, | ||
const SimTK::Matrix & | statesTrajectory, | ||
const SimTK::Matrix & | controlsTrajectory, | ||
const SimTK::Matrix & | multipliersTrajectory, | ||
const SimTK::Matrix & | derivativesTrajectory, | ||
const SimTK::RowVector & | parameters | ||
) |
This constructor is for use with the implicit dynamics mode, and allows specifying a derivativesTrajectory.
OpenSim::MocoTrajectory::MocoTrajectory | ( | const SimTK::Vector & | time, |
std::vector< std::string > | state_names, | ||
std::vector< std::string > | control_names, | ||
std::vector< std::string > | input_control_names, | ||
std::vector< std::string > | multiplier_names, | ||
std::vector< std::string > | derivative_names, | ||
std::vector< std::string > | parameter_names, | ||
const SimTK::Matrix & | statesTrajectory, | ||
const SimTK::Matrix & | controlsTrajectory, | ||
const SimTK::Matrix & | inputControlsTrajectory, | ||
const SimTK::Matrix & | multipliersTrajectory, | ||
const SimTK::Matrix & | derivativesTrajectory, | ||
const SimTK::RowVector & | parameters | ||
) |
OpenSim::MocoTrajectory::MocoTrajectory | ( | const SimTK::Vector & | time, |
const std::map< std::string, NamesAndData< SimTK::Matrix >> & | continuousVars, | ||
const NamesAndData< SimTK::RowVector > & | parameters = {} |
||
) |
|
explicit |
Read a MocoTrajectory from an STO file (see STOFileAdapter).
See output of write() for the correct format.
|
virtualdefault |
|
inlinevirtual |
Returns a dynamically-allocated copy of this trajectory.
You must manage the memory for return value.
Reimplemented in OpenSim::MocoSolution.
double OpenSim::MocoTrajectory::compareContinuousVariablesRMS | ( | const MocoTrajectory & | other, |
std::map< std::string, std::vector< std::string >> | columnsToUse = {} |
||
) | const |
Compute the root-mean-square error between the continuous variables of this trajectory and another.
The RMS is computed by numerically integrating the sum of squared error across states, controls, Input controls, Lagrange multipliers, and derivatives and dividing by the number of columns and the time duration. The calculation can be expressed as follows:
\[ \epsilon_{\textrm{RMS}} = \sqrt{\frac{1}{N(t_f - t_i)} \int_{t_i}^{t_f} \left( \sum_{ i \in \textrm{states} } \epsilon_i(t)^2 + \sum_{ i \in \textrm{controls} } \epsilon_i(t)^2 + \sum_{ i \in \textrm{mult} } \epsilon_i(t)^2 + \sum_{ i \in \textrm{deriv} } \epsilon_i(t)^2 \right) dt }, \]
where \( N \) is the number of columns, \( t_i \) is the minimum of the two initial times, \( t_f \) is the maximum of the two final times, and \( \epsilon \) indicates an error.
When the two trajectories do not cover the same time range, we assume values of 0 for the trajectory with "missing" time (we do NOT assume that the error is 0 over the non-overlapping time range).
First, the trajectories are splined and sampled. The number of sampling points is taken to be the number of times in the trajectory with the greater number of times. Numerical integration is performed on the sampled points using the trapezoidal rule.
By default, all states, controls, and multipliers are compared, and it is expected that both trajectories have the same states, controls, and multipliers. Alternatively, you can specify the specific states, controls, Input controls, multipliers, and derivatives to compare as keys for columnsToUse
. Values are an empty vector to compare all columns for that key, {"none"}
(single-entry vector with value "none") to compare none of the columns for that key, or a vector of column labels to compare for that key. Leaving out a key means no columns for that key are compared. Both trajectories must have at least 6 time nodes. If the number of columns to compare is 0, this returns 0.
double OpenSim::MocoTrajectory::compareContinuousVariablesRMSPattern | ( | const MocoTrajectory & | other, |
std::string | columnType, | ||
std::string | pattern | ||
) | const |
This is an alternative interface for compareContinuousVariablesRMS() that uses regular expression patterns to select columns.
The parameter columnType is "states", "controls", "multipliers", or "derivatives". All columns for the provided column type whose entire name matches the provided regular expression are included in the root-mean-square.
double OpenSim::MocoTrajectory::compareParametersRMS | ( | const MocoTrajectory & | other, |
std::vector< std::string > | parameterNames = {} |
||
) | const |
Compute the root-mean-square error between the parameters in this trajectory and another.
The RMS is computed by dividing the sum of the squared errors between corresponding parameters and then dividing by the number of parameters compared. By default, all parameters are compared, and it is expected that both trajectories have the same parameters. Alternatively, you can specify the specific parameters to compare.
|
static |
(Experimental) Create a trajectory from a states trajectory and controls trajectory (i.e, from Manager::getStatesTable() and Model::getControlsTable()).
The time columns from the two tables must match exactly. The times in the trajectory will be those from the tables. This does not (yet) handle parameters.
|
inline |
|
protected |
MocoTrajectoryIsSealed | if the trajectory is sealed. |
TimeSeriesTable OpenSim::MocoTrajectory::exportToAccelerationsTable | ( | ) | const |
Export the coordinate accelerations from the derivatives trajectory to a TimeSeriesTable.
TimeSeriesTable OpenSim::MocoTrajectory::exportToControlsTable | ( | ) | const |
Export the controls trajectory to a TimeSeriesTable.
Referenced by OpenSim::analyzeMocoTrajectory().
TimeSeriesTable OpenSim::MocoTrajectory::exportToDerivativesTable | ( | ) | const |
Export the derivatives trajectory to a TimeSeriesTable.
TimeSeriesTable OpenSim::MocoTrajectory::exportToDerivativesWithoutAccelerationsTable | ( | ) | const |
Export the derivatives trajectory without coordinate accelerations to a TimeSeriesTable.
Referenced by OpenSim::analyzeMocoTrajectory().
TimeSeriesTable OpenSim::MocoTrajectory::exportToInputControlsTable | ( | ) | const |
Export the Input controls trajectory to a TimeSeriesTable.
TimeSeriesTable OpenSim::MocoTrajectory::exportToMultipliersTable | ( | ) | const |
Export the multipliers trajectory to a TimeSeriesTable.
TimeSeriesTable OpenSim::MocoTrajectory::exportToSpeedsTable | ( | ) | const |
Export the coordinate speeds from the states trajectory to a TimeSeriesTable.
TimeSeriesTable OpenSim::MocoTrajectory::exportToStatesTable | ( | ) | const |
This table can be saved as a Storage file that can be used in the OpenSim GUI to visualize a motion, or as input to OpenSim's conventional tools (e.g., AnalyzeTool).
Controls are not carried over to the states storage.
Referenced by OpenSim::analyzeMocoTrajectory().
StatesTrajectory OpenSim::MocoTrajectory::exportToStatesTrajectory | ( | const MocoProblem & | ) | const |
Controls are not carried over to the StatesTrajectory.
The MocoProblem is necessary because we need the underlying Model to order the state variables correctly.
StatesTrajectory OpenSim::MocoTrajectory::exportToStatesTrajectory | ( | const Model & | ) | const |
This is similar to the above function but requires only a model, not a MocoProblem.
TimeSeriesTable OpenSim::MocoTrajectory::exportToValuesTable | ( | ) | const |
Export the coordinate values from the states trajectory to a TimeSeriesTable.
void OpenSim::MocoTrajectory::generateAccelerationsFromSpeeds | ( | ) |
Compute coordinate accelerations based on coordinate speeds and append to the trajectory.
Coordinate speeds must exist in the original trajectory.
void OpenSim::MocoTrajectory::generateAccelerationsFromValues | ( | ) |
Compute coordinate accelerations based on coordinate position values and append to the trajectory.
Coordinate values must exist in the original trajectory.
void OpenSim::MocoTrajectory::generateControlsFromModelControllers | ( | Model | model, |
bool | overwrite = false |
||
) |
Compute model controls based on any Controllers in the model and append to the trajectory.
The model must contain InputControllers with Inputs that match the Input control names in the trajectory, if they exist.
overwrite
to replace existing control values in the trajectory, if desired. void OpenSim::MocoTrajectory::generateSpeedsFromValues | ( | ) |
Compute coordinate speeds based on coordinate position values and append to the trajectory.
Coordinate values must exist in the original trajectory.
|
inline |
|
inline |
|
inline |
|
inline |
SimTK::VectorView_<double> OpenSim::MocoTrajectory::getControl | ( | const std::string & | name | ) | const |
|
inline |
|
inline |
SimTK::VectorView_<double> OpenSim::MocoTrajectory::getDerivative | ( | const std::string & | name | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
double OpenSim::MocoTrajectory::getFinalTime | ( | ) | const |
The last time in the time vector.
Exception | If numTimes is 0. |
double OpenSim::MocoTrajectory::getInitialTime | ( | ) | const |
The first time in the time vector.
Exception | If numTimes is 0. |
SimTK::VectorView_<double> OpenSim::MocoTrajectory::getInputControl | ( | const std::string & | name | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
SimTK::VectorView_<double> OpenSim::MocoTrajectory::getMultiplier | ( | const std::string & | name | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
const SimTK::Real& OpenSim::MocoTrajectory::getParameter | ( | const std::string & | name | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
SimTK::VectorView_<double> OpenSim::MocoTrajectory::getState | ( | const std::string & | name | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
void OpenSim::MocoTrajectory::insertControlsTrajectory | ( | const TimeSeriesTable & | subsetOfControls, |
bool | overwrite = false |
||
) |
Add additional control columns.
The provided data are interpolated using GCV splines to match the times in this trajectory. By default, we do not overwrite data for controls that already exist in the trajectory; you can change this behavior with overwrite
.
void OpenSim::MocoTrajectory::insertStatesTrajectory | ( | const TimeSeriesTable & | subsetOfStates, |
bool | overwrite = false |
||
) |
Add additional state columns.
The provided data are interpolated using GCV splines to match the times in this trajectory. By default, we do not overwrite data for states that already exist in the trajectory; you can change this behavior with overwrite
.
bool OpenSim::MocoTrajectory::isCompatible | ( | const MocoProblemRep & | , |
bool | requireAccelerations = false , |
||
bool | throwOnError = false |
||
) | const |
Do the state, control, multiplier, derivative, and parameter names in this trajectory match those in the problem? This may not catch all possible incompatibilities.
If the trajectory should have generalized accelerations (for implicit multibody dynamics mode), set requireAccelerations to true. To throw an exception with a detailed message if the problem is not compatible, pass throwOnError as true. To get the detailed message without an exception, set the Logger level to Debug or a more verbose setting (e.g., Logger::setLevel(Logger::Level::Debug)
in C++, and Logger.setLevel(Logger.Level_Debug)
in MATLAB/Python).
bool OpenSim::MocoTrajectory::isNumericallyEqual | ( | const MocoTrajectory & | other, |
double | tol = SimTK::NTraits< SimTK::Real >::getDefaultTolerance() |
||
) | const |
Check if this trajectory is numerically equal to another trajectory.
This uses SimTK::Test::numericallyEqual() internally. Accordingly, the tolerance is both a relative and absolute tolerance (depending on the magnitude of quantities being compared).
|
inlineprotected |
|
inline |
Randomize all data except time using the provided random number generator.
The random numbers are added to the existing data. Use this to perturb an existing solution, probably for a MocoSolver guess. The default random number generator samples uniformly within [-0.1, 0.1].
|
inline |
Randomize all data except time using the provided random number generator.
All data is replaced with the random numbers. Use this to create a completely (pseudo-)random trajectory, probably for a MocoSolver guess. The default random number generator samples uniformly within [-0.1, 0.1].
void OpenSim::MocoTrajectory::resample | ( | SimTK::Vector | newTime | ) |
Resample (interpolate) the data in this trajectory at the provided times.
If all times have the same value (e.g., 0.0), then the value of each variable for all time is its previous value at the initial time.
Exception | if new times are not within existing initial and final times, if the new times are decreasing, or if getNumTimes() < 2. |
double OpenSim::MocoTrajectory::resampleWithFrequency | ( | double | desiredNumTimePointsPerSecond | ) |
Uniformly resample (interpolate) the trajectory to try to achieve the provided frequency of time points per second of the trajectory, while preserving the initial and final times.
The resulting frequency may be higher than what you request (in order to preserve initial and final times), and is returned by this function. Resampling is done by creating a 5-th degree GCV spline of the states and controls and evaluating the spline at the new time points. The degree is reduced as necessary if getNumTimes() < 6, and resampling is not possible if getNumTimes() < 2.
double OpenSim::MocoTrajectory::resampleWithInterval | ( | double | desiredTimeInterval | ) |
Uniformly resample (interpolate) the trajectory to try to achieve the provided time interval between mesh points, while preserving the initial and final times.
The resulting time interval may be shorter than what you request (in order to preserve initial and final times), and is returned by this function. Resampling is done by creating a 5-th degree GCV spline of the states and controls and evaluating the spline at the new time points. The degree is reduced as necessary if getNumTimes() < 6, and resampling is not possible if getNumTimes() < 2.
double OpenSim::MocoTrajectory::resampleWithNumTimes | ( | int | numTimes | ) |
Uniformly resample (interpolate) the trajectory so that it retains the same initial and final times but now has the provided number of time points.
Resampling is done by creating a 5-th degree GCV spline of the states and controls and evaluating the spline at the numTimes
time points. The degree is reduced as necessary if getNumTimes() < 6, and resampling is not possible if getNumTimes() < 2.
void OpenSim::MocoTrajectory::setControl | ( | const std::string & | name, |
const SimTK::Vector & | trajectory | ||
) |
Set the value of a single control variable across time.
The provided vector must have length getNumTimes().
setControl(name, {5, 10})
uses the initializer list overload below; it does not construct a 5-element vector with the value 10.
|
inline |
Set the value of a single control variable across time.
The provided vector must have length getNumTimes(). This variant supports use of an initializer list:
void OpenSim::MocoTrajectory::setDerivative | ( | const std::string & | name, |
const SimTK::Vector & | trajectory | ||
) |
Set the value of a single state derivative variable across time.
The provided vector must have length getNumTimes().
setDerivative(name, {5, 10})
uses the initializer list overload below; it does not construct a 5-element vector with the value 10.
|
inline |
Set the value of a single state derivative variable across time.
The provided vector must have length getNumTimes(). This variant supports use of an initializer list:
void OpenSim::MocoTrajectory::setInputControl | ( | const std::string & | name, |
const SimTK::Vector & | trajectory | ||
) |
Set the value of a single Input control variable across time.
The provided vector must have length getNumTimes().
setInputControl(name, {5, 10})
uses the initializer list overload below; it does not construct a 5-element vector with the value 10.
|
inline |
Set the value of a single Input control variable across time.
The provided vector must have length getNumTimes(). This variant supports use of an initializer list:
void OpenSim::MocoTrajectory::setMultiplier | ( | const std::string & | name, |
const SimTK::Vector & | trajectory | ||
) |
Set the value of a single Lagrange multiplier variable across time.
The provided vector must have length getNumTimes().
setMultiplier(name, {5, 10})
uses the initializer list overload below; it does not construct a 5-element vector with the value 10.
|
inline |
Set the value of a single Lagrange multiplier variable across time.
The provided vector must have length getNumTimes(). This variant supports use of an initializer list:
|
inline |
Resize the time vector and the time dimension of the states, controls, multipliers, and derivatives trajectories, and set all times, states, controls, multipliers, and derivatives to NaN.
void OpenSim::MocoTrajectory::setParameter | ( | const std::string & | name, |
const SimTK::Real & | value | ||
) |
Set the value of a single parameter variable.
This value is invariant across time.
|
inlineprotected |
void OpenSim::MocoTrajectory::setState | ( | const std::string & | name, |
const SimTK::Vector & | trajectory | ||
) |
Set the value of a single state variable across time.
The provided vector must have length getNumTimes().
setState(name, {5, 10})
uses the initializer list overload below; it does not construct a 5-element vector with the value 10.
|
inline |
Set the value of a single state variable across time.
The provided vector must have length getNumTimes(). This variant supports use of an initializer list:
void OpenSim::MocoTrajectory::setStatesTrajectory | ( | const TimeSeriesTable & | states, |
bool | allowMissingColumns = false , |
||
bool | allowExtraColumns = false |
||
) |
Set the states trajectory.
The provided data is interpolated at the times contained within this trajectory. The controls trajectory is not altered. If the table only contains a subset of the states in the trajectory (and allowMissingColumns is true), the unspecified states preserve their pre-existing values.
This function might be helpful if you generate a guess using a forward simulation; you can access the forward simulation's states trajectory using Manager::getStateStorage() or Manager::getStatesTable().
states | The column labels of the table should match the state names (see getStateNames()). By default, the table must provide all state variables. Any data outside the time range of this guess's times are ignored. |
allowMissingColumns | If false, an exception is thrown if there are states in the trajectory that are not in the table. |
allowExtraColumns | If false, an exception is thrown if there are states in the table that are not in the trajectory. |
void OpenSim::MocoTrajectory::setTime | ( | const SimTK::Vector & | time | ) |
Set the time vector.
The provided vector must have the same number of elements as the pre-existing time vector; use setNumTimes() or the "resample..." functions to change the number of times.
setTime({5, 10})
uses the initializer list overload below; it does not construct a 5-element vector with the value 10.
|
inline |
Set the time vector.
The provided vector must have the same number of elements as the pre-existing time vector; use setNumTimes() or the "resample..." functions to change the number of times. This variant supports use of an initializer list. Example:
void OpenSim::MocoTrajectory::trimToIndices | ( | int | newStartIndex, |
int | newFinalIndex | ||
) |
Trim the trajectory to include the rows starting at newStartIndex and and ending at newFinalIndex.
void OpenSim::MocoTrajectory::write | ( | const std::string & | filepath | ) | const |
Save the trajectory to a STO file. Use the ."sto" file extension.