Page 1 of 1

CMC tool on matlab ?

Posted: Mon Feb 19, 2018 2:40 am
by alper75
Dear colleagues,

Currently in internship dealing with OpenSim and Matlab, I would like to know if the CMCtool class and its methods (API) are usable on Matlab ?

Thank you,

Alper

Re: CMC tool on matlab ?

Posted: Mon Feb 19, 2018 11:30 am
by tkuchida
I would like to know if the CMCtool class and its methods (API) are usable on Matlab ?
Yes, you should be able to configure CMCTool and then run it from MATLAB, though loading settings from a setup file might be easier. Please see the "Scripting with Matlab" page in the Confluence documentation (https://simtk-confluence.stanford.edu:8 ... ith+Matlab).

Re: CMC tool on matlab ?

Posted: Tue Feb 20, 2018 3:42 am
by opmahsim2
Hi Tom, could you please help me where my mistake is:


clc
clear all

import org.opensim.modeling.*
model = Model('subject01_metabolics_spring.osim');
cmctool = CMCTool();

%%%%%% Main Settings

cmctool.setModel(model);
cmctool.setDesiredKinematicsFileName('.\RRA\ResultsRRAsubject_adjusted_Kinematics_q.sto')
cmctool.setTaskSetFileName('gait10dof_Kinematics_Tracking_Tasks.xml');

cmctool.setStartTime(0.6);
cmctool.setFinalTime(1.9);
cmctool.setTimeWindow(0.01);


cmctool.setResultsDir('./Resultsout');
cmctool.setOutputPrecision(8);

%%%%%%% Actuators and External Loads

cmctool.setReplaceForceSet(false);
cmctool.setExternalLoadsFileName('.\ExperimentalData\subject01_walk_grf.mot');

%%%%%% something is missing here??

%%%%%%% Integrator Settings

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

cmctool.run();



=========> After run Matlab does not show an error message

but the run creates an "out.log" file that says:

Loaded model walk_subject01_ankle_spring from file subject01_metabolics_spring.osim
Running tool .
Error: failed to construct ExternalLoads from file .\ExperimentalData\subject01_walk_grf.mot. Please make sure the file exists and that it contains an ExternalLoadsobject or create a fresh one.

Exception:
Object: ERR- Could not open file .\ExperimentalData\subject01_walk_grf.mot.
It may not exist or you don't have permission to read it.
file= C:\OpenSim33\src\opensim32\OpenSim\Common\Object.cpp
line= 114

Re: CMC tool on matlab ?

Posted: Tue Feb 20, 2018 11:39 am
by tkuchida
It looks like the file ".\ExperimentalData\subject01_walk_grf.mot" cannot be found. I suggest replacing relative paths with absolute paths. If issues persist, you might want to set up your simulation using the GUI first (to take any MATLAB issues out of the equation), then write the corresponding MATLAB script and ensure your MATLAB results match the results generated using the GUI.

Re: CMC tool on matlab ?

Posted: Tue Feb 20, 2018 1:28 pm
by opmahsim2
thanks a lot Tom, for the "Actuators and External Loads" section in the CMC tool GUI in opensim,

what are the Matlab equivalent codes?

can you help me on this? do you have experience in this?

if you look at what I wrote apparently it is not enough,

Re: CMC tool on matlab ?

Posted: Tue Feb 20, 2018 3:25 pm
by tkuchida
I recommend specifying an absolute path rather than a relative path to rule out a path-related issue (I'm not sure what the working directory will be so I can't tell you where ".\ExperimentalData\subject01_walk_grf.mot" will be pointing). Beyond that, I recommend setting up the simulation using the GUI, saving the setup file, and then writing the MATLAB script such that

Code: Select all

cmctool.print('CMC_setup.xml');
produces the same setup file as you saved from the GUI. The doxygen documentation for CMCTool can be found here: https://simtk.org/api_docs/opensim/api_ ... CTool.html.

Re: CMC tool on matlab ?

Posted: Wed Feb 21, 2018 3:34 am
by opmahsim2
Thanks a lot for your input Tom,