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
Inconsistency between model::getNumStateVariables and state::getNY()
- Charles Yin
- Posts: 11
- Joined: Mon Feb 05, 2018 12:45 am
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Inconsistency between model::getNumStateVariables and state::getNY()
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().
My understanding is that the presence of a BushingForce does not affect the number of state variables mentioned by getNumStateVariables() or State::getNY().
- Charles Yin
- Posts: 11
- Joined: Mon Feb 05, 2018 12:45 am
Re: Inconsistency between model::getNumStateVariables and state::getNY()
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
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
- Christopher Dembia
- Posts: 506
- Joined: Fri Oct 12, 2012 4:09 pm
Re: Inconsistency between model::getNumStateVariables and state::getNY()
If you remove the bushing forces, does the number of states become consistent?
- Charles Yin
- Posts: 11
- Joined: Mon Feb 05, 2018 12:45 am
Re: Inconsistency between model::getNumStateVariables and state::getNY()
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
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