Importing bodies from existing models in OpenSim3.3

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Rory Turnbull
Posts: 28
Joined: Mon Dec 16, 2019 1:57 am

Importing bodies from existing models in OpenSim3.3

Post by Rory Turnbull » Mon Jul 12, 2021 5:48 am

Hi All,

I am currently trying to convert a file backwards from 4.2 to 3.3 for use in SCONE.

I have taken a pre existing gait model and loaded it into MATLAB. In 4.2 I used the following command to load the bodies in as variables so that I could make additions to them.

Code: Select all

% BodyList = osimList2MatlabCell(model,'Body');  % Get a cell array of references to all the bodies in a model
I found in 3.3 that the version of this code is

Code: Select all

    BodyList{1} = model.getObjectByTypeAndName('Body','pelvis');  
This works, however, it saves the Body as an "OpenSimObject" rather than a "Body". Further on in the code when I am trying to create a WeldJoint:

Code: Select all

exoJoint{1} = WeldJoint();
exoJoint{1}.setName('Exo_Anchor_Pelvis');
exoJoint{1}.setParentBody(exoBody{1});
exoJoint{1}.setLocationInParent(locationInParent);
exoJoint{1}.setOrientationInParent(orientationInParent);
exoJoint{1}.setBody(BodyList{1});
% exoJoint{1}.setLocationInChild(locationInChild);
% exoJoint{1}.setOrientationInChild(orientationInChild);
It throws up the following error for the line of code that reads exoJoint{1}.setBody(BodyList{1});


Check for missing argument or incorrect argument data type in call to function 'setBody'.


Is this due to the fact the imported bodies have been saved as OpenSimObjects? and if so is there a way of importing them differently or converting the data type to a body?

Thank you for your help,

Rory Turnbull

Tags:

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

Re: Importing bodies from existing models in OpenSim3.3

Post by Ayman Habib » Mon Jul 12, 2021 10:01 am

Hi Rory,

In general it would be difficult to convert a file backward since the format was made more flexible and not all models can be converted back. As such what you're trying to do is unsupported. AFAIK, Scone has an incarnation that works with version 4.0 so you may want to contact the Scone project for info.

An example of the API change is that a Joint doesn't have a setBody method anymore, instead it has two frames. Frames were introduced in version 4.0 and don't exist in version 3.3.

With that said, if there's a specific functionality or API call that's not behaving as expected in version 4.2, please let us know about it so we can fix it if a bug/issue was introduced.

All the best,
-Ayman

User avatar
Rory Turnbull
Posts: 28
Joined: Mon Dec 16, 2019 1:57 am

Re: Importing bodies from existing models in OpenSim3.3

Post by Rory Turnbull » Mon Jul 12, 2021 2:13 pm

Hi Ayman,

Thank you for your response!

To clarify I have OpenSim 3.3 installed currently and the base model I am using is from a SCONE example which I believe is also using 3.3. Having learnt the MATLAB API for OpenSim 4.1 I was using it as a reference for rebuilding the code in an earlier version. This has worked ok so far but as you have pointed out where there have been large changes to the syntax it does not really help.

Is OpenSim 3.3 is no longer supported on the forum?

Best wishes,
Rory Turnbull

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

Re: Importing bodies from existing models in OpenSim3.3

Post by Ayman Habib » Mon Jul 12, 2021 2:34 pm

Hello Rory,

Thanks for the clarification. Version 3.3 definitely continues to be supported (on the forum and elsewhere), I was just making sure we're clear on the expectations when translating code between versions.

If you prefer to stay with 3.3 for this specific use case, I'd suggest you download and wire Matlab to OpenSim 3.3. The file format is embedded in the API so if you plan to write files for OpenSim 3.3 then you should use the API from the same version.

Hope this helps,
-Ayman

POST REPLY