gazebosim / gazebo-classic

Gazebo classic. For the latest version, see https://github.com/gazebosim/gz-sim
http://classic.gazebosim.org/
Other
1.19k stars 480 forks source link

Visual messages with transparency cause huge FPS drop after upgrade to Gazebo 7 #2051

Open osrf-migration opened 8 years ago

osrf-migration commented 8 years ago

Original report (archived issue) by Frederik Zwilling (Bitbucket: fzwilling).

The original report had attachments: minimal-breaking-example.zip


Hi, we recently upgraded from Gazebo 5.1 to 7.3 and had major problems with the FPS in gzclient dropping to 2 FPS while using the same models and plugins which worked fine in 5.1.

By creating a minimal breaking example, I found that the problem is caused by Visual messages with a set transparency value in a populated world.

In the attachment and below you can find my minimal breaking example. It consists of a world of similar complexity to my application in the RoboCup Logistics League and a plugin creating a blinking light with Visual messages.

With Gazebo 7 this runs at 8 FPS. By commenting the line that sets the transparency of the visual msg or downgrading to Gazebo 5.1, this runs above 26 FPS.

I already created a workaround for our application by omitting using transparency, but I think this is a bug you want to fix.

(I am using an Intel Core i7-3770 CPU @ 3.40GHz × 8 and an Intel Corporation Xeon E3-1200 v2/3rd Gen Core processor Graphics Controller with Fedora 23. )

World file:

#!sdf

<?xml version="1.0" ?>
<sdf version="1.4">
  <world name="RCLL">
    <gui>
      <camera name="user camera">
    <pose>1 -2 9.5 0 1.1 1.56</pose>
      </camera>
    </gui>
    <physics type="ode">
      <max_step_size>0.004</max_step_size>
      <real_time_factor>1</real_time_factor>
      <real_time_update_rate>300</real_time_update_rate>
    </physics>
    <scene>
      <shadows>0</shadows>
    </scene>
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <include>
      <uri>model://sun</uri>
    </include>

    <!-- Added some models to reach a similar complexity -->
    <include>
      <uri>model://youbot</uri>
      <pose>0 1 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>0 2 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>1 1 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>1 2 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>2 1 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>2 2 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>3 1 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>3 2 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>4 1 0.2 0 0 0</pose>
    </include>
    <include>
      <uri>model://youbot</uri>
      <pose>4 2 0.2 0 0 0</pose>
    </include>

    <!-- this plugin causes the FPS drop -->
    <plugin name="breaking_plugin" filename="libbreaking_plugin.so" />
  </world>
</sdf>

Plugin:

#!c++

#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <gazebo/transport/transport.hh>

using namespace gazebo;

class LightControl : public WorldPlugin
{
public:
  LightControl(){};
  ~LightControl(){};

  virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
  {
    world_ = _world;
    update_connection_ = event::Events::ConnectWorldUpdateBegin(boost::bind(&LightControl::OnUpdate, this, _1));
    node_ = transport::NodePtr(new transport::Node());
    node_->Init(world_->GetName());
    visPub_ = this->node_->Advertise<msgs::Visual>("~/visual", /*max number of lights*/ 3*12);
    last_sent_time_ = world_->GetSimTime().Double();
  }

  virtual void OnUpdate(const common::UpdateInfo &)
  {
    double time = world_->GetSimTime().Double();    
    if(time - last_sent_time_ < 0.1)
      return;
    last_sent_time_ = time;

    state_on = !state_on;

    msgs::Visual msg;

    //////////// this line costs ~20 FPS in Gazbeo 7
    msg.set_transparency(0.0);
    ///////////

    msgs::Geometry *geomMsg = msg.mutable_geometry();
    geomMsg->set_type(msgs::Geometry::CYLINDER);
    geomMsg->mutable_cylinder()->set_radius(0.05);
    geomMsg->mutable_cylinder()->set_length(0.1);
    msg.set_cast_shadows(false);
    msg.set_parent_name("light::link");
    msg.set_name("light::link::redon");
#if GAZEBO_MAJOR_VERSION > 5
    msgs::Set(msg.mutable_pose(), ignition::math::Pose3d(1, 0, 0.085, 0, 0, 0));
#else
    msgs::Set(msg.mutable_pose(), math::Pose(1, 0, 0.085, 0, 0, 0));
#endif
    msgs::Set(msg.mutable_material()->mutable_diffuse(), common::Color(0.8, 0, 0, 0.8));
    msgs::Set(msg.mutable_material()->mutable_emissive(), common::Color(1.0, 0.3, 0.3, 1.0));
    if(state_on)
      msg.set_visible(true);
    else
      msg.set_visible(false);
    visPub_->Publish(msg);
  }

private:
  physics::WorldPtr world_;
  event::ConnectionPtr update_connection_;
  transport::NodePtr node_;
  transport::PublisherPtr visPub_;
  double last_sent_time_;
  bool state_on = true;
};

GZ_REGISTER_WORLD_PLUGIN(LightControl)
osrf-migration commented 8 years ago

Original comment by Frederik Zwilling (Bitbucket: fzwilling).