Changing Actuator Optimal Force Iteratively using MATLAB and/or Python

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Ali Khalilianmotamed Bonab
Posts: 47
Joined: Mon Aug 13, 2018 6:28 am

Changing Actuator Optimal Force Iteratively using MATLAB and/or Python

Post by Ali Khalilianmotamed Bonab » Mon Mar 04, 2019 8:08 am

To whom it may concern,
I want to add an actuator to my model and change its optimal force in each simulation iteratively.
I would appreciate if you let me know how I can change the optimal force of the actuator iteratively using Matlab and/or python code.

To clarify what I want, short pseudocode provided as follows:

MATLAB:

For i = 1:n
set actuator optimal force = i
run OpenSim CMC
return results
end


I am adding the actuator using GUI https://simtk-confluence.stanford.edu/d ... in+the+GUI and when I am checking the Model's XML file or Actuators XML file, I cannot see the added actuators on them.

I am looking forward to hearing from you as soon as possible.
Ali.

Tags:

User avatar
Dimitar Stanev
Posts: 1096
Joined: Fri Jan 31, 2014 5:14 am

Re: Changing Actuator Optimal Force Iteratively using MATLAB and/or Python

Post by Dimitar Stanev » Tue Mar 05, 2019 1:01 am

You should keep in mind that both a muscles and other types of force components (e.g. CoordinateActuator, TorqueActuator -> reserve actuators) derive from an Actuator base class

https://simtk.org/api_docs/opensim/api_ ... uator.html

Also note that changing the optimal force of a muscle does not affect the muscle, because there is a separate function call for changing its isometric force.

You can get a set of model actuators by calling the function

Code: Select all

actSet = model.updActuators()
Then you can iterate over the set

Code: Select all

% not sure whether this starts from 0 or zero you should check
% in OpenSim v4.0 there is a support for iterators
% https://simtk-confluence.stanford.edu/display/OpenSim/Scripting+with+Matlab
for i=1:actSet.getSize()  
    actSet(i).setOptimalForce(someValue)
end
Then you should export your model to a file and execute the CMC methods by loading the xml setup file.

User avatar
barak ostraich
Posts: 42
Joined: Thu Apr 12, 2018 12:17 am

Re: Changing Actuator Optimal Force Iteratively using MATLAB and/or Python

Post by barak ostraich » Tue Mar 31, 2020 1:19 am

i try to getOptimalForce after

const Set<OpenSim::Actuator>& actuators = _model.updActuators();

but i get :

'class OpenSim::Actuator' has no member named 'getOptimalForce'

how can i get the torqeactuators?

User avatar
Thomas Uchida
Posts: 1793
Joined: Wed May 16, 2012 11:40 am

Re: Changing Actuator Optimal Force Iteratively using MATLAB and/or Python

Post by Thomas Uchida » Wed Apr 01, 2020 2:34 pm

i try to getOptimalForce after
const Set<OpenSim::Actuator>& actuators = _model.updActuators();
but i get :
'class OpenSim::Actuator' has no member named 'getOptimalForce'
how can i get the torqeactuators?
getOptimalForce() is a method in the TorqueActuator class, not the Actuator class. You need to downcast, something like this:

Code: Select all

auto myTorqueActuator = dynamic_cast<const TorqueActuator*>(myActuator);
if (myTorqueActuator) {
    ...
}
You can search the GitHub repo (https://github.com/opensim-org/opensim-core) for "dynamic_cast" for examples.

POST REPLY