Smooth Sphere Half Space Force Parameters

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
User avatar
Rory Turnbull
Posts: 28
Joined: Mon Dec 16, 2019 1:57 am

Smooth Sphere Half Space Force Parameters

Post by Rory Turnbull » Sun Jun 06, 2021 3:34 am

Hi All,

I have recently started using MOCO having worked with OpenSim for a while. It is fairly well documented within this Forum and in a few papers, that the HuntCrossleyForce model needs to be changed to a SmoothSphereHalfSpaceForce.

Having looked at the .cpp definitions for both (https://simbody.github.io/3.7.0/classSi ... Force.html) it indicates that that the parameters are applied using the same method in Matlab.

Code: Select all

softTissueForce = SmoothSphereHalfSpaceForce();
% softTissueForce = HuntCrossleyForce();
softTissueForce.setName('SoftTissueInteraction');
stiffness = 10e3;
dissipation =1; 
friction = [0 0 0]; % default
transitionVelocity = 0.01; % default transition velocity
cf = 1e-5; % ConstantContactForce
bd = 300; % HertzSmoothing
bv = 50; % HuntCrossleySmoothing


softTissueForce.setStiffness(stiffness);
softTissueForce.setDissipation(dissipation);
softTissueForce.setStaticFriction(friction(1));
softTissueForce.setDynamicFriction(friction(2));
softTissueForce.setViscousFriction(friction(3));
softTissueForce.setTransitionVelocity(transitionVelocity);
When the HuntCrossleyForce is used this code works fine, but when the SmoothSphereHalfSpaceForce is used I get the following error.

Check for missing argument or incorrect argument data type in call to function 'setStiffness'.
Error in Model (line 1198)
softTissueForce.setStiffness(stiffness);


I have also tried combining them into one line using setParameters() but that didn't work either at it didn't recognise setParameters at all. The error suggests that it is the data type that is the issue but both functions call for the same data type and it doesn't change. I am sure there is a simple answer to this that I have missed but any help would be appreciated!

Best wishes,
Rory Turnbull

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

Re: Smooth Sphere Half Space Force Parameters

Post by Nicholas Bianco » Sun Jun 06, 2021 11:31 am

Hi Rory,

You'll need to set the SmoothSphereHalfSpaceForce parameters using the property methods directly:

Code: Select all

softTissueForce.set_stiffness(stiffness);
softTissueForce.set_dissipation(dissipation);
softTissueForce.set_static_friction(friction(1));
softTissueForce.set_dynamic_friction(friction(2));
softTissueForce.set_viscous_friction(friction(3));
softTissueForce.set_transition_velocity(transitionVelocity);
Currently, there are no convenience get/set functions for the properties (e.g., setStiffness()), which we sometimes use to wrap the property methods.

Best,
Nick

User avatar
Rory Turnbull
Posts: 28
Joined: Mon Dec 16, 2019 1:57 am

Re: Smooth Sphere Half Space Force Parameters

Post by Rory Turnbull » Mon Jun 07, 2021 5:53 am

Hi Nick,

Great! I had tried a couple of variations but not that one!

Thank you very much for your help,
Rory

User avatar
Pasha van Bijlert
Posts: 214
Joined: Sun May 10, 2020 3:15 am

Re: Smooth Sphere Half Space Force Parameters

Post by Pasha van Bijlert » Sat Jun 26, 2021 10:21 am

Hi all,

Below is some Matlab code to add the SSHSForce (and contact geometry) to a model, should someone be looking to add this to their custom-built models (I adapted it from code for the HuntCrossley force I found on the forums somewhere).

I added the force to the componentset, I seem to remember that in an earlier version of Moco this was a requirement for one of the post-processing scripts to work (I think that might be the GRF vector script that comes with the 2D walking example?).

Nick, I was hoping you could clear a few things up for me.

1)
I didn't specify the smoothing parameters, but if I use force.get_hertz_smoothing I get the default values in the Matlab API. These don't show up in the model .xml file. Should these be specified manually, or does Moco revert to default settings if you leave them unspecified?

2) "derivative smoothing" seems to have been renamed to "constant_contact_force" in the newest version of Moco. I didn't realize this at first, and I just copied an older formulation into a newer model (manually via the .osim file). The model ran without errors. Is this because "derivative_smoothing" just gets ignored, and moco fills in a default value for "constant_contact_force"?

