Moco Track with Contact modeling

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
Azarang Asadi
Posts: 14
Joined: Wed Nov 06, 2019 8:36 am

Moco Track with Contact modeling

Post by Azarang Asadi » Wed Nov 22, 2023 2:02 pm

I have recently tried to use spheres for foot ground contact modeling. I have all my mocap data including GRF. What I'm trying to do is to compare my contact results to experimental GRF to make sure my contact model is working so that I can do the ret of my research. I have 6 spheres per foot. In addition to GRF comparison, I want to compare ankle torques as well so I can assure my simulation is close enough to the true torques. For the true torques I used inverse dynamics in OpenSim. To compare torques, I used :

Code: Select all

outputPaths = StdVectorString();
outputPaths.add('.*')
outs= opensimMoco.analyzeMocoTrajectory(osimModel,solution,outputPaths);	
and the output had labels like /forceset/reserve_jointset_hip_r_hip_rotation_r|actuation which I though should be the same as the moments from inverse dynamics. But upon comparison, they are not even similar. So I think this is not same as the torques?

Now to compare GRFs I used:

Code: Select all

contact_r = StdVectorString();
contact_r.add('HCF1_r');
contact_r.add('HCF2_r');
contact_r.add('HCF3_r');
contact_r.add('HCF4_r');
contact_r.add('HCF5_r');
contact_r.add('HCF6_r');

contact_l = StdVectorString();
contact_l.add('HCF1_l');
contact_l.add('HCF2_l');
contact_l.add('HCF3_l');
contact_l.add('HCF4_l');
contact_l.add('HCF5_l');
contact_l.add('HCF6_l');

externalForcesTableFlat = opensimMoco.createExternalLoadsTableForGait(osimModel,solution,contact_r,contact_l);
STOFileAdapter.write(externalForcesTableFlat,'GRF.sto');

Now this one gave me all 0 s for center of pressure. Why? what am I doing wrong? Any inputs?

I have attached all the files. model, GRF table from createExternalLoadsTableForGait, solution which is generated using MocoTrack with state tracking goal.
Attachments
Solution&GRF.zip
MocoSolution and GRF from createExternalLoadsTableForGait
(133.32 KiB) Downloaded 19 times
model_TDupdated.osim
Model file
(172.11 KiB) Downloaded 23 times

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

Re: Moco Track with Contact modeling

Post by Nicholas Bianco » Thu Nov 23, 2023 10:51 am

Hi Azarang,

If you download the OpenSim 4.4.1 API release, "createExternalLoadsTableForGait" will include the correct center of pressure calculations to let you do a direct comparison between your Moco results and inverse dynamics.

Best,
Nick

User avatar
Azarang Asadi
Posts: 14
Joined: Wed Nov 06, 2019 8:36 am

Re: Moco Track with Contact modeling

Post by Azarang Asadi » Thu Nov 23, 2023 3:25 pm

Hey Nick,

Thanks for your reply. I did use that and still my COP is 0. I have attached the GRF file. Also how can I get individual forces of each contact element? What I noticed is that when SmoothSphereHalfSpaceForce is used for force, it does not show in GUI under contact forces while Hunt-Crossley shows up in GUI.
Attachments
GRF.zip
(24.35 KiB) Downloaded 20 times

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

Re: Moco Track with Contact modeling

Post by Nicholas Bianco » Mon Nov 27, 2023 10:35 am

Hi Azarang,

I'll need a little more information to help you troubleshoot here. Could you describe your simulation in more detail? Are you tracking foot-ground contact forces in your simulation? Have you plotted the simulated forces against the experimental forces? If the tracking is good then createExternalLoadsTableForGait (with OpenSim 4.4.1) should give you reasonable results.
What I noticed is that when SmoothSphereHalfSpaceForce is used for force, it does not show in GUI under contact forces while Hunt-Crossley shows up in GUI.
Do the SmoothSphereHalfSpaceForce elements at least show up in the Forces dropdown in the left panel?

Best,
Nick

User avatar
Azarang Asadi
Posts: 14
Joined: Wed Nov 06, 2019 8:36 am

Re: Moco Track with Contact modeling

Post by Azarang Asadi » Mon Nov 27, 2023 11:32 am

Hi Nick,

I'm just doing a simple track with contact modeling to make sure that my simulation is close enough to the experimental data and then I'm planning to make some changes to my controls using the control tracking goal to create new motions. Here's the simple code I used to get a simulation of my experimental data and make sure that the mocotrack is yielding the results close to the experiment.

Code: Select all

import org.opensim.modeling.*;
track = MocoTrack();
track.setName("TDTest");

modelProcessor = ModelProcessor("s98_pre_scaled_41_contacts&treadmill.osim");
modelProcessor.append(ModOpRemoveMuscles());
modelProcessor.append(ModOpAddReserves(250));
track.setModel(modelProcessor);

