Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
-
Evan Dooley
- Posts: 33
- Joined: Sun Nov 24, 2019 11:17 am
Post
by Evan Dooley » Thu Jun 11, 2020 7:16 am
Hello,
I am working on a project using a full body model in 4.1. Instead of rewriting the model in Matlab, I was hoping to load the existing model and then make a couple adjustments to fit my project. I was wondering how you can edit the joints in Matlab. I tried this:
Code: Select all
modelFilePath = 'E:\22_BuildWalkerInMatlab';
modelFile = 'FullBodyModel_SimpleArms_Hamner2010_Markers_v4_0.osim'; % _v2_0 opened and saved in 4.1 to get v4
model = Model(fullfile(modelFilePath, modelFile));
% put human on floor
groundPelvis = model.getJointSet().get('ground_pelvis');
% groundPelvis = model.getJointSet();
Human_TX = groundPelvis.upd_coordinates(3); % OpenSim starts counting at 0, so translation starts at 3
Human_TX.setRange([-10, 10]);
Human_TX.setName('Human_TX');
Human_TX.setDefaultValue(0.5);
Human_TY = groundPelvis.upd_coordinates(4);
Human_TY.setRange([-5, 5]);
Human_TY.setName('Human_TY');
Human_TY.setDefaultValue(1);
Human_TZ = groundPelvis.upd_coordinates(5);
Human_TZ.setRange([-5, 5]);
Human_TZ.setName('Human_TZ');
Human_TZ.setDefaultValue(-0.25);
allJoints = model.getJointSet();
allJoints.cloneAndAppend(groundPelvis);
allJoints.connectToModel(model);
model.addJoint(groundPelvis); % add joint back to model
But I get this error that says that I can't access this joint when I try to put the updated version back in:
Error using ottobock_v3 (line 45)
Java exception occurred:
java.lang.RuntimeException: Component 'ground_pelvis' already owned by tree
to which 'jointset' belongs. Clone the component to adopt a fresh copy.
Thrown at Component.cpp:1224 in markAsPropertySubcomponent().
at
org.opensim.modeling.opensimSimulationJNI.Model_private_addJoint(Native
Method)
at org.opensim.modeling.Model.private_addJoint(Model.java:976)
at org.opensim.modeling.Model.addJoint(Model.java:110)
Has anyone seen this before? Is there a way around this?
Or a place with more documentation of usable commands for the Matlab/OpenSim interface? Mostly, I've been piecing it together based on methodsview(), examples from the resources, answers on this forum, and the common scripting page. There seem to be duplicates and updates and I was just wondering what the best place to start looking for options might be.
Thanks,
EAD
Tags:
-
Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Post
by Christopher Dembia » Thu Jun 11, 2020 2:53 pm
Emily:
It seems like you want to edit a joint that's already in your model. Use the following to obtain the joint of interest:
Code: Select all
groundPelvis = model.updJointSet().get('ground_pelvis');
I changed `get` to `upd`; this tells OpenSim that you plan to edit the resulting joint.
When you edit `groundPelvis` you're actually editing the joint that's inside your model. So you do not need to add this joint to the model again. Remove the following lines:
Code: Select all
allJoints.cloneAndAppend(groundPelvis);
allJoints.connectToModel(model);
model.addJoint(groundPelvis); % add joint back to model
This should help avoid the error you got.
-
Evan Dooley
- Posts: 33
- Joined: Sun Nov 24, 2019 11:17 am
Post
by Evan Dooley » Fri Jun 12, 2020 9:06 am
Thanks for the feedback. I do want to edit a joint that's already in the model.
I tried your suggestion and am now getting this error:
Error using ottobock_v3 (line 129)
Java exception occurred:
java.lang.RuntimeException: SimTK Exception thrown at Joint.cpp:142:
Internal bug detected: Joint::constructCoordinate() must be passed
enumerations in the same order as the enumerations have been defined
(Assertion 'static_cast<unsigned>(cix) == idx' failed).
Please file an Issue at https://github.com/simbody/simbody/issues.
Include the above information and anything else needed to reproduce the
problem.
at org.opensim.modeling.opensimSimulationJNI.Model_private_addBody(Native
Method)
at org.opensim.modeling.Model.private_addBody(Model.java:972)
at org.opensim.modeling.Model.addBody(Model.java:70)
I thought this meant that I needed to specify all six coordinates in the update, but adding the rotational coordinates resulted in the same error:
Code: Select all
groundPelvis = model.updJointSet().get('ground_pelvis');
% groundPelvis = model.getJointSet();
Human_RX = groundPelvis.upd_coordinates(0); % OpenSim starts counting at 0
Human_RX.setRange([-10, 10]);
Human_RX.setName('Human_RX');
Human_RX.setDefaultValue(0);
Human_RY = groundPelvis.upd_coordinates(1);
Human_RY.setRange([-5, 5]);
Human_RY.setName('Human_RY');
Human_RY.setDefaultValue(0);
Human_RZ = groundPelvis.upd_coordinates(2);
Human_RZ.setRange([-5, 5]);
Human_RZ.setName('Human_RZ');
Human_RZ.setDefaultValue(0);
Human_TX = groundPelvis.upd_coordinates(3); % OpenSim starts counting at 0, so translation starts at 3
Human_TX.setRange([-10, 10]);
Human_TX.setName('Human_TX');
Human_TX.setDefaultValue(0.5);
Human_TY = groundPelvis.upd_coordinates(4);
Human_TY.setRange([-5, 5]);
Human_TY.setName('Human_TY');
Human_TY.setDefaultValue(1);
Human_TZ = groundPelvis.upd_coordinates(5);
Human_TZ.setRange([-5, 5]);
Human_TZ.setName('Human_TZ');
Human_TZ.setDefaultValue(-0.25);
-
Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Post
by Christopher Dembia » Fri Jun 12, 2020 9:56 am
The error message indicates that you invoked Model.addBody(). I don't see this in the code you sent, so the error might originate from elsewhere in your code.
-
Evan Dooley
- Posts: 33
- Joined: Sun Nov 24, 2019 11:17 am
Post
by Evan Dooley » Fri Jun 12, 2020 10:09 am
Okay. I do invoke it later in the code.
The goal of the full model is to have a human and a posterior walker that can have a contact between the two. I built the posterior walker using the Matlab/OpenSim interface and it works as expected. I thought I could add the human by importing the existing human model and then adding the posterior walker components to that model.
Is this a reasonable thought process or do I need to code the human in from an empty model as well to get this to work?
Thanks,
EAD
-
Carmichael Ong
- Posts: 401
- Joined: Fri Feb 24, 2012 11:50 am
Post
by Carmichael Ong » Mon Jun 15, 2020 12:04 am
You should be able to load a full human model and then add additional components to the existing model.