Page 1 of 1

Inconsistency between model::getNumStateVariables and state::getNY()

Posted: Tue Dec 10, 2019 9:51 am
by simreal
Hello,
I have met a problem that the number of states obtained from model::getNumStateVariables is inconsistent with the one get from state::getNY() due to the exist of bushing force. Up to my knowledge, state::getNY() will take bushing force into account while the model::getNumStateVariables doesn't.
I want to ask experts, if I want to make these two consistent, how could I add the bushing force into model::getNumStateVariables.
Thanks.

-Charles

Re: Inconsistency between model::getNumStateVariables and state::getNY()

Posted: Tue Dec 10, 2019 4:51 pm
by chrisdembia
This may occur if your model contains joints that could have 3 rotations. The SimTK State has a slot for a 4th quaternion coordinate, which OpenSim does not use.

My understanding is that the presence of a BushingForce does not affect the number of state variables mentioned by getNumStateVariables() or State::getNY().

Re: Inconsistency between model::getNumStateVariables and state::getNY()

Posted: Wed Dec 11, 2019 9:45 am
by simreal
Hello Christopher,
I have tested this problem on model 'ToyLandingModel.osim' . I attach my test codes here:

1) For obtaining the number of states from the method 'model::getNumStateVariables()':

osimModel = Model('ToyLandingModel.osim');
Nstates = osimModel.getNumStateVariables();
(also, I can get all the names for states by using osimModel.getStateVariableNames(). Where I noticed that states vector is formulated as : x = [coordinates, velocities, muscle activations, muscle fiber lengths]^T, the last two items are aligned interlacedly)

and the result is:

Nstates =

194

2) For the number from 'state::getNY()':

osimState = osimModel.initSystem();
numStates = osimState.getNY();

and the result is:

numStates =

197

There is the inconsistency.

As I have noticed that there are three bushing forces defined in this model: BackBushing, ankle_r_bushing, ankle_l_bushing. It is clear that osimState.getNY() has accounted the bushing forces while the former didn't.

Therefore, how do I operate in order to let them be consistent?

Thank you.

-Charles

Re: Inconsistency between model::getNumStateVariables and state::getNY()

Posted: Wed Dec 11, 2019 11:15 am
by chrisdembia
If you remove the bushing forces, does the number of states become consistent?

Re: Inconsistency between model::getNumStateVariables and state::getNY()

Posted: Wed Dec 11, 2019 2:27 pm
by simreal
Hello,

Yes. They are consistent after delete the bushing force.

numStates =

194

and

Nstates =

194

Actually, I need to define bushing forces among some bodies (haven't yet decided) in order to constraint two components. I have ever tried with the 'Constraints' function but failed. \

I want to make these two consistent because I need to achieve this:

osimState.setTime(t);
numVar = osimState.getNY();
for i = 0:1:numVar-1
osimState.updY().set(i, x(i+1,1));
end

osimModel.computeStateVariableDerivatives(osimState);

which is cited from 'OpenSimPlantFunction.m' in the project 'DynamicWalkingStarter'. Where the dimension of x is donated by model::getNumStateVariables.

Thank you.

-Charles