Implementation of CMC using MATLAB API
- Maya Madhavan
- Posts: 8
- Joined: Wed Mar 20, 2013 12:12 pm
Implementation of CMC using MATLAB API
Hello,
I am an intern and first time user of OpenSim. I am trying to write a MATLAB script that implements CMCTool through the API. My script runs until this line: cmcTool.setForceSetFiles([residualMotorsFilePath residualMotors]); where the string inside is the full path of a file with residual motors which would in the GUI be an additional force set file appended to the model's. This returns the error "No method 'setForceSetFiles' with matching signature found for class 'org.opensim.modeling.CMCTool'."
Can anyone explain this error especially as previous lines of my code such as
cmcTool.setDesiredKinematicsFileName([desiredKinematicsFilePath desiredKinematics]); are running normally.
Thank you!
I am an intern and first time user of OpenSim. I am trying to write a MATLAB script that implements CMCTool through the API. My script runs until this line: cmcTool.setForceSetFiles([residualMotorsFilePath residualMotors]); where the string inside is the full path of a file with residual motors which would in the GUI be an additional force set file appended to the model's. This returns the error "No method 'setForceSetFiles' with matching signature found for class 'org.opensim.modeling.CMCTool'."
Can anyone explain this error especially as previous lines of my code such as
cmcTool.setDesiredKinematicsFileName([desiredKinematicsFilePath desiredKinematics]); are running normally.
Thank you!
- Maarten Afschrift
- Posts: 7
- Joined: Sat Oct 20, 2012 4:09 am
Re: Implementation of CMC using MATLAB API
Hello,
I think you should first make an ArrayStr from the path, since SetForceSetFile requires an ArrayStr as input.
Maybe this works:
cmcTool.setForceSetFiles(ArrayStr([residualMotorsFilePath residualMotors]))
But I'm also a first time user of Opensim (this could be wrong).
Maarten,
I think you should first make an ArrayStr from the path, since SetForceSetFile requires an ArrayStr as input.
Maybe this works:
cmcTool.setForceSetFiles(ArrayStr([residualMotorsFilePath residualMotors]))
But I'm also a first time user of Opensim (this could be wrong).
Maarten,
- Maya Madhavan
- Posts: 8
- Joined: Wed Mar 20, 2013 12:12 pm
Re: Implementation of CMC using MATLAB API
Thank you Maarten, that seemed to help!
Maya
Maya
- Maya Madhavan
- Posts: 8
- Joined: Wed Mar 20, 2013 12:12 pm
Re: Implementation of CMC using MATLAB API
Now when I run my script, I get the error
SimTK Exception thrown at InteriorPointOptimizer.cpp:261:
Optimizer failed: Ipopt: Infeasible problem detected (status 2)
OPTIMIZATION FAILED...
CMC.computeControls: WARN- The optimizer could not find a solution at time = 0.000000.
If using the fast target, try using the slow target.
Starting at a slightly different initial time may also help.
I know that this error is being caused by my specifying the external loads using
cmcTool.setExternalLoadsFileName([externalLoadsFilePath externalLoads]);
because without this line the script runs and produces an output. However I am not sure where the error comes from because I am specifying for the same xml file I used to set up external loads when running the CMC tool in the GUI, which worked without a problem. I would very much appreciate anyone's input on this.
Thanks,
Maya
SimTK Exception thrown at InteriorPointOptimizer.cpp:261:
Optimizer failed: Ipopt: Infeasible problem detected (status 2)
OPTIMIZATION FAILED...
CMC.computeControls: WARN- The optimizer could not find a solution at time = 0.000000.
If using the fast target, try using the slow target.
Starting at a slightly different initial time may also help.
I know that this error is being caused by my specifying the external loads using
cmcTool.setExternalLoadsFileName([externalLoadsFilePath externalLoads]);
because without this line the script runs and produces an output. However I am not sure where the error comes from because I am specifying for the same xml file I used to set up external loads when running the CMC tool in the GUI, which worked without a problem. I would very much appreciate anyone's input on this.
Thanks,
Maya
- Jennifer Hicks
- Posts: 30
- Joined: Wed Sep 07, 2005 4:40 pm
Re: Implementation of CMC using MATLAB API
Maya -
As Ajay noted in his email, you can open the setup (XML) files in any editor (Notepad++ will color code for you) and take a look at the settings. Compare the file generated by your Matlab scripts (the tool should have a print command or similar). Please verify that the files and paths are correct in your setup files and are the same between the GUI version and Matlab version.
Also, do you have other versions of OpenSim on your machine? It is possible that you are using one via the GUI and another via the command line. Check your system path.
You can also check out your ground reaction forces by visualizing in the GUI:
http://simtk-confluence.stanford.edu:80 ... h+a+Motion
or
http://simtk-confluence.stanford.edu:80 ... ap%29+Data
Best wishes,
Jen
As Ajay noted in his email, you can open the setup (XML) files in any editor (Notepad++ will color code for you) and take a look at the settings. Compare the file generated by your Matlab scripts (the tool should have a print command or similar). Please verify that the files and paths are correct in your setup files and are the same between the GUI version and Matlab version.
Also, do you have other versions of OpenSim on your machine? It is possible that you are using one via the GUI and another via the command line. Check your system path.
You can also check out your ground reaction forces by visualizing in the GUI:
http://simtk-confluence.stanford.edu:80 ... h+a+Motion
or
http://simtk-confluence.stanford.edu:80 ... ap%29+Data
Best wishes,
Jen
- Maya Madhavan
- Posts: 8
- Joined: Wed Mar 20, 2013 12:12 pm
Re: Implementation of CMC using MATLAB API
Thank you very much for the response. I was able to print a setup file from my script and one used in the GUI, and they are specifying the same files except there are no force set files specified in the xml file printed by the script. The line in my script that I thought would specify the force set files was
cmcTool.setForceSetFiles(ArrayStr([residualMotorsFilePath residualMotors]));
Where [residualMotorsFilePath residualMotors] is the full file path for the residual motors file. Is there an error in how I have specified this?
Thanks,
Maya
cmcTool.setForceSetFiles(ArrayStr([residualMotorsFilePath residualMotors]));
Where [residualMotorsFilePath residualMotors] is the full file path for the residual motors file. Is there an error in how I have specified this?
Thanks,
Maya
- Jennifer Hicks
- Posts: 30
- Joined: Wed Sep 07, 2005 4:40 pm
Re: Implementation of CMC using MATLAB API
Maya -
You should use the call:
cmcTool.setExternalLoadsFileName([residualMotorsFilePath residualMotors]);
See the CMCTool doxygen for other calls:
https://simtk.org/api_docs/opensim/api_ ... CTool.html
I believe the setForceSetFiles is an internal method not intended for
Jen
You should use the call:
cmcTool.setExternalLoadsFileName([residualMotorsFilePath residualMotors]);
See the CMCTool doxygen for other calls:
https://simtk.org/api_docs/opensim/api_ ... CTool.html
I believe the setForceSetFiles is an internal method not intended for
Jen
- Maya Madhavan
- Posts: 8
- Joined: Wed Mar 20, 2013 12:12 pm
Re: Implementation of CMC using MATLAB API
When I used the call, setExternalLoadsFileName, it successfully changed the <external_loads_file> parameter in the setup file. I was trying to set the <force_set_files> parameter, so I found out what was wrong with the earlier setForceSetFiles call, I should have used
cmcTool.setForceSetFiles(ArrayStr([residualMotorsFilePath residualMotors],1)); to specify the array with length 1. Now, when I run my script I get a printed setup file which exactly matches the setup file that I used when running CMC in the GUI.
In fact, I can take the setup file printed by my script and load into the GUI and it is able to run. However, when I try to run the MATLAB script directly I still get the same error. I only have OpenSim 3.0 on my computer I believe.
Thanks,
Maya
cmcTool.setForceSetFiles(ArrayStr([residualMotorsFilePath residualMotors],1)); to specify the array with length 1. Now, when I run my script I get a printed setup file which exactly matches the setup file that I used when running CMC in the GUI.
In fact, I can take the setup file printed by my script and load into the GUI and it is able to run. However, when I try to run the MATLAB script directly I still get the same error. I only have OpenSim 3.0 on my computer I believe.
Thanks,
Maya
- Ayman Habib
- Posts: 2252
- Joined: Fri Apr 01, 2005 12:24 pm
Re: Implementation of CMC using MATLAB API
Hi Maya,
The GUI and Matlab interface exercise the same code so I expect similar behavior, only difference could be in the assumptions dealing with working directory and relative paths since the GUI makes no assumptions about it while the Matlab environment may do. Try first with making all paths to files absolute, (ideally without spaces in them), and that will help you find out if this's a path/working-directory issue or not and let us know how it goes.
Best regards,
-Ayman
The GUI and Matlab interface exercise the same code so I expect similar behavior, only difference could be in the assumptions dealing with working directory and relative paths since the GUI makes no assumptions about it while the Matlab environment may do. Try first with making all paths to files absolute, (ideally without spaces in them), and that will help you find out if this's a path/working-directory issue or not and let us know how it goes.
Best regards,
-Ayman
- Maya Madhavan
- Posts: 8
- Joined: Wed Mar 20, 2013 12:12 pm
Re: Implementation of CMC using MATLAB API
Hi Ayman,
I checked and ensured that the setup file created by my script had all the full paths specified. I was eventually able to resolve the issue by creating a new CMCTool object using the setup file that my script had created,which than ran and produced the same output as the GUI, as follows:
cmcTool.print(['C:\OpenSimModels\FullBody_PlantarFlexionModel_05311
3\setupScript.xml']);
newTool = CMCTool('C:\OpenSimModels\FullBody_PlantarFlexionModel_053113\setu
pScript.xml');
newTool.run();
I am now attempting another script to run Forward Dynamics with Muscle Analysis. I was able to insert the Muscle Analysis into the Analysis Set in the forward dynamics setup file using the code
fwdTool = ForwardTool();
musclea = MuscleAnalysis();
musclea.setStartTime(0.03);
musclea.setEndTime(0.99);
fwdTool.getAnalysisSet().insert(0,musclea);
But when I use fwdTool.run() it only outputs the forward dynamics results in the result directory without the result of the Muscle Analysis. Is there some code to initialize the muscle analysis that I am missing? Thank you for your time.
Maya
I checked and ensured that the setup file created by my script had all the full paths specified. I was eventually able to resolve the issue by creating a new CMCTool object using the setup file that my script had created,which than ran and produced the same output as the GUI, as follows:
cmcTool.print(['C:\OpenSimModels\FullBody_PlantarFlexionModel_05311
3\setupScript.xml']);
newTool = CMCTool('C:\OpenSimModels\FullBody_PlantarFlexionModel_053113\setu
pScript.xml');
newTool.run();
I am now attempting another script to run Forward Dynamics with Muscle Analysis. I was able to insert the Muscle Analysis into the Analysis Set in the forward dynamics setup file using the code
fwdTool = ForwardTool();
musclea = MuscleAnalysis();
musclea.setStartTime(0.03);
musclea.setEndTime(0.99);
fwdTool.getAnalysisSet().insert(0,musclea);
But when I use fwdTool.run() it only outputs the forward dynamics results in the result directory without the result of the Muscle Analysis. Is there some code to initialize the muscle analysis that I am missing? Thank you for your time.
Maya