AddBiomechanics icon indicating copy to clipboard operation
AddBiomechanics copied to clipboard

Investigate mismatches between SKEL model distribution in nimblephysics and OpenSim

Open nickbianco opened this issue 1 year ago • 37 comments
trafficstars

Issue reported here: https://simtk.org/plugins/phpBB/viewtopicPhpbb.php?f=91&t=17422&p=48432

nickbianco avatar Feb 06 '24 18:02 nickbianco

Related, there seems to be an issue with visualizing an EllipsoidJoint in the GUI:

image

In the Simbody visualizer I get this:

image (1)

The latter image seems to confirm that there is indeed a mismatch between the nimblephysics and OpenSim EllipsoidJoint definitions.

nickbianco avatar Feb 07 '24 19:02 nickbianco

FYI @aymanhab, there might be a GUI issue related to EllipsoidJoint based on my comment above.

nickbianco avatar Feb 07 '24 19:02 nickbianco

This is the output returned when trying to load the model with the big blue sphere in opensim 4.4:

Object::newInstanceOfType(): object type '{ConstantCurvatureJoint}' is not a registered Object! It will be ignored.

AlbertoCasasOrtiz avatar Feb 13 '24 22:02 AlbertoCasasOrtiz

The ConstantCurvatureJoint wasn't added until 4.5, so that error is expected. We should see if loading a model with an EllipsoidJoint and no ConstantCurvatureJoint works in 4.4.

nickbianco avatar Feb 13 '24 22:02 nickbianco

Thanks @nickbianco Can you attach the model or a link to it here so I can try the 4.5 GUI?

aymanhab avatar Feb 13 '24 23:02 aymanhab

@aymanhab here is the OpenSim version of Marilyn Keller's SKEL model, with markers removed since some of those were incorrect.

bsm_no_markers.zip

nickbianco avatar Feb 13 '24 23:02 nickbianco

For the record, the problematic big blueberry sphere is coming from scapulothoracic_l joint which happens to have -ve radii (-.08, -.19999, -.083)

aymanhab avatar Feb 13 '24 23:02 aymanhab

Aha! Thanks for finding that @aymanhab.

nickbianco avatar Feb 14 '24 00:02 nickbianco

Another update, I got the markers to visualize after fixing the frame socket names. These also look wrong:

image

nickbianco avatar Feb 14 '24 00:02 nickbianco

One more: loading the sample motion has the model's spine at nearly a right angle:

image

This is definitely an issue with the ConstantCurvatureJoint definition, since the motion is accompanied by the following output to the console:

WARNING! ConstantCurvatureJoint position outside of its supported range! X rotation reached position 6.35505, which is above upper bound 1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! Y rotation reached position 6.29097, which is above upper bound 1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! X rotation reached position 6.35505, which is above upper bound 1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! Y rotation reached position 6.29097, which is above upper bound 1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! X rotation reached position 6.35505, which is above upper bound 1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! Y rotation reached position 6.29097, which is above upper bound 1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! X rotation reached position 6.35505, which is above upper bound 1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! Y rotation reached position 6.29097, which is above upper bound 1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! Y rotation reached position -6.36803, which is below lower bound -1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! Y rotation reached position -6.36803, which is below lower bound -1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! Y rotation reached position -6.36803, which is below lower bound -1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.
WARNING! ConstantCurvatureJoint position outside of its supported range! Y rotation reached position -6.36803, which is below lower bound -1.56079. This will lead to unphysical behavior. Please adjust your model or simulation to avoid this state.

nickbianco avatar Feb 14 '24 00:02 nickbianco

After corresponding with @MarilynKeller, she informed me that the missing geometry files were not originally created from existing VTP files. After attempting to convert the distributed files (via this script) and loading them into OpenSim, she received an XML parsing error:

Visualizer couldn't open lunate_l.vtp because:
SimTK Exception thrown at PolygonalMesh.cpp:411: Error detected by Simbody method PolygonalMesh::loadVtpFile(): Attempt to load a VTK PolyData (.vtp) file from file name '/Users/mkeller2/Dropbox/MPI/TML/osim_models/test_vtp/Geometry/lunate_l.vtp' failed with message: SimTK Exception thrown at Xml.cpp:723: Error detected by Simbody method Xml::element::getValue(): Element <DataArray> is not a value element. (Required condition 'isValueElement()' was not met.)

Attached below is an example of a converted file.

lunate_l.zip

nickbianco avatar Feb 14 '24 20:02 nickbianco

Here's the vtp file converted to .obj file which should work out of the box by changing the name in the osim file to lunate_l.obj lunate_l.zip opensim_snapshot

aymanhab avatar Feb 15 '24 22:02 aymanhab

