Matlab error in finding parent body using Opensim 4.2 API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Sina Tabeiy
Posts: 8
Joined: Thu Sep 05, 2019 4:15 am

Matlab error in finding parent body using Opensim 4.2 API

Post by Sina Tabeiy » Tue Jul 06, 2021 1:35 am

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

Tags:

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

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

Post by Ayman Habib » Tue Jul 06, 2021 9:13 am

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

User avatar
Sina Tabeiy
Posts: 8
Joined: Thu Sep 05, 2019 4:15 am

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

Post by Sina Tabeiy » Tue Jul 06, 2021 11:35 am

Hello Ayman,

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

POST REPLY