MATLAB crashes while creating .osim model with API

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Anne Koelewijn
Posts: 14
Joined: Tue Aug 26, 2014 6:42 am

MATLAB crashes while creating .osim model with API

Post by Anne Koelewijn » Thu Nov 16, 2017 9:30 am

Hi,

I created a MATLAB function to write an .osim file with scaled mass/length parameters from an existing .osim file. This function makes MATLAB crash. Sometimes it will work once or twice, but eventually MATLAB will crash.

I've included the log file of a crash, and also the MATLAB function that I use. It's a .txt file because I could not attach .m files. I use 32-bit MATLAB R2015b and Opensim 3.3 on a 64-bit computer. Could you tell me why the function makes MATLAB crash?

Thanks,
Anne
Attachments
createRandomOpenSimPerson_random.txt
(2.32 KiB) Downloaded 44 times
hs_error_pid1428.log
(34.02 KiB) Downloaded 25 times

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

Re: MATLAB crashes while creating .osim model with API

Post by Thomas Uchida » Thu Nov 16, 2017 1:30 pm

Not sure this is the only problem, but there seems to be a logical inconsistency at lines 35 and 39. It looks like you want to choose random polynomials of degree 4 for your splines, but these random coefficients should be chosen outside the for loop; if chosen inside the loop, you are essentially assigning random y values which may cause issues downstream. You might try replacing rand() with arbitrary but fixed numbers to rule out any memory-related issues associated with running the script repeatedly, then perhaps try plotting the random (x,y) points you are using to define the splines when the script crashes.

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: MATLAB crashes while creating .osim model with API

Post by Christopher Dembia » Thu Nov 16, 2017 1:32 pm

Tom has a good point about the random points; I'm not sure if addPoint() supports adding points out of order.

Here are a few additional suggestions:

1. When editing items in a set, use `updBodySet()`, etc. instead of `getBodySet()`. Similarly, `getSpatialTransform()` should be `updSpatialTransform()`.

2. Line 24 should be `joint = model.updJointSet().get(iJnt);` and you should not overwrite the joint in line 48; you are modifying the one that's already in the model.

3. Line 56: When accessing a specific joint, access it by name, not by index. For example, `model.getJointSet().get('hip')`.

I suspect that the presence of line 48 is causing the crash. If that's not it, then it's likely the `setFunction()` calls in line 46-47. Try commenting out those lines and see if that avoids the crash. If so, then try using `setFunction(spline1.clone())`.

User avatar
Anne Koelewijn
Posts: 14
Joined: Tue Aug 26, 2014 6:42 am

Re: MATLAB crashes while creating .osim model with API

Post by Anne Koelewijn » Fri Nov 17, 2017 8:15 am

Thanks for the help! These three suggestions, and using setFunction(spline1.clone()) solved the problem. I checked if the random order of the numbers in the spline is a problem, but it is not.

POST REPLY