Skip to content

Commit f96d955

Browse files
committed
added common doc & print entity system plugin doc
1 parent f0024fc commit f96d955

10 files changed

Lines changed: 461 additions & 2 deletions
27.4 KB
Loading
147 KB
Loading
160 KB
Loading

docs/common-code-system-plugin.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ We will take help of components to find entity integer value like:
8383
<summary>b. search the entity by its name</summary>
8484
8585
```c++
86-
std::string name = _ecm.Component<components::Name>(entity)->Data();
86+
// find the entity (int value) which has Name Component with value as "xyz"
87+
targetEntity = _ecm.EntityByComponents(components::Name("xyz"));
8788
```
8889

8990
```c++
@@ -121,12 +122,26 @@ We will take help of components to find entity integer value like:
121122
122123
...``Cmd`` means to command to change that container value like ```LinearVelocityCmd```, ```WorldPoseCmd```, ```VisualCmd```
123124
125+
### Read
126+
<details>
127+
<summary>a. Component</summary>
128+
129+
```c++
130+
//find Name component value of the entity(any entity_type eg model,link,world etc)
131+
auto Name = _ecm.Component<components::Name>(this->targetEntity);
132+
this->modelName = Name->Data();
133+
```
134+
135+
</details>
136+
137+
124138
#### Write
125139
<details>
126140
<summary>a. SetComponentData</summary>
127141

128142
```c++
129143
const gz::math::Vector3d vel(0.0, 0.0, this->zVelocity);
144+
//set the LinearVelocityCmd component value to be vel
130145
_ecm.SetComponentData<components::LinearVelocityCmd>(this->targetEntity,{vel});
131146
```
132147
</details>
@@ -135,6 +150,7 @@ We will take help of components to find entity integer value like:
135150
<summary>b. mutable component</summary>
136151
137152
```c++
153+
//set the LinearVelocityCmd component value to be vel
138154
auto velComp = _ecm.Component<components::LinearVelocityCmd>(this->targetEntity);
139155
velComp->Data() = vel;
140156
```
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
![enity_world](assets/images/entity_world_point.png)
53+
54+
```xml
55+
<world>
56+
57+
<plugin> </<plugin>>
58+
59+
</world>
60+
```
61+
so here ```_entity``` is world entity
62+
63+
64+
![model_entity](assets/images/entity_model_point.png)
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+

docs/image-1.png

13.4 KB
Loading

docs/image-2.png

27.4 KB
Loading

docs/image.png

147 KB
Loading

0 commit comments

Comments
 (0)