Nice! I used @MarilynKeller's script to convert the other PLY files into VTP files (see attached). @aymanhab could you convert those to obj files too?

Geometry.zip

nickbianco avatar Feb 15 '24 23:02 nickbianco

Sure, will write a script to do it and will post it here by tomorrow.

aymanhab avatar Feb 16 '24 00:02 aymanhab

Can OpenSim load .obj meshes ? I assumed it was only .vtp. That would make things much easier.

MarilynKeller avatar Feb 16 '24 16:02 MarilynKeller

Absolutely, we support vtp, obj and stl files for meshes.

aymanhab avatar Feb 16 '24 16:02 aymanhab

Geometry_obj.zip

aymanhab avatar Feb 16 '24 17:02 aymanhab

Thanks @aymanhab! These worked great:

image

Note that the geometries for both patellas were not included in the BSM distribution Geometry folder, so I'm using the VTP files from the GUI distribution for those.

nickbianco avatar Feb 16 '24 19:02 nickbianco

It's clear that the EllipsoidJoint definitions are wrong, and the ConstantCurvatureJoint coordinates from the motion file still produce a ~90 degree lean in the torso. I'll now start looking to the mismatches in these joint definitions.

@MarilynKeller if you have any details on how the model was exported from nimblephysics to OpenSim, that could be useful here.

nickbianco avatar Feb 16 '24 19:02 nickbianco

As far as I know, the model is not really "exported" from nimblephysics. It was created as a .osim xml, and parsed by nimblephysics/dart directly here
The constant curvature joint is defined here and the ellipsoid joint here.

I hope this helps.

MarilynKeller avatar Feb 19 '24 09:02 MarilynKeller

That is helpful to know. This suggests that our test coverage of these joints in OpenSim isn't as quite as strong as it could be.

I will continue to investigate.

nickbianco avatar Feb 20 '24 19:02 nickbianco

I need to choose a full-body OpenSim model, and I have potential applications with SMPL meshes, so the BSM model from SKEL would be the perfect fit. I'm not sure how to help but if I can, I will!

What would be the idea? Editing the joint definitions in Nimble Physics, or in OpenSim? Either way, the model is not going to work in one of these applications anymore, right?

davidpagnon avatar Apr 26 '24 06:04 davidpagnon

@davidpagnon the first step would be to identify the differences in the implementation of the EllipsoidJoint in nimblephysics and OpenSim. The nimblephysics implementation is here, and the Simbody implementation (which OpenSim uses) is here. The implementation of OpenSim::EllipsoidJoint uses Simbody's Ellipsoid mobilized body class.

EDIT: I corrected the link for Simbody's implementation of Ellipsoid.

nickbianco avatar Apr 26 '24 17:04 nickbianco

Thanks! I won't be able to work on it within the next two weeks, but if it has not been solved by then I'll have a look!

davidpagnon avatar Apr 26 '24 18:04 davidpagnon

Sounds good @davidpagnon! Thanks for being willing to take a look.

nickbianco avatar Apr 26 '24 18:04 nickbianco

Hi all, unfortunately, I've been busier than I expected, and I can't give a date when I'll be able to dive into it... If anyone is on it, I'm interested in any case! I'll keep you updated if my schedule clears up.

davidpagnon avatar May 17 '24 10:05 davidpagnon

Hi @davidpagnon, thanks for the update and no worries. Actually, @keenon and I recently realized that the ellipsoid joint between Nimble and OpenSim are implemented very differently, so there's not much to investigate here. We essentially need to rewrite the Nimble ellipsoid joint to match OpenSim, which is some nontrivial geometry work.

nickbianco avatar May 17 '24 16:05 nickbianco

Thanks, that's what I figured, and I got overwhelmed 😅 Not to put you under pressure or anything, but do you have a rough idea of when it will be done (and when it will be supported by Addbiomechanics )?

davidpagnon avatar May 18 '24 20:05 davidpagnon

We currently don't have a timeline for this fix. But we will reprioritize as more people find it useful.

@keenon, I'm wondering if the easiest solution is just to implement your version of the ellipsoid joint in OpenSim. OpenSim's EllipsoidJoint relies on Simbody's notion of a mobilizer, which I'm not sure dart/Nimble actually support.

nickbianco avatar May 21 '24 17:05 nickbianco

Hi @nickbianco,

Thank you for your work on the model. I noticed a few missing elements: the left and right patella are listed in the osim file (<mesh_file>l_patella.obj</mesh_file>, <mesh_file>r_patella.obj</mesh_file>, but their geometries are not included. I've attached screenshots for reference. Additionally, the clavicles are absent from the osim file.

Do you have any thoughts on how to address these issues?

image

image

Arish2022 avatar Oct 26 '24 15:10 Arish2022