Page 1 of 1

Problem with the position of the model

Posted: Sat Oct 13, 2018 5:38 am
by zurenarrh
Hi all,

I'm a beginner with OpenSim, and recently I'm trying to import model file and visualize it through Python. According to the official document, I wrote some code to import the standard model file 'gait2345_simbody.osim' as follow:

Code: Select all

import opensim


folderName = 'E:/OpenSim 3.3/Models/Gait2354_Simbody'


modelFileName = folderName + '/gait2354_simbody_test.osim'
myModel = opensim.Model(modelFileName)

myModel.setUseVisualizer(True)
myState = myModel.initSystem()

while 1:
	myModel.getVisualizer().show(myState)
When I ran my code, the visualizer runs fine, but the funny thing is that half part of the model is buried under ground as shown below:
Image
Does anyone know how to adjust the position of the model in the visualizer so that the model can 'stand' on the ground? I'm trying to edit the '.osim' file through notepad++, but nothing works yet. Besides, is there some advice about how to deal with the interaction between the feet of model and the ground?

Thanks,
Zurenarrh

Re: Problem with the position of the model

Posted: Sun Oct 14, 2018 2:27 am
by mitkof6
You can change the position of the pelvis body:

Code: Select all

model.updCoordinateSet().get(coordinate_name).setValue(state, value)

Re: Problem with the position of the model

Posted: Sun Oct 14, 2018 6:43 am
by zurenarrh
Sorry to bother again, I try to fix it myself through the official document, but the API part are all c++, and there's no detailed explanation about 'updCoordinateSet()'. I'm not sure what the variables 'coordinate_name' and 'value' mean in the code and how to get their values before adding them into the code.(I tried to use the code, but failed.)

Thanks,
Zurenarrh

Re: Problem with the position of the model

Posted: Sun Oct 14, 2018 6:46 am
by zurenarrh
mitkof6 wrote:
Sun Oct 14, 2018 2:27 am
You can change the position of the pelvis body:

Code: Select all

model.updCoordinateSet().get(coordinate_name).setValue(state, value)
Sorry to bother again, I try to fix it myself through the official document, but the API part are all c++, and there's no detailed explanation about 'updCoordinateSet()'. I'm not sure what the variables 'coordinate_name' and 'value' mean in the code and how to get their values before adding them into the code.(I tried to use the code, but failed.)

Thanks,
Zurenarrh

Re: Problem with the position of the model

Posted: Sun Oct 14, 2018 10:58 am
by tkuchida
Here's a MATLAB version; Python should be analogous.

Code: Select all

% OpenSim 3.3
import org.opensim.modeling.*;
model = Model('gait2354_simbody.osim');
model.setUseVisualizer(true);
state = model.initSystem();
model.updCoordinateSet().get('pelvis_ty').setValue(state, 0.95);
model.getVisualizer().show(state);
The following pages in the Confluence documentation may be useful:
- "Common Scripting Commands", https://simtk-confluence.stanford.edu/d ... g+Commands
- "Scripting in Python", https://simtk-confluence.stanford.edu/d ... +in+Python

Re: Problem with the position of the model

Posted: Tue Oct 16, 2018 3:38 am
by zurenarrh
tkuchida wrote:
Sun Oct 14, 2018 10:58 am
Here's a MATLAB version; Python should be analogous.

Code: Select all

% OpenSim 3.3
import org.opensim.modeling.*;
model = Model('gait2354_simbody.osim');
model.setUseVisualizer(true);
state = model.initSystem();
model.updCoordinateSet().get('pelvis_ty').setValue(state, 0.95);
model.getVisualizer().show(state);
The following pages in the Confluence documentation may be useful:
- "Common Scripting Commands", https://simtk-confluence.stanford.edu/d ... g+Commands
- "Scripting in Python", https://simtk-confluence.stanford.edu/d ... +in+Python
Thanks for your advice, the documentation you offered helps a lot!