This is an example using the MocoTrack tool that also shows how to minimize the total metabolic rate employing the Bhargava2004SmoothedMuscleMetabolics.
#include <OpenSim/Moco/MocoGoal/MocoOutputGoal.h>
#include <OpenSim/Moco/osimMoco.h>
void gaitTrackingMetabolics() {
using SimTK::Pi;
track.
setName(
"gaitTrackingMetabolics");
Model baseModel(
"2D_gait.osim");
for (
const auto& coord : model.getComponentList<
Coordinate>()) {
symmetryGoal->addStatePair({coord.getStateVariableNames()[0],
std::regex_replace(coord.getStateVariableNames()[0],
std::regex("_r"), "_l")});
symmetryGoal->addStatePair({coord.getStateVariableNames()[1],
std::regex_replace(coord.getStateVariableNames()[1],
std::regex("_r"), "_l")});
}
symmetryGoal->addStatePair({coord.getStateVariableNames()[0],
std::regex_replace(coord.getStateVariableNames()[0],
std::regex("_l"), "_r")});
symmetryGoal->addStatePair({coord.getStateVariableNames()[1],
std::regex_replace(coord.getStateVariableNames()[1],
std::regex("_l"), "_r")});
}
symmetryGoal->addStatePair({coord.getStateVariableNames()[0],
coord.getStateVariableNames()[0]});
symmetryGoal->addStatePair({coord.getStateVariableNames()[1],
coord.getStateVariableNames()[1]});
}
}
symmetryGoal->addStatePair({"/jointset/groundPelvis/pelvis_tx/speed"});
symmetryGoal->addControlPair({"/lumbarAct"});
for (
const auto& muscle : model.getComponentList<
Muscle>()) {
symmetryGoal->addStatePair({muscle.getStateVariableNames()[0],
std::regex_replace(muscle.getStateVariableNames()[0],
std::regex("_r"), "_l")});
}
symmetryGoal->addStatePair({muscle.getStateVariableNames()[0],
std::regex_replace(muscle.getStateVariableNames()[0],
std::regex("_l"), "_r")});
}
}
metGoal->setOutputPath("/metabolics|total_metabolic_rate");
metGoal->setDivideByDisplacement(true);
metGoal->setDivideByMass(true);
problem.
setStateInfo(
"/jointset/groundPelvis/pelvis_tilt/value",
{-20 * Pi / 180, -10 * Pi / 180});
problem.
setStateInfo(
"/jointset/groundPelvis/pelvis_tx/value", {0, 1});
"/jointset/groundPelvis/pelvis_ty/value", {0.75, 1.25});
{-10 * Pi / 180, 60 * Pi / 180});
{-10 * Pi / 180, 60 * Pi / 180});
"/jointset/knee_l/knee_angle_l/value", {-50 * Pi / 180, 0});
"/jointset/knee_r/knee_angle_r/value", {-50 * Pi / 180, 0});
problem.
setStateInfo(
"/jointset/ankle_l/ankle_angle_l/value",
{-15 * Pi / 180, 25 * Pi / 180});
problem.
setStateInfo(
"/jointset/ankle_r/ankle_angle_r/value",
{-15 * Pi / 180, 25 * Pi / 180});
problem.
setStateInfo(
"/jointset/lumbar/lumbar/value", {0, 20 * Pi / 180});
full.write("gaitTrackingMetabolics_solution_fullcycle.sto");
std::cout << "The metabolic cost of transport is: "
}
int main() {
try {
gaitTrackingMetabolics();
} catch (const std::exception& e) { std::cout << e.what() << std::endl; }
return EXIT_SUCCESS;
}