OpenSim Moco  0.2.0
exampleMocoInverse.cpp

This is an example using the MocoInverse tool with a complex model to prescribe walking.

/* -------------------------------------------------------------------------- *
* OpenSim Moco: exampleMocoInverse.cpp *
* -------------------------------------------------------------------------- *
* Copyright (c) 2019 Stanford University and the Authors *
* *
* Author(s): Christopher Dembia *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain a *
* copy of the License at http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* -------------------------------------------------------------------------- */
#include <Moco/osimMoco.h>
using namespace OpenSim;
int main() {
// Construct the MocoInverse tool.
MocoInverse inverse;
inverse.setName("example3DWalking_MocoInverse");
// Construct a ModelProcessor and set it on the tool. The default
// muscles in the model are replaced with optimization-friendly
// DeGrooteFregly2016Muscles, and adjustments are made to the default muscle
// parameters.
ModelProcessor modelProcessor =
ModelProcessor("subject_walk_armless.osim") |
ModOpAddExternalLoads("grf_walk.xml") |
// Only valid for DeGrooteFregly2016Muscles.
// Only valid for DeGrooteFregly2016Muscles.
inverse.setModel(modelProcessor);
// Construct a TableProcessor of the coordinate data and pass it to the
// inverse tool. TableProcessors can be used in the same way as
// ModelProcessors by appending TableOperators to modify the base table.
// A TableProcessor with no operators, as we have here, simply returns the
// base table.
inverse.setKinematics(TableProcessor("coordinates.sto"));
// Initial time, final time, and mesh interval.
inverse.set_initial_time(0.81);
inverse.set_final_time(1.79);
inverse.set_mesh_interval(0.02);
// By default, Moco gives an error if the kinematics contains extra columns.
// Here, we tell Moco to allow (and ignore) those extra columns.
inverse.set_kinematics_allow_extra_columns(true);
// Solve the problem and write the solution to a Storage file.
MocoInverseSolution solution = inverse.solve();
solution.getMocoSolution().write(
"example3DWalking_MocoInverse_solution.sto");
return EXIT_SUCCESS;
}
OpenSim::ModOpIgnoreTendonCompliance
Turn off tendon compliance for all muscles in the model.
Definition: ModelOperators.h:56
OpenSim::MocoInverseSolution
This class holds the solution from MocoInverse.
Definition: MocoInverse.h:34
OpenSim::ModOpReplaceMusclesWithDeGrooteFregly2016
Invoke DeGrooteFregly2016Muscle::replaceMuscles() on the model.
Definition: ModelOperators.h:29
OpenSim::ModOpAddExternalLoads
Add external loads (e.g., ground reaction forces) to the model from a XML file.
Definition: ModelOperators.h:256
OpenSim::ModelProcessor
This class describes a workflow for processing a Model using ModelOperators.
Definition: ModelProcessor.h:47
OpenSim::MocoInverse
This tool solves problems in which the kinematics are prescribed and you seek the actuator (e....
Definition: MocoInverse.h:101
OpenSim::MocoTrajectory::write
void write(const std::string &filepath) const
Save the trajectory to file(s). Use a ".sto" file extension.
OpenSim::ModOpScaleActiveFiberForceCurveWidthDGF
Scale the active fiber force curve width for all DeGrooteFregly2016Muscles in the model.
Definition: ModelOperators.h:138
OpenSim
The utilities in this file are categorized as follows:
Definition: About.h:24
OpenSim::MocoInverse::solve
MocoInverseSolution solve() const
Solve the problem returned by initialize() and compute the outputs listed in output_paths.
OpenSim::ModOpIgnorePassiveFiberForcesDGF
Turn off passive fiber forces for all DeGrooteFregly2016Muscles in the model.
Definition: ModelOperators.h:122
OpenSim::TableProcessor
This class describes a workflow for processing a table using TableOperators.
Definition: TableProcessor.h:47
OpenSim::ModOpAddReserves
Add reserve actuators to the model using ModelFactory::createReserveActuators.
Definition: ModelOperators.h:218