Gazebo | Ignition | Community
Ask Your Question
0

VisualPlugin not loaded not constructed at all

asked 2021-01-19 11:42:18 -0600

torydebra gravatar image

Hi,

I have problems running a VisualPlugin. When I put its tag under the <visual> tag of a <link>, it seems that it is not read at all when launching gazebo (neither its constructor is called).

Putting the <plugin> tag under <model> or <world> makes the plugin costructor called and an error about uncorrect plugin type (as expected).

When commanding:

 gzserver world/box.world --verbose

Nothing is printed about the plugin

I am using gazebo 9 installed with ROS melodic.

Thanks for any help!

world file:

<?xml version="1.0"?> 
<sdf version="1.4">
  <world name="default">

    <!-- Ground Plane -->
    <include>
      <uri>model://ground_plane</uri>
    </include>

    <include>
      <uri>model://sun</uri>
    </include>

    <model name="box">

      <pose>0 0 5 0 0 0</pose>
      <link name="link">

        <collision name="collision">
          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>
        </collision>

        <visual name="visual">

          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>

          <!--  Not Costructed at all    -->
          <plugin name="visualize_forces" filename="libvisualize_forces.so"/>
        </visual>    

      </link>

      <!--  Costructed, but not loaded, and immediately destroyed (as expected)    -->
      <!--      <plugin name="visualize_forces" filename="libvisualize_forces.so"/>-->

    </model>   

    <!--  Costructed, but not loaded, and immediately destroyed (as expected)    -->
    <!--      <plugin name="visualize_forces" filename="libvisualize_forces.so"/>-->

  </world>
</sdf>

cpp:

#include <gazebo/common/common.hh>
#include <gazebo/rendering/Visual.hh>
#include <gazebo/rendering/rendering.hh>
#include <gazebo/msgs/msgs.hh>

namespace gazebo
{

  class GZ_RENDERING_VISIBLE VisualizeForces : public VisualPlugin
  {
    public: 

    VisualizeForces() {gzmsg << "Constructor" << std::endl;}
    virtual ~VisualizeForces() {gzmsg << "Destructor" << std::endl;}

    void Init() override {gzmsg << "Init" << std::endl;}

    void Load(rendering::VisualPtr _visual, sdf::ElementPtr _sdf ) override
    {
        gzmsg << "Load" << std::endl;
    }
  };

  GZ_REGISTER_VISUAL_PLUGIN(VisualizeForces)
}

I attach the files

C:\fakepath\box.world

C:\fakepath\VisualizeForces.cpp

Fast CmakeLists.txt:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

find_package(gazebo REQUIRED)
include_directories(${GAZEBO_INCLUDE_DIRS})
link_directories(${GAZEBO_LIBRARY_DIRS})
list(APPEND CMAKE_CXX_FLAGS "${GAZEBO_CXX_FLAGS}")

add_library(visualize_forces SHARED src/VisualizeForces.cpp)
target_link_libraries(visualize_forces ${GAZEBO_LIBRARIES})
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-15 02:17:13 -0600

ahcorde gravatar image

Hi,

you are launching Gazebo without interface gzserver world/box.world --verbose. You are building a VisualPlugin, you must need to run the interface to be able to load this plugin

I tried with gazebo and I can see your traces:

gazebo --verbose ../box.sdf 
Gazebo multi-robot simulator, version 11.3.0
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

[Msg] Waiting for master.
Gazebo multi-robot simulator, version 11.3.0
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

[Msg] Waiting for master.
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: 192.168.1.42
[Msg] Loading world file [/home/ahcorde/tmp/gazebo_help/build/../box.sdf]
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: 192.168.1.42
[Msg] Constructor
[Msg] Load
[Msg] Init
[Msg] Init
[Msg] Destructor
edit flag offensive delete link more

Comments

Thanks for the help!

I see now, the visualPlugin is a matter of the gzclient and not gzserver (I think in your code above there is a missing gzclient --verbose). I was expecting to see the prints on the terminal with gzserver

By the way, I run gzclient, too, but the problem was that I did not have exported the GAZEBO_PLUGIN_PATH on this terminal :D

torydebra gravatar imagetorydebra ( 2021-02-15 03:22:49 -0600 )edit

If you have a camera or GPU ray sensor in your world, visual plugin will also be loaded. If you run that with client, you will see the message twice as separate scenes (and therefore visuals) will be created on the server side as well as the client side.

Veerachart gravatar imageVeerachart ( 2021-02-16 01:28:00 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-01-19 11:42:18 -0600

Seen: 30 times

Last updated: Feb 15