Page 1 of 1

Matlab crashes after running ForwardTool

Posted: Fri Aug 10, 2018 12:13 am
by roja
Hi all,

I am trying to run ForwardTool in the Matlab. All of my codes was working perfectly yesterday and the codes were able to save analysis results in .sto file. But today I encountered a problem. When I am running Matlab codes, Matlab crashes and gives me this error:
"Matlab has encountered an internal problem and needs to close". I checked err.log and out.log. err.log was blank and there was no error or warning in out.log. I saw Forum topic 7978 (viewtopicPhpbb.php?f=91&t=7978). One hypothesis was that Matlab script expecting the output immediately after calling iktool.run (in my case ForwardTool.run) and because it does not have enough time it runs into this problem. To solve this issue, I used pause() function to give some time in order to generate the output. But it still does not work. I don't know what is the problem. Below are my codes to get a better idea of what's going on.

Code: Select all

import org.opensim.modeling.*;
model = Model('arm26.osim');
state = model.initSystem;
muscles= model.getMuscles();
nMuscles = muscles.getSize();
Activation         = [0.05, 0.05, 0.05, 0.05, 0.05, 0.05];
maxIsometricForce  = [798.52, 624.3, 624.3, 624.3, 435.56, 987.26];
optimalFiberLength = [0.134, 0.1134, 0.1138, 0.1157, 0.1321, 0.0858];
tendonSlackLength  = [0.134, 0.098, 0.0908, 0.2723, 0.1923, 0.0535];
pennationAngle 	   = [0.20943951, 0.15707963, 0.15707963, 0, 0, 0];

for i = 0:nMuscles-1
	muscles.get(i).setActivation(state, Activation(i+1));
    muscles.get(i).setMaxIsometricForce(maxIsometricForce(i+1));
    muscles.get(i).setOptimalFiberLength(optimalFiberLength(i+1));
    muscles.get(i).setTendonSlackLength(tendonSlackLength(i+1));
    muscles.get(i).setPennationAngleAtOptimalFiberLength(pennationAngle(i+1));
end

%Setting up the controller
initialTime = 0.0;
finalTime = 3.0;

muscleController = PrescribedController();
muscleController.setName('Constant Controller');
muscleController.setActuators(model.updActuators());

Excitation1=0.1;
Excitation2=0.1;
Excitation3=0.1;
Excitation4=0.1;
Excitation5=0.1;
Excitation6=0.1;

muscleController.prescribeControlForActuator('TRIlong', Constant(Excitation1));
muscleController.prescribeControlForActuator('TRIlat', Constant(Excitation2));
muscleController.prescribeControlForActuator('TRImed', Constant(Excitation3));
muscleController.prescribeControlForActuator('BIClong', Constant(Excitation4));
muscleController.prescribeControlForActuator('BICshort', Constant(Excitation5));
muscleController.prescribeControlForActuator('BRA', Constant(Excitation6));

model.addController(muscleController);
model.disownAllComponents();
model.print('arm26_controller.osim');

osimModel = Model('arm26_controller.osim');
osimModel.setUseVisualizer(true);
state=osimModel.initSystem;

tool = ForwardTool(); 
tool.setModel(osimModel);
tool.setStartTime(0);
tool.setFinalTime(2);
tool.setSolveForEquilibrium(true);

Muscle_AnL = MuscleAnalysis('arm26_controller.osim');
KinMtic=Kinematics('arm26_controller.osim');
PnT_KinMtic=PointKinematics('arm26_controller.osim');
Actu=Actuation('arm26_controller.osim');
BdY_KinMtic=BodyKinematics('arm26_controller.osim');
Joint_React=JointReaction('arm26_controller.osim');
InduCd_Acc=InducedAccelerations('arm26_controller.osim');
Force_RporT=ForceReporter('arm26_controller.osim');

