Skip to content

Commit d27c3e2

Browse files
Describe magic name attribute for pluginlib XML (ros2#5835)
Signed-off-by: Christoph Fröhlich <[email protected]>
1 parent b81dc71 commit d27c3e2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

source/Tutorials/Beginner-Client-Libraries/Pluginlib.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Create ``~/ros2_ws/src/polygon_plugins/plugins.xml`` with the following code:
222222
<class type="polygon_plugins::Square" base_class_type="polygon_base::RegularPolygon">
223223
<description>This is a square plugin.</description>
224224
</class>
225-
<class type="polygon_plugins::Triangle" base_class_type="polygon_base::RegularPolygon">
225+
<class type="polygon_plugins::Triangle" base_class_type="polygon_base::RegularPolygon" name="awesome_triangle>
226226
<description>This is a triangle plugin.</description>
227227
</class>
228228
</library>
@@ -240,6 +240,7 @@ A couple things to note:
240240
* ``base_class``: The fully qualified base class type for the plugin.
241241
For us, that's ``polygon_base::RegularPolygon``.
242242
* ``description``: A description of the plugin and what it does.
243+
* ``name`` (optional): A lookup name (i.e. magic name) used by the class loader.
243244

244245
2.3 CMake Plugin Declaration
245246
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -279,7 +280,7 @@ Edit ``~/ros2_ws/src/polygon_base/src/area_node.cpp`` to contain the following:
279280

280281
try
281282
{
282-
std::shared_ptr<polygon_base::RegularPolygon> triangle = poly_loader.createSharedInstance("polygon_plugins::Triangle");
283+
std::shared_ptr<polygon_base::RegularPolygon> triangle = poly_loader.createSharedInstance("awesome_triangle");
283284
triangle->initialize(10.0);
284285

285286
std::shared_ptr<polygon_base::RegularPolygon> square = poly_loader.createSharedInstance("polygon_plugins::Square");
@@ -304,7 +305,7 @@ The ``ClassLoader`` is the key class to understand, defined in the ``class_loade
304305

305306
There are a number of ways to instantiate an instance of the class.
306307
In this example, we're using shared pointers.
307-
We just need to call ``createSharedInstance`` with the fully-qualified type of the plugin class, in this case, ``polygon_plugins::Square``.
308+
We just need to call ``createSharedInstance`` with a reference to the plugin: This can be either the fully-qualified type of the plugin class (the ``type`` attribute of the declaration XML file, e.g. ``polygon_plugins::Square``), or the optional magic name (the ``name`` attribute of the declaration XML file, e.g., ``awesome_triangle``).
308309

309310
Important note: the ``polygon_base`` package in which this node is defined does NOT depend on the ``polygon_plugins`` class.
310311
The plugins will be loaded dynamically without any dependency needing to be declared.

0 commit comments

Comments
 (0)