This tutorial shows how to create an executable that loads physics engine plugins on Ubuntu, according to the desired feature list.
Overview
Physics Plugin integrates external physics engines into the Ignition Physics. It allows users to select from multiple supported physics engines based on their simulation needs. This tutorial will describe how to load a compiled physics plugin using Ignition Physics API.
Prerequisites
Write a simple loader
-We will use a simplified physics plugin example for this tutorial. Source code can be found at ign-physics/examples folder.
First, create a workspace for the example plugin loader.
Then download the example loader into your current directory by:
Examine the code
At the top of the file hello_world_loader.cc
, we include the headers that will be used in our code. After the std
C++ libraries are the Loader.hh
and PluginPtr.hh
, which provides main functionalities for loading physics plugins and plugin pointers. Next includes from ignition::physics are the tools for retrieving Feature and Entity from physics plugins (please refer to Understanding the physics plugin tutorial for their design concepts).
Next, in the main function, the loader requires users to provide a path for desired plugins to be loaded. The plugin names are retrieved by ignition::plugin::Loader::LoadLib member function.
Assuming the correct path, our loader will instantiate all plugins that are available in the path using ignition::plugin::Loader::Instantiate member function. Then for each instantiated plugin, using ignition::physics::RequestEngine3d<Features>::From, it will request an engine implementing a FeaturePolicy (3D in this case).
Setup CMakeLists.txt for CMake build
Now create a file named CMakeLists.txt
with your favorite editor and add these lines for finding ign-plugin
and ign-physics
dependencies in Citadel release. After that, add the executable pointing to our file and add linking library so that cmake
can compile it.
If you find CMake syntax difficult to understand, take a look at the official tutorial here.
Build and run
Compile the loader
Your current loader folder should look like this
Now you can build the loader by:
This will generate the hello_world_loader
executable under build
folder. This loader will load any plugin that implements the GetEngineInfo
feature, and print the engine name.
Load existing plugins
For example, if you have the Ignition Physics plugin for DART compiled, find where it is installed with (you may need administrative rights: sudo
on Linux platform):
You may find more than one file. Choose one of them, and load it with the loader by:
And you'll see the engine info:
At the time of writing, Ignition Physics is shipped with DART and TPE physics plugins installed. Following the above steps, you can load TPE
by the library name libignition-physics-tpe-plugin.so
or other custom plugins by their corresponding names.