osimModel.addAnalysis(Muscle_AnL);
osimModel.addAnalysis(KinMtic);
osimModel.addAnalysis(PnT_KinMtic);
osimModel.addAnalysis(Actu);
osimModel.addAnalysis(BdY_KinMtic);
osimModel.addAnalysis(Joint_React);
osimModel.addAnalysis(InduCd_Acc);
osimModel.addAnalysis(Force_RporT);

tool.setName('FORWARD_ARM26_RESULT');
% Run the simulation
tool.run(); 
pause(5);


I have OpenSim 3.3, Matlab 2014b, Windows 8.1, 64 bit everything.
I will appreciate if anybody can help me to solve this issue and get my codes work again.

RoZi

Re: Matlab crashes after running ForwardTool

Posted: Fri Aug 10, 2018 1:54 am
by tkuchida
All of my codes was working perfectly yesterday and the codes were able to save analysis results in .sto file. But today I encountered a problem.
Which lines did you add between when it was working yesterday and when it stopped working today? Another issue appears to be that you're creating the underlying computational system on line 3, setting values in the State on line 13, and then creating a new State on line 48; the changes you made on line 13 will have no effect on your simulation.

Re: Matlab crashes after running ForwardTool

Posted: Fri Aug 10, 2018 9:45 am
by roja
Which lines did you add between when it was working yesterday and when it stopped working today?
I didn't add or remove anything in the codes, I mean both codes are exactly the same (before getting an error and after getting an error).
I removed lines 13 and the loop, but still getting the error.
I have noticed that after removing "point kinematic" analysis and deactivating visualizer, codes generating results in .sto file for the rest of analysis. but if I add visualizer line in my codes, even without having "Point Kinematics" among analysis, Matlab crashes. I took a look at results when there were not any issues and I have noticed that the .sto file generated for "Point Kinematic" results was NONAME --> " FORWARD_ARM26_RESULT_PointKinematics_NONAME_acc" and all data was zero in the file.
Do you have any idea?? Is there any problem with my graphic card? Why it can not generate "Kinematic Point" result and it going to crash when I add this analysis in my codes?

Thanks,

Re: Matlab crashes after running ForwardTool

Posted: Fri Aug 10, 2018 10:09 pm
by tkuchida
I didn't add or remove anything in the codes, I mean both codes are exactly the same (before getting an error and after getting an error).
If you booted your computer, ran your MATLAB code, restarted, and ran the same MATLAB code, then I would expect the behavior to be the same.
Why it can not generate "Kinematic Point" result and it going to crash when I add this analysis in my codes?
The line in your code is

Code: Select all

PnT_KinMtic=PointKinematics('arm26_controller.osim');
which is incorrect (this constructor would be used if you saved the Analysis configuration to XML). I think you want to call

Code: Select all

PnT_KinMtic=PointKinematics(model);

Re: Matlab crashes after running ForwardTool

Posted: Thu Jul 18, 2019 12:13 am
by narakrish
Hello,

I am facing the same issue. I am using the following code.

Code: Select all

import org.opensim.modeling.*
model = Model('healthy_subject1_scaled_RRA_adjusted.osim');
ft = ForwardTool('fwd_settings_new.xml'); %changed final_time to 0.05
ft.setModel(model);
ft.setInitialTime(1.19);
ft.setFinalTime(1.2);
When I evaluate the code line by line, I see that matlab crashes at line 3, on the settings file. I have created this settings file from the GUI and works fine from the GUI. However, when I try to run from matlab, matlab crashes, saying there was an internal error. Could someone please help as to what is wrong with my settings file? It is a very urgent issue. Thanks a lot for your time.I am attaching the settings file.

Re: Matlab crashes after running ForwardTool

Posted: Thu Jul 18, 2019 12:31 am
by tkuchida
I would try replacing

Code: Select all

<model_file />
on line 5 of "fwd_settings_new.xml" with

Code: Select all

<model_file>healthy_subject1_scaled_RRA_adjusted.osim</model_file>

Re: Matlab crashes after running ForwardTool

Posted: Mon Jul 22, 2019 12:14 pm
by narakrish
Hello,

Thank you. I had resolved it the same way :).

Thanks,