Page 1 of 1

Matlab error in finding parent body using Opensim 4.2 API

Posted: Tue Jul 06, 2021 1:35 am
by sinatabeiy
Dear all,

I've been practicing to find parent body in OpenSim 4.2 since 'getParent()' command was unfortunately deleted in API 4.0+.
So, I used the code below to find the parent body of 'tibia_r' and get its name:

-----------------------------------------------------
import org.opensim.modeling.*;
clear all; clc;
osimModel = Model('gait2354_simbody.osim');
bodyName = 'tibia_r';
modelJointSet = osimModel.getJointSet();
N_j = modelJointSet.getSize();


for n_j = 0:N_j-1

jointParentName = char(modelJointSet.get(n_j).getParentFrame().findBaseFrame().getName());
end


if strcmp(jointParentName, bodyName)

distalJointSetNames(n_d) = {char(modelJointSet.get(n_j).getName())};
n_d = n_d + 1;
end
-----------------------------------------------------


But unfortunately it showed up the error below:

-----------------------------------------------------
Java exception occurred:
java.lang.RuntimeException: Socket parent_frame of type PhysicalFrame in /jointset/ground_pelvis of type CustomJoint is not
connected.
Thrown at Component.h:3300 in getConnectee().

at org.opensim.modeling.opensimSimulationJNI.Joint_getParentFrame(Native Method)

at org.opensim.modeling.Joint.getParentFrame(Joint.java:161)
-----------------------------------------------------

I tried to use the command "connectSocket_parent_frame()" in my code as I found on Doxygen; but unfortunately, the following error showed up:

No method 'connectSocket_parent_frame' with matching signature found for class 'org.opensim.modeling.Joint'.

-----------------------------------------------------
Now, what can I do to get the parent body name in my case?
Any advice you could give would be much appreciated.
Thanks in advance.

Regards

Re: Matlab error in finding parent body using Opensim 4.2 API

Posted: Tue Jul 06, 2021 9:13 am
by aymanh
Hello,

Generally speaking you can't inspect the model structure to find connections etc. until you call initSystem on the model.

Hope this helps,
-Ayman

Re: Matlab error in finding parent body using Opensim 4.2 API

Posted: Tue Jul 06, 2021 11:35 am
by sinatabeiy
Hello Ayman,

Thank you for your speedy and precise answer. It worked properly!