Page 1 of 1

Adding actuators for static optimization through MATLAB

Posted: Tue Nov 20, 2018 10:29 am
by stefanschmid
Hi all

We are trying to run a static optimization through MATLAB with an added set of residual actuators. According to a previous forum post (viewtopicPhpbb.php?f=91&t=8480&p=0&start=0&view=), we have added our actuator set using the follwing code (blue highlighted section):

import org.opensim.modeling.*
model = Model(modelfile);
statop = AnalyzeTool(statopsetupfile);
statop.setModel(model)
ForceSet = ArrayStr();
ForceSet.set(0,'S:\Examplepath\FeetActuators.xml');
statop.setForceSetFiles(ForceSet);

statop.setCoordinatesFileName(motionfile)
statop.setExternalLoadsFileName(extloadsfile);
statop.setResultsDir(resultpath);
statop.run();

The problem is that it does not seem to actually add the actuator set and we don't get the message '"Adding force object set from S:\Examplepath\FeetActuators.xml'. Is there something missing in our code?

Thank you very much for your help!

All the best
-Stefan

Re: Adding actuators for static optimization through MATLAB

Posted: Tue Nov 20, 2018 10:44 am
by jimmy
Hi, Stefan-

This seems similar to previous issues I have had with changing the external loads file when using a pre-existing Setup file. What (probably) happens is that the internal forceset of the object is only constructed at the initial construction of the AnalyzeTool(). I was able to work around by writing the setup back to file after making all my changes, instantiating from the file, and running. For you it would look something like;

Code: Select all

...
statop.print(statopsetupfile_temp)
statop = AnalyzeTool(statopsetupfile_temp);
statop.run()

Re: Adding actuators for static optimization through MATLAB

Posted: Tue Nov 20, 2018 11:27 am
by stefanschmid
Hi James

Thank you very much for your suggestion. What now happens is the following:

When I write the setup back to file (statop.print(statopsetupfile_temp)), it does not include writing out the model file (i.e. the line where the the model file name should be remains <model_file />), which causes MATLAB to crash after re-initializing the AnalyzeTool with the "new" setup file. I assume this happens when the the AnalyzeTool tries to add the actuator set to a model that is not yet defined.

Have you by any chance also encountered this issue?

All the best
-Stefan

Re: Adding actuators for static optimization through MATLAB

Posted: Tue Nov 20, 2018 12:41 pm
by stefanschmid
Hi James

I have been able to resolve the issue by adding the following line before writing the setup back to file:

statop.setModelFilename(modelfile);

Thanks again for your support!

All the best
-Stefan