NeLy-EPFL / flygym

Simulating embodied sensorimotor control with NeuroMechFly v2
https://neuromechfly.org/
Apache License 2.0
26 stars 7 forks source link

Oddities in cardinal vector sensing #215

Closed sibocw closed 1 month ago

sibocw commented 1 month ago

See #214. Two things are unclear to me:

  1. Why is the forward vector tilted up by about 30 degrees?
  2. Why is the order left-up-front instead of front-left-up, as is the case in the mesh file?

My guess is that these have to do with how the model is configured in Blender, but I'm deferring it because it's still functional and changing it will break backward compatibility. In the meantime, help is greatly appreciated.

For reference, here's the mesh file for the thorax and the issues above do not seem to be present in the Mesh file as (based on my understanding of how MeshLab visualizes bodies, screenshot below).

image

Thorax.zip

stepanove commented 1 month ago

Hi @sibocw, it looks like this issue comes from mujoco mesh preprocessing algorithm

Positioning and orienting is complicated by the fact that vertex data in the source asset are often relative to coordinate frames whose origin is not inside the mesh. In contrast, MuJoCo expects the origin of a geom’s local frame to coincide with the geometric center of the shape. We resolve this discrepancy by pre-processing the mesh in the compiler, so that it is centered around (0,0,0) and its principal axes of inertia are the coordinate axes. We save the translation and rotation offsets applied to the source asset in mjModel.mesh_pos and mjModel.mesh_quat; these are required if one reads vertex data from the source and needs to re-apply the transform.

If you specify inertial properties of the thorax manually, it makes axes look ok. Снимок экрана от 2024-09-25 00-04-10 Probably you can use mjModel.mesh_quat to correct axes orientation, or maybe it makes sense to just create a dummy toplevel body and read its position/oriantaion instead of "Thorax". Снимок экрана от 2024-09-25 00-46-44

sibocw commented 1 month ago

Thank you @stepanove for this information! It's really helpful. I have fixed this issue in #219 .

stepanove commented 1 month ago

You're welcome @sibocw, I'm glad to be of help :)