Repository navigation
Fix PyBullet stale inverse dynamics cache after dynamics change or body removal (#4809) - #4817
Open
paneendrakumar0 wants to merge 1 commit into
Conversation
…dy removal (bulletphysics#4809) In PhysicsServerCommandProcessor, calculateInverseDynamics and calculateMassMatrix cache btInverseDynamics::MultiBodyTree (and cRBDModel) instances indexed by btMultiBody* pointer. Previously, two cache synchronization issues occurred: 1. processChangeDynamicsInfoCommand changed base or link mass/inertia without invalidating the cached inverse dynamics tree or RBD model, causing subsequent inverse dynamics and mass matrix calculations to return stale results computed with pre-mutation mass values. 2. processRemoveBodyCommand deleted btMultiBody instances without removing them from m_inverseDynamicsBodies or m_inverseKinematicsHelpers. When a new body reused the freed memory address or body ID 0, calculations for the new body silently used the old body's cached tree. This patch: - Invalidate and free cached inverse dynamics trees (and RBD models) when mass or local inertia is modified in processChangeDynamicsInfoCommand. - Invalidate and free cached inverse dynamics trees and inverse kinematics helpers when a multibody is removed in processRemoveBodyCommand. - Adds regression tests in unittests.py covering both dynamic mass mutation and body reuse scenarios. Signed-off-by: paneendrakumar0 <paneendra100@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4809.
Description
In
examples/SharedMemory/PhysicsServerCommandProcessor.cpp,calculateInverseDynamicsandcalculateMassMatrixcachebtInverseDynamics::MultiBodyTree(andcRBDModel) instances indexed by rawbtMultiBody*pointer inm_inverseDynamicsBodies(andm_rbdModels).Previously, two cache synchronization issues occurred:
processChangeDynamicsInfoCommand()changed base or link mass/inertia without invalidating the cached inverse dynamics tree or RBD model. Subsequent calls tocalculateInverseDynamicsandcalculateMassMatrixcontinued using the stale pre-mutation tree.processRemoveBodyCommand()deletedbtMultiBodyinstances without purging them fromm_inverseDynamicsBodiesorm_inverseKinematicsHelpers. When a new body was allocated at the same memory address or reused body ID 0, calculations for the new body silently used the old body's cached tree.Solution
deleteCachedInverseDynamicsBodyanddeleteCachedBodyDatahelpers toPhysicsServerCommandProcessorInternalData.PhysicsServerCommandProcessor::processChangeDynamicsInfoCommand(), purge the cached inverse dynamics tree and RBD model wheneverCHANGE_DYNAMICS_INFO_SET_MASSorCHANGE_DYNAMICS_INFO_SET_LOCAL_INERTIA_DIAGONALis present inclientCmd.m_updateFlags.PhysicsServerCommandProcessor::processRemoveBodyCommand(), clean up bothm_inverseDynamicsBodiesandm_inverseKinematicsHelpersprior to deletingbodyHandle->m_multiBody.test_inverse_dynamics_cache_invalidationinexamples/pybullet/unittests/unittests.pycovering both dynamics mutation and body reuse after removal.