opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
797 stars 320 forks source link

RuntimeError: std::exception in 'SimTK::State & OpenSim::Model::initSystem() #1716

Closed nikorose87 closed 7 years ago

nikorose87 commented 7 years ago

Hi

The week before I had to rebuild Opensim from source. Now, checking some algorithms the next error is shown:

CustomJoint 'ankle_r' has collinear axes and are not well-defined. Please fix and retry loading.

This error is presented after doing scaling and before initiate IK. Precisely, in the InitSystem() of the model.

I don't know how this error appeared if last week my algorithms run well. Thank you

chrisdembia commented 7 years ago

Do you know which commit you were using previously (and which commit now causes the error)?

nikorose87 commented 7 years ago

I don't know which Opensim version I was using but I built it one month ago more or less. Now I have one built on last Friday.

chrisdembia commented 7 years ago

Thank you for reporting. Could you submit a minimal OSIM file that produces this error? You could attach it to this PR as a zip.

Do you indeed have two collinear axes in your CustomJoint?

nikorose87 commented 7 years ago

Well, basically I could. However, I work with models 2354 and 2392 to compare my own models. So you could try with those models. I attached the models just to see if something was changed in the API, nevertheless I checked in the GUI and everything seems to be ok. OpensimModels.tar.gz

nikorose87 commented 7 years ago

The error appear with any gait model, this is to say, models modified by 2392 and 2354 models

chrisdembia commented 7 years ago

Thank you for the files and additional information.

nikorose87 commented 7 years ago

Do you indeed have two collinear axes in your CustomJoint?

No sir, I have the three translation and rotations. Regards.

chrisdembia commented 7 years ago

@nikorose87 I was not able to reproduce this bug with the models you provided. It seems that you provided the generic models from the OpenSim distribution, but that the error occurred with a scaled model. Please upload files that you are sure reproduce the bug (this might involve sending over any MATLAB/Python scripts you're using).

nikorose87 commented 7 years ago

@chrisdembia I'm attaching the scaled model and part of the code done to scale this model

## Scaling, IK, ID and RRA
#Setting markers to model

Newmarkers = osim.MarkerSet(model,Dir+'/gait2354_Scale_MarkerSet.xml')
mystate = model.initSystem()
model.replaceMarkerSet(mystate,Newmarkers)

##Scaling
scaletool = osim.ScaleTool(Dir+'/subject01_Setup_Scale.xml')
scaletool.getModelScaler().setOutputModelFileName(scalemodel)
path2sub = scaletool.getPathToSubject()
scaletool.getModelScaler().processModel(model,path2sub)

##IK
#Loading scale model into a new model
model = osim.Model(Dir+'/'+scalemodel)
mystate = model.initSystem()
## Inverse Kinematics
iktool = osim.InverseKinematicsTool(Dir+'/subject01_Setup_IK.xml')
iktool.setModel(model)
iktool.setOutputMotionFileName("IK2354APIresults.sto")
iktool.run()
mystate = model.initSystem()

Gait2354_Simbody.tar.gz

Thanks for all.

chrisdembia commented 7 years ago

I was able to reproduce the CustomJoint exception with the following code:

import opensim
m = opensim.Model('subject01_simbody_adjustedAPI.osim')
m.initSystem()

The issue is that the model file has commas where periods are expected:

                        <TransformAxis name="rotation1">
                            <!--Names of the coordinates that serve as the independent variables         of the transform function.-->
                            <coordinates>subtalar_angle_r</coordinates>
                            <!--Rotation or translation axis for the transform.-->
                            <axis>0,78717961000000003 0,60474746000000001 -0,12094949000000001</axis>
                            <!--Transform function of the generalized coordinates used to        represent the amount of displacement along a specified axis.-->
                            <LinearFunction name="function">
                                <coefficients> 1 0</coefficients>
                            </LinearFunction>
                        </TransformAxis>

This is probably related to your "locale" settings. Perhaps, in the past month, you changed some system-wide settings for whether your computer uses periods or commas for decimals? I have limited ability to test this on my computer, since my computer does not produce commas in place of periods.

chrisdembia commented 7 years ago

@nikorose87 it would be helpful if you could explain any settings you may have altered that could have caused the use of commas.

To force the serialization of properties to use periods, we could alter locale settings in the property serialization code (http://stackoverflow.com/questions/15220861/how-can-i-set-the-comma-to-be-a-decimal-point) (untested):

std::cout.imbue(std::locale(std::cout.getloc(), new std::numpunct<char>());
aymanhab commented 7 years ago

Thanks for the investigation @chrisdembia The application/GUI assumes the use of locale=US since that's what's used when we create the model/setup/data files. It would be more portable (and easier to share with co-authors/community) if everybody used the same US locale.

chrisdembia commented 7 years ago

Thanks Ayman. Does the GUI set any settings explicitly? It's not clear to me if we should explicitly force the OpenSim libraries to use locale=US, or if we should just expect users to set operating system options accordingly (I'm not even sure how the operating system settings work).

nikorose87 commented 7 years ago

Well. Thanks to all for the solution. I just changed the "locale" configuration and Inertia also the scaling process were solved. However, another error was shown but I will present in another issue.

Regards.

chrisdembia commented 7 years ago

Thanks @nikorose87 . Could you explain how you changed the "locale" configuration? Such information would be useful for us to better understand this issue, and perhaps help other users avoid similar situations.

aymanhab commented 7 years ago

Just to clear up @chrisdembia The GUI uses locale mainly because it can be translated to different languages. We generally do not parse xml files on the GUI side so locale doesn't matter for that. The reason we switched to explicit specification of locale was so that preferences (e.g. sizes of muscles etc.) are stored as strings and parsed and if using wrong locale we used to end up with big-red sphere engulfing the model. The local specification is a command line argument on the opensim.conf file.

chrisdembia commented 7 years ago

Okay thanks for the helpful explanation.

nikorose87 commented 7 years ago

Of course! Well, probably my linux distro had configured the locale settings in US_format before. Now, after booting my system is likely linux set the NUMERIC locale to the place where you live. So, checking the locale config I had my native country configuration in numeric and consequently I just changed the file in: /etc/default/locale.

chrisdembia commented 7 years ago

Ah okay, thank you. I hope it is okay for you to use the US locale.