Obtain contact information between entities (name and location)

asked 2023-07-20 11:25:28 -0600

gsisinna gravatar image

updated 2023-07-20 11:26:16 -0600

Good morning everyone, I am writing a plugin in C++ for gz sim (Garden) and I cannot use contact sensor to get contact information between two objects. In particular I would like to know which <collision> make contact and then trace it back to the model_entity and create a detachable_joint between the two entities.

To work around this I have temporarily used a gpu_lidar sensor (just to check the distance values), but I would need something that could return more complete information about the entities involved, rather than just the distance of the single lidar beam in one direction.

I tried following this tutorial, but it turns out to be dated to gazebo classic and I can't find anything else.

I have already tried creating components for my gripper_link, as below:

  // Create a ContactSensor component for the gripper
  if (_ecm.Component<components::ContactSensor>(gripper_entity) == nullptr)
  {
    _ecm.CreateComponent(gripper_entity, components::ContactSensor());
    gzerr << "[GripperManager] created ContactSensor component for " << gripper_link << std::endl;
  }
  else
  {
    gzerr << "[GripperManager] ContactSensor component already exists for " << gripper_link << std::endl;
  }

  // Create a ContactSensorData component for the gripper
  if (_ecm.Component<components::ContactSensorData>(gripper_entity) == nullptr)
  {
    _ecm.CreateComponent(gripper_entity, components::ContactSensorData());
    gzerr << "[GripperManager] created ContactSensorData component for " << gripper_link << std::endl;
  }
  else
  {
    gzerr << "[GripperManager] ContactSensorData component already exists for " << gripper_link << std::endl;
  }

But I get only absent values even if I put something in contact:

  // Print the ContactSensorData component data for the gripper
  auto contact_sensor_data_comp = _ecm.Component<components::ContactSensorData>(gripper_entity);
  auto contact_sensor_comp = _ecm.Component<components::ContactSensor>(gripper_entity);
  auto contact_sensor_data = contact_sensor_data_comp->Data();
  auto contact_sensor = contact_sensor_comp->Data();

  gzerr << "ContactSensorData for " << gripper_link << std::endl;
  gzerr << "ContactSensorData: " << contact_sensor_data.DebugString() << std::endl;

Does anyone have more information about this or could point me to a reference?

Thanks!

edit retag flag offensive close merge delete