Page 1 of 1

Getting CoM of body and Ground Reaction force in matlab

Posted: Sat Feb 11, 2017 10:58 pm
by haolee
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?

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

Posted: Sun Feb 12, 2017 3:28 am
by tkuchida
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.

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

Posted: Thu Feb 16, 2017 10:08 pm
by haolee
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?

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

Posted: Fri Feb 17, 2017 1:15 am
by tkuchida
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)];

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

Posted: Thu Mar 09, 2017 10:44 pm
by haolee
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?

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

Posted: Fri Mar 10, 2017 3:16 am
by tkuchida
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