Using metabolics probe with DeGrooteFregly2016Muscle

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
User avatar
Ross Miller
Posts: 375
Joined: Tue Sep 22, 2009 2:02 pm

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Ross Miller » Mon Apr 27, 2020 4:10 am

Hi Karthick,

I think you can use the following code to extract the states and controls from a previous solution (from a MocoTrajectory, specifically) and write them to .sto files:

Code: Select all

prevSolution = MocoTrajectory('your_previous_moco_solution.sto'); % Load previous solution into memory
prevStatesTable = prevSolution.exportToStatesTable(); % Extract previous solution's states
prevControlsTable = prevSolution.exportToControlsTable(); % Extract previous solution's controls
opensimMoco.writeTableToFile(prevStatesTable,'states.sto'); % Write states table to storage file
opensimMoco.writeTableToFile(prevControlsTable,'controls.sto'); % Write controls table to storage file
Would you mind sharing your code for running the metabolics probe? I'm interesting in doing this too.

Ross

User avatar
Karthick Ganesan
Posts: 119
Joined: Thu Oct 10, 2013 12:11 am

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Karthick Ganesan » Mon Apr 27, 2020 11:32 am

Thanks Ross Miller for sharing this code. I will try it.
I used the following setup file along with the commands :
analyzeTool = AnalyzeTool('name of setup file.xml')
analyzeTool.run()
If you are doing it outside a moco study please make sure to create a MocoStudy() first.

I manually added the probes from the tutorial :
https://simtk-confluence.stanford.edu:8 ... bolic+Cost

It is possible to add these probes programmatically. If you wish to do so this thread may be useful.
viewtopicPhpbb.php?f=91&t=11516&p=32196&start=0&view=

Also it is possible to use a generic setup file for the analysis and grammatically assign values like start time , end time etc . Hope this helps.

Karthick
Attachments
analyze_setup2.xml
(4.45 KiB) Downloaded 105 times
2D_gait_complianttendon_metabolics.osim
(221.34 KiB) Downloaded 89 times

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

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Nicholas Bianco » Tue Apr 28, 2020 2:53 pm

Hi everyone,

There is an alternative utility we built into Moco that might be more convenient than using the OpenSim AnalyzeTool. There is a method called analyze() built into Moco study that accepts a MocoTrajectory and a vector of strings to model outputs and returns a TimeSeriesTable of those outputs corresponding to your solution. It can be used like this:

Code: Select all

study = MocoStudy()
% Your MocoStudy defined here.
solution = study.solve()

outputPaths = StdVectorString()
outputPaths.add('<component_path>|<output_name>')
% Add more paths to outputPaths here

% outputTable is TimeSeriesTable with time vector equal to the MocoTrajectory
outputTable = study.analyze(solution, outputPaths)

Hopefully that will speed your post-optimization analyses!

Best,
-Nick

User avatar
Ross Miller
Posts: 375
Joined: Tue Sep 22, 2009 2:02 pm

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Ross Miller » Wed May 06, 2020 5:56 am

That is helpful, thanks Nick. Is there a way with study.analyze to have it calculate and report the fiber velocities for DeGrooteFregly2016 muscles?

Ross

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

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Nicholas Bianco » Wed May 06, 2020 12:07 pm

Ross,

The DeGrooteFregly2016 muscle derives from OpenSim's base Muscle class, so you can use all the outputs available to that class. You can get fiber velocity (or normalized fiber velocity) by adding the output paths like so:

Code: Select all

outputPaths = StdVectorString()
outputPaths.add('/forceset/soleus_r\|fiber_velocity')
outputPaths.add('/forceset/soleus_r\|normalized_fiber_velocity')
The extra backslash in front of the vertical bar is necessary to escape that character, since we use a regex check internally (vertical bar has a different meaning in regex). Speaking of regex, you can get all the muscle fiber velocities using a regex sequence like this:

Code: Select all

outputPaths = StdVectorString()
outputPaths.add('.*fiber_velocity')
Best,
-Nick

User avatar
Karthick Ganesan
Posts: 119
Joined: Thu Oct 10, 2013 12:11 am

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Karthick Ganesan » Thu May 07, 2020 6:37 am

Thanks Nick. What should be the output path for calculating all/individual muscle's moment about a joint (say Moment_ankle_angle_r)? Is there a way to do a complete Muscle Analysis?
Karhick

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

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Nicholas Bianco » Thu May 07, 2020 11:00 am

Hi Karthick,

To compute muscle moments, you'll need to compute muscle moment arms. Moment arms are not available as an output since you need to provide the state AND which coordinate you want the moment arm about:

