Page 1 of 1

coordinates

Posted: Thu Aug 03, 2017 1:43 pm
by shayanlut
hello,
i have a simple matlab code which loads the model and makes a free falling.
clear all;
import org.opensim.modeling.*
foot1 = Model('C:\Users\shayan\Desktop\model-20170712T165116Z-001/foot1.osim');
s = foot1.initSystem();
manager = Manager(foot1);
x0 = foot1.updCoordinateSet().get('y');
x0.setDefaultValue(3);
manager.setInitialTime(0);
manager.setFinalTime(.04);
manager.integrate(s);
what i want to do is to change the initial state (in my case y, showing the height). using following lines in the above code seems to do the job:
x0 = foot1.updCoordinateSet().get('y');
x0.setDefaultValue(3);

however, the change happens only in .sto or .mot file. and i want to retrieve (see the value) it through matlab. do the previous two lines change the values for center of mass?if so, why running this line (foot1.calcMassCenterPosition(s)) results in a different value than my default value (which was 3)?
the second question is:how can i get the value of state y from one simulation to use it as starting position for another simulation?
regards
Shayan

Re: coordinates

Posted: Fri Aug 04, 2017 3:01 pm
by tkuchida
You can set the default value of the Coordinate, as you are doing, but you would need to call setDefaultValue() before calling initSystem(). However, to specify initial conditions for a simulation, I recommend setting the value of the Coordinate once the State has been created. Here's a simple example (MATLAB, OpenSim 3.3):

Code: Select all

import org.opensim.modeling.*;

model = Model('arm26.osim');
model.setUseVisualizer(true);
state = model.initSystem();

coordName = 'r_elbow_flex';
coord = model.getCoordinateSet().get(coordName);
fprintf('%s coordinate changed from %0.6f', coordName, coord.getValue(state));
coord.setValue(state, 0.5); %radians
fprintf(' to %0.6f\n', coord.getValue(state));

model.getVisualizer().show(state);