Gazebo | Ignition | Community
Ask Your Question

Some contacts not detected

asked 2016-01-10 12:09:46 -0600

debz gravatar image

updated 2016-01-15 10:35:30 -0600


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:



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"




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->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; 
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-01-11 03:57:37 -0600

AndreiHaidu gravatar image

Hi there,

I also noticed something similar, in a plugin, if you do not subscribe to the contacts topic then the contact manager does not have any contacts (myContactManagerPtr->GetContacts()).

myContactSub = my_gz_node->Subscribe("~/physics/contacts", &MyPluginClass::DummyContactsCallback, this);

Another thing that might cause the problem, if the contacts do not change for a given amount of time they are not published anymore (you can check this by spawning a box in an empty world, visualize the contacts, and after a while they disappear)

Cheers, Andrei

edit flag offensive delete link more


Hi, thx for your answer. Do you mean that I just need to subscribe and keep on working with the manager or I'd better use the topic subscription system to get the contacts ?

debz gravatar imagedebz ( 2016-01-11 14:48:17 -0600 )edit

Well both might work, depending on how you want to get to the contacts.But I think there was a difference between them, however I cannot recall it anymore :)

AndreiHaidu gravatar imageAndreiHaidu ( 2016-01-12 09:27:28 -0600 )edit

I tried this with my plugin (update of the gazebo_ros_create.cpp from Turtlebot) with Jade (Gazebo 5.1) and I still can't get this to work. I can see contacts in Gazebo, but the filter topic is always empty. std::string topic = mgr->CreateFilter(base_geom_name_, base_geom_name_); contact_sub_ = gazebo_node_->Subscribe(topic, &GazeboRosCreate::OnContact, this); where base_geom_name_ is the name of the collision object in the base link

dcconner gravatar imagedcconner ( 2016-02-04 17:07:52 -0600 )edit

Question Tools

1 follower


Asked: 2016-01-10 12:09:46 -0600

Seen: 1,382 times

Last updated: Jan 15 '16