How can I realize the system to a new stage? - MatLab API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

How can I realize the system to a new stage? - MatLab API

Post by Sina Porsa » Tue May 28, 2013 9:38 pm

Hi Everyone,
I was wondering if it is possible to realize the system to a new stage, using MatLab API?
In C++ i use this:

Code: Select all

model.getMultibodySystem().realize(state, Stage::Acceleration);
Is there any similar method available, if I want to use matlab API?
Thanks
Sina

User avatar
Ayman Habib
Posts: 2244
Joined: Fri Apr 01, 2005 12:24 pm

Re: How can I realize the system to a new stage? - MatLab AP

Post by Ayman Habib » Thu May 30, 2013 3:04 pm

Hi Sina,

The SimTK::MultibodySystem is not considered part of the API we're exposing to our Matlab users. Please let us know the use-case so we can help you find alternative calls on the OpenSim API level that can get you the result you want. Ideally there are some quantities that you want computed (rather than realization in itself.)

Please let us know more details so we can help you out.

Best regards,
-Ayman

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: How can I realize the system to a new stage? - MatLab AP

Post by Sina Porsa » Thu May 30, 2013 4:34 pm

Hi Ayman and Thank you
I have described my method in one of my old posts:
https://simtk.org/forums/viewtopic.php? ... tion#p8872
I was wondering if it is possible to do the same thing using MatLab API?
Here is a brief description of what I need: I need a function which has 2 inputs arrays:
1- Array X, which is equal to the states at a particular time(joint angles, angular velocities, muscle fiber lengths and muscle activations)
2- Array U, which is the muscle excitations at the same time

and the output is the derivative of states. ---> Xdot( @t* ) = func(U*,X*,t*)

Based on Ajay's post on above mentioned link, after I have updated the model state variables and excitations ,I must realize the system to the acceleration stage to access Xdot from the state.

thanks
Sina

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: How can I realize the system to a new stage? - MatLab AP

Post by Sina Porsa » Tue Jun 18, 2013 6:21 pm

Hi Ayman,
I was just wondering if you have any suggestions for me regarding this problem?
Thanks
Sina

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: How can I realize the system to a new stage? - MatLab AP

Post by Sina Porsa » Tue Jun 18, 2013 8:01 pm

I was wondering if it is possible to pass the model and other parameters to a mex-file to do the calculations?

User avatar
Ayman Habib
Posts: 2244
Joined: Fri Apr 01, 2005 12:24 pm

Re: How can I realize the system to a new stage? - MatLab AP

Post by Ayman Habib » Wed Jun 19, 2013 9:15 am

Hi Sina,

In the latest 3.1 beta release you can call

Code: Select all

model.computeStateVariableDerivatives(s)
and this has the effect of realizing to Acceleration. Please check the Doxygen documentation of this method for more details.

Best regards,
-Ayman

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: How can I realize the system to a new stage? - MatLab AP

Post by Sina Porsa » Wed Jun 19, 2013 6:02 pm

Hi Ayman
That's great! thanks!

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: How can I realize the system to a new stage? - MatLab AP

Post by Sina Porsa » Wed Jun 19, 2013 11:15 pm

Hi Ayman,
It seems that this method has some problems. If excitation/activation dynamics is based on Thelen 2003, then I expect da/dt=0 when excitation equals activation. But the following script returns non-zero values :

Code: Select all

osimModel = Model('tug_of_war_muscles.osim');
% SET DEFAULT ACTIVATION OF MUSCLES
actuatorSet = osimModel.getActuators();
for muscleIndx= 0:actuatorSet.getSize()-1
    theMuscle =ActivationFiberLengthMuscle.safeDownCast(actuatorSet.get(muscleIndx) );
    theMuscle.set_default_activation(0.5);
end
% SET CONTROLLER FOR MUSCLES
muscleController = PrescribedController();
muscleController.setActuators(osimModel.updActuators());
for muscleIndx= 0:actuatorSet.getSize()-1
    muscleController.prescribeControlForActuator(muscleIndx, Constant(0.5));
end
osimModel.addController(muscleController);
% CALCULATE DERIVATIVES
States = osimModel.initSystem();
Derivatives=osimModel.computeStateVariableDerivatives(States );
As you can see, I set both activation and excitaion to the same value (0.5) and I expect da/dt to be zero. But da/dt is equal to -1.8018.
Am I missing sth in my script?
Regards
Sina

POST REPLY