Getting CoM of body and Ground Reaction force in matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Hao Lee
Posts: 32
Joined: Sun Jun 12, 2016 11:52 pm

Getting CoM of body and Ground Reaction force in matlab

Post by Hao Lee » Sat Feb 11, 2017 10:58 pm

I am currently using matlab to develop the control to my model, however, I faced some difficulties.
I try to use

Code: Select all

pelvis =  osimModel.getBodySet().get('Pelvis');
com= pelvis.getMassCenter();
but it turned out that
No method 'getMassCenter' with matching signature found for class 'org.opensim.modeling.Body'.
but I checked the class list of opensim, Body class should have getMassCenter function, why it is not working in matlab?

Also, if I want to get the ground reaction force in my model.
I defined the contact force as LFootFroce

Code: Select all

lf_grf = osimModel.getForceSet().get('LFootForce');
force=lf_grf.getStateVariable();
but again the getStateVariable won't work.

Is there any user manual that teach user how to use OpenSim or SimTK API functions in matlab?

User avatar
Thomas Uchida
Posts: 1777
Joined: Wed May 16, 2012 11:40 am

Re: Getting CoM of body and Ground Reaction force in matlab

Post by Thomas Uchida » Sun Feb 12, 2017 3:28 am

Body class should have getMassCenter function, why it is not working in matlab?
The error indicates that there is no method with the matching signature. In OpenSim 3.3, the Body::getMassCenter() method requires an argument; see https://simtk.org/api_docs/opensim/api_ ... f4189949f8.
the getStateVariable won't work.
This appears to be the same issue; see https://simtk.org/api_docs/opensim/api_ ... bb2d11378f.
Is there any user manual that teach user how to use OpenSim or SimTK API functions in matlab?
There are some tips on the "Scripting with Matlab" page on Confluence (http://simtk-confluence.stanford.edu:80 ... ith+Matlab) and some example scripts in the OpenSim\Scripts\Matlab directory.

User avatar
Hao Lee
Posts: 32
Joined: Sun Jun 12, 2016 11:52 pm

Re: Getting CoM of body and Ground Reaction force in matlab

Post by Hao Lee » Thu Feb 16, 2017 10:08 pm

thanks, I believe my problem is solved
However, I wonder how can I turn the result I get, which is Vec3 into numbers?
Is there any function in openSim support that?

User avatar
Thomas Uchida
Posts: 1777
Joined: Wed May 16, 2012 11:40 am

Re: Getting CoM of body and Ground Reaction force in matlab

Post by Thomas Uchida » Fri Feb 17, 2017 1:15 am

The methodsview function in Matlab will tell you what methods are available for a specified OpenSim object (see the "Scripting with Matlab" page on Confluence: http://simtk-confluence.stanford.edu:80 ... ith+Matlab). In the case of a Vec3, I think the following will work:

Code: Select all

v_matlab = [myVec3.get(0), myVec3.get(1), myVec3.get(2)];

User avatar
Hao Lee
Posts: 32
Joined: Sun Jun 12, 2016 11:52 pm

Re: Getting CoM of body and Ground Reaction force in matlab

Post by Hao Lee » Thu Mar 09, 2017 10:44 pm

I successfully use the getMassCenter now, however, all the data I retrieve is [ 0 0 0]. I wonder does this function only retrieve the CoM in the end-frame (i.e., if I want the CoM in the hand, it will only return me the coordinate of CoM in hand's frame?) Is there any function that I can retrieve the CoM in the base frame?

User avatar
Thomas Uchida
Posts: 1777
Joined: Wed May 16, 2012 11:40 am

Re: Getting CoM of body and Ground Reaction force in matlab

Post by Thomas Uchida » Fri Mar 10, 2017 3:16 am

The SimbodyEngine::transformPosition() method calls SimTK::MobilizedBody::findStationLocationInAnotherBody(), which does the following: "Given a station S on this body B, return the location on another body A which is at the same location in space."

OpenSim::SimbodyEngine – https://simtk.org/api_docs/opensim/api_ ... ngine.html
SimTK::MobilizedBody – https://simtk.org/api_docs/simbody/3.5/ ... dBody.html

POST REPLY