This is an example using the MocoTrack tool with a complex model to track walking.
29 import opensim
as osim
31 def torqueDrivenMarkerTracking():
34 track = osim.MocoTrack()
35 track.setName(
"torque_driven_marker_tracking")
42 modelProcessor = osim.ModelProcessor(
"subject_walk_scaled.osim")
44 modelProcessor.append(osim.ModOpAddExternalLoads(
"grf_walk.xml"))
46 modelProcessor.append(osim.ModOpRemoveMuscles())
49 modelProcessor.append(osim.ModOpAddReserves(250.0, 1.0))
50 track.setModel(modelProcessor)
55 track.setMarkersReferenceFromTRC(
"marker_trajectories.trc")
60 track.set_allow_unused_references(
True)
64 track.set_markers_global_tracking_weight(10)
68 markerWeights = osim.MocoWeightSet()
69 markerWeights.cloneAndAppend(osim.MocoWeight(
"R.ASIS", 20))
70 markerWeights.cloneAndAppend(osim.MocoWeight(
"L.ASIS", 20))
71 markerWeights.cloneAndAppend(osim.MocoWeight(
"R.PSIS", 20))
72 markerWeights.cloneAndAppend(osim.MocoWeight(
"L.PSIS", 20))
73 markerWeights.cloneAndAppend(osim.MocoWeight(
"R.Knee", 10))
74 markerWeights.cloneAndAppend(osim.MocoWeight(
"R.Ankle", 10))
75 markerWeights.cloneAndAppend(osim.MocoWeight(
"R.Heel", 10))
76 markerWeights.cloneAndAppend(osim.MocoWeight(
"R.MT5", 5))
77 markerWeights.cloneAndAppend(osim.MocoWeight(
"R.Toe", 2))
78 markerWeights.cloneAndAppend(osim.MocoWeight(
"L.Knee", 10))
79 markerWeights.cloneAndAppend(osim.MocoWeight(
"L.Ankle", 10))
80 markerWeights.cloneAndAppend(osim.MocoWeight(
"L.Heel", 10))
81 markerWeights.cloneAndAppend(osim.MocoWeight(
"L.MT5", 5))
82 markerWeights.cloneAndAppend(osim.MocoWeight(
"L.Toe", 2))
83 track.set_markers_weight_set(markerWeights)
87 track.set_initial_time(0.48)
88 track.set_final_time(1.61)
89 track.set_mesh_interval(0.02)
92 solution = track.solveAndVisualize()
94 def muscleDrivenStateTracking():
97 track = osim.MocoTrack()
98 track.setName(
"muscle_driven_state_tracking")
104 modelProcessor = osim.ModelProcessor(
"subject_walk_scaled.osim")
105 modelProcessor.append(osim.ModOpAddExternalLoads(
"grf_walk.xml"))
106 modelProcessor.append(osim.ModOpIgnoreTendonCompliance())
107 modelProcessor.append(osim.ModOpReplaceMusclesWithDeGrooteFregly2016())
109 modelProcessor.append(osim.ModOpIgnorePassiveFiberForcesDGF())
111 modelProcessor.append(osim.ModOpScaleActiveFiberForceCurveWidthDGF(1.5))
117 modelProcessor.append(osim.ModOpReplacePathsWithFunctionBasedPaths(
118 "subject_walk_scaled_FunctionBasedPathSet.xml"))
119 track.setModel(modelProcessor)
126 track.setStatesReference(osim.TableProcessor(
"coordinates.sto"))
130 track.set_allow_unused_references(
True)
135 track.set_track_reference_position_derivatives(
True)
138 track.set_initial_time(0.48)
139 track.set_final_time(1.61)
140 track.set_mesh_interval(0.02)
145 study = track.initialize()
149 problem = study.updProblem()
150 effort = osim.MocoControlGoal.safeDownCast(problem.updGoal(
"control_effort"))
151 effort.setWeight(0.1)
156 model = modelProcessor.process()
158 forceSet = model.getForceSet()
159 for i
in range(forceSet.getSize()):
160 forcePath = forceSet.get(i).getAbsolutePathString()
161 if 'pelvis' in str(forcePath):
162 effort.setWeightForControl(forcePath, 10)
166 problem.addGoal(osim.MocoInitialActivationGoal(
'initial_activation'))
169 solver = osim.MocoCasADiSolver.safeDownCast(study.updSolver())
170 solver.set_optim_convergence_tolerance(1e-3)
171 solver.set_optim_constraint_tolerance(1e-4)
174 solution = study.solve()
175 study.visualize(solution)
179 torqueDrivenMarkerTracking()
182 muscleDrivenStateTracking()