I want to delete a collision of a certain Link at a certain point in time during the simulation run. How can I implement it through code

I want to delete a collision of a certain Link at a certain point in time during the simulation run. How can I implement it through code

Hi @huqin-RM,

I assumed this would simply be a matter of writing a plugin that reads the info from the SDF in its Configure() and deletes the corresponding entity from the Entity Component Manager (ECM) in its PreUpdate() when the duration has lapsed.

I gave it a try, see this implementation.

Unfortunately, I did not get it to work.

The plugin does remove the collision (box_collision) from the ECM, as initially it is listed in the Entity Tree, and then it disappears from the Entity Tree after the set delay:

But the box does not drop. So it seems that even though the collision entity is removed from the ECM, the corresponding info is still present in the physics subsystem.

As far as I understand the code, it is the physics plugin that deals with creating the gz::physics counterparts for gz::sim items.
It unfortunately supports removal only for full models, and hence not just the collisions.

I think to get it to work, the RemovePhysicsEntities() function needs an extra entry _ecm.EachRemoved<components::Collision>() similar to the current _ecm.EachRemoved<components::Model>() and _ecm.EachRemoved<components::DetachableJoint>().

Hope this helps, let me know if you get it to work.

Re,
Johan

Hi,

I tried with the following added to the RemovePhysicsEntities() method:

   _ecm.EachRemoved<components::Collision>(
      [&](const Entity &_entity, const components::Collision *
          /* _collision */) -> bool
      {
         gzdbg << "Removing collision entity." << std::endl;
         this->entityCollisionMap.Remove(_entity);
         return true;
      });

The debug message gets printed, yet the box still does not drop.

This surpasses my understanding of the implementation; it is sad that there is so little documentation and code comments.

Re,
Johan

As @jrtg mentioned, Gazebo currently only supports removing models at runtime. To remove collisions and other types of entities, the corresponding removal feature for the type of entity has to be implemented in gz-physics https://github.com/gazebosim/gz-physics/blob/63a74864004c4a8509c78b4f47add19b4d7100b1/include/gz/physics/RemoveEntities.hh. You can then call that function in RemovePhysicsEntities in the physics system of Gazebo.