ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Ok, so I found a solution. To get access to the gazebo shapes you have to create a Gazebo Plugin. There is a tutorial on Gazebo how to do that.

After that you can access Model->Body->Geom->Shape->BoxShape.

    gazebo::physics::ModelPtr model = this->world_->GetModel(req.model_name);
    if (!model)
    {
      ROS_ERROR("GetModelProperties: model [%s] does not exist",req.model_name.c_str());
      res.success = false;
      res.status_message = "GetModelProperties: model does not exist";
      return false;
    }
    else
    {

  // get model parent name
  gazebo::physics::ModelPtr parent_model = boost::dynamic_pointer_cast<gazebo::physics::Model>(model->GetParent());

  // get list of child bodies, geoms
  for (unsigned int i = 0 ; i < model->GetChildCount(); i ++)
  {
    gazebo::physics::LinkPtr body = boost::dynamic_pointer_cast<gazebo::physics::Link>(model->GetChild(i));
    if (body)
    {
      // get list of geoms
      for (unsigned int j = 0; j < body->GetChildCount() ; j++)
      {
        gazebo::physics::CollisionPtr geom = boost::dynamic_pointer_cast<gazebo::physics::Collision>(body->GetChild(j));

        if (geom)
        { 
          res.geom_name = geom->GetName();
          gazebo::physics::ShapePtr shape(geom->GetShape ());

          if (shape->HasType (gazebo::physics::Base::BOX_SHAPE))
          {
            gazebo::physics::BoxShape *box = static_cast<gazebo::physics::BoxShape*>(shape.get ());
            math::Vector3 tmp_size = box->GetSize ();
            geometry_msgs::Vector3 size;
            size.x = tmp_size.x;
            size.y = tmp_size.y;
            size.z = tmp_size.z;

            res.size = size;
          }
        }
      }
    }
  }
  res.success = true;
  res.status_message = "GetModelProperties: got properties";
  return true;
}
return true;