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.
Changing Actuator Optimal Force Iteratively using MATLAB and/or Python
- Ali Khalilianmotamed Bonab
- Posts: 47
- Joined: Mon Aug 13, 2018 6:28 am
- Dimitar Stanev
- Posts: 1096
- Joined: Fri Jan 31, 2014 5:14 am
Re: Changing Actuator Optimal Force Iteratively using MATLAB and/or Python
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
Then you can iterate over the set
Then you should export your model to a file and execute the CMC methods by loading the xml setup file.
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()
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
- barak ostraich
- Posts: 42
- Joined: Thu Apr 12, 2018 12:17 am
Re: Changing Actuator Optimal Force Iteratively using MATLAB and/or Python
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?
const Set<OpenSim::Actuator>& actuators = _model.updActuators();
but i get :
'class OpenSim::Actuator' has no member named 'getOptimalForce'
how can i get the torqeactuators?
- Thomas Uchida
- Posts: 1793
- Joined: Wed May 16, 2012 11:40 am
Re: Changing Actuator Optimal Force Iteratively using MATLAB and/or Python
getOptimalForce() is a method in the TorqueActuator class, not the Actuator class. You need to downcast, something like this: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?
Code: Select all
auto myTorqueActuator = dynamic_cast<const TorqueActuator*>(myActuator);
if (myTorqueActuator) {
...
}