0
$\begingroup$

Gazebo Answers logo

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; 
  }
}

Originally posted by debz on Gazebo Answers with karma: 198 on 2016-01-10

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Gazebo Answers logo

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


Originally posted by AndreiHaidu with karma: 2108 on 2016-01-11

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by debz on 2016-01-11:
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 ?

Comment by AndreiHaidu on 2016-01-12:
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 :)

Comment by dcconner on 2016-02-04:
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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.