Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimTK Execption - Inertial Matrix Triangle Inequality Bug #3941

Closed
alexbeattie42 opened this issue Oct 15, 2024 · 12 comments · Fixed by opensim-org/opensim-models#183 or #3980
Closed
Assignees

Comments

@alexbeattie42
Copy link
Contributor

Problem

When running the opensim example for the IMU-IK solver ("opensense") the following exception is thrown:

what(): SimTK Exception thrown at MassProperties.h:542: Error detected by Simbody method Inertia::operator-=(): Diagonals of an Inertia matrix must satisfy the triangle inequality; got 0.000105365,0.00021073,0.00105365. (Required condition 'Ixx+Iyy+Slop>=Izz && Ixx+Izz+Slop>=Iyy && Iyy+Izz+Slop>=Ixx' was not met.)

Reproduction

I have created a minimum reproduction of the issue here.

Solution

I'm unsure if the warning is correct and the provided example is wrong or the example is correct and the warning is wrong. Once that is established a solution can be determined.

Notes

  • It seems the error is coming from this file. According to the git blame, that line was last modified 10 years ago by @chrisdembia

  • @ksomml has encountered this same issue here

@nickbianco nickbianco self-assigned this Oct 15, 2024
@nickbianco
Copy link
Member

This looks to me to not necessarily be a bug in the code, but rather an issue with the mass properties in the model. But I wouldn't expect such an error running the example out-of-the-box like this. @alexbeattie42, perhaps run the example through a debugger so we can take a look at a stack trace?

@alexbeattie42
Copy link
Contributor Author

Sure thing. @nickbianco Here's the full backtrace from gdb:

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007fffec4a5463 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:78
#2  0x00007fffec44c120 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007fffec4334c3 in __GI_abort () at abort.c:79
#4  0x00007fffebc97b2c in __gnu_cxx::__verbose_terminate_handler () at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#5  0x00007fffebcadf3a in __cxxabiv1::__terminate (handler=<optimized out>)
    at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#6  0x00007fffebc9752a in std::terminate () at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#7  0x00007fffebcae1f6 in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x555555597f00 <typeinfo for SimTK::Exception::ErrorCheck>, 
    dest=0x555555571440 <SimTK::Exception::ErrorCheck::~ErrorCheck()>) at /usr/src/debug/gcc/gcc/libstdc++-v3/libsupc++/eh_throw.cc:98
#8  0x00007ffff5871e17 in SimTK::Inertia_<double>::errChk(char const*) const ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#9  0x00007ffff5a4de95 in SimTK::Inertia_<double>::operator-=(SimTK::Inertia_<double> const&) ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#10 0x00007ffff5b28f3c in SimTK::Inertia_<double> SimTK::operator-<double>(SimTK::Inertia_<double> const&, SimTK::Inertia_<double> const&) ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#11 0x00007ffff5b2871c in SimTK::MassProperties_<double>::calcCentralInertia() const ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#12 0x00007ffff5a503a0 in RigidBodyNode::RigidBodyNode(SimTK::MassProperties_<double> const&, SimTK::Transform_<double> const&, SimTK::Transform_<double> const&, RigidBodyNode::QDotHandling, RigidBodyNode::QuaternionUse, bool) ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#13 0x00007ffff5bc0204 in ImmobileRigidBodyNode::ImmobileRigidBodyNode(SimTK::MassProperties_<double> const&, SimTK::Transform_<double> const&, SimTK::Transform_<double> const&, SimTK::UIndex const&, SimTK::USquaredIndex const&, SimTK::QIndex const&) ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#14 0x00007ffff5bc2057 in RBNodeWeld::RBNodeWeld(SimTK::MassProperties_<double> const&, SimTK::Transform_<double> const&, SimTK::Transform_<double> const&, SimTK::UIndex const&, SimTK::USquaredIndex const&, SimTK::QIndex const&) ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#15 0x00007ffff5bbfa64 in SimTK::MobilizedBody::WeldImpl::createRigidBodyNode(SimTK::UIndex&, SimTK::USquaredIndex&, SimTK::QIndex&) const ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#16 0x00007ffff59dd4ce in SimTK::MobilizedBodyImpl::realizeTopology(SimTK::State&, SimTK::UIndex&, SimTK::USquaredIndex&, SimTK::QIndex&) const () from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#17 0x00007ffff5befa3a in SimbodyMatterSubsystemRep::endConstruction(SimTK::State&) ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#18 0x00007ffff5bf0022 in SimbodyMatterSubsystemRep::realizeSubsystemTopologyImpl(SimTK::State&) const ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#19 0x00007ffff48e500e in SimTK::Subsystem::Guts::realizeSubsystemTopology(SimTK::State&) const ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKcommon.so.3.8
#20 0x00007ffff5a1e755 in SimTK::MultibodySystemRep::realizeTopologyImpl(SimTK::State&) const ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKsimbody.so.3.8
#21 0x00007ffff48eb981 in SimTK::System::Guts::realizeTopology() const ()
   from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKcommon.so.3.8
