This is an example using the MocoInverse tool with a complex model to prescribe walking. This example also shows how to track electromyography data.
#include <Moco/osimMoco.h>
#include <OpenSim/Common/Adapters.h>
void solveMocoInverse() {
inverse.setName("example3DWalking_MocoInverse");
inverse.
setModel(modelProcessor);
inverse.set_initial_time(0.81);
inverse.set_final_time(1.79);
inverse.set_mesh_interval(0.02);
inverse.set_kinematics_allow_extra_columns(true);
solution.
getMocoSolution().
write(
"example3DWalking_MocoInverse_solution.sto");
}
void solveMocoInverseWithEMG() {
inverse.setName("example3DWalking_MocoInverseWithEMG");
inverse.setModel(modelProcessor);
inverse.set_initial_time(0.81);
inverse.set_final_time(1.79);
inverse.set_mesh_interval(0.02);
inverse.set_kinematics_allow_extra_columns(true);
TimeSeriesTable controlsRef("electromyography.sto");
controlsRef.updDependentColumn("soleus") *= 0.77;
controlsRef.updDependentColumn("gastrocnemius") *= 0.87;
controlsRef.updDependentColumn("tibialis_anterior") *= 0.37;
tracking->setReference(controlsRef);
tracking->setReferenceLabel("/forceset/soleus_r", "soleus");
tracking->setReferenceLabel("/forceset/gasmed_r", "gastrocnemius");
tracking->setReferenceLabel("/forceset/gaslat_r", "gastrocnemius");
tracking->setReferenceLabel("/forceset/tibant_r", "tibialis_anterior");
solution.
write(
"example3DWalking_MocoInverseWithEMG_solution.sto");
controlsRef.removeColumn("medial_hamstrings");
controlsRef.removeColumn("biceps_femoris");
controlsRef.removeColumn("vastus_lateralis");
controlsRef.removeColumn("vastus_medius");
controlsRef.removeColumn("rectus_femoris");
controlsRef.removeColumn("gluteus_maximus");
controlsRef.removeColumn("gluteus_medius");
controlsRef.setColumnLabels({"/forceset/soleus_r", "/forceset/gasmed_r",
"/forceset/tibant_r"});
controlsRef.appendColumn("/forceset/gaslat_r",
controlsRef.getDependentColumn("/forceset/gasmed_r"));
STOFileAdapter::write(controlsRef, "controls_reference.sto");
}
int main() {
solveMocoInverse();
solveMocoInverseWithEMG();
return EXIT_SUCCESS;
}