track.setStatesReference(TableProcessor("s98_pre_1_coordinates_41_updated.mot"));
track.set_allow_unused_references(true);
track.set_states_global_tracking_weight(100);
track.set_track_reference_position_derivatives(true);

stateWeights = MocoWeightSet();
stateWeights.cloneAndAppend(MocoWeight('/jointset/ground_pelvis/pelvis_ty/value',1));
track.set_states_weight_set(stateWeights);


track.set_initial_time(1.55);
track.set_final_time(3.35);
track.set_mesh_interval(0.05);

study = track.initialize();
solver = study.initCasADiSolver();
solver.set_optim_convergence_tolerance(1e-3);
solver.set_optim_constraint_tolerance(1e-3);
solver.set_optim_max_iterations(6000);
solution = study.solve();
study.visualize(solution);
solution.write('solution.sto')

then when I have the solution, I use the following code to get the GRF table:


Code: Select all

sol = MocoTrajectory('solution.sto');
model = modelProcessor.process();

contact_r = StdVectorString();
contact_r.add('HCF1_r');
contact_r.add('HCF2_r');
contact_r.add('HCF3_r');
contact_r.add('HCF4_r');
contact_r.add('HCF5_r');
contact_r.add('HCF6_r');

contact_l = StdVectorString();
contact_l.add('HCF1_l');
contact_l.add('HCF2_l');
contact_l.add('HCF3_l');
contact_l.add('HCF4_l');
contact_l.add('HCF5_l');
contact_l.add('HCF6_l');

externalForcesTableFlat = opensimMoco.createExternalLoadsTableForGait(model,sol,contact_r,contact_l);
opensimMoco.writeTableToFile(externalForcesTableFlat,'GRF.sto');
I have attached the plots for the GRFs. Also to answer that question
Do the SmoothSphereHalfSpaceForce elements at least show up in the Forces dropdown in the left panel?
They show up in other forces but not the contact forces. Same as the 2D gait tracking model in moco resources.

Thank you,
Azarang
Attachments
files.zip
(306.08 KiB) Downloaded 23 times

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

Re: Moco Track with Contact modeling

Post by Nicholas Bianco » Tue Nov 28, 2023 11:09 am

Hi Azarang,

The problem you've configured with MocoTrack does not contain a MocoContactTrackingGoal, so I wouldn't be surprised if the contact forces didn't look correct. Note that MocoContactTrackingGoal will only track the force componets of the GRFs not the torques.

I'm not sure what to say about the COPs. If you've set up OpenSim 4.4.1 correctly, it should compute COPs based on your foot-ground contact forces.
They show up in other forces but not the contact forces. Same as the 2D gait tracking model in moco resources.
That should be fine then. The GUI might group force elements based on whether or not they are in the Model's ForceSet, but that is just for visualization in the Navigator.

User avatar
Azarang Asadi
Posts: 14
Joined: Wed Nov 06, 2019 8:36 am

Re: Moco Track with Contact modeling

Post by Azarang Asadi » Thu Dec 14, 2023 12:18 pm

Hi Nick,

Doesn't moco track automatically add effort goal to any problem? with the above code my GRF look kinda similiar to the experimental data. I thought I can track the coordinates with

Code: Select all

track.setStatesReference(TableProcessor("s98_pre_1_coordinates_41_updated.mot"));
track.set_allow_unused_references(true);
track.set_states_global_tracking_weight(100);
while the the effort is getting minimized. So basically like moco Inverse but without GRF. Cause when I do moco inverse with my contact model and no GRF, I get GRFs that are way off from the experimental data.

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

Re: Moco Track with Contact modeling

Post by Nicholas Bianco » Fri Dec 15, 2023 10:34 am

Hi Azarang,

Yes, MocoTrack adds a MocoControlGoal to the problem automatically, and you can add state tracking via the snippet you've provided. But currently, contact force tracking needs to be added manually via the MocoStudy.
Cause when I do moco inverse with my contact model and no GRF, I get GRFs that are way off from the experimental data.
Foot-ground contact models depend on the model's configuration between the feet and the ground. If the kinematics you provide to MocoInverse has the feet penetrating too far into the ground, then the foot-ground contact model will produce large, unrealistic contact forces.

If you want to use foot-ground contact, you will need to adjust your model kinematics until the foot-ground interactions produces realistic forces (using a custom MocoStudy, or some other calibration approach). Going directly to MocoInverse likely will not work.

Best,
Nick

User avatar
Azarang Asadi
Posts: 14
Joined: Wed Nov 06, 2019 8:36 am

Re: Moco Track with Contact modeling

Post by Azarang Asadi » Mon Dec 18, 2023 10:36 am

Thank you so much Nick. This really helped ,cause I've been getting good results with Moco Track but not inverse when I have contact model. Thanks again.

POST REPLY