[FEATURE] Add public API to RigidEntity for kinematic and potential energy.#2613
Conversation
Add get_kinetic_energy(), get_potential_energy(), and get_total_energy() methods to RigidEntity for computing mechanical energy in simulation. - Kinetic energy uses generalized-coordinate mass matrix (handles all inertial coupling terms for articulated bodies) - Potential energy sums m_i * g^T * p_i over all links - All methods support envs_idx for parallel environments Closes Genesis-Embodied-AI#2309 Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
duburcqa
left a comment
There was a problem hiding this comment.
This is invalid. It does not take into account motor armature.
- Add RigidSolver.recompute_mass_matrix() to get clean mass matrix (structural inertia + armature, no implicit damping) - get_kinetic_energy() now recomputes mass matrix before use - Delete test_energy.py; add 2 function-based tests to test_rigid_physics.py - Tests: no class, no precision requirement, marked @pytest.mark.required Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
|
Thanks for the review! Addressed all feedback. Motor armature fix: The root issue was that Fix: Added Test changes:
|
- Add unit [J] to all energy method titles - Remove redundant return descriptions - Remove invalid Note about mid-step calls - Add Note about mass matrix recomputation performance - Use 120-char linewidth for docstrings - Remove implementation detail about implicit damping Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
- Merge test_energy_conservation_free_fall and test_energy_kinetic_potential_relation into one test - Add 2 spheres: undamped (dampratio=0) and damped (default) - Verify analytical KE/PE during free fall (semi-implicit Euler formulas) - Verify energy conservation for undamped sphere, strict decrease for damped - Track first ground impact timestep Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
- Wrap docstrings to 120 chars linewidth - Skip mass matrix recomputation for non-approximate_implicitfast integrators - Remove recompute_mass_matrix() from RigidSolver, call kernel directly in RigidEntity - Parameterize test with both Euler and approximate_implicitfast integrators - One line per option in test entity creation - Use non-zero timeconst in undamped sol_params to avoid NaN on field backend Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
|
@Lidang-Jiang Some comments are still open. |
|
I will help you to investigate the nan issue. |
|
|
1f9c7cc to
bcca404
Compare
thanks |
bcca404 to
7eeeaaf
Compare
…s near zero. Add eps parameter to imp_aref to prevent NaN from 1/(dampratio²) when dampratio ≈ 0. Reject dampratio < EPS in _sanitize_sol_params with a clear error message explaining that dampratio controls spring stiffness, not velocity damping. Document the impedance model semantics in default_solver_params docstring. Update energy conservation test to use nearly elastic contact params (timeconst=10, dampratio=0.001) with tighter tolerance.
7eeeaaf to
4cc40d5
Compare
…nergy. (Genesis-Embodied-AI#2613) Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com> Co-authored-by: Alexis Duburcq <alexis.duburcq@gmail.com>
Summary
get_kinetic_energy(),get_potential_energy(), andget_total_energy()methods toRigidEntityKE = 0.5 * dq^T * M(q) * dq) for accurate computation on articulated bodiesm_i * g^T * p_iover all links, supporting arbitrary gravity directionsenvs_idxfor parallel environmentsCloses #2309
API Demo Output
Full output
Unit Test Results
pytest output (13 tests, all passed)
Test Plan