# Revision history [back]

### Some contacts not detected

Hello,

I use a ModelPlugin to check collisions between my robot and some cubes around. I use the ContactManger of the world attached to the model of the robot. This works most of the time, but I regularly fall in a situation where the robot is stucked on a cube, and the ContactManager doesn't report the contact. The weirdest thing is that, in this situation, if I use the client and click on "view"->"contacts", the ContactManager suddenly see the contact. I tried this enough times to be sure that this is not a coincidence. So, by activating the contacts view in the client, the ContactManger is able to see the contact.

Does anyone has an idea where the problem is ?

Here is the doc of the ContactManager:

http://osrf-distributions.s3.amazonaws.com/gazebo/api/2.0.0/classgazebo_1_1physics_1_1ContactManager.html

Cheers

### Some contacts not detected

Hello,

I use a ModelPlugin to check collisions between my robot and some cubes around. I use the ContactManger of the world attached to the model of the robot. This works most of the time, but I regularly fall in a situation where the robot is stucked on a cube, and the ContactManager doesn't report the contact. The weirdest thing is that, in this situation, if I use the client and click on "view"->"contacts", the ContactManager suddenly see the contact. I tried this enough times to be sure that this is not a coincidence. So, by activating the contacts view in the client, the ContactManger is able to see the contact.

Does anyone has an idea where the problem is ?

Here is the doc of the ContactManager:

http://osrf-distributions.s3.amazonaws.com/gazebo/api/2.0.0/classgazebo_1_1physics_1_1ContactManager.html

Cheers

EDIT (with problem solved)

I just put the code here, since I had some boost shared_ptr errors trying to implement the suggested solution. This code here works (no contact detection forgotten anymore). I still think this is an important issue for gazebo. The fact that some contacts are not detected might be the result of some asynchronous functions in ODE for object collision detection and the ContactManager class which is not design to handle this. This is a weird trick to register to a topic to get it working properly.

#include "ContactsManager.hh"

ContactsManager::ContactsManager()
{

}

ContactsManager::~ContactsManager()
{
gazebo::transport::fini();
}

void ContactsManager::Init(gazebo::physics::ContactManager* contactManager, std::string worldName)
{
this->contactManager = contactManager;
this->isContact = false;
// Subscribe to Contact topic
this->contactNod = gazebo::transport::NodePtr(new gazebo::transport::Node());
this->contactNod->Init(worldName);
this->contactSub = this->contactNod->Subscribe("~/physics/contacts", &ContactsManager::contactsCallBack, this);

}

bool ContactsManager::checkCollisions()
{
if(this->isContact == true)
{
this->isContact = false;
return true;
}
return false;
}

void ContactsManager::contactsCallBack(ConstWorldStatisticsPtr &_msg)
{
unsigned int count = this->contactManager->GetContactCount();
std::vector<gazebo::physics::Contact*> contacts = this->contactManager->GetContacts();
for(unsigned int i=0; i < count; i++)
{
std::string name1 = contacts[i]->collision1->GetName();
std::string name2 = contacts[i]->collision2->GetName();
// Apply some filters here
std::cout << "[contact] " << i << ": " << name1 << " -- " << name2 << std::endl;
this->isContact = true;
}
}