diff --git a/gazebo_grasp_plugin/include/gazebo_grasp_plugin/GazeboGraspFix.h b/gazebo_grasp_plugin/include/gazebo_grasp_plugin/GazeboGraspFix.h
index b3e3ef356ae4540a5a2d73efe3b16b730aa6e30c..d5486fc89d3d89e1a8b32653e6169712312f058d 100644
--- a/gazebo_grasp_plugin/include/gazebo_grasp_plugin/GazeboGraspFix.h
+++ b/gazebo_grasp_plugin/include/gazebo_grasp_plugin/GazeboGraspFix.h
@@ -249,6 +249,9 @@ class GazeboGraspFix : public ModelPlugin
//last time OnUpdate() was called
common::Time prevUpdateTime;
+
+ //ContactManager filter to be removed in destructor
+ std::string filter_name;
};
}
diff --git a/gazebo_grasp_plugin/src/GazeboGraspFix.cpp b/gazebo_grasp_plugin/src/GazeboGraspFix.cpp
index 5162d5ca979e7b9a44cf4fccc976e56276d4d9ad..3c73f5dad45b09acde6648d94b0da624a23672c0 100644
--- a/gazebo_grasp_plugin/src/GazeboGraspFix.cpp
+++ b/gazebo_grasp_plugin/src/GazeboGraspFix.cpp
@@ -36,6 +36,14 @@ GazeboGraspFix::GazeboGraspFix(physics::ModelPtr _model)
////////////////////////////////////////////////////////////////////////////////
GazeboGraspFix::~GazeboGraspFix()
{
+ // Release filter to make it safe to reload the model with plugin
+ if (!filter_name.empty() && this->world)
+ {
+ physics::PhysicsEnginePtr physics = GetPhysics(this->world);
+ physics::ContactManager *contactManager = physics->GetContactManager();
+ if (contactManager)
+ contactManager->RemoveFilter(filter_name);
+ }
this->update_connection.reset();
if (this->node) this->node->Fini();
this->node.reset();
@@ -261,7 +269,8 @@ void GazeboGraspFix::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
physics::ContactManager *contactManager = physics->GetContactManager();
contactManager->PublishContacts(); // TODO not sure this is required?
- std::string topic = contactManager->CreateFilter(model->GetScopedName(),
+ filter_name = model->GetScopedName();
+ std::string topic = contactManager->CreateFilter(filter_name,
collisionNames);
if (!this->contactSub)
{