|
| 1 | +## Common In All System Plugin |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +1) Go to a standalone plugin folder: |
| 6 | +```bash |
| 7 | +cd <path-to>/gazebo-sim-plugins-tutorial/standalone_gz_sim_plugins/<plugin_name> |
| 8 | +``` |
| 9 | + |
| 10 | +2) Build: |
| 11 | +```bash |
| 12 | +mkdir build && cd build |
| 13 | +cmake .. |
| 14 | +make |
| 15 | +cd .. |
| 16 | +``` |
| 17 | + |
| 18 | +3) Export plugin path (so Gazebo Sim can find it): |
| 19 | +```bash |
| 20 | +export GZ_SIM_SYSTEM_PLUGIN_PATH=$(pwd)/build |
| 21 | +``` |
| 22 | + |
| 23 | +4) Launch Gazebo Sim with an SDF: |
| 24 | +```bash |
| 25 | +gazebo sim -v 4 <sdf_file_path>.sdf |
| 26 | +``` |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +Notes:<br> |
| 31 | +- "-v 4" prints debug logs (useful while developing)<br> |
| 32 | +- If Gazebo can’t find the plugin, re-check GZ_SIM_SYSTEM_PLUGIN_PATH and that build succeeded.<br> |
| 33 | + |
| 34 | +<br> |
| 35 | + |
| 36 | + |
| 37 | +## Code related |
| 38 | + |
| 39 | +### ```_entity``` of Configure() |
| 40 | + |
| 41 | +```_entity``` is the entity it attached to ```world,model,light``` etc |
| 42 | + |
| 43 | + |
| 44 | +```c++ |
| 45 | +void PrintEntitySystemPlugin::Configure(const Entity &_entity, |
| 46 | + const std::shared_ptr<const sdf::Element> &_sdf, |
| 47 | + EntityComponentManager &_ecm, |
| 48 | + EventManager &/*_eventMgr*/) |
| 49 | +``` |
| 50 | +
|
| 51 | +
|
| 52 | + |
| 53 | +
|
| 54 | +```xml |
| 55 | +<world> |
| 56 | +
|
| 57 | + <plugin> </<plugin>> |
| 58 | +
|
| 59 | +</world> |
| 60 | +``` |
| 61 | +so here ```_entity``` is world entity |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +here it ```_entity``` is model entity |
| 67 | + |
| 68 | + |
| 69 | +### Plugin in XML |
| 70 | + |
| 71 | +need register the plugin with all the class it inhertited |
| 72 | +```c++ |
| 73 | +// Register the plugin with Gazebo Sim |
| 74 | +GZ_ADD_PLUGIN(gz::sim::systems::PrintEntitySystemPlugin, |
| 75 | + gz::sim::System, |
| 76 | + gz::sim::ISystemConfigure, |
| 77 | + gz::sim::ISystemPreUpdate) |
| 78 | +``` |
| 79 | +
|
| 80 | +alias |
| 81 | +```c++ |
| 82 | +GZ_ADD_PLUGIN_ALIAS(gz::sim::systems::PrintEntitySystemPlugin, |
| 83 | + "gz::sim::systems::PrintEntitySystemPlugin") |
| 84 | +``` |
| 85 | + |
| 86 | +Important: |
| 87 | +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(...)``` |
| 88 | + |
| 89 | +so |
| 90 | + |
| 91 | +``` |
| 92 | +<!-- custom plugin attach to world--> |
| 93 | +<plugin |
| 94 | + filename="PrintEntitySystemPlugin" |
| 95 | + name="gz::sim::systems::PrintEntitySystemPlugin"> |
| 96 | +</plugin> |
| 97 | +
|
| 98 | +``` |
| 99 | + |
| 100 | +```filename= PrintEntitySystemPlugin``` |
| 101 | + |
| 102 | + or |
| 103 | + |
| 104 | +```filename= libPrintEntitySystemPlugin.so``` |
| 105 | + |
| 106 | +so no other name is allowed |
| 107 | + |
| 108 | +comes from CMakeList.txt |
| 109 | + |
| 110 | +```cmake |
| 111 | +add_library(PrintEntitySystemPlugin SHARED PrintEntitySystemPlugin.cc) |
| 112 | +set_property(TARGET PrintEntitySystemPlugin PROPERTY CXX_STANDARD 17) |
| 113 | +target_link_libraries(PrintEntitySystemPlugin |
| 114 | + PUBLIC gz-plugin${GZ_PLUGIN_VER}::gz-plugin${GZ_PLUGIN_VER} |
| 115 | + PUBLIC gz-sim${GZ_SIM_VER}::gz-sim${GZ_SIM_VER}) |
| 116 | +``` |
| 117 | + |
0 commit comments