3) I scaled up the stiffness of the force because the mass of my model is several orders of magnitude higher than a human (8000kg, it's a T. rex model). I believe the other parameters (basically all damping parameters) are mainly to aid convergence, so I'd left them at the default value. Would there be a good reason to scale these up as well?

Thanks,

Pasha

Code: Select all


%% Add contacts
ground=model.getGround();
%% Make a Contact Half Space
groundContactLocation = Vec3(0,0.0,0);
groundContactOrientation = Vec3(0,0,-1.57);
groundContactSpace = ContactHalfSpace(groundContactLocation, groundContactOrientation, ground);
groundContactSpace.setName('GroundContact');
model.addContactGeometry(groundContactSpace);

%% Make a Right Foot Contact
foot_r=model.getBodySet.get('foot_r'); %or whatever body you want

RightFootContactSphere = ContactSphere();
RightFootContactSphere.setRadius(r_contactsphere);
RightFootContactSphere.setLocation( Vec3(-0.9,-3.05,0.5) );
RightFootContactSphere.setFrame(foot_r)
RightFootContactSphere.setName('RFootContact');
model.addContactGeometry(RightFootContactSphere);

%% Define Contact Force Parameters
stiffness           = 50000000; %CAREFUL, I SCALED THIS UP BECAUSE MY MODEL IS 8000KG
dissipation         = 2.0;
staticFriction      = 0.8;
dynamicFriction     = 0.4;
viscousFriction     = 0.4;
transitionVelocity  = 0.2;

ConstantContactForce = 1e-5; % ConstantContactForce
HertzSmoothing = 300; % HertzSmoothing
HuntCrossleySmoothing = 50; % HuntCrossleySmoothing

%%  right foot
SSHSForceRightFoot = SmoothSphereHalfSpaceForce();

SSHSForceRightFoot.setName('RFootForce');
SSHSForceRightFoot.connectSocket_sphere(RightFootContactSphere);
SSHSForceRightFoot.connectSocket_half_space(groundContactSpace);

SSHSForceRightFoot.set_stiffness(stiffness);
SSHSForceRightFoot.set_dissipation(dissipation);
SSHSForceRightFoot.set_static_friction(staticFriction);
SSHSForceRightFoot.set_dynamic_friction(dynamicFriction);
SSHSForceRightFoot.set_viscous_friction(viscousFriction);
SSHSForceRightFoot.set_transition_velocity(transitionVelocity);


model.get_ComponentSet.addComponent(SSHSForceRightFoot);

model.finalizeConnections();


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

Re: Smooth Sphere Half Space Force Parameters

Post by Nicholas Bianco » Mon Jun 28, 2021 9:03 pm

I didn't specify the smoothing parameters, but if I use force.get_hertz_smoothing I get the default values in the Matlab API. These don't show up in the model .xml file. Should these be specified manually, or does Moco revert to default settings if you leave them unspecified?
Yes, Moco uses defaults for anything not specified in the XML.
"derivative smoothing" seems to have been renamed to "constant_contact_force" in the newest version of Moco. I didn't realize this at first, and I just copied an older formulation into a newer model (manually via the .osim file). The model ran without errors. Is this because "derivative_smoothing" just gets ignored, and moco fills in a default value for "constant_contact_force"?
Yes, "derivative_smoothing" was renamed to "constant_contact_force", but the parameters are the same. A constant contact force is applied to the model so that the contact spheres are never technically out of contact with the half-space. This prevents any discontinuities associated with a sphere coming in contact with a half-space, meaning that the model is differentiable. This is why it was originally called "derivative_smoothing".
I scaled up the stiffness of the force because the mass of my model is several orders of magnitude higher than a human (8000kg, it's a T. rex model). I believe the other parameters (basically all damping parameters) are mainly to aid convergence, so I'd left them at the default value. Would there be a good reason to scale these up as well?
I'd say you probably don't need to adjust the other parameter much, if at all. But it's hard to say if you need adjustments without comparing to experimental data (although I hear that T. Rex force plate data is a little hard to come by :D).

-Nick

User avatar
Pasha van Bijlert
Posts: 214
Joined: Sun May 10, 2020 3:15 am

Re: Smooth Sphere Half Space Force Parameters

Post by Pasha van Bijlert » Tue Jun 29, 2021 2:10 am

Thanks for clearing that up!
A constant contact force is applied to the model so that the contact spheres are never technically out of contact with the half-space. This prevents any discontinuities associated with a sphere coming in contact with a half-space, meaning that the model is differentiable.
I think you have a webinar up on YouTube (with Chris Dembia) that shows a graph of the force? I A/B'ed the regular hunt-crossley force and this one a few months back and it was substantially faster.
(although I hear that T. Rex force plate data is a little hard to come by :D)
I'm honestly still holding out for the moment I get whisked away from an excavation by a billionaire philanthropist to check out his new theme park.

Thanks,

Pasha

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

Re: Smooth Sphere Half Space Force Parameters

Post by Nicholas Bianco » Tue Jun 29, 2021 9:40 am

I A/B'ed the regular hunt-crossley force and this one a few months back and it was substantially faster
You mean that the SmoothSphereHalfSpaceForce is faster, right? Just double checking.

User avatar
Pasha van Bijlert
Posts: 214
Joined: Sun May 10, 2020 3:15 am

Re: Smooth Sphere Half Space Force Parameters

Post by Pasha van Bijlert » Wed Jun 30, 2021 1:50 pm

Yes, SSHSForce was substantially faster (although I got pretty good convergence using a regular Hunt Crossley Force in a simple 2D 7 DOF 8 muscles model already, even using quasi-random initial guesses). The performance benefit is definitely worth it on more complicated models. Using SSHSF, a 14 DOF 2D model converged with a random initial guess after about 3 hours, after which I could use that solution for a whole gamut of speeds. I've got a conference coming up next week which needs some prep, but afterwards I might try my hand at 3D predictive simulations, and quadrupedal ones, to see how I fare (I'm not sure if anyone has attempted quadrupedal locomotion in MOCO before?)

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

Re: Smooth Sphere Half Space Force Parameters

Post by Nicholas Bianco » Wed Jun 30, 2021 3:00 pm

Great, thanks for clarifying! Cool that it works with the regular Hunt-Crossley force too.

I don't think anyone has tried quadrupedal motion with Moco yet.

User avatar
Jiacheng Weng
Posts: 26
Joined: Wed Jan 15, 2020 1:05 pm

Re: Smooth Sphere Half Space Force Parameters

Post by Jiacheng Weng » Thu Jul 08, 2021 7:41 pm

mn13rt wrote:
Sun Jun 06, 2021 3:34 am
When the HuntCrossleyForce is used this code works fine, but when the SmoothSphereHalfSpaceForce is used I get the following error.
HI Rory,

if you are using MATLAB, you can always use methodsview(variable) to check the available methods. This helps you to look up any functionality that you need. The method names are very self explanatory. In Python, just use dir(variable).

Cheers,
Jiacheng

POST REPLY