This is an example that uses the MocoInverse tool and EMG data to create an EMG-driven simulation of walking. This example is used in hands-on workshops, and accordingly has blanks that users must fill in. See exampleSquatToStand_answers.m for a completed version.
3import exampleEMGTracking_helpers
as helpers
16model = helpers.getWalkingModel()
31inverse.set_initial_time( )
32inverse.set_final_time( )
33inverse.set_mesh_interval( )
34inverse.set_constraint_tolerance( )
35inverse.set_convergence_tolerance( )
37if not os.path.isfile(
'effortSolution.sto'):
46emgReference = osim.TimeSeriesTable(
'emg.sto')
47helpers.compareSolutionToEMG(emgReference,
'effortSolution.sto')
63tracking.setReference( )
64tracking.setReferenceLabel(
'/forceset/gasmed_l',
'gastrocnemius')
65tracking.setReferenceLabel(
'/forceset/tibant_l',
'tibialis_anterior')
66tracking.setReferenceLabel(
'/forceset/bfsh_l',
'biceps_femoris')
67tracking.setReferenceLabel( )
74tracking.addScaleFactor(
'gastroc_factor',
'/forceset/gasmed_l', [0.01, 1.0])
75tracking.addScaleFactor(
'tibant_factor',
'/forceset/tibant_l', [0.01, 1.0])
76tracking.addScaleFactor(
'bifem_factor',
'/forceset/bfsh_l', [0.01, 1.0])
77tracking.addScaleFactor( )
84solver = osim.MocoCasADiSolver.safeDownCast(study.updSolver())
85solver.resetProblem(problem)
92if not os.path.isfile(
'trackingSolution.sto'):
98trackingSolution = osim.MocoTrajectory(
'trackingSolution.sto')
99gastroc_factor = trackingSolution.getParameter(
'gastroc_factor')
100tibant_factor = trackingSolution.getParameter(
'tibant_factor')
101bifem_factor = trackingSolution.getParameter(
'bifem_factor')
106print(
'\nOptimized scale factor values:')
107print(
'------------------------------')
108print(
'gastrocnemius = ' + str(gastroc_factor))
109print(
'tibialis anterior = ' + str(tibant_factor))
110print(
'biceps femoris short head = ' + str(bifem_factor))
111print(
'gluteus = ' + str(gluteus_factor))
114gastroc = emgReference.updDependentColumn(
'gastrocnemius')
115tibant = emgReference.updDependentColumn(
'tibialis_anterior')
116bifem = emgReference.updDependentColumn(
'biceps_femoris')
117gluteus = emgReference.updDependentColumn(
'gluteus')
118for t
in np.arange(emgReference.getNumRows()):
120 gastroc[t] = gastroc_factor * gastroc[t]
121 tibant[t] = tibant_factor * tibant[t]
122 bifem[t] = bifem_factor * bifem[t]
123 gluteus[t] = gluteus_factor * gluteus[t]
127helpers.compareSolutionToEMG(emgReference,
'effortSolution.sto',
128 'trackingSolution.sto')