Controls in ID and realization stage

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Míriam Febrer-Nafría
Posts: 26
Joined: Thu Apr 18, 2013 4:14 am

Controls in ID and realization stage

Post by Míriam Febrer-Nafría » Fri Jun 01, 2018 8:09 am

Hi all,

I have a question related to the definition of external ground reaction forces as controls, to use the in an inverse dynamics analysis, and the realization of the system.

In the model we have defined the Ground Reaction Forces as two sets of three Point Actuators and three Torque Actuators acting at the left and right calcaneous.

We have a mexfile in .cpp that we call from Matlab. We have as inputs coordinates (q), velocities (qdot), accelerations (knownUdot) and GRFs (controls).

Per each time step, the main part of the code is:

Code: Select all

       
        s.setQ(q);
        s.setU(qdot);
   
        osimModel.getMultibodySystem().realize(s, Stage::Position);
                
        osimModel.updControls(s) = controls;
        osimModel.markControlsAsValid(s);
        
        Tau = idSolver.solve(s,knownUdot);
1. If we don't realize the system, we get an error that says: "This Result Measure cannot be marked valid in a State where this measure's Subsystem has been realized only to stage Instance, because its value was declared to depend on stage Velocity. To mark it valid, we require that the State have been realized at least to the previous stage (Position in this case)" .

2. If we realize at Position or Velocity level, the results are the same (and are correct, because we are comparing them our previous way of solving Inverse Dynamics, and also with the results from ID Tool in the GUI). Why there's no difference between realizing at position and velocity level?

But if we look to the definitions of these functions in the OpenSim API, it seems that we should be at the Dynamics Stage:

SimTK::Vector & OpenSim::Model::updControls(const SimTK::State & s) const
This call invalidates the dynamics of the model and invalidates the value of the controls until they are marked as valid when the update is completed


void OpenSim::Model::markControlsAsValid(const SimTK::State & s) const
Mark controls as valid after an update at a given state.
Indicates that controls are valid for use at the dynamics stage. If the stage is Velocity or lower the controls will remain invalid.


3. If we realize at Dynamics level, then the controls are not taken into account (We can see this comparing to the previous results, and also because the residual vertical force is around 500-600 N, that corresponds aprox. to the weight). This means that in updControls or in markControlsAsValid, the stage is realized to dynamics?

Thanks,
Miriam Febrer

Tags:

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

Re: Controls in ID and realization stage

Post by Christopher Dembia » Thu Jun 07, 2018 5:04 pm

Hey Miriam:

The InverseDynamicsSolver::solve() function realizes to dynamics for you only if you have not yet already realized to dynamics:

Code: Select all

Vector InverseDynamicsSolver::solve(const SimTK::State &s, const SimTK::Vector &udot, 
    const SimTK::Vector &appliedMobilityForces, const SimTK::Vector_<SimTK::SpatialVec>& appliedBodyForces)
{
    ...
    if(s.getSystemStage() < SimTK::Stage::Dynamics)
        getModel().getMultibodySystem().realize(s,SimTK::Stage::Dynamics);
    ...
}
https://github.com/opensim-org/opensim- ... er.cpp#L83


This explains why there is no difference between whether or not you realize to Position or Velocity. Also, this could explain why realizing to Dynamics on your own causes the results to change: the InverseDynamicsSolver will no longer realize to Dynamics for you, and it's important that realizing to dynamics happens *after* you update the controls.

Let me know if this explanation was not clear.

User avatar
Míriam Febrer-Nafría
Posts: 26
Joined: Thu Apr 18, 2013 4:14 am

Re: Controls in ID and realization stage

Post by Míriam Febrer-Nafría » Mon Jun 11, 2018 2:52 pm

Thanks, Chris.

POST REPLY