Building Gazebo Harmonic Plugin

Dear reader,

I want to migrate an existing plugin for a vacuum gripper from Gazebo-classic to Gazebo Harmonic. I have created a CMakeLists.txt for this:

cmake_minimum_required(VERSION 3.8)
project(ros_industrial_actuators)

cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)

#============================================================================
# Find gz-cmake
#============================================================================
find_package(gz-cmake3 REQUIRED)

#--------------------------------------
# Find gz-common
#--------------------------------------
gz_find_package(gz-common5
                 COMPONENTS profiler
                 REQUIRED)
set(GZ_COMMON_VER ${gz-common5_VERSION_MAJOR})

#--------------------------------------
# Find gz-plugin
#--------------------------------------
gz_find_package(gz-plugin2 REQUIRED COMPONENTS register)
set(GZ_PLUGIN_VER ${gz-plugin2_VERSION_MAJOR})

#--------------------------------------
# Find gz-msgs
#--------------------------------------
gz_find_package(gz-msgs10 REQUIRED)
set(GZ_MSGS_VER ${gz-msgs10_VERSION_MAJOR})


#--------------------------------------
# Find gz-sim
#--------------------------------------
gz_find_package(gz-sim8 REQUIRED)
set(GZ_SIM_VER ${gz-sim8_VERSION_MAJOR})

#============================================================================
# Configure the project
#============================================================================
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#gz_configure_project(VERSION_SUFFIX)


#============================================================================
# Set project-specific options
#============================================================================
set (DRI_TESTS TRUE CACHE BOOL "True to enable DRI tests")

option(ENABLE_PROFILER "Enable Gazebo Profiler" FALSE)

if(ENABLE_PROFILER)
  add_definitions("-DGZ_PROFILER_ENABLE=1")
else()
  add_definitions("-DGZ_PROFILER_ENABLE=0")
endif()


add_library(VacuumGripper vacuum_gripper/VacuumGripper.cc)
set_property(TARGET VacuumGripper PROPERTY CXX_STANDARD 17)


target_link_libraries(VacuumGripper
  PRIVATE
    gz-common${GZ_COMMON_VER}::gz-common${GZ_COMMON_VER}
    gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER}
    gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER}
)

install(TARGETS
  VacuumGripper
  DESTINATION lib/${PROJECT_NAME}
)
install(TARGETS
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

# Install models
install(DIRECTORY models
  DESTINATION share/${PROJECT_NAME}/
)

# Install launch
install(DIRECTORY launch
  DESTINATION share/${PROJECT_NAME}/
)

# Python package installation
ament_python_install_package(${PROJECT_NAME})

# Python installation
install(PROGRAMS
  ros_industrial_actuators/vacuum_gripper.py
  launch
  DESTINATION lib/${PROJECT_NAME}
)

# Install package.xml
install(FILES package.xml
  DESTINATION share/${PROJECT_NAME}
)

ament_package()

The CMakeLists.txt is compiled correctly.

I have also created a model.sdf file:

<?xml version="1.0"?>
<sdf version="1.6">
  <model name="vacuum_gripper">
    <static>true</static>

    <plugin
      filename="VacuumGripper"
      name="vacuum_gripper::VacuumGripper">
    </plugin>
  </model>
</sdf>

When loading the vacuum_gripper.sdf the following error message is given:

[gazebo-5] [Err] [SystemLoader.cc:92] Failed to load system plugin [VacuumGripper] : Could not find shared library.

Unfortunately I am unable to fill in the CMakeLists.txt correctly.

I used Gazebo Sim: Create System Plugins as a reference for this plugin.

Who can help me with this? Thanks in advance for your answer.
Gerard

Apparently, the tutorial is missing a key piece: the GZ_SIM_SYSTEM_PLUGIN_PATH variable, where you have to add your lib folder. I’ll create an issue for that.

Issue created: Tutorial for custom plugins is missing reference to GZ_SIM_SYSTEM_PLUGIN_PATH · Issue #2850 · gazebosim/gz-sim · GitHub . If you’d like, you can try to put together a pull request adding that information. It’s not that difficult! :slight_smile:

Thanks Martin,
Could you be a bit more specific. I am not an expert in creating CMakelists.txt files. Do you mean:

set(GZ_SIM_SYSTEM_PLUGIN_PATH DESTINATION lib/${PROJECT_NAME})

Unfortunately this does not work.

Thanks in advance,
Kind regards,
Gerard

No, this is not a cmakelists thing. It is an environment variable you have to set in the terminal where you launch Gazebo.

Thanks! This works.

Kind regards Gerard

Can you tell me in detail how you implement this in harmonic?

Thank you in advance