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();