Running Static Optimization in Matlab?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Jack Zhao
Posts: 94
Joined: Thu Jul 24, 2014 7:15 am

Re: Running Static Optimization in Matlab?

Post by Jack Zhao » Sat Feb 24, 2018 3:49 am

edwards9 wrote:When attemping static optimization from matlab using the AnalyzeTool approach described above I get the following error message:

analyzeTool.verifyControlsStates: ERROR- a storage object containing the time histories of states was not specified. at org.opensim.modeling.opensimModelJNI.AnalyzeTool_run__SWIG_0(Native Method) at org.opensim.modeling.AnalyzeTool.run(AnalyzeTool.java:154Error using AleenBatch_IK_ID_Opensim (line 127) Java exception occurred: java.io.IOException: analyzeTool.verifyControlsStates: ERROR- a storage object containing the time histories of states was not specified

Any ideas how to deal with this error?

Thanks,

Brent
Dear William:
I have the same issue and have you solved the problem ? It would be highly appreciated if you have solved it and inform us.

Best regards
Jack

User avatar
z imn
Posts: 35
Joined: Sun Sep 17, 2017 7:11 am

Re: Running Static Optimization in Matlab?

Post by z imn » Thu Apr 12, 2018 11:52 pm

does anyone solves this error?
i have the same error...
please help me for solving this
thanks

User avatar
Josh Baxter
Posts: 29
Joined: Fri Mar 11, 2016 12:29 pm

Re: Running Static Optimization in Matlab?

Post by Josh Baxter » Fri Apr 13, 2018 12:15 pm

can you share an example of the setup xml? Does the file have an absolute path? does the path have any space characters (i've found this to cause problems).

User avatar
z imn
Posts: 35
Joined: Sun Sep 17, 2017 7:11 am

Re: Running Static Optimization in Matlab?

Post by z imn » Sat Apr 14, 2018 12:38 am

thank you dear josh for your response
this is my so setup file.

<?xml version="1.0" encoding="UTF-8" ?>
<OpenSimDocument Version="30000">
<AnalyzeTool>
<!--Name of the .osim file used to construct a model.-->
<model_file>scaled_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 an force set for the model.-->
<force_set_files> cmc_actuators_2.xml</force_set_files>
<!--Directory used for writing results.-->
<results_directory>E:\phd_mechanic\API\API_modeling\complete\so</results_directory>
<!--Output precision. It is 8 by default.-->
<output_precision>8</output_precision>
<!--Initial time for the simulation.-->
<initial_time>6.57</initial_time>
<!--Final time for the simulation.-->
<final_time>8.25</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>20000</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-008</minimum_integrator_step_size>
<!--Integrator error tolerance. When the error is greater, the integrator step size is decreased.-->
<integrator_error_tolerance>1e-005</integrator_error_tolerance>
<!--Set of analyses to be run during the investigation.-->
<AnalysisSet name="Analyses">
<objects>
<StaticOptimization name="StaticOptimization">
<!--Flag (true or false) specifying whether whether on. True by default.-->
<on>true</on>
<!--Start time.-->
<start_time>6.57</start_time>
<!--End time.-->
<end_time>8.25</end_time>
<!--Specifies how often to store results during a simulation. More specifically, the interval (a positive integer) specifies how many successful integration steps should be taken before results are recorded again.-->
<step_interval>1</step_interval>
<!--Flag (true or false) indicating whether the results are in degrees or not.-->
<in_degrees>true</in_degrees>
<!--If true, the model's own force set will be used in the static optimization computation. Otherwise, inverse dynamics for coordinate actuators will be computed for all unconstrained degrees of freedom.-->
<use_model_force_set>true</use_model_force_set>
<!--A double indicating the exponent to raise activations to when solving static optimization. -->
<activation_exponent>2</activation_exponent>
<!--If true muscle force-length curve is observed while running optimization.-->
<use_muscle_physiology>true</use_muscle_physiology>
<!--Value used to determine when the optimization solution has converged-->
<optimizer_convergence_criterion>0.0001</optimizer_convergence_criterion>
<!--An integer for setting the maximum number of iterations the optimizer can use at each time. -->
<optimizer_max_iterations>100</optimizer_max_iterations>
</StaticOptimization>
</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>el.xml</external_loads_file>
<!--Storage file (.sto) containing the time history of states for the model. This file often contains multiple rows of data, each row being a time-stamped array of states. The first column contains the time. The rest of the columns contain the states in the order appropriate for the model. In a storage file, unlike a motion file (.mot), non-uniform time spacing is allowed. If the user-specified initial time for a simulation does not correspond exactly to one of the time stamps in this file, inerpolation is NOT used because it is sometimes necessary to an exact set of states for analyses. Instead, the closest earlier set of states is used.-->
<states_file>a.mot</states_file>
<!--Motion file (.mot) or storage file (.sto) containing the time history of the generalized coordinates for the model. These can be specified in place of the states file.-->
<coordinates_file>E:\phd_mechanic\API\API_modeling\complete\ik\IKOutput_1.mot</coordinates_file>
<!--Storage file (.sto) containing the time history of the generalized speeds for the model. If coordinates_file is used in place of states_file, these can be optionally set as well to give the speeds. If not specified, speeds will be computed from coordinates by differentiation.-->
<speeds_file />
<!--Low-pass cut-off frequency for filtering the coordinates_file data (currently does not apply to states_file or speeds_file). A negative value results in no filtering. The default value is -1.0, so no filtering.-->
<lowpass_cutoff_frequency_for_coordinates>6</lowpass_cutoff_frequency_for_coordinates>
</AnalyzeTool>
</OpenSimDocument>

User avatar
Romain Martinez
Posts: 5
Joined: Thu Sep 15, 2016 6:33 am

Re: Running Static Optimization in Matlab?

Post by Romain Martinez » Tue May 08, 2018 12:08 pm

Same error here.

Code: Select all

RuntimeError: std::exception in 'bool OpenSim::AnalyzeTool::run()': analyzeTool.verifyControlsStates: ERROR- a storage object containing the time histories of states was not specified.
xml file:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<OpenSimDocument Version="30516">
	<AnalyzeTool name="wu_DapOF6H2_3">
		<!--Name of the .osim file used to construct a model.-->
		<model_file>/home/romain/Documents/codes/pyosim/Misc/project_sample/dapo/_models/wu_scaled_markers.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> /home/romain/Documents/codes/pyosim/Misc/project_sample/_templates/wu_actuators.xml</force_set_files>
		<!--Directory used for writing results.-->
		<results_directory>/home/romain/Documents/codes/pyosim/Misc/project_sample/dapo/3_static_optimization</results_directory>
		<!--Output precision.  It is 8 by default.-->
		<output_precision>8</output_precision>
		<!--Initial time for the simulation.-->
		<initial_time>1.3500000000000001</initial_time>
		<!--Final time for the simulation.-->
		<final_time>4.2599999999999998</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>false</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>
				<StaticOptimization name="StaticOptimization">
					<!--Flag (true or false) specifying whether on. True by default.-->
					<on>true</on>
					<!--Start time.-->
					<start_time>1.3500000000000001</start_time>
					<!--End time.-->
					<end_time>4.2599999999999998</end_time>
					<!--Specifies how often to store results during a simulation. More specifically, the interval (a positive integer) specifies how many successful integration steps should be taken before results are recorded again.-->
					<step_interval>5</step_interval>
					<!--Flag (true or false) indicating whether the results are in degrees or not.-->
					<in_degrees>true</in_degrees>
					<!--If true, the model's own force set will be used in the static optimization computation.  Otherwise, inverse dynamics for coordinate actuators will be computed for all unconstrained degrees of freedom.-->
					<use_model_force_set>true</use_model_force_set>
					<!--A double indicating the exponent to raise activations to when solving static optimization.  -->
					<activation_exponent>2</activation_exponent>
					<!--If true muscle force-length curve is observed while running optimization.-->
					<use_muscle_physiology>true</use_muscle_physiology>
					<!--Value used to determine when the optimization solution has converged-->
					<optimizer_convergence_criterion>0.0001</optimizer_convergence_criterion>
					<!--An integer for setting the maximum number of iterations the optimizer can use at each time.  -->
					<optimizer_max_iterations>10000</optimizer_max_iterations>
				</StaticOptimization>
			</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>temp.xml</external_loads_file>
		<!--Storage file (.sto) containing the time history of states for the model. This file often contains multiple rows of data, each row being a time-stamped array of states. The first column contains the time.  The rest of the columns contain the states in the order appropriate for the model. In a storage file, unlike a motion file (.mot), non-uniform time spacing is allowed.  If the user-specified initial time for a simulation does not correspond exactly to one of the time stamps in this file, interpolation is NOT used because it is sometimes necessary to use an exact set of states for analyses.  Instead, the closest earlier set of states is used.-->
		<states_file />
		<!--Motion file (.mot) or storage file (.sto) containing the time history of the generalized coordinates for the model. These can be specified in place of the states file.-->
		<coordinates_file>/home/romain/Documents/codes/pyosim/Misc/project_sample/dapo/1_inverse_kinematic/wu_DapOF6H2_3.mot</coordinates_file>
		<!--Storage file (.sto) containing the time history of the generalized speeds for the model. If coordinates_file is used in place of states_file, these can be optionally set as well to give the speeds. If not specified, speeds will be computed from coordinates by differentiation.-->
		<speeds_file />
		<!--Low-pass cut-off frequency for filtering the coordinates_file data (currently does not apply to states_file or speeds_file). A negative value results in no filtering. The default value is -1.0, so no filtering.-->
		<lowpass_cutoff_frequency_for_coordinates>5</lowpass_cutoff_frequency_for_coordinates>
	</AnalyzeTool>
</OpenSimDocument>

User avatar
Romain Martinez
Posts: 5
Joined: Thu Sep 15, 2016 6:33 am

Re: Running Static Optimization in Matlab?

Post by Romain Martinez » Tue May 08, 2018 12:40 pm

I just fixed my problem by using the setStatesFromMotion method from AnalyzeTool.

Code: Select all

model = osim.Model('wu_scaled_markers.osim')
motion = osim.Storage('wu_SarCF12H5_2.mot')
state = model.initSystem()
analyze_tool.setStatesFromMotion(state, motion, True)

POST REPLY