Skip to content

Common In All System Plugin

Common In All System Plugin

1) Go to a standalone plugin folder:

cd <path-to>/gazebo-sim-plugins-tutorial/standalone_gz_sim_plugins/<plugin_name>

2) Build:

mkdir build && cd build
cmake ..
make
cd ..

3) Export plugin path (so Gazebo Sim can find it):

export GZ_SIM_SYSTEM_PLUGIN_PATH=$(pwd)/build

4) Launch Gazebo Sim with an SDF:

gazebo sim -v 4 <sdf_file_path>.sdf

Notes:
- "-v 4" prints debug logs (useful while developing)
- If Gazebo can’t find the plugin, re-check GZ_SIM_SYSTEM_PLUGIN_PATH and that build succeeded.


_entity of Configure()

_entity is the entity it attached to world,model,light etc

void PrintEntitySystemPlugin::Configure(const Entity &_entity,
    const std::shared_ptr<const sdf::Element> &_sdf,
    EntityComponentManager &_ecm,
    EventManager &/*_eventMgr*/)

enity_world

<world>

    <plugin>  </<plugin>>

</world>
so here _entity is world entity

model_entity

here it _entity is model entity

Plugin in XML

need register the plugin with all the class it inhertited

// Register the plugin with Gazebo Sim
GZ_ADD_PLUGIN(gz::sim::systems::PrintEntitySystemPlugin,
              gz::sim::System,
              gz::sim::ISystemConfigure,
              gz::sim::ISystemPreUpdate)

alias

GZ_ADD_PLUGIN_ALIAS(gz::sim::systems::PrintEntitySystemPlugin,
                    "gz::sim::systems::PrintEntitySystemPlugin")

Important: only name=gz::sim::systems::PrintEntitySystemPlugin allowed for plugin you can't put any other name because it how we define on the alis GZ_ADD_PLUGIN_ALIAS(...)

so

<!-- custom plugin attach to world-->
<plugin
    filename="PrintEntitySystemPlugin"
    name="gz::sim::systems::PrintEntitySystemPlugin">
</plugin>

filename= PrintEntitySystemPlugin

or

filename= libPrintEntitySystemPlugin.so

so no other name is allowed

comes from CMakeList.txt

add_library(PrintEntitySystemPlugin SHARED PrintEntitySystemPlugin.cc)
set_property(TARGET PrintEntitySystemPlugin PROPERTY CXX_STANDARD 17)
target_link_libraries(PrintEntitySystemPlugin
  PUBLIC gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER}
  PUBLIC gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER})