Home | Tutorials | Wiki | Issues
Ask Your Question
0

Cannot Compile Custom Plugins

asked 2019-05-17 10:57:27 -0500

Hello,

I went through the Write-a-Plugin tutorials and decided to try and write one to get the process down. To start, I just tried to replace some words in the tutorial code to see if I was understanding it correctly. It turns out I'm not, and I'm very confused as to what's going wrong as I get this when I run the 'make' command in the build directory. The tutorials run without error, but when I change the class name, the compiler no longer recognizes it:

/home/joey/Gazebo Stuff/bart_world_plugin/plugin_test.cc:10:3: error: expected class-name before ‘{’ token
   {
   ^
In file included from /usr/include/gazebo-9/gazebo/common/common.hh:36:0,
                 from /usr/include/gazebo-9/gazebo/gazebo_core.hh:19,
                 from /usr/include/gazebo-9/gazebo/gazebo.hh:20,
                 from /home/joey/Gazebo Stuff/bart_world_plugin/plugin_test.cc:2:
/home/joey/Gazebo Stuff/bart_world_plugin/plugin_test.cc: In function ‘gazebo::ModelPlugin* gazebo::RegisterPlugin()’:
/usr/include/gazebo-9/gazebo/common/Plugin.hh:432:26: error: cannot convert ‘gazebo::PluginTest*’ to ‘gazebo::ModelPlugin*’ in return
     return new classname();\
                          ^
/home/joey/Gazebo Stuff/bart_world_plugin/plugin_test.cc:37:3: note: in expansion of macro ‘GZ_REGISTER_MODEL_PLUGIN’
   GZ_REGISTER_MODEL_PLUGIN(PluginTest)
   ^
CMakeFiles/plugin_test.dir/build.make:62: recipe for target 'CMakeFiles/plugin_test.dir/plugin_test.cc.o' failed
make[2]: *** [CMakeFiles/plugin_test.dir/plugin_test.cc.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/plugin_test.dir/all' failed
make[1]: *** [CMakeFiles/plugin_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

The file in question is based off model_push.cc; this is my "custom" plugin, plugin_test.cc where I only changed class name and the public name in what I believed to be the correct spots:

#include <functional>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <ignition/math/Vector3.hh>

namespace gazebo
{
  class PluginTest : public PluginTestPlugin
  {
    public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
    {
      // Store the pointer to the model
      this->model = _parent;

      // Listen to the update event. This event is broadcast every
      // simulation iteration.
      this->updateConnection = event::Events::ConnectWorldUpdateBegin(
          std::bind(&PluginTest::OnUpdate, this));
    }

    // Called by the world update start event
    public: void OnUpdate()
    {
      // Apply a small linear velocity to the model.
      this->model->SetLinearVel(ignition::math::Vector3d(0, 500, 0));
    }

    // Pointer to the model
    private: physics::ModelPtr model;

    // Pointer to the update event connection
    private: event::ConnectionPtr updateConnection;
  };

  // Register this plugin with the simulator
  GZ_REGISTER_MODEL_PLUGIN(PluginTest)
}

Here's 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(plugin_test SHARED plugin_test.cc)
target_link_libraries(plugin_test ${GAZEBO_LIBRARIES})

The only other thing I could find on the topic of a custom plugin not compiling was solved by adding another include, but that didn't seem to have an effect on my plugin.

edit retag flag offensive close merge delete

Comments

Found the problem: apparently the public name has to be ModelPlugin (in this case, at least). I'm assuming that the first word changes depending on plugin type?

JosephT gravatar imageJosephT ( 2019-05-18 08:55:31 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-05-19 12:44:45 -0500

chapulina gravatar image

Found the problem: apparently the public name has to be ModelPlugin (in this case, at least). I'm assuming that the first word changes depending on plugin type?

Correct, the name coming after public there is the name of the class which your plugin is inheriting from. In your case, since you're using GZ_REGISTER_MODEL_PLUGIN, you need to inherit from gazebo::ModelPlugin. There are also other types available, like WorldPlugin and VisualPlugin.

See this tutorial for more info.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-05-17 10:55:10 -0500

Seen: 70 times

Last updated: May 19