Code: Select all

coordSet = model.getCoordinateSet();
coord = coordSet.get('<desired_coord_name>');

muscle = model.getMuscles().get('<desired_muscle_name>');

% state must be realized to Position stage
momentArmAboutCoord = muscle.computeMomentArm(state, coord);
You'll need to compute moment arms at all time points, and then compute muscle forces at the same time points and multiply together to get moments.

User avatar
Iris Magnusdottir
Posts: 19
Joined: Thu Nov 01, 2018 2:04 am

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Iris Magnusdottir » Mon May 11, 2020 3:54 am

Hi all,

I have added the metabolic probe to my model but it looks like the muscles in the probes are not connected to the muscles in my model. I get the following error when I try to run the Analyze Tool in OpenSim with my MocoSolution:
WARNING: Umberger2010MuscleMetabolicsProbe_MetabolicMuscleParameter: Muscle 'muscle name' not found in model. Ignoring...)

As Chris commented earlier in the tread:
chrisdembia wrote:
Thu Feb 27, 2020 3:27 pm
Make sure to use a PrescribedController to enforce the correct muscle excitations, which are required by the metabolics probes. The PrescribedController requires a STO file for controls.
where I guess the STO file can be obtained by:
rosshm wrote:
Mon Apr 27, 2020 4:10 am

Code: Select all

prevSolution = MocoTrajectory('your_previous_moco_solution.sto'); % Load previous solution into memory
prevControlsTable = prevSolution.exportToControlsTable(); % Extract previous solution's controls
opensimMoco.writeTableToFile(prevControlsTable,'controls.sto'); % Write controls table to storage file
So my question is, will the PrescribedController solve this issue? How do I add it?

And finally, how would I run the analyze tool to extract the ProbeReporter?
nbianco wrote:
Tue Apr 28, 2020 2:53 pm

Code: Select all

study = MocoStudy()
% Your MocoStudy defined here.
solution = study.solve()

outputPaths = StdVectorString()
outputPaths.add('<component_path>|<output_name>')
% Add more paths to outputPaths here

% outputTable is TimeSeriesTable with time vector equal to the MocoTrajectory
outputTable = study.analyze(solution, outputPaths)

I'm confused how this all works together as the PrescribedController needs the controls from the solution, and then it looks like the analyze tool is running at the same time as the solution.

Any help is highly appriciated,
Regards,
Iris

User avatar
Karthick Ganesan
Posts: 119
Joined: Thu Oct 10, 2013 12:11 am

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Karthick Ganesan » Mon May 11, 2020 6:13 am

Hi Iris,
Using OpenSim's AnalyzeTool and Moco's analyze method are two different approaches. If you are using the analyze tool then you have to specify the states and controls.sto files obtained from the Moco solution. In this case make sure in your model muscles are under force set. If you are using 'study.analyze()', please note that you are calling this method after ''study.solve()''. That is you already have the solution.
Hope this clarifies some of your queries.
Best,
Karthick.

User avatar
Iris Magnusdottir
Posts: 19
Joined: Thu Nov 01, 2018 2:04 am

Re: Using metabolics probe with DeGrooteFregly2016Muscle

Post by Iris Magnusdottir » Mon May 11, 2020 8:00 am

Thank you Karthick.

I tried using the states and controls from my MocoSolution with the Analyze Tool (both in OpenSim GUI and with accessing it through Moco using Matlab) but the total metabolic energy was maximum 130 (not sure about the units here), but this is way below what is reported in the Simulation-Based Design to Reduce Metabolic Cost (https://simtk-confluence.stanford.edu:8 ... bolic+Cost) example which reaches a maximum of approx 1750.

I have double checked that my muscles are under ForceSet. As mentioned above, I think the muscles are not being read by the probe. I have made sure that the same naming is used in both.

How did you use a PrescribedController to enforce the correct muscle excitations?

I should maybe mention that I am using MocoInverse tool as I am not interested in changes in kinematics.
I just tested the following code to see if the analyze tool would work with MocoInverse:

Code: Select all

outputPaths = StdVectorString();
outputPaths.add('/forceset/soleus_r\|fiber_velocity')
outputTable = inverse.analyze(solution, outputPaths);
which gave me an error: Undefined function 'analyze' for input arguments of type
'org.opensim.modeling.MocoInverse'.
I tried the inverse.analyze() as I haven't defined a study in my code, only inverse = MocoInverse(). I am basing my code on the exampleMocoInverse.m code in example3DWalking.

POST REPLY