MocoStateTracking
Posted: Tue Jul 19, 2022 4:29 am
Dear Moco users and developer team,
I am working on a MocoState Tracking problem. In the end, I want to use MocoTrack to validate some output from ParameterOptimization. I want to establish which muscle-tendon parameter configurations are best to track measured kinematics and GRFs.
As a first step I try to simply track coordinates and apply GRFs. Please see code below. THe problem I am facing is that the solution does not at all look like the measured kinematics. It "walks" backwards and floats through the ground.
I am wondering if you have any suggestions for me to get a stable tracking solution. Are there maybe some peculiarities in the code? I am using Python 3.8 and OpenSim 4.3
Thanks for your time and kind regards
Christian
I am working on a MocoState Tracking problem. In the end, I want to use MocoTrack to validate some output from ParameterOptimization. I want to establish which muscle-tendon parameter configurations are best to track measured kinematics and GRFs.
As a first step I try to simply track coordinates and apply GRFs. Please see code below. THe problem I am facing is that the solution does not at all look like the measured kinematics. It "walks" backwards and floats through the ground.
I am wondering if you have any suggestions for me to get a stable tracking solution. Are there maybe some peculiarities in the code? I am using Python 3.8 and OpenSim 4.3
Thanks for your time and kind regards
Christian
Code: Select all
for name in dir():
if not name.endswith('FileName'):
del globals()[name]
import opensim as osim
import os
#
Path = r'C:\Users\.......'
os.chdir(Path)
Scaled_modelFileName = os.path.join(Path, 'LowerLimbFootModel.osim')
GRF_SourceFilename = os.path.join(Path,'grf_CluFO_01_Okt202112_Filt.xml')
States_Filename = os.path.join(Path,'Okt202112_Kinematics_q.sto')#'MocoInverseWithEMG_Okt202108_Clubfoot_Final_NoMocoProblem.sto')
ReserveActuatorStrength = 25
Output_FilenameMocoTrack = os.path.join(Path,'MocoTrack_Solution_test.sto')
start_time = 0.7
end_time = 1.5#1.87
#%% Construct a ModelProcessor and set it on the tool. The default
modelProcessor = osim.ModelProcessor(Scaled_modelFileName)#('Patient_SCALED.osim')
modelProcessor.append(osim.ModOpAddExternalLoads(GRF_SourceFilename))#('grf_walk_PiG.xml'))
modelProcessor.append(osim.ModOpIgnoreTendonCompliance())
modelProcessor.append(osim.ModOpReplaceMusclesWithDeGrooteFregly2016())
modelProcessor.append(osim.ModOpIgnorePassiveFiberForcesDGF())
modelProcessor.append(osim.ModOpScaleActiveFiberForceCurveWidthDGF(1.5))
modelProcessor.append(osim.ModOpAddReserves(ReserveActuatorStrength))
track = osim.MocoTrack()
track.setName("CoordTracking")
track.setModel(modelProcessor)
track.setStatesReference(osim.TableProcessor(States_Filename))
track.set_states_global_tracking_weight(50)
track.set_control_effort_weight(0.001)
track.set_allow_unused_references(True)
track.set_track_reference_position_derivatives(True);
track.set_apply_tracked_states_to_guess(True)
# track.set_scale_state_weights_with_range(True)
track.set_initial_time(start_time)
track.set_final_time(end_time)
track.set_mesh_interval(0.04)
#%% Coordinate tracking to create guess file
study = track.initialize()
problem = study.updProblem()
effort = osim.MocoControlGoal.safeDownCast(problem.updGoal("control_effort"))
model = modelProcessor.process()
model.initSystem()
forceSet = model.getForceSet()
for i in range(forceSet.getSize()):
forcePath = forceSet.get(i).getAbsolutePathString()
if 'pelvis' in str(forcePath):
effort.setWeightForControl(forcePath, 10)
solution = study.solve()
solution.unseal()
solution.write(Output_FilenameMocoTrack)
study.visualize(solution)