Matlab crashes after running ForwardTool

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
RoZi A
Posts: 13
Joined: Sat Feb 06, 2016 10:04 pm

Matlab crashes after running ForwardTool

Post by RoZi A » Fri Aug 10, 2018 12:13 am

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

User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: Matlab crashes after running ForwardTool

Post by Thomas Uchida » Fri Aug 10, 2018 1:54 am

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.

User avatar
RoZi A
Posts: 13
Joined: Sat Feb 06, 2016 10:04 pm

Re: Matlab crashes after running ForwardTool

Post by RoZi A » Fri Aug 10, 2018 9:45 am

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,

User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: Matlab crashes after running ForwardTool

Post by Thomas Uchida » Fri Aug 10, 2018 10:09 pm

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);

User avatar
suparna dey
Posts: 14
Joined: Fri Feb 01, 2019 5:39 am

Re: Matlab crashes after running ForwardTool

Post by suparna dey » Thu Jul 18, 2019 12:13 am

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.
Attachments
fwd_settings_new.xml
(3.73 KiB) Downloaded 20 times

User avatar
Thomas Uchida
Posts: 1792
Joined: Wed May 16, 2012 11:40 am

Re: Matlab crashes after running ForwardTool

Post by Thomas Uchida » Thu Jul 18, 2019 12:31 am

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>

User avatar
suparna dey
Posts: 14
Joined: Fri Feb 01, 2019 5:39 am

Re: Matlab crashes after running ForwardTool

Post by suparna dey » Mon Jul 22, 2019 12:14 pm

Hello,

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

Thanks,

POST REPLY