test_mass_props_and_com

Regression tests for two MJBody mass-property bugs.

  1. _com site position: the auto-created <body>_com site must report the body’s true center of mass, not the body frame origin. MuJoCo latches a site’s sameframe at compile time; because the site is created at the body origin it latches to mjSAMEFRAME_BODY and mj_local2Global then ignores the later attempt to move it to the CoM, pinning site_xpos to the body frame origin. The orientation of the _com site must remain the body (origin) frame, not the principal-inertia frame.

  2. Inertia update on mass change: MJBody::updateMujocoModelFromMassProps rescales the inertia tensor with the ratio newMass / body_mass but overwrites body_mass with newMass first, making the ratio identically 1.0 – so the inertia never changes when the mass does.

test_mass_props_and_com.test_com_site_reports_true_center_of_mass()[source]

The _com site must sit at the true CoM (offset from the body origin) and keep the body-origin frame orientation, not the principal-inertia frame.

test_mass_props_and_com.test_inertia_rescales_with_mass()[source]

When the body mass changes, the rotational inertia must scale with it.

A constant torque produces angular acceleration alpha = tau / I. As the mass (and hence inertia) grows, alpha must shrink proportionally. With the inertia-update bug the inertia never changes, so alpha stays constant and the early/late angular-acceleration ratio is ~1 instead of ~0.5.