OpenSim Moco
0.4.0
|
This tool constructs problems in which state and/or marker trajectory data are tracked while solving for model kinematics and actuator controls.
"Tracking" refers to cost terms that minimize the error between provided reference data and the associated model quantities (joint angles, joint velocities, marker positions, etc).
State reference data (joint angles and velocities), marker reference data (x/y/z marker motion capture trajectories), or both may be provided via the states_reference
and markers_reference
properties. For each set of reference data provided, a tracking cost term is added to the internal MocoProblem.
setMarkersReference() only accepts a scalar TimeSeriesTable (either directly or via a TableProcessor) containing x/y/x marker position values. A TimeSeriesTableVec3 of markers is not accepted, but you may use the flatten() method to convert to a scalar TimeSeriesTable:
If you wish to set the markers reference directly from a TRC file, use setMarkersReferenceFromTRC().
The states_global_tracking_weight
and markers_global_tracking_weight
properties apply a cost function weight to all tracking error associated provided reference data. The states_weight_set
and markers_weight_set
properties give you finer control over the tracking costs, letting you set weights for individual reference data tracking errors.
By default, a MocoControlCost term is added to the underlying problem with a weight of 0.001. Control effort terms often help smooth the problem solution controls, and minimally affect the states tracking solution with a sufficiently low weight. Use the minimize_control_effort
and control_effort_weight
properties to customize these settings.
A time range that is compatible with all reference data may be provided. If no time range is set, the widest time range that is compatible will all reference data will be used.
If you would like to track joint velocities but only have joint angles in your states reference, enable the track_reference_position_derivatives
property. When enabled, the provided position-level states reference data will be splined in order to compute derivatives. If some velocity-level information exists in the reference, this option will fill in the missing data with position derivatives and leave the existing velocity data intact. This is not enabled by default, but is recommended for improving tracking performance and reducing convergence times.
Since the data in the provided references may be altered by TableProcessor operations or appended to by track_reference_position_derivatives
, the tracked data is printed to file in addition to the problem solution. The tracked data files have the following format "<tool_name>_tracked_<data_type>.sto" (e.g. "MocoTool_tracked_states.sto").
Construct a tracking problem by setting property values and calling solve():
If you wish to further customize the underlying MocoProblem before solving, instead of calling solve(), call initialize() which returns a pre-configured MocoStudy object:
#include <Moco/Moco/MocoTrack.h>
Public Member Functions | |
OpenSim_DECLARE_PROPERTY (states_reference, TableProcessor, "States reference data to be tracked. If provided, a " "MocoStateTrackingGoal term is created and added to the internal " "MocoProblem. ") | |
OpenSim_DECLARE_PROPERTY (states_global_tracking_weight, double, "The weight for the MocoStateTrackingGoal that applies to tracking " "errors for all states in the reference.") | |
OpenSim_DECLARE_PROPERTY (states_weight_set, MocoWeightSet, "A set of tracking weights for individual state variables. The " "weight names should match the names of the column labels in the " "file associated with the 'states_reference' property.") | |
OpenSim_DECLARE_PROPERTY (scale_state_weights_with_range, bool, "Use the range, or the distance between the maximum and minimum " "value, of each reference quantity to scale the weight " "for the associated tracking error in the cost. The scale is " "computed by the inverse of the range, so a reference quantity " "that changes less across the trajectory has a larger weight. ") | |
OpenSim_DECLARE_PROPERTY (track_reference_position_derivatives, bool, "Option to track the derivative of position-level state reference " "data if no velocity-level state reference data was included in " "the `states_reference`. If velocity-reference reference data was " "provided for some coordinates but not others, this option will " "only " "apply to the coordinates without speed reference data. " "(default: false)") | |
OpenSim_DECLARE_PROPERTY (markers_reference, TableProcessor, "Motion capture marker reference data to be tracked. The columns " "in " "the table should correspond to scalar x/y/z marker position " "values and the columns labels should have consistent suffixes " "appended to the model marker names. If provided, a " "MocoMarkerTrackingGoal term is created and added to the internal " "MocoProblem.") | |
OpenSim_DECLARE_PROPERTY (markers_global_tracking_weight, double, "The weight for the MocoMarkerTrackingGoal that applies to " "tracking " "errors for all markers in the reference.") | |
OpenSim_DECLARE_PROPERTY (markers_weight_set, MocoWeightSet, "A set of tracking weights for individual marker positions. The " "weight names should match the marker names in the " "file associated with the 'markers_reference' property.") | |
OpenSim_DECLARE_PROPERTY (allow_unused_references, bool, "Allow references to contain data not associated with any " "components " "in the model (such data would be ignored). Default: false.") | |
OpenSim_DECLARE_PROPERTY (guess_file, std::string, "Path to a STO file containing a guess for the problem. The path " "can " "be absolute or relative to the setup file. If no file is " "provided, " "then a guess constructed from the variable bounds midpoints will " "be " "used.") | |
OpenSim_DECLARE_PROPERTY (apply_tracked_states_to_guess, bool, "If a `states_reference` has been provided, use this setting to " "replace the states in the guess with the states reference data. " "This " "will override any guess information provided via `guess_file`.") | |
OpenSim_DECLARE_PROPERTY (minimize_control_effort, bool, "Whether or not to minimize actuator control effort in the problem." "Default: true.") | |
OpenSim_DECLARE_PROPERTY (control_effort_weight, double, "The weight on the control effort minimization cost term, if it " "exists. Default: 0.001") | |
void | setStatesReference (TableProcessor states) |
Set the states reference TableProcessor. More... | |
void | setMarkersReference (TableProcessor markers) |
Set the markers reference TableProcessor. More... | |
void | setMarkersReferenceFromTRC (const std::string &filename, double lowpassFilterFreq=6.0) |
Set the markers reference directly from a TRC file. More... | |
MocoStudy | initialize () |
MocoSolution | solve (bool visualize=false) |
Public Member Functions inherited from OpenSim::MocoTool | |
OpenSim_DECLARE_OPTIONAL_PROPERTY (initial_time, double, "The start of the time interval. " "All data must start at or before this time. " "(default: earliest time available in all provided data)") | |
OpenSim_DECLARE_OPTIONAL_PROPERTY (final_time, double, "The end of the time interval. " "All data must end at or after this time. " "(default: latest time available in all provided data)") | |
OpenSim_DECLARE_PROPERTY (mesh_interval, double, "The time duration of each mesh interval " "(default: 0.020 seconds).") | |
OpenSim_DECLARE_PROPERTY (clip_time_range, bool, "Set the time range to be 1e-3 shorter on both ends to leave space " "for finite difference estimates (default: false).") | |
OpenSim_DECLARE_PROPERTY (model, ModelProcessor, "The musculoskeletal model to use.") | |
void | setModel (ModelProcessor model) |
Additional Inherited Members | |
Protected Member Functions inherited from OpenSim::MocoTool | |
void | updateTimeInfo (const std::string &dataLabel, const double &dataInitial, const double &dataFinal, TimeInfo &info) const |
This function updates a TimeInfo so the initial and final times are within the data times provided. More... | |
std::string | getFilePath (const std::string &file) const |
Get the canonicalized absolute pathname with respect to the setup file directory from a given pathname which can be relative or absolute. More... | |
std::string | getDocumentDirectory () const |
Get the (canonicalized) absolute directory containing the file from which this tool was loaded. More... | |
|
inline |
Set the markers reference TableProcessor.
|
inline |
Set the markers reference directly from a TRC file.
By default, the marker data is lowpass filtered with a 6 Hz cutoff frequency, but you may set any frequency using the optional argument. If the markers data is in millimeters (detected via the 'Units' metadata tag), then it is converted to meters.
|
inline |
Set the states reference TableProcessor.