Using metabolics probe with DeGrooteFregly2016Muscle
- Karthick Ganesan
- Posts: 119
- Joined: Thu Oct 10, 2013 12:11 am
Re: Using metabolics probe with DeGrooteFregly2016Muscle
Before setting up and running analyze tool try defining a study: study = MocoStudy().
Please see one of my posts above where I have uploaded a setup file specifying states and controls.
Please see one of my posts above where I have uploaded a setup file specifying states and controls.
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Using metabolics probe with DeGrooteFregly2016Muscle
The function analyze() is available in two places: MocoStudy (study.analyze()) and as a free function (opensimMoco.analyze()). MocoInverse does not provide analyze().
- Nicholas Bianco
- Posts: 1041
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Using metabolics probe with DeGrooteFregly2016Muscle
Iris,
Based on your error message,
To expand on Karthick's helpful suggestions: the study.analyze() method doesn't need a PrescribedController, the controls from the provided MocoTrajectory are applied to the model for you. If you do decide to use study.analyze() over the AnalyzeTool, then look into the Output called "probe_outputs" that is included for every class derived from Probe (including the Umberger2010MuscleMetabolicsProbe).
-Nick
Based on your error message,
it looks like you need to provide the muscle names for each metabolic muscle parameter. Double check your model file to make sure they all have the correct muscle names. If that doesn't help, then I think we'll need more information to debug this issue.WARNING: Umberger2010MuscleMetabolicsProbe_MetabolicMuscleParameter: Muscle 'muscle name' not found in model. Ignoring...)
To expand on Karthick's helpful suggestions: the study.analyze() method doesn't need a PrescribedController, the controls from the provided MocoTrajectory are applied to the model for you. If you do decide to use study.analyze() over the AnalyzeTool, then look into the Output called "probe_outputs" that is included for every class derived from Probe (including the Umberger2010MuscleMetabolicsProbe).
-Nick
- Iris Magnusdottir
- Posts: 19
- Joined: Thu Nov 01, 2018 2:04 am
Re: Using metabolics probe with DeGrooteFregly2016Muscle
Thank you all for the helpful feedback.
My previous error disappeared when I edited my ProbeSet, adding <enabled>true</enabled> and <aerobic_factor>1.5</aerobic_factor>.
If I use the Analyze Tool (instead of analyze.study()), do I then need a PrescribedController?
I am now running the Analyze Tool as shown in the code below. I get error messages when reading the controls.sto and states.sto, see attached file (Errors.txt). Still, I get very high values for metabolic cost, which seem to be too high, see figure below.
How would I make sure that the Analyze Tool can read the actuators and fiber_lengths from the model (the nature of the errors)?
For the other approach (analyze.study()), how would I define a MocoStudy when using MocoInverse? Will I then need to define a outputPath for the Probe?
I will attach my model file below as well (which is a slightly modified version of the gait2392 model).
Thank you for taking the time to help me out.
My previous error disappeared when I edited my ProbeSet, adding <enabled>true</enabled> and <aerobic_factor>1.5</aerobic_factor>.
If I use the Analyze Tool (instead of analyze.study()), do I then need a PrescribedController?
I am now running the Analyze Tool as shown in the code below. I get error messages when reading the controls.sto and states.sto, see attached file (Errors.txt). Still, I get very high values for metabolic cost, which seem to be too high, see figure below.
How would I make sure that the Analyze Tool can read the actuators and fiber_lengths from the model (the nature of the errors)?
For the other approach (analyze.study()), how would I define a MocoStudy when using MocoInverse? Will I then need to define a outputPath for the Probe?
I will attach my model file below as well (which is a slightly modified version of the gait2392 model).
Thank you for taking the time to help me out.
Code: Select all
import org.opensim.modeling.*;
inverse = MocoInverse();
modelProcessor = ModelProcessor('subject_walk_rra2_probed_weld_millard.osim');
modelProcessor.append(ModOpAddExternalLoads('grf_walk.xml'));
modelProcessor.append(ModOpIgnoreTendonCompliance());
modelProcessor.append(ModOpReplaceMusclesWithDeGrooteFregly2016());
modelProcessor.append(ModOpIgnorePassiveFiberForcesDGF());
modelProcessor.append(ModOpScaleActiveFiberForceCurveWidthDGF(1.5));
modelProcessor.append(ModOpAddReserves(1.0));
inverse.setModel(modelProcessor);
inverse.setKinematics(TableProcessor('rra_walk_2_Kinematics_q.sto'));
inverse.set_initial_time(0.81);
inverse.set_final_time(1.79);
inverse.set_mesh_interval(0.02);
inverse.set_kinematics_allow_extra_columns(true);
solution = inverse.solve();
solution.getMocoSolution().write('MocoInverse_solution.sto');
% States and controls
prevSolution = MocoTrajectory('MocoInverse_solution.sto');
prevStatesTable = prevSolution.exportToStatesTable();
prevControlsTable = prevSolution.exportToControlsTable();
opensimMoco.writeTableToFile(prevStatesTable,'states.sto');
opensimMoco.writeTableToFile(prevControlsTable,'controls.sto');
analyzeTool = AnalyzeTool('Setup_Analyze.xml'); % this file calls the states and controls files created above
analyzeTool.run();
- Attachments
-
- Setup_Analyze.xml
- (4.8 KiB) Downloaded 113 times
-
- subject_walk_rra2_probed_weld_millard.osim
- (739.41 KiB) Downloaded 114 times
-
- gait.png (17.05 KiB) Viewed 2399 times
-
- Errors.txt
- (21.81 KiB) Downloaded 100 times
- Nicholas Bianco
- Posts: 1041
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Using metabolics probe with DeGrooteFregly2016Muscle
Hi Iris,
Part of your issue is that you need to print out the model created by the ModelProcessor so that it's compatible with your states and controls file. For example, you've added reserves to the model that the base model doesn't have and you've disabled tendon compliance but the base model hasn't (hence why you see errors related to fiber length states). To do this, you can do the following:
If you call initialize on the MocoInverse object you can retrieve the underlying MocoStudy. The Umberger2010MuscleMetabolicsProbe has an output called "probe_outputs" that returns a vector of values from the problem. Based on your model it would look something like this:
However, I'm not sure this will work in MATLAB, since the outputTable should be of type TimeSeriesTable_<Vector> (this is C++ notation), but it doesn't seem like that type is supported in MATLAB.
So it seems like you'll need the AnalyzeTool. If you use the AnalyzeTool, you will need a PrescribedController so that the correct controls are applied to the model at each time point.
-Nick
Part of your issue is that you need to print out the model created by the ModelProcessor so that it's compatible with your states and controls file. For example, you've added reserves to the model that the base model doesn't have and you've disabled tendon compliance but the base model hasn't (hence why you see errors related to fiber length states). To do this, you can do the following:
Code: Select all
modelUpdated = modelProcessor.process();
modelUpdated.print('model_updated.osim'); % or whatever you want to name it
Code: Select all
study = inverse.initialize();
outputPaths = StdVectorString();
outputPaths.add('/probeset/metabolics\|probe_outputs');
outputTable = study.analyze(solution.getMocoSolution(), outputPaths);
So it seems like you'll need the AnalyzeTool. If you use the AnalyzeTool, you will need a PrescribedController so that the correct controls are applied to the model at each time point.
-Nick
- Iris Magnusdottir
- Posts: 19
- Joined: Thu Nov 01, 2018 2:04 am
Re: Using metabolics probe with DeGrooteFregly2016Muscle
Thank you Nick!
I believe I managed to get the PrescribedController to work. My error occurred as the header in my control.sto file was not the same as in the ForceSet in my model (.sto had a /forceset/ prefix).
What I did was:
Where I then used the model_updated_pc.osim file in the Analyze Tool.
My results are now similar to the Metabolic Cost Tutorial.
Thank you all!
I believe I managed to get the PrescribedController to work. My error occurred as the header in my control.sto file was not the same as in the ForceSet in my model (.sto had a /forceset/ prefix).
What I did was:
Code: Select all
model = Model('model_updated.osim');
pc = PrescribedController('controls.sto'); % file generated from solution
model.addController(pc);
model.finalizeConnections();
model.print('model_updated_pc.osim');
My results are now similar to the Metabolic Cost Tutorial.
Thank you all!
- Karthick Ganesan
- Posts: 119
- Joined: Thu Oct 10, 2013 12:11 am
Re: Using metabolics probe with DeGrooteFregly2016Muscle
Dear All,
As Iris pointed out, the name of the controls in the storage file has '/forceset/' prefix whereas name of the control in the model does not have it. I manually removed this prefix in the storage file using 'replace all' in Matlab editor. I want to do this with scripting since I have to run many simulations. Any suggestions?
Thanks,
Karthick.
As Iris pointed out, the name of the controls in the storage file has '/forceset/' prefix whereas name of the control in the model does not have it. I manually removed this prefix in the storage file using 'replace all' in Matlab editor. I want to do this with scripting since I have to run many simulations. Any suggestions?
Thanks,
Karthick.
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Using metabolics probe with DeGrooteFregly2016Muscle
You can edit the column labels before you write the controls storage file:
In a future release of Moco, PrescribedController will accept the `/forceset/` prefix.
Code: Select all
controls = solution.exportToControlsTable();
labels = controls.getColumnLabels();
<edit the labels to remove the prefix>
controls.setColumnLabels(labels);
STOFileAdapter.write(controls, "controls.sto");
- Iris Magnusdottir
- Posts: 19
- Joined: Thu Nov 01, 2018 2:04 am
Re: Using metabolics probe with DeGrooteFregly2016Muscle
Hi all,
I would like to compute the ankle plantarflexion moment using my exoskeleton and compare the moment generated by my device with muscle moments with and without assistance, as done by Dembia et al (2017).
Previously in this thread, Nick suggested the following:
And then to multiply moment arm and muscle force. However, this does not seem to work in Matlab. I get the following error: No method 'computeMomentArm' with matching signature found for class 'org.opensim.modeling.Muscle'.
Correct me if I'm wrong, but the "state" in this code, refers to the state of the muscle selected right?
I am using MocoInverse and so far used the Analyze Tool to get various parameters from my solution.
Is it possible to use JointReaction to compute joint moment?
I saw that Karthick was interested in something similar. Would love to know if that worked out.
Thanks!
Iris
I would like to compute the ankle plantarflexion moment using my exoskeleton and compare the moment generated by my device with muscle moments with and without assistance, as done by Dembia et al (2017).
Previously in this thread, Nick suggested the following:
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);
Correct me if I'm wrong, but the "state" in this code, refers to the state of the muscle selected right?
I am using MocoInverse and so far used the Analyze Tool to get various parameters from my solution.
Is it possible to use JointReaction to compute joint moment?
I saw that Karthick was interested in something similar. Would love to know if that worked out.
Thanks!
Iris
- Iris Magnusdottir
- Posts: 19
- Joined: Thu Nov 01, 2018 2:04 am
Re: Using metabolics probe with DeGrooteFregly2016Muscle
Just to answer my own question in case it might help someone else.
I managed to find the joint moments using MuscleAnalysis and sum up the muscle moments that act around the ankle joint.
However, it only reports the moments of muscles in the model. How can I see the contribution of my PathActuator (motor) to ankle moment?
Thanks!
I managed to find the joint moments using MuscleAnalysis and sum up the muscle moments that act around the ankle joint.
However, it only reports the moments of muscles in the model. How can I see the contribution of my PathActuator (motor) to ankle moment?
Thanks!