Page 1 of 1

Scripting vs. GUI

Posted: Mon Aug 20, 2018 8:31 am
by gagliart
Hi,

I am running in some issues with scripting some basic functions.

I have run successfully the CMC via the GUI in both v3.3 and v4 (windows and mac) using the following files (using "Filter Kinematics" with 6Hz).

Unfortunately, when I run the same simulation via scripting I receive always this error:

CMC.computeControls: ERROR- Optimizer could not find a solution.
Unable to find a feasible solution at time = 0.1125.
Model cannot generate the forces necessary to achieve the target acceleration.
Possible issues: 1. not all model degrees-of-freedom are actuated,
2. there are tracking tasks for locked coordinates, and/or
3. there are unnecessary control constraints on reserve/residual actuators.
This happens both with python and matlab.

Below the python script I used:

Code: Select all

import opensim as osim

pth='';
taskFile='GIL01_CMC_Tasks.xml'
kinematicFile=pth+'GIL01_fast5_ik.mot'
modelFile=pth+'GIL01_gait2392_simbody.osim'

model = osim.Model(modelFile)
state = model.initSystem();
cmctool = osim.CMCTool()
cmctool.setModel(model)
cmctool.setLowpassCutoffFrequency(6.0)
cmctool.setDesiredKinematicsFileName(kinematicFile)
cmctool.setTaskSetFileName(taskFile);
fsf=osim.ArrayStr()
fsf.append('GIL01_CMC_Actuators.xml');
cmctool.setForceSetFiles(fsf)

cmctool.setMaximumNumberOfSteps(20000);
cmctool.setMaxDT(1);
cmctool.setMinDT(0.00000001);
cmctool.setErrorTolerance(0.00001);

cmctool.run();
What am I doing wrong?

Thanks for your help.

Re: Scripting vs. GUI

Posted: Mon Aug 20, 2018 8:42 am
by jimmy
A strategy would be to use cmc.print() to write the cmc tool to file, then compare against the setup file you are using in the GUI.

Re: Scripting vs. GUI

Posted: Mon Aug 20, 2018 8:53 am
by gagliart
Hi James,
thanks for your quick reply.
I checked the xml file with the setup from the script and it is identical to the one generated with the interface.
Actually, as a sanity check I loaded the xml file generated from the script in the GUI and the simulation runs smoothly.
There is something wrong in the script itself but I cannot figure out what exactly.
Any idea what can be wrong?
Thanks!

Re: Scripting vs. GUI

Posted: Mon Aug 20, 2018 9:17 am
by jimmy
There doesn't seem to be an external loads file- is that intentional?

Re: Scripting vs. GUI

Posted: Mon Aug 20, 2018 10:25 am
by gagliart
Hi James,
yes, this was intentional in both the GUI and in python/matlab. The fact that it works in the GUI suggests that it is not critical factor to run the CMC. At this point I am more interested in understanding why scripting is different from GUI rather than the accuracy of the results.

Do you think that the GUI can work without the external load while the script needs it? Why is that?

thanks!

Re: Scripting vs. GUI

Posted: Mon Aug 20, 2018 12:32 pm
by jimmy
There does seem to be an error when instantiating a default CMCTool() and running from scripting (Python or Matlab). It is most likely because how the initial state is set in the tool- ill have to do some more testing, but there is a temporary workaround. It seems that when the tool is constructed using an input setup file, the internal state is correctly set and you can run as normal (at least from the tests I ran on Matlab), so if you print the tool setup to file and then read back in you should be able to run it;

The below is Matlab code

Code: Select all

import org.opensim.modeling.*

taskFile = fullfile(path, 'GIL01_CMC_Tasks.xml');
kinematicFile= fullfile(path,'GIL01_fast5_ik.mot');
modelFile= fullfile(path, 'GIL01_gait2392_simbody.osim');
ResultsDir = 'CMCResults_script';

cmctool = CMCTool();
model = Model(modelFile);
cmctool.setModel(model)

cmctool.setModelFilename(modelFile);
cmctool.setLowpassCutoffFrequency(6.0)
cmctool.setDesiredKinematicsFileName(kinematicFile)
cmctool.setTaskSetFileName(taskFile);
fsf=ArrayStr()
fsf.append('GIL01_CMC_Actuators.xml');
cmctool.setForceSetFiles(fsf)
% Set the Results Dir
cmctool.setResultsDir(ResultsDir)
% Set the analyses time
cmctool.setInitialTime(0.11250003)
cmctool.setFinalTime(0.97083336)

cmctool.setMaximumNumberOfSteps(20000);
cmctool.setMaxDT(1);
cmctool.setMinDT(0.00000001);
cmctool.setErrorTolerance(0.00001);

cmctool.print('Setup_CMC.xml')

cmc = CMCTool('Setup_CMC.xml');

cmc.run()


Re: Scripting vs. GUI

Posted: Mon Aug 20, 2018 1:06 pm
by gagliart
Thanks so much for the help: it works. Do you know if this is a common issue with all tools e.g. RRATool or AnalysisTool?

Re: Scripting vs. GUI

Posted: Mon Aug 20, 2018 1:23 pm
by jimmy
It may turn out to be. It will be hard to tell until we test each one. If you do see similar issues with RRA and Analysis, try the workaround and please let me know here. Once we have a fix, I will post here.