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

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Charles Yin
Posts: 11
Joined: Mon Feb 05, 2018 12:45 am

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

Post by Charles Yin » Tue Dec 10, 2019 9:51 am

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

Tags:

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

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

Post by Christopher Dembia » Tue Dec 10, 2019 4:51 pm

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().

User avatar
Charles Yin
Posts: 11
Joined: Mon Feb 05, 2018 12:45 am

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

Post by Charles Yin » Wed Dec 11, 2019 9:45 am

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

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

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

Post by Christopher Dembia » Wed Dec 11, 2019 11:15 am

If you remove the bushing forces, does the number of states become consistent?

User avatar
Charles Yin
Posts: 11
Joined: Mon Feb 05, 2018 12:45 am

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

Post by Charles Yin » Wed Dec 11, 2019 2:27 pm

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

POST REPLY