Error when Adding a MocoParameter in Python
Posted: Tue Mar 14, 2023 12:34 pm
Hello,
I am running a Moco state tracking problem through the Python API and am getting an error when trying to add a MocoParameter to the problem. I started with a basic test of an example from the class documentation to make sure I have the setup right, and I am already having issues.
Code Snippet:
Without the two lines involving the "param" variable, everything runs as expected. After adding those lines, the program seems to get hung up after printing details about the Jacobian and Lagrangian Hessian values:
Am I using/implementing the MocoParameter correctly? Is there something I should be doing in addition/instead of what I am currently doing to get OpenSim to optimize a variable like this? Please let me know if you have any suggestions for me to improve/correct my setup.
For reference, I am using the Subject 14, no load, free speed, trial 2 data from this dataset: https://simtk.org/projects/assistloadwalk#. The parameter ranges were set to their extrema in the input kinematics +/- 5% of the range in the input data to allow some variance within the simulation.
Adjustments I made to the model:
1. In an attempt to get better foot-ground contact measurements from Moco, I unlocked the mtp and subtalar joints, repositioned toe-based markers to have the corresponding toe body as their parent, and reran IK with the new model.
2. I added contact spheres and forces according to the configuration provided here: https://simtk.org/projects/umocod. I scaled the positions of the spheres based on the corresponding scale factor of the parent body. I scaled the radii of the contact spheres based on the cube root of the product of the parent body's scale factors.
3. I used the ModOpReplaceMusclesWithDeGrooteFregly2016() model operator method to prepare the model for use with Moco.
I've attached the Moco setup file (comments removed to reduce size enough to attach) to provide additional information on the problem I am attempting to run.
I am running a Moco state tracking problem through the Python API and am getting an error when trying to add a MocoParameter to the problem. I started with a basic test of an example from the class documentation to make sure I have the setup right, and I am already having issues.
Code Snippet:
Code: Select all
# Inside custom class for managing the MocoStudy
# Any variables that aren't defined here are defined earlier in the code
study = osim.MocoStudy()
# model processing
...
# Problem definition
problem = study.updProblem()
problem.setModelAsCopy(self.model)
problem.setTimeBounds(self.initialTime, self.finalTime)
# Test MocoParameter with example for Matlab from the documentation
param = osim.MocoParameter('soleus_r_fiber_length', '/forceset/soleus_r', 'optimal_fiber_length', osim.MocoBounds(0.04, 0.06))
problem.addParameter(param)
# Some additional setup, then study.solve()
For reference, I am using the Subject 14, no load, free speed, trial 2 data from this dataset: https://simtk.org/projects/assistloadwalk#. The parameter ranges were set to their extrema in the input kinematics +/- 5% of the range in the input data to allow some variance within the simulation.
Adjustments I made to the model:
1. In an attempt to get better foot-ground contact measurements from Moco, I unlocked the mtp and subtalar joints, repositioned toe-based markers to have the corresponding toe body as their parent, and reran IK with the new model.
2. I added contact spheres and forces according to the configuration provided here: https://simtk.org/projects/umocod. I scaled the positions of the spheres based on the corresponding scale factor of the parent body. I scaled the radii of the contact spheres based on the cube root of the product of the parent body's scale factors.
3. I used the ModOpReplaceMusclesWithDeGrooteFregly2016() model operator method to prepare the model for use with Moco.
I've attached the Moco setup file (comments removed to reduce size enough to attach) to provide additional information on the problem I am attempting to run.