HuntCrossleyForce Implementation in Moco

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
Dhruv Gupta
Posts: 30
Joined: Sat Aug 29, 2015 11:23 am

HuntCrossleyForce Implementation in Moco

Post by Dhruv Gupta » Mon Mar 16, 2020 2:33 pm

Hello Moco admin,

First of all, Thanks for creating Moco. It makes direct collocation so much more user friendly.

I am trying to use the Hunt Crossley Force. Based on the reading some literature (Serrancoli et al 2019 [Subject-Exoskeleton Contact Model Calibration Leads to Accurate Interaction Force Predictions] Appendix 1), my understanding is that we need the smoothed model of the HuntCrossleyForce. I think the force class SmoothSphereHalfSpaceForce implements this smoothed model (https://opensim-org.github.io/opensim-moco-site/docs/). Please correct me if I am wrong, I am still learning Moco.

I was trying to implement this force class SmoothSphereHalfSpaceForce in Moco (using MATLAB) and I am having the hardest time setting the socket for the half sphere and the sphere. The function that I believe I need is setPropertyIndex_socket_half_sphere_frame and setPropertyIndex_socket_sphere_frame, respectively. The methodsview tells me that the argument required for these functions is of type org.opensim.modeling.SWIGTYPE_p_PropertyIndex. I am having the hardest time finding the org.opensim.modeling.SWIGTYPE_p_PropertyIndex for the sockets like '/ground', '/bodyset/calcn_r', '/bodyset/toes_r', etc.
Can you help me with these? Or if you could add a new function where we can simply specify the sockets as a strings? I noticed that other force classes like PointActuators, CoordinateActuators have the function set_body that works really well.

I appreciate your help!

Dhruv

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

Re: HuntCrossleyForce Implementation in Moco

Post by Aaron Fox » Mon Mar 16, 2020 8:00 pm

Hi Dhruv,

I had some trouble getting my head around this but managed to get this to work using one of the classes convenience constructors. Here's an example I have of attaching a sphere to the right heel that connects to the ground (similar location to one in the example2D walking code. Note the need to get the socket frame as a body frame from the model, as well as the need to get the ground as a frame too.

Code: Select all

contactHeel_r = SmoothSphereHalfSpaceForce('contactSphereHeel_r',...    %object name
        Frame.safeDownCast(contactModel.getBodySet().get('calcn_r')),...     %sphere socket frame
        heelPos_r,...     %sphere location in body frame in Vec3 format I think
        0.032,...       %radius
        Frame.safeDownCast(contactModel.getGround()),...     %socket half space frame
        Vec3(0,0,0),...     %socket half space location
        Vec3(0,0,-1.5707963267948966));     %half space orientation   
The rest of the parameters I was able to set using the relevant 'set_*' functions, and then added this object as a component:

Code: Select all

contactModel.addComponent(Component.safeDownCast(contactHeel_r));	%contactModel is the model object
Hope that helps,

Aaron

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

Re: HuntCrossleyForce Implementation in Moco

Post by Christopher Dembia » Tue Mar 17, 2020 5:51 pm

Thanks Dhruv, for your question, and Aaron, for your great answer.

I'm surprised the downcasts are necessary. If you find that they are not necessary, please report your finding :)

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

Re: HuntCrossleyForce Implementation in Moco

Post by Aaron Fox » Wed Mar 18, 2020 3:02 am

With regard to the downcasts I think this is probably one of those situations where the code worked, perhaps not in the most efficient manner, but it worked so I left it :D

User avatar
Dhruv Gupta
Posts: 30
Joined: Sat Aug 29, 2015 11:23 am

Re: HuntCrossleyForce Implementation in Moco

Post by Dhruv Gupta » Wed Mar 18, 2020 1:01 pm

Thanks for the answer Aaron. It seems to work. Cheers! :D

Chris, Thanks for response as well. I will post if I find that one works better than the other. :)

User avatar
Dhruv Gupta
Posts: 30
Joined: Sat Aug 29, 2015 11:23 am

Re: HuntCrossleyForce Implementation in Moco

Post by Dhruv Gupta » Mon Mar 30, 2020 8:54 am

Something that I did observe was that if I add the hunt crossley force in a function and call that function again and again, MATLAB tends to crash after a few calls if the safeDownCasts are there. If I remove the safeDownCasts, it works fine. I do not know what causes that, it could be just my computer, but I am reporting it here just in case someone else faces a similar problem.

POST REPLY