Page 1 of 1
How can I realize the system to a new stage? - MatLab API
Posted: Tue May 28, 2013 9:38 pm
by porsasina
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
Re: How can I realize the system to a new stage? - MatLab AP
Posted: Thu May 30, 2013 3:04 pm
by aymanh
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
Re: How can I realize the system to a new stage? - MatLab AP
Posted: Thu May 30, 2013 4:34 pm
by porsasina
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
Re: How can I realize the system to a new stage? - MatLab AP
Posted: Tue Jun 18, 2013 6:21 pm
by porsasina
Hi Ayman,
I was just wondering if you have any suggestions for me regarding this problem?
Thanks
Sina
Re: How can I realize the system to a new stage? - MatLab AP
Posted: Tue Jun 18, 2013 8:01 pm
by porsasina
I was wondering if it is possible to pass the model and other parameters to a mex-file to do the calculations?
Re: How can I realize the system to a new stage? - MatLab AP
Posted: Wed Jun 19, 2013 9:15 am
by aymanh
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
Re: How can I realize the system to a new stage? - MatLab AP
Posted: Wed Jun 19, 2013 6:02 pm
by porsasina
Hi Ayman
That's great! thanks!
Re: How can I realize the system to a new stage? - MatLab AP
Posted: Wed Jun 19, 2013 11:15 pm
by porsasina
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