In this tutorial, we are going to implement a new path planning algorithm within a plugin.
planning algorithm in a plugin
The code of this tutorial can be found in src/tutorial_2.cc. The compilation and installation instructions can be found in src/CMakeLists.txt.
Planner
File src/tutorial_2.cc implements class hpp::tutorial::Planner, deriving from abstract class hpp::core::PathPlanner. In this section, we explain some specific parts of the code.
is a macro containing the forward declaration of class Planner as well as PlannerWkPtr_t for weak pointer to class Planner. See hpp/util/pointer.hh for details.
As most classes, hpp::core::PathPlanner and any derived class are manipulated via shared pointers. Users are not allowed to define variables of the type. Instead, they are required to call method create and to store the resulting shared pointer. For this reason, the constructors are all protected.
create calls protected method init that is explained later on.This method runs one step of our the algorithm. The new algorithm is a basic version of PRM. Notice the compactness of the code.
Method init takes as input a weak pointer to a new instance and stores this weak pointer as a private member. This enables any object to create a shared pointer to itself on demand using the following line of code
which is the shared pointer equivalent to this when using simple pointers.
init always calls the parent implementation so that the parent part of the object also stores a weak pointer to itself.tutorial-2.so
Now that the new class hpp::tutorial::Planner has been implemented, we are going to add it via a plugin.
class hpp::tutorial::Plugin derives from abstract class hpp::core::ProblemSolverPlugin. Upon loading of the plugin by hppcorbaserver, method impl_initialize is called. This method register our new path planning class with key "TutorialPRM"
This macro register the new plugin.
The compilation and installation is done in file src/CMakeLists.txt by the following lines
These two lines declare a new plugin the source file of which is tutorial-2.cc and install this plugin into lib/hppPlugins subdirectory of the installation prefix.
problem.
To solve a problem with the new path planning algorithm, we simply need to follow the same steps as in tutorial 1, except that we should source script/tutorial_2.py instead of script/tutorial_1.py
The above lines load the plugin and select the new path planner.