Moco analyze() function

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Christian Greve
Posts: 41
Joined: Mon Jun 13, 2016 11:14 pm

Moco analyze() function

Post by Christian Greve » Tue Aug 30, 2022 1:42 am

Dear Moco users,

I am trying to perform muscle analysis on a Moco Solution in Python. First I used this code:

Code: Select all

solution = study.solve()
    outputs = osim.StdVectorString()
    outputs.append('.*active_force_length_multiplier')
    table = study.analyze(solution, outputs)


However, I received the error message that the speeds and values were not in the trajectory. Good point I thought and appended the speeds and values from a MovoInverse solution with some additional code:

Code: Select all

solution = study.solve()
    solution.insertStatesTrajectory(osim.TimeSeriesTable(MocoInverseSolutionFileName))
    outputs = osim.StdVectorString()
    outputs.append('.*active_force_length_multiplier')
    table = study.analyze(solution, outputs)
The error message I receive now is that 176 states which are in the solution are not in the model...these are for example: "/forceset/semiten_r".

I also tried the standard OpenSimAnalyze function which works but does not provide valid outputs (e.g. straight line for normalized muscle_lengths during a gait cycle).

So summarizing....I want to perform muscle analysis on a MocoStudy solution but have trouble to get the analyze() function running. Do you have any suggestions?

Thanks and kind regards

Christian

User avatar
Nicholas Bianco
Posts: 1003
Joined: Thu Oct 04, 2012 8:09 pm

Re: Moco analyze() function

Post by Nicholas Bianco » Tue Aug 30, 2022 11:02 am

Hi Christian,

This is a known issue with MocoInverse, since the problem prescribes kinematics, so all coordinate values and speeds are removed from the problem.

You almost had the right fix, but you accidentally inserted the entire MocoInverse solution into the states trajectory, rather than just the states.

Code: Select all

solutionWithKinematics = osim.MocoTrajectory(MocoInverseSolutionFileName)
statesTable = solutionWithKinematics.exportToStatesTable()

# The states table also includes muscle states, but since we leave the
# 'overwrite' argument false, this should work. 
solution.insertStatesTrajectory(statesTable)
-Nick

User avatar
Christian Greve
Posts: 41
Joined: Mon Jun 13, 2016 11:14 pm

Re: Moco analyze() function

Post by Christian Greve » Wed Sep 07, 2022 6:49 am

Thanks a lot Nick! That solved the problem....

Regards

Christian

POST REPLY