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_armless.osim")
44 modelProcessor.append(osim.ModOpAddExternalLoads(
"grf_walk.xml"))
46 modelProcessor.append(osim.ModOpRemoveMuscles())
49 modelProcessor.append(osim.ModOpAddReserves(250))
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.81)
88 track.set_final_time(1.65)
89 track.set_mesh_interval(0.05)
92 solution = track.solveAndVisualize()
94 def muscleDrivenStateTracking():
97 track = osim.MocoTrack()
98 track.setName(
"muscle_driven_state_tracking")
104 modelProcessor = osim.ModelProcessor(
"subject_walk_armless.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))
112 track.setModel(modelProcessor)
119 track.setStatesReference(osim.TableProcessor(
"coordinates.sto"))
120 track.set_states_global_tracking_weight(10)
124 track.set_allow_unused_references(
True)
129 track.set_track_reference_position_derivatives(
True)
132 track.set_initial_time(0.81)
133 track.set_final_time(1.65)
134 track.set_mesh_interval(0.08)
139 study = track.initialize()
143 problem = study.updProblem()
144 effort = osim.MocoControlGoal.safeDownCast(problem.updGoal(
"control_effort"))
149 model = modelProcessor.process()
151 forceSet = model.getForceSet()
152 for i
in range(forceSet.getSize()):
153 forcePath = forceSet.get(i).getAbsolutePathString()
154 if 'pelvis' in str(forcePath):
155 effort.setWeightForControl(forcePath, 10)
158 solution = study.solve()
159 study.visualize(solution)
163 torqueDrivenMarkerTracking()
169 muscleDrivenStateTracking()