#22 0x00007ffff48ea9d0 in SimTK::System::realizeTopology() const () from /home/alexbeat/opensim-core/sdk/Simbody/lib/libSimTKcommon.so.3.8
#23 0x00007ffff6b80edd in OpenSim::Model::initializeState (this=this@entry=0x5555558ce1c0)
    at /home/alexbeat/opensim-workspace/opensim-core-source/OpenSim/Simulation/Model/Model.cpp:529
#24 0x00007ffff6d3e18f in OpenSim::Model::initSystem (this=0x5555558ce1c0)
--Type <RET> for more, q to quit, c to continue without paging--c
    at /home/alexbeat/opensim-workspace/opensim-core-source/OpenSim/Simulation/Model/Model.h:404
#25 OpenSim::IMUPlacer::run (this=0x7fffffffafb0, visualizeResults=false)
    at /home/alexbeat/opensim-workspace/opensim-core-source/OpenSim/Simulation/OpenSense/IMUPlacer.cpp:106
#26 0x000055555556c6a2 in main ()

@nickbianco
Copy link
Member

Okay, the exception occurs after this initSystem call inside IMUPlacer::run(). The model is loaded in a few lines before without any modifications, so it does seem to be an issue with the model file. You could try loading the model separately from IMUPlacer and calling initSystem to confirm. The next thing to do is figure out what part of the model is causing the error.

The following line from the stack trace suggests that it has something to do with a body in the model associated with a WeldJoint:

#15 0x00007ffff5bbfa64 in SimTK::MobilizedBody::WeldImpl::createRigidBodyNode(SimTK::UIndex&, SimTK::USquaredIndex&, SimTK::QIndex&) const ()

The following joints in the model from the example data are welded: "mtp_l", "mtp_r", "subtalar_l", "subtalar_r", "radius_hand_l", and "radius_hand_r".

@alexbeattie42
Copy link
Contributor Author

Following up on this issue, none of the Rajagopal models (or any variant of them) load in the GUI for me. I have tested other models which do load and work properly (like subject07 or gait2329). This leads me to believe there is a problem with the Rajagopal models and the latest version of OpenSim.

@nickbianco
Copy link
Member

@alexbeattie42, is the issue with Rajagopal models not loading related to this issue somehow? If not, could you open a separate issue on https://github.com/opensim-org/opensim-gui, or another one here if you think it is specific to the API?

@alexbeattie42
Copy link
Contributor Author

@nickbianco The reason this is related to the Rajagopal model is because the reproduction of this issue only occurs when using the Rajagopal model. I can use the exact same code (in the reproduction) with the other models and it works without error. So changing the model fixes the problem which leads me to believe that it is a problem with the model (or how it is being used/interpreted).

@aymanhab aymanhab self-assigned this Nov 26, 2024
@aymanhab
Copy link
Member

@alexbeattie42 Is this a distributed GUI (e.g. 4.5) or your own built GUI? If the latter it could be a problem introduced after 4.5 was released last year. The GUI doesn't do anything special, just initSystem after constructing the model from the file, so very likely this is an API issue. Just need clarification to investigate. Thank you

@nickbianco nickbianco removed their assignment Nov 26, 2024
@alexbeattie42
Copy link
Contributor Author

alexbeattie42 commented Nov 27, 2024

@aymanhab This is on my custom build version of core and a GUI build based on that (so not the 4.5 release). It is my suspicion that it is not a problem with the GUI and with core as you mention but I don't have a way to test that. I'm also now noticing that for the x, y, z values in the error messages the final value is one order of magnitude larger than the prior two. So adding a decimal zero would allow the constraints to be satisfied.

This makes me think there is a math/multiplication implementation difference in a system math library (or something like that) but I'm not sure how to find where or why.

@alexbeattie42
Copy link
Contributor Author

@nickbianco I searched in the model file and found the reference values were provided in the file. I was able to fix the issue by modifying the 2 problematic weld joints in the model.

@aymanhab I have also tested the fixed model in the GUI and once the weld joints are corrected the model loads and displays without issue.

@aymanhab
Copy link
Member

Thanks @alexbeattie42 that's totally understandable. I don't think anybody is relying on these numbers be accurate to that number of digits so please open a PR on the opensim-models repo where the models are maintained and will merge it for future releases. Thanks for the find 👍

One more note, are you using a debug build? it's possible we had this assertion failing for a while but it was being ignored because releases are done in "release" mode. Just trying to figure out why this broke or what changed since 4.5. Thanks again.

@alexbeattie42
Copy link
Contributor Author

I will open a PR in that repo soon. There are also some copies of that model in this repository (ex. here). Should those also be updated?

I am currently building with --config Release

@aymanhab
Copy link
Member

Sure, let's update them all. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants