exampleSquatToStand- MocoPeriodicityGoal

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
Mouaad BOUFADNA
Posts: 22
Joined: Mon Mar 16, 2020 3:24 am

exampleSquatToStand- MocoPeriodicityGoal

Post by Mouaad BOUFADNA » Thu Jun 04, 2020 3:35 am

I everyone

I'm trying to reproduce the SquatToStand example with a load.

In the example, the osim model used consider only the right leg.

I'd like to use a model with both legs (ex : gait2353 or gait2392 simbody).

I'm trying to integrate the the symmetry like this (from the example2Dwalking) :

Code: Select all

% % Symmetry 
symmetryGoal = MocoPeriodicityGoal('symmetryGoal');
problem.addGoal(symmetryGoal);
model = modelProcessor.process();
model.initSystem();

% Symmetric coordinate values (except for pelvis_tx) and speeds
for i = 1:model.getNumStateVariables()
    currentStateName = string(model.getStateVariableNames().getitem(i-1));
    if startsWith(currentStateName , '/jointset')
        if contains(currentStateName,'_r')
            pair = MocoPeriodicityGoalPair(currentStateName, ...
                           regexprep(currentStateName,'_r','_l') );
            symmetryGoal.addStatePair(pair);
        end
        if contains(currentStateName,'_l')
            pair = MocoPeriodicityGoalPair(currentStateName, ...
                           regexprep(currentStateName,'_l','_r'));
            symmetryGoal.addStatePair(pair);
        end
        if (~contains(currentStateName,'_r') && ...
            ~contains(currentStateName,'_l') && ...
            ~contains(currentStateName,'pelvis_tx/value')  && ...
            ~contains(currentStateName,'/activation'))
            symmetryGoal.addStatePair(MocoPeriodicityGoalPair(currentStateName));
        end
    end
end

% Symmetric muscle activations
for i = 1:model.getNumStateVariables()
    currentStateName = string(model.getStateVariableNames().getitem(i-1));
    if endsWith(currentStateName,'/activation')
        if contains(currentStateName,'_r')
            pair = MocoPeriodicityGoalPair(currentStateName, ...
                           regexprep(currentStateName,'_r','_l'));
            symmetryGoal.addStatePair(pair);
        end
        if contains(currentStateName,'_l')
            pair = MocoPeriodicityGoalPair(currentStateName, ...
                           regexprep(currentStateName,'_l','_r'));
            symmetryGoal.addStatePair(pair);
        end
    end
end

% Symmetric coordinate actuator controls
symmetryGoal.addControlPair(MocoPeriodicityGoalPair('/lumbarAct'));
In my position bounds, I inserted those :

Code: Select all

% Position bounds: the model should start in a squat and finish 
% standing up.
problem.setStateInfo('/jointset/ground_pelvis/pelvis_tilt/value', [-20*pi/180, -10*pi/180]);
problem.setStateInfo('/jointset/ground_pelvis/pelvis_tx/value', [0, 1]);
problem.setStateInfo('/jointset/ground_pelvis/pelvis_ty/value', [0.75, 1.25]);

problem.setStateInfo('/jointset/hip_r/hip_flexion_r/value', ...
    [-2, 0.5], -2, 0);
problem.setStateInfo('/jointset/hip_l/hip_flexion_l/value', ...
    [-2, 0.5], -2, 0);

problem.setStateInfo('/jointset/knee_r/knee_angle_r/value', ...
    [-2, 0], -2, 0);

problem.setStateInfo('/jointset/knee_l/knee_angle_l/value', ...
    [-2, 0], -2, 0);
problem.setStateInfo('/jointset/ankle_r/ankle_angle_r/value', ...
    [-0.5, 0.7], -0.5, 0);

problem.setStateInfo('/jointset/ankle_l/ankle_angle_l/value', ...
    [-0.5, 0.7], -0.5, 0);
Then I got this error message :

Code: Select all

Error using exampleRugbyLift (line 122)
Java exception occurred:
java.lang.RuntimeException: Could not find state '/jointset/ground_pelvis/pelvis_rist/value'.
	Thrown at MocoPeriodicityGoal.cpp:71 in initializeOnModelImpl().

	at org.opensim.modeling.opensimMocoJNI.MocoStudy_initCasADiSolver(Native Method)

	at org.opensim.modeling.MocoStudy.initCasADiSolver(MocoStudy.java:113)
Is my MocoPeriodicityGoing wrong ?

How should I correct it/or proceed to symmetry in the Squat to Stand case ?

Thank you

User avatar
Aaron Fox
Posts: 271
Joined: Sun Aug 06, 2017 10:54 pm

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Aaron Fox » Thu Jun 04, 2020 3:53 am

Hi Mouaad,

I've come across this annoying little thing to miss in some gait simulations. You'll notice the state that it says can't be found includes 'pelvis_rist' which I'm assuming should be 'pelvis_list'. What I suspect is happening is your use of regex is replacing the '_l' in this with '_r' causing the mismatched state names (I had the same thing with 'hip_rotation' becoming 'hip_lotation'!). I got around this by including the trailing slash in the regex expression (i.e. '_r/' to '_l/'). This generally works as the right and left notation for the lower limb joint coordinates is at the end of the state name.

One thing you should also consider is using an if statement to avoid including the pelvis coordinates in these left to right / right to left periodicity goals, as they aren't applicable from a side to side perspective. I believe the 2D gait example code that comes with Moco will have some code that demonstrates how to exclude relevant pelvis coordinates from periodicity goals like this.

Aaron

User avatar
Mouaad BOUFADNA
Posts: 22
Joined: Mon Mar 16, 2020 3:24 am

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Mouaad BOUFADNA » Thu Jun 04, 2020 4:37 am

Hi Aaron

Thank you for your help !

I fixed this error. The symmetry seems to work, but now I have another problem.

I have this message error :

Code: Select all

Error using exampleRugbyLift (line 153)
Java exception occurred:
java.lang.RuntimeException: No info available for state '/forceset/glut_med1_r/fiber_length'.
	Thrown at MocoProblemRep.cpp:629 in getStateInfo().

	at org.opensim.modeling.opensimMocoJNI.MocoStudy_solve(Native Method)

	at org.opensim.modeling.MocoStudy.solve(MocoStudy.java:125)
Should I add a control pair like this :

Code: Select all

periodicityGoal.addControlPair(MocoPeriodicityGoalPair('/forceset/.../'));

?

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

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Karthick Ganesan » Thu Jun 04, 2020 7:28 am

Hi Mouaad,
Did you replace the muscles in your model with DegrooteFregley2016Muscle? As I understand Moco only supports this. In its formulation normalized tendon force is the state variable not the fiber length.
Best,
Karthick.

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

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Nicholas Bianco » Thu Jun 04, 2020 9:59 am

Hi Mouaad,

In example2DWalking, we use the MocoPeriodicityGoal to create symmetry across time, meaning that we only need to simulate a half gait cycle, and then create a full gait cycle by "repeating" that half gait cycle (it's a little more complicated than that, but that's the basic idea). This notion of symmetry is different from what I think you're trying to achieve: to have the left and right legs produce the same motion at the same time. In this case, MocoPeriodicityGoal might not be as helpful to you. You might prefer constraints that couple the leg coordinates together.

I'm curious to know if you really need to add the second leg for your project. If you treat the model as a planar model, you could double the muscle strengths to approximate having both legs. Adding a second leg to exampleSquatToStand is a non-trivial problem, since you cannot simply use weld joints to glue both feet to the ground (it creates a kinematic loop, which is disallowed by Simbody). At some point you'd need a kinematic constraint, either at the feet or the somewhere farther up the body (i.e., the hip), but these can be tricky to get to work well.

-Nick

User avatar
Mouaad BOUFADNA
Posts: 22
Joined: Mon Mar 16, 2020 3:24 am

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Mouaad BOUFADNA » Fri Jun 05, 2020 7:41 am

Hi Nicholas

Ok I see ! I thought this goal allowed to replicate symmetricaly the calculation from right to left leg. Indeed, this is different from the goal objective.

For my project, I have another movement configuration with offset feet, one leg behind the other. I guess muscle activation or fiber length won't be the same for each leg.
So what I was thinking if it is complex to simulate with a two legs-model is to use the one leg- one and place firstly the leg in backward position and proceed to the problem resolving, and secondly in backward position. Like this, I could have the info on right and left legs by considering a "perfect symmetry".

For the first part of my project (the movement with both legs parallel), I can start by resolving the problem with one leg and consider the same results for the second, if I suppose that both legs are identical and have the same physical & physiological properties.
In a second time, I can double the muscle strengths as you suggest and resolve the problem; and then ssee what's best version.

Thank you for your help !

Mouaad

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Christopher Dembia » Fri Jun 05, 2020 9:18 am

In this case, you may want to model foot-ground contact using a compliant contact model, as done in example2DWalking.

I'm not sure you can decompose the problem as you suggest.

User avatar
Mouaad BOUFADNA
Posts: 22
Joined: Mon Mar 16, 2020 3:24 am

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Mouaad BOUFADNA » Mon Jun 08, 2020 1:37 am

Hi Christopher

This is what my Project supervisor suggested me.

In this case, all the part about symmetry is not useful for my objective ? Can I remove it ?
And focus for exemple on the FinalTimeGoal ?

The objective of my movement is to lift the quickiest possible to reach as fast as possible the peak height (here I am not considering the upper limb implication, just the lower).
It seems to be the best goal for me.

Thank you for your help

Mouaad

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

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Nicholas Bianco » Thu Jun 11, 2020 10:31 am

Mouaad --

It's still not totally clear what you are trying to accomplish, but I think that is probably fine to remove the symmetry constraints for your squat-to-stand problem. These symmetry constraints are useful for speeding up optimizations that are large but have exploitable symmetry (e.g., healthy walking). The squat-to-stand problem solves fairly quickly without symmetry constraints.

And yes, if your goal is to simulate the quickest possible lifting task, then you should use a MocoFinalTimeGoal.

-Nick

User avatar
Mouaad BOUFADNA
Posts: 22
Joined: Mon Mar 16, 2020 3:24 am

Re: exampleSquatToStand- MocoPeriodicityGoal

Post by Mouaad BOUFADNA » Sun Jun 14, 2020 9:27 am

Hi Nicholas

Indeed, I deleted all the symmetry code and it works very well with using the example2DWalking.
I still need to proceed to 2 different simulations to simulate the whole movement (one for fleixon, one for extension) with transposed initial/final positions.

But now my main problem is to create the table with GRF.

Now I have modified the code, it doesn't work to create the .sto file with the GRF values of my movement.

I have this error message :

Code: Select all

No method 'createExternalLoadsTableForGait' with matching signature found for class 'org.opensim.modeling.opensimMoco'.

Error in example2DWalking (line 155)
externalForcesTableFlat = opensimMoco.createExternalLoadsTableForGait(model, contact_r, contact_l);
This is how I wrote the code to create this file :

Code: Select all

externalForcesTableFlat = opensimMoco.createExternalLoadsTableForGait(model, contact_r, contact_l);
opensimMoco.writeTableToFile(externalForcesTableFlat, ...
                            'LiftPrediction_solution2GRF.sto');
I tried to write 'createExternalLoadsTableforLift' to have a match wih my solution but it failed

POST REPLY