Page 1 of 1

Running CMC in MATLAB Error

Posted: Wed Mar 13, 2019 12:03 am
by alik
To whom it may concern,
I am trying to run my model using Matlab and I am getting an error in each try:

Code: Select all

Exception:
  Could not open file
  ../CMC/3DGaitModelwithSimpleArms_states.sto
In order to run my model, I am calling XML file that has been already built for CMC properties.
When I am running the same model with the same XML file, it is working and when I am trying to run the system with the same XML and Model on Matlab, I am getting the error as mentioned above.

To Clarify the problem's potential source:

1) I added some bodies to the original model and some weld joints,
2) When I am using the original model, this code is working,
3) I added the bodies and joints by editing model.osim file,

Code: Select all


clc; clear; close all
import org.opensim.modeling.*

model = Model("Model.osim");
actSet = model.getActuators;
probes = model.getProbeSet;
model.initSystem();
cmc = CMCTool('Setting.xml');
           resdir ='Dir'
           cmc.setResultsDir(resdir);
           cmc.run();
I would appreciate if someone can help to fix the issue as soon as possible.
Many Thanks.

Re: Running CMC in MATLAB Error

Posted: Wed Mar 13, 2019 5:01 am
by jimmy
in your 'Settings.xml' file, there is a path to '../CMC/3DGaitModelwithSimpleArms_states.sto'. This path is incorrect and CMC can't find the file. You will need to change the path to the file.

Re: Running CMC in MATLAB Error

Posted: Wed Mar 13, 2019 5:43 am
by alik

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<OpenSimDocument Version="40000">
	<CMCTool name="Model">
		<!--Name of the .osim file used to construct a model.-->
		<model_file>../../Model.osim</model_file>
		<!--Replace the model's force set with sets specified in <force_set_files>? If false, the force set is appended to.-->
		<replace_force_set>false</replace_force_set>
		<!--List of xml files used to construct a force set for the model.-->
		<force_set_files> ../gait2392_CMC_Actuators.xml</force_set_files>
		<!--Directory used for writing results.-->
		<results_directory>results_directory</results_directory>
		<!--Output precision.  It is 8 by default.-->
		<output_precision>8</output_precision>
		<!--Initial time for the simulation.-->
		<initial_time>0.22900000000000001</initial_time>
		<!--Final time for the simulation.-->
		<final_time>0.96099999999999997</final_time>
		<!--Flag indicating whether or not to compute equilibrium values for states other than the coordinates or speeds.  For example, equilibrium muscle fiber lengths or muscle forces.-->
		<solve_for_equilibrium_for_auxiliary_states>true</solve_for_equilibrium_for_auxiliary_states>
		<!--Maximum number of integrator steps.-->
		<maximum_number_of_integrator_steps>30000</maximum_number_of_integrator_steps>
		<!--Maximum integration step size.-->
		<maximum_integrator_step_size>1</maximum_integrator_step_size>
		<!--Minimum integration step size.-->
		<minimum_integrator_step_size>1e-08</minimum_integrator_step_size>
		<!--Integrator error tolerance. When the error is greater, the integrator step size is decreased.-->
		<integrator_error_tolerance>1.0000000000000001e-05</integrator_error_tolerance>
		<!--Set of analyses to be run during the investigation.-->
		<AnalysisSet name="Analyses">
			<objects />
			<groups />
		</AnalysisSet>
		<!--Controller objects in the model.-->
		<ControllerSet name="Controllers">
			<objects />
			<groups />
		</ControllerSet>
		<!--XML file (.xml) containing the forces applied to the model as ExternalLoads.-->
		<external_loads_file>subject01_Run_20002_cycle1_GRF_v240.xml</external_loads_file>
		<!--List of individual Actuators by individual or user-defined group name  to be excluded from CMC's control.-->
		<actuators_to_exclude />
		<!--Motion (.mot) or storage (.sto) file containing the desired point trajectories.-->
		<desired_points_file />
		<!--Motion (.mot) or storage (.sto) file containing the desired kinematic trajectories.-->
		<desired_kinematics_file>subject01_Run_20002_cycle1_Kinematics_q.sto</desired_kinematics_file>
		<!--File containing the tracking tasks. Which coordinates are tracked and with what weights are specified here.-->
		<task_set_file>../gait2392_CMC_Tasks.xml</task_set_file>
		<!--File containing the constraints on the controls.-->
		<constraints_file>subject01_Run_20002_cycle1_ControlConstraints.xml</constraints_file>
		<!--File containing the controls output by RRA. These can be used to place constraints on the residuals during CMC.-->
		<rra_controls_file />
		<!--Low-pass cut-off frequency for filtering the desired kinematics. A negative value results in no filtering. The default value is -1.0, so no filtering.-->
		<lowpass_cutoff_frequency>-1</lowpass_cutoff_frequency>
		<!--Time window over which the desired actuator forces are achieved. Muscles forces cannot change instantaneously, so a finite time window must be allowed. The recommended time window for RRA is about 0.001 sec, and for CMC is about 0.010 sec.-->
		<cmc_time_window>0.01</cmc_time_window>
		<!--Flag (true or false) indicating whether to use the fast CMC optimization target. The fast target requires the desired accelerations to be met. The optimizer fails if the accelerations constraints cannot be met, so the fast target can be less robust.  The regular target does not require the acceleration constraints to be met; it meets them as well as it can, but it is slower and less accurate.-->
		<use_fast_optimization_target>true</use_fast_optimization_target>
		<!--Preferred optimizer algorithm (currently support "ipopt" or "cfsqp", the latter requiring the osimCFSQP library.-->
		<optimizer_algorithm>cfsqp</optimizer_algorithm>
		<!--Step size used by the optimizer to compute numerical derivatives. A value between 1.0e-4 and 1.0e-8 is usually appropriate.-->
		<numerical_derivative_step_size>0.0001</numerical_derivative_step_size>
		<!--Convergence tolerance for the optimizer. The smaller this value, the deeper the convergence. Decreasing this number can improve a solution, but will also likely increase computation time.-->
		<optimization_convergence_tolerance>0.0001</optimization_convergence_tolerance>
		<!--Maximum number of iterations for the optimizer.-->
		<optimizer_max_iterations>1000</optimizer_max_iterations>
		<!--Print level for the optimizer, 0 - 3. 0=no printing, 3=detailed printing, 2=in between-->
		<optimizer_print_level>0</optimizer_print_level>
		<!--True-false flag indicating whether or not to turn on verbose printing for cmc.-->
		<use_verbose_printing>false</use_verbose_printing>
	</CMCTool>
</OpenSimDocument>

So this is the XML file that I am using for running CMC, When I am running it on GUI, it is working but it is not working on the MATLAB. I could not find the state setting in this XML file.

Furthermore, when I am running CMC, it is supposed to generate the state file at the first iterations which was not in my simulations.

I would be grateful if you can make more clarifications on this issue to find out the problem possible sources.

Re: Running CMC in MATLAB Error

Posted: Wed Mar 13, 2019 2:50 pm
by alik
Many Thanks from the Dr James Dunne for his precious time.

I am writing for anyone who may face this problem to solve their problems.
So, as Dr. James said to me, The GUI manages some file path for you that the API doesn't.

ANY SMALL TYPO, any wrong directory can cause this issue.

My suggestion is checking directory and name of folders one by one.
It will fix the problem.