Scripting vs. GUI

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Thomas Gagliardi
Posts: 10
Joined: Mon Mar 12, 2018 7:28 am

Scripting vs. GUI

Post by Thomas Gagliardi » Mon Aug 20, 2018 8:31 am

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.
Attachments
GIL01_CMC_Actuators.zip
(936 Bytes) Downloaded 29 times
GIL01_CMC_Tasks.xml
(27.12 KiB) Downloaded 140 times
GIL01_fast5_ik.mot
(66.33 KiB) Downloaded 31 times
GIL01_gait2392_simbody.osim
(588.88 KiB) Downloaded 137 times
Last edited by Thomas Gagliardi on Mon Aug 20, 2018 8:45 am, edited 1 time in total.

Tags:

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Scripting vs. GUI

Post by jimmy d » Mon Aug 20, 2018 8:42 am

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.

User avatar
Thomas Gagliardi
Posts: 10
Joined: Mon Mar 12, 2018 7:28 am

Re: Scripting vs. GUI

Post by Thomas Gagliardi » Mon Aug 20, 2018 8:53 am

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!

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Scripting vs. GUI

Post by jimmy d » Mon Aug 20, 2018 9:17 am

There doesn't seem to be an external loads file- is that intentional?

User avatar
Thomas Gagliardi
Posts: 10
Joined: Mon Mar 12, 2018 7:28 am

Re: Scripting vs. GUI

Post by Thomas Gagliardi » Mon Aug 20, 2018 10:25 am

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!

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Scripting vs. GUI

Post by jimmy d » Mon Aug 20, 2018 12:32 pm

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()


User avatar
Thomas Gagliardi
Posts: 10
Joined: Mon Mar 12, 2018 7:28 am

Re: Scripting vs. GUI

Post by Thomas Gagliardi » Mon Aug 20, 2018 1:06 pm

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?

User avatar
jimmy d
Posts: 1375
Joined: Thu Oct 04, 2007 11:51 pm

Re: Scripting vs. GUI

Post by jimmy d » Mon Aug 20, 2018 1:23 pm

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.

POST REPLY