This is an example using the MocoTrack tool with a complex model to track walking.
#include <OpenSim/Actuators/CoordinateActuator.h>
#include <OpenSim/Actuators/ModelOperators.h>
#include <OpenSim/Moco/osimMoco.h>
void torqueDrivenMarkerTracking() {
MocoTrack track;
track.setName("torque_driven_marker_tracking");
ModelProcessor modelProcessor("subject_walk_armless.osim");
modelProcessor.append(ModOpAddExternalLoads("grf_walk.xml") );
modelProcessor.append(ModOpRemoveMuscles());
modelProcessor.append(ModOpAddReserves(250));
track.setModel(modelProcessor);
track.setMarkersReferenceFromTRC("marker_trajectories.trc");
track.set_allow_unused_references(true);
track.set_markers_global_tracking_weight(10);
MocoWeightSet markerWeights;
markerWeights.cloneAndAppend({"R.ASIS", 20});
markerWeights.cloneAndAppend({"L.ASIS", 20});
markerWeights.cloneAndAppend({"R.PSIS", 20});
markerWeights.cloneAndAppend({"L.PSIS", 20});
markerWeights.cloneAndAppend({"R.Knee", 10});
markerWeights.cloneAndAppend({"R.Ankle", 10});
markerWeights.cloneAndAppend({"R.Heel", 10});
markerWeights.cloneAndAppend({"R.MT5", 5});
markerWeights.cloneAndAppend({"R.Toe", 2});
markerWeights.cloneAndAppend({"L.Knee", 10});
markerWeights.cloneAndAppend({"L.Ankle", 10});
markerWeights.cloneAndAppend({"L.Heel", 10});
markerWeights.cloneAndAppend({"L.MT5", 5});
markerWeights.cloneAndAppend({"L.Toe", 2});
track.set_markers_weight_set(markerWeights);
track.set_initial_time(0.81);
track.set_final_time(1.65);
track.set_mesh_interval(0.05);
MocoSolution solution = track.solveAndVisualize();
}
void muscleDrivenStateTracking() {
MocoTrack track;
track.setName("muscle_driven_state_tracking");
ModelProcessor modelProcessor("subject_walk_armless.osim");
modelProcessor.append(ModOpAddExternalLoads("grf_walk.xml"));
modelProcessor.append(ModOpIgnoreTendonCompliance());
modelProcessor.append(ModOpReplaceMusclesWithDeGrooteFregly2016());
modelProcessor.append(ModOpIgnorePassiveFiberForcesDGF());
modelProcessor.append(ModOpScaleActiveFiberForceCurveWidthDGF(1.5));
track.setModel(modelProcessor);
track.setStatesReference(TableProcessor("coordinates.sto"));
track.set_states_global_tracking_weight(10);
track.set_allow_unused_references(true);
track.set_track_reference_position_derivatives(true);
track.set_initial_time(0.81);
track.set_final_time(1.65);
track.set_mesh_interval(0.08);
MocoStudy study = track.initialize();
MocoProblem& problem = study.updProblem();
MocoControlGoal& effort =
dynamic_cast<MocoControlGoal&>(problem.updGoal("control_effort"));
Model model = modelProcessor.process();
for (const auto& coordAct : model.getComponentList<CoordinateActuator>()) {
auto coordPath = coordAct.getAbsolutePathString();
if (coordPath.find("pelvis") != std::string::npos) {
effort.setWeightForControl(coordPath, 10);
}
}
MocoSolution solution = study.solve();
study.visualize(solution);
}
int main() {
torqueDrivenMarkerTracking();
muscleDrivenStateTracking();
return EXIT_SUCCESS;
}
The Moco interface is contained within the OpenSim namespace.
Definition: Moco.dox:5