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 <OpenSim/Actuators/ModelOperators.h>
#include <OpenSim/Common/Adapters.h>
#include <OpenSim/Moco/osimMoco.h>
void solveMocoInverse() {
inverse.
setName(
"example3DWalking_MocoInverse");
"subject_walk_scaled_FunctionBasedPathSet.xml"));
"example3DWalking_MocoInverse_solution.sto");
}
void solveMocoInverseWithEMG() {
inverse.
setName(
"example3DWalking_MocoInverseWithEMG");
"subject_walk_scaled_FunctionBasedPathSet.xml"));
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"));
}
int main() {
solveMocoInverse();
solveMocoInverseWithEMG();
return EXIT_SUCCESS;
}